mach10 icon indicating copy to clipboard operation
mach10 copied to clipboard

Review cycle loses track of latest review when PR comments grow long

Open LeanAndMean opened this issue 8 months ago • 3 comments

Summary

When running /mach10:pr-review followed by /mach10:pr-review-fix in an iterative review cycle, Claude may fail to locate the most recent review comment. This happens because gh pr view <pr-number> --comments returns the full comment history, which grows with each review-fix iteration. Claude's context window fills with older comments and it stops reading before reaching the latest review at the bottom. The problem compounds: the more review cycles you run, the more likely the fix command targets stale findings.

Current Behavior

  1. /mach10:pr-review posts two comments (review + independent assessment) but does not report their comment IDs to the user or in the "next steps" output.
  2. /mach10:pr-review-fix uses gh pr view <pr-number> --comments to fetch all comments, then heuristically searches for "the most recent review comment" by looking for the structured review format (Critical/Important/Suggestions + model attribution).
  3. After 2-3 review cycles, the comment history becomes long enough that Claude truncates it or anchors on an earlier review, fixing already-addressed findings or missing new ones.
  4. The same fragility exists in /mach10:pr-review-fix Step 4, which tells feature-dev to "locate the most recent review comment" from all comments -- a second opportunity to pick the wrong one.

Proposed Behavior

The review and fix commands should use explicit comment identification so the fix command always targets the correct review, regardless of how many review cycles have occurred.

Exploration of Approaches

This issue requires a deep dive into the review cycle workflow and evaluation of multiple options. The implementation plan should explore and compare at least the following approaches:

Approach A -- Comment ID passthrough

  • /mach10:pr-review retrieves the comment IDs (from gh pr view --json comments) for both the review comment and the assessment comment after posting them in Steps 4 and 6.
  • At the end (Step 9), output these IDs alongside the next-step suggestion: /mach10:pr-review-fix <pr-number> --review-comment <id> --assessment-comment <id> <issue-numbers>.
  • /mach10:pr-review-fix accepts optional comment IDs in its argument parsing (Step 1) and, when present, fetches only those specific comments via gh api repos/{owner}/{repo}/issues/comments/{id} instead of reading the full comment history.
  • Fallback: when IDs are not provided (e.g., user invokes pr-review-fix manually), fall back to the current heuristic with improved instructions (see Approach C).

Approach B -- Reverse-chronological comment fetching

  • Instead of gh pr view --comments, use gh api with ?sort=created&direction=desc&per_page=5 to fetch only the most recent comments.
  • Parse the first review-format comment found (it will be the latest one).
  • Pros: No argument changes needed. Cons: Fragile if non-review comments are posted between cycles; still heuristic-based.

Approach C -- Improved heuristic instructions (minimal change)

  • Add explicit instructions to pr-review-fix Step 2: "Fetch comments using gh pr view <pr-number> --json comments, parse the JSON array, and select the LAST comment whose body contains the review format markers. Do NOT stop reading before the end of the comment list."
  • Add a unique marker string to review comments (e.g., <!-- mach10-review-v1 -->) that can be searched for programmatically.
  • Pros: Smallest change. Cons: Still relies on Claude correctly processing long output.

Approach D -- Hybrid (recommended for evaluation)

  • Implement Approach A (comment ID passthrough) as the primary mechanism.
  • Implement Approach C (improved heuristics + markers) as the fallback for manual invocations.
  • This gives deterministic behavior in the normal workflow while remaining usable when IDs are unavailable.

Acceptance Criteria

  • /mach10:pr-review outputs the comment IDs for both the review and assessment comments as part of its final CLI output (Step 7 or 9)
  • /mach10:pr-review "next steps" suggestion includes the comment IDs in the recommended /mach10:pr-review-fix invocation
  • /mach10:pr-review-fix accepts optional comment ID arguments and uses them to fetch specific comments when provided
  • /mach10:pr-review-fix falls back gracefully when comment IDs are not provided, with improved instructions for identifying the latest review
  • The approach chosen is documented in the issue comments before implementation begins

