Skip to content

fix(pending): a held copy is claimed before its Send now types it - #3608

Merged
devswha merged 1 commit into
mainfrom
fix/pending-resend-claim
Nov 10, 2026
Merged

devswha merged 1 commit into
mainfrom
fix/pending-resend-claim

Conversation

@devswha

@devswha devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner

Change

Follow-ups to #3173 (queued follow-ups recovered as held after a disconnect), from the two reviews of its last head. Each is a way the bridge alone could let a held message be typed twice or offered for the wrong pane; in one browser whose storage works, the page's own re-read before a press already stops the double sends.

The claim comes before the dispatch. A Send now of a saved copy removed the held receipt, typed the text, and only then recorded sent under the pane ID it started with. A turn is its pane ID's, so when herdr moved the pane while the text was on its way, the outcome landed under the old ID and a second tab's copy under the new one was typed again (a resend there with another generation typed at the same time). The handler now puts a sending claim among the receipts before anything is typed. The move carries it, every resend of that ID under any pane ID answers pending_busy while it stands, and the send's end is recorded under the ID the pane has then: sent, the "not confirmed" note, or the held receipt back in place when nothing was typed.

The "not confirmed" note outlives its owner's record. When a Send now ended without an answer inside the first minute after the reload, the closed owner's record aged out as dismissed 60 s after the close, and that removal erased the note. Only the record's own disposition was left, and past 1,024 later dispositions the other tab's copy was typed again. A dismissed removal now ends only a held receipt.

A pane that ended leaves no held receipt. herdr may give its ID to another pane, and the same browser attaching there was told the old pane's copy was held, with Send now, for a terminal it was never written for. The pane's held receipts now go when it ends, and a follow-up the bridge still holds for it gets none when its connection closes later (the same failure with the pane ending first). What was sent, or may have been, stays and only refuses.

The page's proof no longer stretches when the device's clock is set back. The bridge ends its receipt on a forward-only clock; the page ended its proof on the wall clock. What is left of a proof now runs on a clock that steps forward by the larger of what the wall clock and performance.now() moved since it was last read, so a wall clock set back takes nothing from the time that passed and a sleep performance.now() did not count is still counted.

Validation

All on commit 5f414757d.

  • bun run check fast: passed (unit: 15255 pass, 0 fail, 51 skip; typecheck, build, generated types and themes, workflow syntax).
  • CI runner image (herdr-ci-runner:local, a clone of this commit, each through bun run check run), all passed: the contract tests server/pending-input.contract.test.ts and server/submit.contract.test.ts (228 pass, 0 fail), and the browser regressions pending-pane-switch-regression.ts, composer-fit-demo-regression.ts, held-rows-demo-regression.ts, restored-draft-demo-regression.ts, composer-draft-demo-regression.ts, chat-local-send-follow-demo-regression.ts.
  • New tests, each failing on main's code and passing here:
    • server/core/pending.test.ts: a pane moved while a Send now is on its way, for each end of the send (sent, not confirmed, nothing typed): the other tab's resend under the new ID with another generation is answered pending_busy during the flight (on main it typed at the same time), and afterwards the outcome is known under the new ID. The harness's turns are now per pane ID, as in the bridge.
    • server/core/pending.test.ts: a Send now that ends without an answer inside the owner's first minute, then the record's expiry and 1,100 other dispositions: the other tab's resend is still pending_uncertain (on main it typed).
    • server/core/pending.test.ts: a pane that ended with one held receipt and one message still held on a live connection that closes afterwards: a browser attaching under the reused ID is told neither as held; a follow-up taken for the new pane is held and told as before.
    • src/lib/pendingMessages.test.ts: a proof ends after the time that passed with the device clock set back an hour, and after a sleep the forward-only clock did not count. The file's clock tests now move both clocks together.
  • Not run: bun run check full; the full browser sequence of a pane move during a send (the tests drive the bridge and the store directly). The branch is based on main as of fix(cli): ovis add takes a line as an answer only when it was typed after its request was shown #3581 and merges with today's main without conflicts.

🤖 Generated with Claude Code

Follow-ups to #3173, from the reviews of its last head.

- The resend handler claims the ID among the receipts (`sending`) before the dispatch. A pane move
  carries the claim, every resend of that ID under any pane ID answers pending_busy while it
  stands, and the send's end is recorded under the ID the pane has then: sent, the "not confirmed"
  note, or the held receipt back in place when nothing was typed. Before, a pane herdr moved while
  the text was on its way left the outcome under the old ID, and the other tab's copy under the
  new one could be typed again.
