fix(agent-manager): reload the snapshot only for expired review failures

Content rejections such as an empty body or a bad line range leave the snapshot valid, so gate the reload on the host's reload hints instead of every failed comment. Extend the regression test to cover the non-expiry cases.
This commit is contained in:
marius-kilocode
2026-09-15 18:45:31 +02:00
parent 3a98691ca1
commit 82b65bd4d0
2 changed files with 10 additions and 3 deletions
@@ -80,10 +80,12 @@ describe("PR diff comment state", () => {
state.dispose()
})
it("keeps the cached snapshot when a comment succeeds or belongs elsewhere", () => {
it("keeps the cached snapshot when a comment succeeds, fails on content, or belongs elsewhere", () => {
const { posted, receive, state, comment } = setup()
receive(comment({ success: true, error: undefined }) as ExtensionMessage)
receive(comment({ error: "A review comment body is required." }) as ExtensionMessage)
receive(comment({ error: "Selected lines are not in a complete review hunk." }) as ExtensionMessage)
receive(comment({ worktreeId: "other" }) as ExtensionMessage)
receive(comment({ projectId: "other" }) as ExtensionMessage)
@@ -84,10 +84,15 @@ export function createPRDiffCommentState(opts: Options) {
}
// The host caps its snapshot store, so a comment can fail against a snapshot
// it has already dropped. Drop the cached snapshot and reload, so the next
// attempt is bound to a snapshot the host still holds.
// it has already dropped. Those failures, and the context/ref changes that
// invalidate a snapshot, end with the host's reload hints; content errors
// (empty body, bad line range, unconfirmed write) must not force a reload.
// Keep in sync with the throw messages in review-actions.ts and
// pr-status-bridge.ts.
const expired = /(?:Reload the review|Refresh and try again|Reopen the PR review)/
const release = opts.onMessage((message) => {
if (message.type !== "agentManager.createReviewCommentResult" || message.success) return
if (!expired.test(message.error ?? "")) return
const ctx = typeof message.worktreeId === "string" ? message.worktreeId : undefined
const route = target(ctx)
if (!route || route.projectId !== message.projectId) return