Skip to content

fix(inbox): keep a PR review's unsent comments and Viewed until a new commit - #2640

Merged
backnotprop merged 32 commits into
mainfrom
fix/pr-review-keep-on-same-head
Nov 5, 2026
Merged

backnotprop merged 32 commits into
mainfrom
fix/pr-review-keep-on-same-head

Conversation

@backnotprop

@backnotprop backnotprop commented Nov 5, 2026 •

Copy link
Copy Markdown
Owner

Fixes a data loss in the Inbox's PR page. Unsent line comments and Viewed ticks were kept per updated_at, which moves with a label, a teammate's comment or a review. Any of those deleted them. Same head on the old code, in the DOM test: Comments, 2 became Comments, 1 and viewed: ['src/retry.ts'] became []. It also read the diff again and took the reader down, losing the scroll and a comment being typed.

The fix

  • Kept work is keyed on the head of the patch read, in both scopes, else the list's, else the name already in use (the PR's last update if no head was ever named). A patch naming no head keeps the name it came up under while the list moves, so a comment written on its lines can't be saved under the new head. Other code naming no head takes the list's name again, and the old words wait under theirs.
  • A stack read now names its head, read around its compare as a layer's is. Whole stack posts at that head, so the list catching up no longer offers a second Approve (readHeads now takes both scopes).
  • Reviews post at the head the plan was built on. A dialog left open over a new commit, or a retry after one, used to send the old lines at the new head. Now the server refuses it (pull_moved, its existing sentence), what was typed stays, and reopening builds a plan of the new head, even after a partial or blocked attempt. I chose this over closing the dialog: nothing typed is lost, and nothing is posted at a head the person never read.
  • What is on screen stays until a read names a newer patch. A read that fails or names no head changes nothing, shows no new words, and goes again on the next list read (not when too large or a fork). A list that catches up reads nothing. A list that lands behind the patch or flips back re-reads and deletes nothing.
  • The reader is keyed on the code. New code brings a new reader, so a composer can't save onto a moved line; the same code keeps it, whatever the head reads said.
  • Words stay in view. Until a patch is read here, global comments from other heads and everything in a nameless entry are shown, with nothing stored changed. This also covers a too-large diff and failing head reads. Writing takes what is shown out of the other entries, so nothing comes back after a delete.
  • Stored entries are only cleaned by a patch read here, never by a diff remembered in SEEN. SEEN only draws a diff of the newest head this window read, as the server's cache does, so a list gone back reads the forge first instead of hiding work on the newer head.
  • The server keys its diff cache on head (a label costs no read), and only serves an answer naming the head last read, so a list gone back reads the forge and a null head is asked again.
  • The diff (seenId) is keyed on head and base; updated_at only stands in while the list names no head.

Visible changes: on a real push the old patch stays until the new one lands, instead of "Reading the diff…". The "Review posted" banner stays until the head moves or you leave the page. With a folded panel, the Comments button now shows on a read-only review when there are words to read.