Technical Notes

  • Affected files: commands/pr-review.md, commands/pr-review-fix.md
  • Possibly affected: commands/pr-review-validate.md (same pattern of "find the latest review")
  • GitHub API for fetching a single comment: gh api repos/{owner}/{repo}/issues/comments/{id}
  • Comment IDs are available in the JSON output of gh pr view --json comments (each comment has an id field)
  • The argument-hint frontmatter in pr-review-fix.md would need updating to reflect the new optional parameters

LeanAndMean avatar Mar 06 '26 16:03 LeanAndMean

Implementation Plan

Approach: Hybrid (Approach D from the issue)

  • Primary mechanism: pr-review captures comment IDs after posting and includes them in next-step suggestions. Consumer commands (pr-review-fix, pr-review-validate) accept optional IDs and fetch specific comments via gh api.
  • Fallback: When IDs are not provided (manual invocation), consumer commands use an improved heuristic: fetch comments as JSON, parse the array, find the LAST comment containing an HTML marker (<!-- mach10-review -->).

Stage 1: Update pr-review.md -- comment ID tracking and markers

Goal: Make pr-review the reliable "producer" of comment IDs.

Changes to commands/pr-review.md:

  • Step 4 (Post Review): Add <!-- mach10-review --> HTML marker to the review comment body. After posting, retrieve the comment ID (not just URL) from gh pr view --json comments.
  • Step 6 (Post Assessment): Add <!-- mach10-assessment --> HTML marker to the assessment comment body. After posting, retrieve its comment ID.
  • Step 9 (Recommend Next Steps): Update the suggested command format to include comment IDs:
    • From: /mach10:pr-review-fix <pr-number> <issue-numbers>
    • To: /mach10:pr-review-fix <pr-number> --review-comment <id> --assessment-comment <id> <issue-numbers>

Files: commands/pr-review.md


Stage 2: Update consumer commands and bump version

Goal: Make pr-review-fix and pr-review-validate accept comment IDs with graceful fallback.

Changes to commands/pr-review-fix.md:

  • Frontmatter: Update argument-hint to <pr-number> [--review-comment <id>] [--assessment-comment <id>] [issue-numbers] [context]
  • Step 1 (Parse Input): Add parsing for optional --review-comment and --assessment-comment flags.
  • Step 2 (Gather Context): When comment IDs are provided, fetch specific comments via gh api repos/{owner}/{repo}/issues/comments/{id}. When not provided, fall back to improved heuristic: use gh pr view --json comments, parse the JSON array, and find the LAST comment containing <!-- mach10-review -->. If no marker found, fall back to the current format-based heuristic (structured review format with Critical/Important/Suggestions sections and model attribution).
  • Step 4 (Delegate to Feature Dev): Pass the review content directly to feature-dev in the Skill invocation instead of instructing it to "locate the most recent review comment."

Changes to commands/pr-review-validate.md:

  • Frontmatter: Update argument-hint to <pr-number> [--review-comment <id>]
  • Step 1 (Parse Input): Add parsing for optional --review-comment flag.
  • Step 2 (Read Everything): Same dual-path as pr-review-fix: specific fetch when ID provided, improved heuristic when not. Capture the review comment ID for use in Step 6.
  • Step 6 (Recommend Next Steps): When recommending pr-review-fix, include the review comment ID if available.

Changes to .claude-plugin/plugin.json:

  • Bump version from 0.2.2 to 0.3.0 (new feature: comment ID passthrough)

Files: commands/pr-review-fix.md, commands/pr-review-validate.md, .claude-plugin/plugin.json


This plan will guide staged implementation via /mach10:issue-implement.

LeanAndMean avatar Mar 06 '26 20:03 LeanAndMean

Progress: Stage 1 complete

Commit: b7cada0 — Add comment ID tracking and HTML markers to pr-review command

Changes to commands/pr-review.md

