Skip to content

fix(chat): never resend reply comments after another tab moves the pane mid-send - #2741

Merged
devswha merged 2 commits into
mainfrom
fix/reply-comments-moved-in-another-tab
Nov 4, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/reply-comments-moved-in-another-tab

Conversation

@devswha

@devswha devswha commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes #2356.

What was wrong

With two tabs of one browser on the same pane, moving the pane to another workspace from one tab while the other tab's message carrying reply comments was on its way left those comments for the next message:

  • Only the tab that moved the pane knew where the comments went (ReplyCommentStore.forwards, in memory). The sending tab acknowledged under the old pane ID, found nothing there, and the sent comments stayed under the new ID.
  • No other tab knew which comments that send carried, so a message from the moved pane in any other tab could carry them again before the first was acknowledged.

#2709 (cross-tab send lock) already stops two tabs claiming the same draft, and carryPaneState runs inside that lock, so the moving tab sees the other tab's send lease. This builds on it.

What changes

  • src/lib/paneMove.ts: inside the old ID's send lock, the move reads the old draft's send lease from storage (sendLease, from any tab) and passes it to ReplyCommentStore.move.
  • src/lib/replyComments.ts:
    • Hold in storage. Each comment moved while that send is on its way is stored with heldFor: { draft, at }, the lease it waits for. Every tab's unreserved leaves it out while the lease in storage still has that at, so the hold ends with that exact send (acknowledged, refused, or lapsed after SEND_LEASE_MS). A comment already held for an earlier send keeps that hold when it moves again.
    • Move record. Such a move also leaves { movedTo, at } under the old comments key (it reads as no comments, and the prefix is already under the herdr fence of paneLifetime.ts). removeSent follows these records as well as this tab's own; a record older than SEND_LEASE_MS is not followed. A move of comments still held for an earlier send is recorded too, so a chain of moves is followed to the end. Records are not removed on acknowledgement, since another send may need the same record; they lapse.
    • Wake-ups. A storage event for a send lease refreshes the comment readers, and refresh makes unreserved readers read again; the moving tab refreshes them when the lease it moved under ends there.
    • IDs. Comment IDs are random instead of a per-tab counter. Two tabs saving in the same millisecond got the same ID, and a send removes by ID.
  • src/lib/composerDraft.ts: the lease parsing moved into the exported sendLease (unchanged behaviour), plus isSendLeaseKey.
  • No record or hold is written when no send is on its way, so ordinary moves leave nothing behind.

Validation

  • Reproduced on origin/main 9390fa1: the first new test in src/lib/paneMove.test.ts models each tab as its own ComposerDraftStore + ReplyCommentStore over one shared storage (the issue's steps). On main it leaves ["carried", "for the next message"] under the new ID; with the fix only ["for the next message"].
  • The five cases from the Codex review below (third tab, second move, two sends with two moves, a later send ending first, a retired herdr's send) are tests in the same file; all five fail on the first head d54847a and pass now. A further test checks an expired record is not followed.
  • bun test paneMove, replyComments, composerDraft, composerDraftAgentOnly, paneLifetime, diffLineNotes and the Composer tests: 83 pass, 0 fail.
  • bun run check fast: green (typecheck, build, unit 11052 pass / 0 fail).
  • Not run: check full, a real two-tab Chromium run.

Not covered

  • The agent-only mark race from the issue's last comment (ovis:composer-agent-only:<pane> cleared in a separate storage operation from the draft) is a draft-format change and is not touched here.
  • Comments moved while another tab's send is on its way are held back whole, including one saved after that send began; it goes with the next message once that send settles. A hold whose sending tab closed lapses with the lease (120 s) but frees in other tabs only at their next comment refresh.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 6 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 4331eb8 and 9a3ecc0.

Files selected for processing: 5
  • changelog.d/reply-comments-moved-in-another-tab.md
  • src/lib/composerDraft.ts
  • src/lib/paneMove.test.ts
  • src/lib/paneMove.ts
  • src/lib/replyComments.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Review round on d54847a: omo CLEAR; Codex Terra (xhigh) BLOCK with 1 HIGH + 4 MEDIUM, all five reproduced with its scratch tests and fixed in the new head:

  • HIGH, hold only in the moving tab (a third tab or a reload could send the comments again): the hold now lives on the moved comments in storage (heldFor, tied to the exact send lease), so every tab sees it.
  • MEDIUM, a second move broke the chain: a move of comments still held for an earlier send also leaves a record.
  • MEDIUM, one acknowledgement deleted another send's record / MEDIUM, a retired herdr's send deleted a new send's record: records are no longer removed on acknowledgement; they lapse after the send lease.
  • MEDIUM, a later send ending first released an earlier send's hold: holds are per send lease, not a shared in-memory set.

Each case is now a test in src/lib/paneMove.test.ts (fails on d54847a, passes now). bun run check fast green. PR body updated.

@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Re-review on 9a3ecc0: omo CLEAR; Codex Terra (xhigh) found no HIGH. It confirmed the five earlier cases are fixed and reported these, left unfixed here (fix rounds are capped at one, and each needs cross-tab timing within one storage write or a herdr replacement that reuses the pane ID):

  • MEDIUM: an acknowledgement in another tab that lands between move's write of the destination list and its write of the move record removes nothing at the destination.
  • MEDIUM: a tab still showing the old pane ID that saves a comment right after another tab moved it overwrites the move record, so the sender's acknowledgement no longer follows the move.
  • MEDIUM: after a herdr replacement that reuses a pane ID, a page's in-memory forward from the old herdr is preferred over the new stored record.
  • LOW: a stored heldFor without a numeric at (malformed storage only) hides that comment.

CodeRabbit skipped this PR (no review ran); the omo and Codex reviews above stand in.

@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Merge note: merged on the omo review (CLEAR at 9a3ecc0), Codex Terra (round-1 HIGH and MEDIUMs reproduced and fixed with tests; round 2 has no HIGH, its narrow-race MEDIUMs are listed above) and green checks. CodeRabbit skipped this head. The agent-only mark race from the issue's last comment is not covered here.

@devswha
devswha merged commit 7a923ab into main Nov 4, 2026
15 of 16 checks passed
@devswha
devswha deleted the fix/reply-comments-moved-in-another-tab branch November 4, 2026 12:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reply comments: a pane move made in another tab can send the same comments twice

1 participant