- A `dismissed` removal (the owner's uncertain record aging out) ends only a held receipt, so the
  note that a Send now may have typed the copy stays its ten minutes.
- A pane that ends takes its held receipts away, and a follow-up the bridge still holds for it
  gets none when its connection closes later: herdr may give the ID to another pane.
- The page reckons what is left of a held proof on a clock that steps by the larger of the wall
  clock's and performance.now's movement, so a device clock set back does not stretch it.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Bug Fixes
    • Prevented duplicate Send now attempts when a message is moving between panes or another tab is already sending it.
    • Improved held-message receipt handling when a pane ends or its ID is reused, preventing old messages from reappearing.
    • Made receipt expiry more reliable when device clocks move backward or pause during sleep.
  • Documentation
    • Updated guidance on held-message receipts and resend behavior.

The server now serializes held-message resends and tracks pane termination. The client now uses a forward-only proof clock for held-receipt expiry. Tests cover concurrent resends, pane moves and reuse, uncertain outcomes, and wall-clock changes.

Changes: Held-message resend lifecycle

Layer / File(s) Summary
Serialize resends and handle pane termination
server/core/pending.ts, server/core/pending.test.ts, DESIGN.md, changelog.d/queued-resend-claim.md
The server records an in-flight claim before a resend, settles the claim under the pane’s current ID, and prevents ended panes from restoring held receipts. Tests cover concurrent requests, pane moves and reuse, and uncertain outcomes. The design and changelog describe these behaviors.
Track held-receipt expiry with a proof clock
src/lib/pendingMessages.ts, src/lib/pendingMessages.test.ts
The client uses wall-clock and performance-clock elapsed time to advance a proof clock. Receipt checks, expiry timers, and resumed deadlines use this clock. Tests cover clock rollback and simulated sleep.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Possibly related issues

  • devswha/ovis#3169 — This change blocks concurrent resends while a send claim is active. The provided evidence does not establish whether a queued resend remains blocked after the first send becomes uncertain.

Possibly related PRs

  • devswha/ovis#3173 — That PR adds resumable held receipts; this PR adds resend claims, pane-end handling, and proof-expiry behavior for them.

Suggested reviewers: jimbb

Merge Risk: Minimal · up to 5f414

This change serializes held-message resends, drops held receipts when a pane ends, and makes the receipt expiry timer robust to clock rollback. No concrete merge-blocking risk is identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title clearly describes the main change: claiming a held copy before Send now types it.
Description check Passed The description includes both required sections. It explains the problem and resulting behavior, and lists validation results and skipped checks.
Docstring Coverage Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 6 functions across 4 files. (2 skipped: 2 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a2239f5 and 5f41475.

Files selected for processing: 6

  • DESIGN.md
  • changelog.d/queued-resend-claim.md
  • server/core/pending.test.ts
  • server/core/pending.ts
  • src/lib/pendingMessages.test.ts
  • src/lib/pendingMessages.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 3 remain after this review.

@devswha
devswha merged commit 4bba664 into main Nov 10, 2026
21 checks passed
@devswha

devswha commented Nov 10, 2026

Copy link
Copy Markdown
Owner Author

Merge pass

Merged head 5f414757d38c as 4bba6648f0da on GitHub's checks, with no unresolved review threads.

Reviewer Verdict Note
claude CLEAR
codex CLEAR

Merge pass note (head 5f41475). Both reviewers CLEAR. No sequence was found that types a message twice or after Discard in one browser with working storage. Left for one PR after the release (LOW; each needs a press on a held card for a pane ID herdr reused):

  • A tab told a copy is held before its pane ended can still Send it now after herdr gives the ID to another pane (the resend path does not check that the pane ended).
  • The "pane ended" memory is keyed by pane ID and the wall clock: a move of the new pane, a clock set back, or more than 1024 other ends still offer the ended pane's copy; a pane moved into an ended ID loses its own held receipt. Marking the records themselves fixes all four.
  • A Send now naming the old ID that waits behind that ID's turn across a move is not covered by the claim (pre-existing).
  • The guards that make the claim safe in the owner's first minute (keepReceipts skipping sending, claim.gone, restore's held guard) have no test.
  • (Codex, MEDIUM, not run) A clock rollback defeats the fence for a reused pane ID; same fix as the second item.

CodeRabbit did not post findings on this head.

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.

1 participant