Step 4 (Post Review):

  • Added <!-- mach10-review --> HTML marker as the first line of review comment bodies
  • Changed comment retrieval to extract the numeric comment ID from the URL (issuecomment- fragment) instead of using the GraphQL node ID from --json comments .id
  • Carries both the URL (for Step 6 cross-linking) and numeric ID (for Step 9) forward

Step 6 (Post Assessment):

  • Added <!-- mach10-assessment --> HTML marker as the first line of assessment comment bodies
  • Added matching URL retrieval and numeric ID extraction
  • Fixed grammar: "The comment must:" to "The comment must include:" for consistency with Step 4

Step 9 (Recommend Next Steps):

  • Displays both comment IDs for user reference
  • Updated the suggested pr-review-fix invocation to include --review-comment <id> and --assessment-comment <id> flags

Design decisions

  • Numeric IDs via URL extraction rather than GraphQL node IDs. The REST API endpoint gh api repos/{owner}/{repo}/issues/comments/{id} (which stage 2 will use) requires numeric database IDs.
  • HTML markers at the top of comment bodies for maximum visibility to parsers and zero impact on rendered output.
  • Consistent retrieval pattern between Steps 4 and 6 using gh pr view --json comments --jq '.comments[-1].url'.

Next

Stage 2: Update consumer commands (pr-review-fix.md, pr-review-validate.md) to accept and use comment IDs, with fallback heuristics using the HTML markers. Bump version to 0.3.0.

LeanAndMean avatar Mar 06 '26 21:03 LeanAndMean

Progress: Stage 2 complete

Commit: d7398cf — Add comment ID acceptance and fallback heuristics to consumer commands

Changes to commands/pr-review-fix.md

Frontmatter: Updated argument-hint to include [--review-comment <id>] [--assessment-comment <id>] flags.

Step 1 (Parse Input): Added parsing for optional --review-comment and --assessment-comment flags, each followed by a numeric ID. Updated example inputs to show the new flag syntax.

Step 2 (Gather Context): Replaced the single-path "fetch all comments" approach with dual-path logic:

  • Primary (ID provided): Fetches specific comment via gh api repos/{owner}/{repo}/issues/comments/<id>
  • Fallback (no ID): Fetches --json comments, parses the array from the END, looks for <!-- mach10-review --> marker, then falls back to format-based heuristic
  • Assessment comment: fetched only when --assessment-comment ID is explicitly provided; no heuristic fallback (too risky to guess)

Step 4 (Delegate to Feature Dev): Replaced the fragile "locate the most recent review comment" instruction with inline content passing — the review comment body is now embedded directly in the Skill invocation prompt, eliminating the second opportunity for the model to pick the wrong comment.

Changes to commands/pr-review-validate.md

Frontmatter: Updated argument-hint to include [--review-comment <id>] flag.

Step 1 (Parse Input): Added parsing for optional --review-comment flag with examples.

Step 2 (Read Everything): Same dual-path approach as pr-review-fix. In the fallback path, extracts the numeric comment ID from the url field for use in Step 6 recommendations.

Step 6 (Recommend Next Steps): Updated to include --review-comment <id> in the suggested pr-review-fix invocation when a review comment ID is known (either from the flag or extracted during fallback).

Changes to .claude-plugin/plugin.json

Bumped version from 0.2.2 to 0.3.0 (new feature: comment ID passthrough).

Design decisions

  • No heuristic fallback for assessment comments — only the review comment gets a marker-based fallback; assessment is optional enrichment that should be explicitly targeted.
  • Inline content passing in Step 4 rather than telling feature-dev to re-fetch comments. This completely eliminates the fragile second lookup identified in the issue.
  • Asymmetric flag support between the two commands: pr-review-fix accepts both --review-comment and --assessment-comment; pr-review-validate accepts only --review-comment (it does not consume the assessment).

Summary

Both stages are now complete. The full review cycle now supports deterministic comment identification:

  1. pr-review produces comment IDs and HTML markers (stage 1)
  2. pr-review-fix and pr-review-validate consume those IDs with graceful fallback (stage 2)

LeanAndMean avatar Mar 09 '26 15:03 LeanAndMean