Second Approve. It did go out: on the list-head rule, which main has too, Whole stack posted at A, the list reached B, Approve came back, and a second review went at B (run in the DOM test; the server's duplicate check includes the head). So this predates the PR. Fixed here.

Migration and outdated. Nameless entries move whole once a patch is read here. A comment written since this PR has a stamp, which decides. An older Inbox's comment has none, so it gets outdated when updated_at has changed since the entry's key, or when a head is named that the list doesn't name, a list naming none included. That leaves these false labels, which codeAnnotationAnchor.ts treats as the safe direction:

  • An old entry on a PR whose updated_at moved but whose head didn't: nothing stored can tell.
  • An edited comment stays outdated, since its line number is no more trustworthy after an edit.

No missing label is known now. The earlier note here, about a null head and a write, is closed: an old entry on a changed PR is labelled as soon as it's seen, with or without a head. That changes one behaviour a test held before: with no head known, it used to carry no label until one was named.

codeAnnotationAnchor.ts moved from packages/review-editor/utils to packages/ui/utils, unchanged but for its two type imports, because the Inbox's first load may not name @plannotator/review-editor (tests/entry-assets.test.ts). The module has only type imports, so no viewer code came with it.

Saved comments survive a push (the owner's decision), as GitHub's pending comments do. On screen and in storage; only Viewed ticks drop.

  • Where it shows. Each line comment keeps what it was read on: readHead, readBase, a stamp of the patch, and the anchor text and context from codeAnnotationAnchor.ts. It's drawn on the diff only on the same patch, or the same code at the same side and lines. Otherwise it's only in the Comments panel, labelled "Written on older code" (an optional codeAnnotationNote prop on AnnotationPanel: the one packages/ui change, since the panel lives there; no caller but this one passes it).
  • Post on GitHub sends it against the commit it was read on, in that commit's lines. A review names one commit, so each older commit gets its own comment review, its body the shared See inline comments., as GitHub's docs and pr-github.ts require one. The verdict and typed words go at the head on screen; a verdict always goes, with that same body if it has no words of its own. The dialog's row starts with the commit, so a long repository name can't hide it: "Simplify extensions to thin wrappers: server-owned prompts, vendor trim, dumb-pipe CLI #801 — read at 1111111". What went leaves every stored entry of the review, so a push landing during a post can't bring it back to go twice. A comment counts as gone only if a target the forge accepted carried it, and when GitHub refuses an older commit the plan is rebuilt from what it held, not from what came in under the dialog: another window's comments, or a new head's view of the ones planned, wait for the next plan. already_posted at an older commit counts as went. A comment on lines outside the diff (Expand arrows on the Inbox's PR page and guided reviews #2635's outsideDiff) never goes at an older commit: it stays in the main comment at the head.
  • The fallback is the labelled [Outdated note in the body, or inline at the head if the code still reads the same. It applies when the commit has gone (pull_commit_gone, from pulls/N/commits, or GitHub refusing that commit or its lines (part of the diff, part of the same hunk, Path could not be resolved) or answering 422 with no reason; at a head the list still names, only when pulls/N/commits no longer has it. Any other refusal, such as your own PR, a pending review or too quickly, stays pull_review_failed, and a full list of 250, GitHub's most, not naming the commit says nothing), and when the lines can't be vouched for: same head on another patch (a retarget, unless the same code is still at those lines), read with no head named, or another base. Words are never lost and nothing goes on a moved line, by the model in the tests.
  • The refusal is gone on GitHub. A dialog left open over a push posts at the commit read. Approve there approves that commit: the banner says "Approved on GitHub" and the new head still offers Approve, as it hasn't been approved. A force-push under the dialog is the one refusal left: what was typed stays, and Retry shows the new plan without sending.
  • GitLab uses the note route. Its docs describe position[head_sha] as "SHA referencing HEAD of this merge request", and say nothing about placing a thread on an older version or what happens otherwise, so I couldn't verify it. Same code goes inline at the head, other code goes in the body, labelled. The pull_moved refusal stays on GitLab, with the T8/T9 fixes: Retry shows the new plan, and typed words never become an Approve.

A comment is forgotten only in the words the forge took. What went is noted with its words (postedSignature, moved to postRules.ts, now also the label and decorations), so a comment edited since stays, on screen and in storage, and goes next.

  • Which answers prove it: a target the forge accepted whole, or a partly posted review's comments it does not ask for again (its retry), when postedFileCommentCount agrees; if the count disagrees, nothing counts as gone, so they are sent again rather than lost. already_posted, whose fingerprint holds the same head, action, body and comments, also counts, now at the head too.
  • The dialog posts the comments as they stand. Reopening rebuilds the plan from storage. Send takes in an edit or a deletion that landed under it; another window's new comment still waits for the next plan, which shows it first. All of them deleted: nothing goes and the dialog says so.
  • A partly posted review keeps its narrowed retry, in the current words. What the forge took leaves the panel at once, not at the end, and is not sent again, so a reload no longer posts it twice. A comment that rides the body, new since the body went, goes in the retry. With nothing left to do, the review is over and its main comment is not sent again.
  • A post of unknown result holds the dialog until it is closed. Reopening offers it again, and the Inbox answering already_posted ends it as posted.
  • The server refuses over 500 file-level comments, or a malformed one (422), instead of cutting them for the page to forget.
  • One comment in two entries in different words (a window still on the old head edited it) stays as two comments, for the person to see both and delete one. The second one's id follows from its words, so every read gives the same one, and a deletion also clears it from the other entry.
  • A partly posted review's main comment that went is not offered again on a new head, on reopen or on Retry; one that did not go stays in the box.
  • Over 500 file comments the dialog says: "This review has too many file comments to post at once (500 at most). Nothing was sent." The server's error stays as it is for agents.
  • Another window's write reaches this one (storage event), so its next save does not write over it. A window that could not store keeps its own copy as the only one. A push's move empties the old entry only once the new one holds the words.

How it looks (real build, a fake gh): pictures at 1440 and 390, light and dark, in /tmp/rv2640c/built-final, taken from a build of this head. The dialog's partial, reopen and too-many-file-comments states are in /tmp/pr-keep-sandbox/walk/f7/j-shots.

Cost. A read that misses the cache costs 3 gh calls in either scope (head, patch, head), 2 more than a stack read used to. A post at an older commit costs one more (pulls/N/commits). Labels now cost none. A read that keeps failing, or names no head, repeats on each list read (2-minute tick, focus at most every 20 s).

Tests. New pullReviewKept.test.tsx covers both scopes, with the real post dialog for the post routes.

  • Reverting each rule fails a test, one mutation at a time: the pin, kept partial plans, a failed read taking the reader, no retry, too-large retried, a null head replacing the patch, other entries out of view, the button, the key flipping, no key, always or never sure, list-head posting, SEEN over any head, a stale cache, read mode writing, no absorb, both label rules, seenId without base, catch-up ignoring base, the regex at 40, sure out of the deps. Added this round: the name following the list, the name sticking over other code, the list-head label off and always on, SEEN over an older head, the newest head never recorded, a verdict or a post without absorb, the banner outliving a head.
  • The earlier sure = !!head && !!readHead.current mutant no longer applies: sure is now just "a patch read here named its head".
  • One mutation failed nothing because its code was dead (the guard against caching a null head). I removed that guard; the hit check already never serves one.
  • This PR's last rounds: about 80 mutations, each on its own, including the reviewer's M6, M13, M19 and M26. All killed but one, though the earlier ones were not repeated on the final code. The survivor is scope === 'layer' in forPost: Whole stack line comments go to "Cannot post inline" anyway, so it only changes the label in Copy as Markdown. The reviewer's M20 is unreachable behind the GitLab check, and M28, the panel's other card branch, has no test.

Results at this head, on Bun 1.4.4 (CI's) for the tests. The browser runs are on a binary built at this exact commit:

  • entry-assets, inbox-pulls, guideFeedback, agents-md-size, codeAnnotationAnchor, outsideDiffComments, review-draft-local and ci-test-lanes: 210 pass.
  • DOM, under --isolate as CI's lanes run them: pullReviewKept, pullReview, pullReviewGlobalComments, usePulls, reviewPane, dom-test-allowlist localReviewDraft and seven AnnotationPanel files: 283 pass. Without --isolate, files in one run share module mocks and fail, also with no file of this PR's (pullReview + pullReviewGlobalComments: 2 fail); no CI lane runs them so.
  • tsc on packages/inbox, apps/inbox, packages/server, packages/core and packages/ui: clean. tsconfig.guide.json: 33 errors, all in packages/review-editor, as on main.
  • inbox-pull-requests.spec.ts on a sandbox binary: 10 pass, 2 skipped. One test walks a line comment over a push: the label shows, then commit_id, line and body at the old commit, then the typed words at the new head.
  • Scratch walks (a stateful fake gh/glab, not committed; they log what the fake received): 6 for this round (the reviewer's B1 by hand in the panel: the forge has the first comment and the new words, once each, no old words, Comments 0 after reload; B2; an edit and a delete under the open dialog; a real second window; an answer lost at the head), 16 of mine, 4 of the reviewer's S scenarios.
  • The reviewer's walk zz-j on this build: 7 pass. T1: both versions shown and posted, Comments 0. T2: main comment once, box empty on reopen. T3: the plain sentence, nothing sent.
  • The last two rounds' 42 mutations, run before the last merge of main: 39 killed. Three survive, none a behaviour: matching done by id gives the same result because onPosted holds the comments as they stood at Send; the listener's key filter only saves a re-read; holding a blocked target in the kept-plan check changes nothing, as planOver drops it. A mutant that drops a blocked target's narrowed retry is killed.

Follow-ups, not in this PR

  • A write landing in the moment before another window's storage event arrives can still write over it.
  • Over 500 line comments the dialog still shows the server's fileComments: at most 500 comments….
  • A comment kept as a second copy (a window on the old head edited it), edited again and posted with no reload while the other window's entry is still there: the earlier version comes back on reload. Nothing is lost; it can post again unless deleted.
  • A half-typed line comment dies on a real push, as it does today. The composer's state lives in AllFilesCodeView with no draft key, so keeping it isn't cheap.
  • Stored keys for abandoned PRs.
  • A lower-layer force-push leaves this layer's diff stale until a reload.
  • A verdict refused after the older comment went, then Cancel: the header still offers it. Approve goes straight; Request changes needs words, as any review with no comments does, because the comment has already gone.
  • A file-level comment on a file a push deleted now has the label, but Post still sends it at the head, where GitHub may refuse the path: the error shows, the words stay, and the person can delete it.
  • A force-push the Inbox hasn't read yet now says "The commit you read is no longer on this pull request." Retry repeats that until the next list read brings the new head.
  • On GitLab, the dialog still shows the old count until a post is refused. Retry then shows the new plan without sending; the refusal's sentence goes with the old plan.
  • After a refused review with no comments left, the header's Approve opens the dialog as Post Comments, so the words are not sent as an approval. Clearing the words, then Cancel and reopening, approves. In a thread's review pane, which reads the PR again on a refusal, Approve stays Approve and the kept words go with it, as on main.
  • After a blocked attempt on the old head, the plan rebuilt at a new head can repeat the main comment typed in the dialog, if it did go: nothing says it did. Keeping the old plan would leave posting stuck, because its head is refused.
  • After an answer lost at the head with the Inbox restarted since, reopening can post the review a second time, as a reload always could: the server's memory of posted reviews does not outlive it.
  • A retarget that changes the code resets the scroll and loses a half-typed comment. The composer no longer floats detached; the same code keeps the reader.

Typecheck. apps/inbox is clean the way the repo's typecheck script runs it, tsc -p apps/inbox/tsconfig.json from the root (TypeScript 6.0.3). From inside apps/inbox, its own TypeScript 5.8.3 gives 12 errors, the same 12 on main, in files this PR doesn't touch. packages/inbox/tsconfig.guide.json reports 33 errors, all in packages/review-editor, none in PlatformPost.tsx.

Merging. Main is merged in as of 4d659c5cf. #2635 is still open. A trial merge conflicts in PullReview.tsx, attachments.ts, inbox-pulls.ts, the two guides and the e2e spec. In attachments.ts keep both the outside-diff heading and the [Outdated line. With those resolved, pullReviewKept passed (119 pass, at the earlier merge), and a comment outside the diff, read before a push, went in the main comment at the head, with Comments at 0. #2639's conflicts were not tried.

#2635 reads Whole stack file contents at the list's head (inbox-pulls.ts:779 there), so with the list behind or ahead, its arrows read a different commit from the patch. That gets fixed where the two meet.

Not checked: real GitHub and GitLab were not exercised. The commit-anchored behaviour rests on GitHub's docs ("Not using the latest commit SHA may render your review comment outdated") and a model in the tests that lands comments at a commit's diff and refuses what it doesn't have. GitHub's docs don't list the exact refusal for a commit off the PR, or say an older commit_id is accepted outright. Also unchecked: GitLab's null head for real, a real retarget or force-push, and whether pulls/N's head can lag the branch tip that a compare reads.

… commit, not a new updated_at

updated_at moves with a label, a teammate's comment or a review, and each move
deleted the person's unsent line comments and Viewed ticks, read the diff again
and took the reader down. Key them on the head commit (the patch's, else the
list's), and the diff on head and base. Entries under the old key move over whole.
…his review read a patch

Whole stack's compare named no head, so a list behind it deleted comments on the
patch. The server now reads the head around a stack's compare too, and caches
diffs by head. A patch naming its head stays until a read names a newer one, so a
list landing on a head still behind it deletes nothing; a new head brings a new
reader, so an open composer cannot save onto a moved line. Stored entries move
only once this review read a patch itself, not on a remembered diff. Line comments
from a key naming no head are marked outdated: they post in the body, labelled.
… or names no head changes nothing

A dialog open over a new commit, or a retry after one, sent its old lines at the new
head. The plan now pins the head it was built on: the server refuses a commit it no
longer takes, what was typed stays, and reopening builds a new plan. A failed or
headless re-read keeps the patch and goes again on the next list read. The reader is
keyed on the code. Global comments and old entries stay in view when no patch has been
read here, and only a named head on a changed PR labels a comment outdated. Whole stack
posts at the patch's head, so catching up no longer offers a second Approve.
…-same-head

# Conflicts:
#	docs/agent-guides/inbox-files-and-guides.md
#	packages/inbox/pulls/PullReview.tsx
…n the forge is ahead

A patch naming no head now keeps the name it came up under while the list
moves, so a comment written on the old lines cannot be saved under the new
head and post there. Other code naming no head takes the list's name again.

An old entry moving to a head the list does not name is marked outdated, so
it goes in the review body rather than inline on today's line.

A diff remembered in the window is drawn only if it is of the newest head
read here, as the server's cache does.
…entries with no list head; keep typed words from becoming an Approve
backnotprop added a commit that referenced this pull request Nov 5, 2026
Takes #2640's rule early so the two merge cleanly: head_sha in both scopes, and
readHeads holds only heads that held still. A file read uses that head, else the
list's, and the client asks nothing when an answer has no head_sha, in either
scope.

Co-Authored-By: Claude <[email protected]>
A saved line comment now survives a real push, on screen and in storage. If
its line reads the same in the new diff it stays drawn; otherwise it is in the
Comments panel as "Written on older code". On GitHub, Post sends it at the
commit the person read, in that commit's lines, as a comment-only review.

If that commit has gone (a force-push), the server answers pull_commit_gone
and the comment goes in the body with its [Outdated] label, unless its lines
still read the same at the new head. GitLab's docs do not say a thread can go
on an older version, so GitLab takes the labelled route. A retarget under the
same head also does, unless the line is still there.

The dialog no longer refuses a push that came in while it was open: what it
showed goes at the commit it opened on.
…-same-head

# Conflicts:
#	docs/agent-guides/inbox-files-and-guides.md
#	packages/inbox/pulls/PostEnding.tsx
#	packages/inbox/pulls/PullReview.tsx
… post

Request changes with every comment on an older commit now sends the verdict,
and older-commit reviews carry the shared body. GitHub's 422 becomes
pull_commit_gone only for a refusal of the commit or its lines, or with no
reason, and at a head the list names only if the commit really left the PR.
A thread's review pane reads the PR again on pull_commit_gone.

What went leaves every stored entry of the review, so a push landing during a
post cannot bring it back; only the comments in the plan count as posted, and
already_posted at an older commit counts as went. A comment on lines outside
the diff never goes at an older commit.

The committed e2e now walks a saved comment over a push to both commits.
When GitHub refused an older commit, the plan was rebuilt from the comments on
screen. A push under the open dialog gave a comment planned for the head a
postAt, so it became an older-commit target nothing sent, and it was then
counted as posted and erased. The rebuild now takes the plan as it stood, a
postAt equal to the plan's head is that review's, and a comment counts as gone
only if a target the forge accepted carried it.

"Reference could not be resolved" no longer reads as the commit being gone;
"start_line must be part of the same hunk" takes the fallback like other
refused lines.
…as they stand

A comment edited after its plan was built was forgotten when its old words
posted. What went is now noted with its words: an edit since stays. The
dialog rebuilds its plan from the comments as they stand on reopen and at
Send; a partly posted review keeps its narrowed retry in the current words,
and what the forge took leaves at once and is not sent again.

A post of unknown result can go again once the dialog is reopened, and the
server's already_posted ends it. Over-limit or malformed file-level comments
are refused, not cut. Another window's write reaches this one, and a push's
move empties the old entry only once the new one holds the words.
…a main comment that went

A window still on the old head could edit a comment another had moved: the
next move kept the head's version and dropped the edit. Both now stay, as two
comments, for the person to see both and delete one.

A partly posted review's main comment stayed in the box over a new commit,
unlocked, and went again. It is cleared if the forge took it. Over 500 file
comments, the dialog now says so in plain words.
…-same-head

# Conflicts:
#	packages/server/inbox.ts
@backnotprop
backnotprop marked this pull request as ready for review November 5, 2026 12:12
@backnotprop backnotprop added the ci:full Run the heavy CI tier on this PR (added by the merge script) label Nov 5, 2026
…names no viewer

PullReview imported them from @plannotator/review-editor, which the guard on
the window's first load refuses by name. The module has no viewer in its
graph (only type imports), so it moves to packages/ui as it is, beside the
CodeAnnotation type it reads. No behaviour changes.
@backnotprop
backnotprop merged commit 32e6baf into main Nov 5, 2026
83 of 86 checks passed
backnotprop added a commit that referenced this pull request Nov 5, 2026
Conflicts kept both sides: `guest` and `codeReview`, the outside-diff and
outdated labels together, `fetchFileContent`/`fileContents` with `fileOpenIn`,
#2640's readHead comment with hasCommit and fileContents, its key comment over
ReaderPart, the union of imports, and both e2e tests (main's first).

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:full Run the heavy CI tier on this PR (added by the merge script)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant