Repository navigation
feat(pr-review): refuse the first submit_review while reviewed files are unread #1014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** | ||
| * What a review pass has read. Fed the real renderers' answers, since the tracker reads them back. | ||
| */ | ||
| import type { PullRequestFile } from "@maple/domain/http" | ||
| import { renderFollowUp } from "@maple/backend/services/pr-review/findings" | ||
| import { assert, describe, it } from "vitest" | ||
| import { renderChangedFiles, renderFileDiffs } from "../mcp/tools/pull-request" | ||
| import { makeReviewCoverage, unreadRefusal } from "./review-coverage" | ||
|
|
||
| const file = (path: string): PullRequestFile => ({ | ||
| path, | ||
| previousPath: null, | ||
| status: "modified", | ||
| additions: 1, | ||
| deletions: 0, | ||
| patch: "@@ -1 +1 @@\n+x", | ||
| }) | ||
|
|
||
| const FILES = [file("src/a.ts"), file("src/b.ts"), file("src/a.test.ts"), file("docs/a.md")] | ||
| const listing = renderChangedFiles("octo/shop", 7, FILES).content[0]!.text | ||
| const diffs = (...paths: Array<string>) => renderFileDiffs(FILES, paths).content[0]!.text | ||
|
|
||
| describe("makeReviewCoverage", () => { | ||
| it("owes nothing before the file list is read", () => { | ||
| assert.deepEqual(makeReviewCoverage("Review pull request #7.").unread(), []) | ||
| }) | ||
|
|
||
| it("owes every reviewed file until a diff answer shows it", () => { | ||
| const coverage = makeReviewCoverage("Review pull request #7.") | ||
| coverage.observe("pr_changed_files", listing) | ||
| assert.deepEqual(coverage.unread(), ["src/a.ts", "src/b.ts", "src/a.test.ts"]) | ||
| coverage.observe("pr_file_diff", diffs("src/a.ts", "src/a.test.ts")) | ||
| assert.deepEqual(coverage.unread(), ["src/b.ts"]) | ||
| coverage.observe("pr_file_diff", diffs("src/b.ts")) | ||
| assert.deepEqual(coverage.unread(), []) | ||
| }) | ||
|
|
||
| it("counts only pr_file_diff answers as reads", () => { | ||
| const coverage = makeReviewCoverage("Review pull request #7.") | ||
| coverage.observe("pr_changed_files", listing) | ||
| coverage.observe("sandbox_read_file", diffs("src/a.ts", "src/b.ts", "src/a.test.ts")) | ||
| assert.lengthOf(coverage.unread(), 3) | ||
| }) | ||
|
|
||
| it("owes a later push only the files its kickoff says changed", () => { | ||
| const followUp = renderFollowUp({ previousSha: "abcdef1234", changedPaths: ["src/b.ts"], open: [] }) | ||
| const coverage = makeReviewCoverage(["Review pull request #7.", ...followUp].join("\n")) | ||
| coverage.observe("pr_changed_files", listing) | ||
| assert.deepEqual(coverage.unread(), ["src/b.ts"]) | ||
|
|
||
| const nothing = makeReviewCoverage( | ||
| renderFollowUp({ previousSha: "abcdef1234", changedPaths: [], open: [] }).join("\n"), | ||
| ) | ||
| nothing.observe("pr_changed_files", listing) | ||
| assert.deepEqual(nothing.unread(), []) | ||
| }) | ||
| }) | ||
|
|
||
| describe("unreadRefusal", () => { | ||
| it("names the files and says a second call goes through", () => { | ||
| const message = unreadRefusal(["src/b.ts"]) | ||
| assert.include(message, "1 reviewed file: src/b.ts.") | ||
| assert.include(message, "call submit_review again now") | ||
| }) | ||
|
|
||
| it("bounds a long list", () => { | ||
| const message = unreadRefusal(Array.from({ length: 45 }, (_, i) => `src/f${i}.ts`)) | ||
| assert.include(message, "src/f29.ts, and 15 more.") | ||
| assert.notInclude(message, "src/f30.ts") | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /** | ||
| * Which of a pull request's reviewed files a review pass has actually read. | ||
| * | ||
| * The prompt says to read every hunk; this is what checks it. One tracker per run, fed every Maple | ||
| * tool answer the run dispatches, including the ones its `review_files` children dispatch through | ||
| * the same handlers. `submit_review` consults it once before recording. | ||
| */ | ||
| import { followUpScope } from "@maple/backend/services/pr-review/findings" | ||
| import { pathsInDiffAnswer, reviewablePathsInListing } from "../mcp/tools/pull-request" | ||
|
|
||
| export interface ReviewCoverage { | ||
| /** One successful tool answer, by tool name. */ | ||
| readonly observe: (tool: string, answer: string) => void | ||
| /** Reviewed files with a patch whose diff no `pr_file_diff` answer has shown yet, in listing order. */ | ||
| readonly unread: () => ReadonlyArray<string> | ||
| } | ||
|
|
||
| /** `kickoff` is the pass's first message: a later push's kickoff narrows which files are due. */ | ||
| export const makeReviewCoverage = (kickoff: string): ReviewCoverage => { | ||
| const scope = followUpScope(kickoff) | ||
| const inScope = scope === undefined ? () => true : (path: string) => scope.includes(path) | ||
| const due = new Set<string>() | ||
| const read = new Set<string>() | ||
| return { | ||
| observe: (tool, answer) => { | ||
| if (tool === "pr_changed_files") { | ||
| for (const path of reviewablePathsInListing(answer)) if (inScope(path)) due.add(path) | ||
| } else if (tool === "pr_file_diff") { | ||
| for (const path of pathsInDiffAnswer(answer)) read.add(path) | ||
| } | ||
| }, | ||
| unread: () => [...due].filter((path) => !read.has(path)), | ||
| } | ||
| } | ||
|
|
||
| const LISTED_UNREAD = 30 | ||
|
|
||
| /** The one-time refusal `submit_review` answers with while files are unread. */ | ||
| export const unreadRefusal = (unread: ReadonlyArray<string>): string => | ||
| [ | ||
| `You have not read the diff of ${unread.length} reviewed ${unread.length === 1 ? "file" : "files"}: ` + | ||
| `${unread.slice(0, LISTED_UNREAD).join(", ")}${unread.length > LISTED_UNREAD ? `, and ${unread.length - LISTED_UNREAD} more` : ""}.`, | ||
| "Read them with pr_file_diff (several per call) or review_files, then call submit_review again. " + | ||
| "If you left them unread on purpose, call submit_review again now and it will be recorded; say in the summary what was not read.", | ||
| ].join(" ") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: MapleTechLabs/maple
Length of output: 6288
🏁 Script executed:
Repository: MapleTechLabs/maple
Length of output: 41797
🏁 Script executed:
Repository: MapleTechLabs/maple
Length of output: 42512
Return unread-file failures to the model.
When the first
submit_reviewcall includes unread files,reviewTooluses default failure handling. TheMapleToolFailurecan end that completion pass before the model receivesunreadRefusal. The autonomous runner then performs a close-out that can record only a partial review. SetfailureMode: "return"so the model receives the refusal and can read the remaining files before submitting again.Suggested fix
success: Schema.String, failure: MapleToolFailure, + failureMode: "return", })🤖 Prompt for AI Agents