Skip to content

fix(chat): confirm a Pi receipt only from text stamped after its send (#2234, #2055) - #2323

Merged
devswha merged 8 commits into
mainfrom
fix/pi-receipts-followups
Oct 29, 2026
Merged

devswha merged 8 commits into
mainfrom
fix/pi-receipts-followups

Conversation

@devswha

@devswha devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Change

Fixes #2234: a Pi receipt could be confirmed by a same-text user record that Ovis did not send.

Pi exposes no submission id, so a receipt is matched by its text on the active branch after the
captured anchor. A message typed into Pi's own terminal and queued while Pi worked, before Ovis
pressed Enter, is appended after that anchor too, and it confirmed Ovis's receipt even when Ovis's
own message was never recorded.

Pi stamps every user message with Date.now() when it is submitted or queued, before it is
appended at message_end (pi-mono agent-session.ts _queueSteer/_queueFollowUp, agent.ts
normalizePromptInput). The anchor now records its capture time, taken before Ovis presses Enter,
and a record stamped no earlier than that capture confirms the receipt. When only an earlier-stamped
record has its text, the receipt is neither confirmed nor left waiting: it settles as
transcript_unconfirmed, which the browser already shows as Sent to Pi · transcript
confirmation unavailable
with Discard. That is the issue's own suggestion ("keeping
identical-text matches uncertain"). A wall clock set back between the capture and Pi's stamp ends
the same way, instead of stranding the receipt and every later one in the pane's FIFO; review
showed that no clock correction can tell those cases apart. A record without a numeric stamp keeps
the old behaviour.

Without a Pi submission id two cases stay indistinguishable, and DESIGN.md names both: the same
text submitted elsewhere after Ovis's Enter, and the same text typed while Pi compacts, which Pi
stages as { text, mode } and stamps only when the stage drains (interactive-mode.ts, Pi 1.3).

Also from #2055 (follow-ups of #2041):

  • A waiting receipt's anchor and its cached append state keep a sha256 digest of the bounded 64 KiB
    tail instead of the tail itself (two 64 KiB strings per receipt before).
  • pi-delivery.test.ts no longer writes ~200 MiB per run: the large-history test uses a sparse
    file, and it still counts every byte read.
  • The server accepts an attach's receipt_resume_id only in the lowercase UUIDv4 form the browser
    generates and keeps (shared/receipt-resume.ts, shared by both), not any 36 hex-or-dash
    characters.
  • The doubled doc comment above PendingInputs.resend() is one comment, and the pending tests pass
    null where it type-checks instead of null as never.

Closes #2234
Closes #2055

The rest of #2055

Reviewed against current main; none is a reproduced, user-visible MEDIUM, so none gets its own issue.

  • Kept by design (DESIGN.md): after the stable-ID disposition is evicted or the bridge restarts, a
    stale held copy stays resendable for offline recovery.
  • An older bridge ignoring withdrawal_only: only a bridge update fixes that; new bridges have it.
  • A signed-in connection filling the 1024-entry disposition history: needs an already authorized
    connection; LOW.
  • A cross-tab resend marking the original row sent without comparing its text: no client path sends
    that; LOW.
  • Two connections pressing Edit on the same first message at once: one draft can get the text twice,
    nothing is delivered or lost; LOW.
  • One over-budget receipt settling the whole batch as unavailable: receipts are checked oldest
    first, and the oldest anchor has the largest append, so it is the one that exceeds the budget;
    the rest could not be matched past it anyway (FIFO).
  • Up to 1024 closed connection objects kept by the history and receipt lists, and the relay parsing
    every browser message as JSON: bounded memory and CPU, LOW.
  • Edit's end-to-end race test being browser-only: the server side is covered by the pending-input
    unit and contract tests.
  • The fix(chat): edit queued messages and resume local Pi receipts #2041 changelog wording: that entry was already released.

Tests

  • server/pi-delivery.test.ts: "does not let a same-text record Pi stamped before the capture
    confirm the receipt", "prefers the record stamped after the capture when an earlier one has the
    same text" and "settles, rather than strands, Ovis's own record stamped while the wall clock was
    set back" all fail with main's matcher.
  • server/pending-input.contract.test.ts (real server, isolated test session, port 0), both
    failing on main: "does not confirm a receipt from the same text Pi stamped before Ovis pressed
    Enter" (two Ovis sends of the same text, then one write with an earlier-stamped terminal record
    and Ovis's first record: on main both receipts are confirmed, now only the first, and the second
    waits for Ovis's own second record), and "settles a receipt as unconfirmed when only an
    earlier-stamped record has its text".
  • server/core/terminals.test.ts refuses 36 dashes, a nil UUID, a v1-shaped UUID and upper case;
    it fails with main's check.
  • bun run check fast: passed on 3536b83 (workflow syntax, generated types/themes, typecheck, build, unit tests).

Remote PCs get the server part with the next REMOTE_BUNDLE_VERSION raise at release.

Review

omo-native-code-reviewer approved twice (5398656, 5a1c83d). Codex (gpt-6.1-sol, fast, xhigh) ran five rounds; each MEDIUM it found is fixed with a test that fails on the commit before it. The findings and their resolutions are in the PR comment below. The last fix (3536b83) did not get a sixth Codex round, under the merge pass's cap for heuristic matchers.

Known limit: a wall clock set back between two of Ovis's sends to one Pi pane, with a reconciliation delayed until all records are present, can still leave a delivered message showing "confirmation unavailable" (dismissible) or waiting until the pane's target changes. Without a Pi submission id, order across a clock step cannot be proven.

LOW, not changed: a Pi build stamping seconds instead of milliseconds would never confirm (upstream and the installed builds use milliseconds); the sparse test file may not be sparse on NTFS (no worse than the 200 MiB the old test wrote).

…capture (#2234)

Pi exposes no submission id, so a receipt matched any same-text user record
appended after its anchor. A message typed into Pi's terminal and queued
before Ovis pressed Enter could therefore confirm Ovis's receipt even when
Ovis's own message was never recorded.

Pi stamps a user message with Date.now() when it is submitted or queued,
before it is appended. The anchor now records its capture time, taken before
Enter, and a record stamped earlier never matches. The same text submitted
elsewhere after Enter stays indistinguishable; DESIGN.md says so.

Also from #2055: an anchor and its append state keep a sha256 digest of the
bounded tail instead of the 64 KiB tail itself, and the large-history test
uses a sparse file instead of writing 200 MiB.
The server took any 36 hex-or-dash characters as an attach's
receipt_resume_id, while the browser only generates and keeps a lowercase
UUIDv4. Both now share one pattern. Also folds the doubled doc comment above
PendingInputs.resend() and drops `null as never` where null type-checks.
)

Codex Sol review: a wall clock set back between the capture and Pi's stamp put
Ovis's own record before the bound, so its receipt waited for good and, being
first in FIFO order, held every later receipt of the pane. The anchor also keeps
the monotonic capture time, and the bound is the capture time on the current
wall clock when that is earlier.

DESIGN.md also names the case the bound cannot cover: Pi stamps input it
staged during compaction only when the stage drains.
…ed text matches (#2234)

Codex Sol's second review: the monotonic correction from the previous commit
let a pre-capture external record confirm after a clock set back, and a clock
set back and restored before reconciliation still stranded Ovis's own record,
which then held every later receipt of the pane. No wall-clock comparison can
tell those apart from a submission order.

So the bound is the capture time again, and a receipt whose text appears
only in records stamped before it is now "ambiguous": it settles as
transcript_unconfirmed, which the browser already shows as "confirmation
unavailable" and lets the user dismiss, and its FIFO successors move on. A
same-text record stamped after the capture is still preferred, and an
earlier one used for an ambiguous settle cannot settle a later receipt.
…s over

omo review (LOW): with a terminal-typed "same" before two Ovis sends of
"same", a reconciliation that ran after Ovis's first record and before its
second reported the second receipt ambiguous, because each reconciliation
scans the branch from the anchor again and met the earlier copy. The copies a
match passes over are now marked used along with it.
…dmits

Codex Sol review (MEDIUM): with the wall clock set back between two captures,
a record stamped before the first receipt's capture can still be no earlier
than the second's, so it may be the second receipt's own. Retiring it with the
first receipt's match left the second waiting for good. A passed-over record
is now retired only when it was stamped before every remaining receipt's
capture in the batch.
Codex Sol review (MEDIUM): the bound for keeping a passed-over record took
every remaining receipt's capture, so an earlier capture of a receipt with
other text kept an old same-text record alive, and the next reconciliation
settled a later same-text receipt as unconfirmed. Only remaining receipts with
the same text count now.
@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Review findings and resolutions (before the first push)

Reviewers: omo-native-code-reviewer and Codex (gpt-6.1-sol, fast, xhigh), each on an adversarial, read-only brief in its own pinned worktree. Commits referenced are on this branch.

Codex round 1 (5398656), BLOCK

  • MEDIUM: a wall clock set back between the capture and Pi's stamp left Ovis's own record below the bound, so its receipt waited for good and held every later receipt of the pane (FIFO). First addressed in 4541307 with a monotonic correction; superseded by 5a1c83d (see round 2).
  • MEDIUM: Pi 1.3 stages input typed during compaction as { text, mode } and stamps it only when the stage drains, so same text typed then can still confirm the receipt. Not fixable without a Pi submission id; narrowed the claim and documented it in DESIGN.md and the matcher's doc comment.

omo round 1 (5398656), APPROVE: no CRITICAL/HIGH/MEDIUM. LOW clock step (same as Codex's first MEDIUM, fixed as above); LOW DESIGN.md wording (fixed in 19eefa8); LOW a Pi build stamping seconds (hypothetical: upstream and installed builds use milliseconds); LOW the sparse test file may not be sparse on NTFS (no worse than the 200 MiB the old test wrote; not checked on Windows).

Codex round 2 (4541307), BLOCK

  • MEDIUM: the lowered bound let a pre-capture external record confirm after a clock set back.
  • MEDIUM: a clock set back and restored before reconciliation still stranded the receipt.
  • Resolved in 5a1c83d: no clock correction; a receipt whose text appears only in records stamped before its capture settles as transcript_unconfirmed (dismissible "confirmation unavailable"), so neither case confirms falsely or strands.

omo round 2 and Codex round 3 (5a1c83d): omo APPROVE with LOW-1, Codex MEDIUM, same defect: an earlier-stamped record a match had skipped made a later same-text receipt ambiguous on the next reconciliation. Fixed in 278020b (passed-over copies are retired with the match). omo's LOW-2 (pre-Enter same text now shows "unavailable") is the intended outcome.

Codex round 4 (278020b), BLOCK

  • MEDIUM: with a clock set back between two captures, retiring every passed-over copy could hide the second receipt's own record. Fixed in 390fd18: a passed-over copy is retired only when stamped before every remaining receipt's capture.

Codex round 5 (390fd18), BLOCK

  • MEDIUM: the bound for keeping a passed-over record counted receipts with other text, so an earlier capture of an other receipt kept an old same record alive, and it settled a later same receipt as unconfirmed on the next reconciliation. Fixed in 3536b83: only remaining same-text receipts count.

Stopping here. Rounds 3 to 5 each found an edge introduced by the previous narrow fix, and each needs the wall clock set back between Ovis's captures plus a delayed reconciliation. Per the merge pass's rule for heuristic matchers (one last round after a fix; findings that need exotic inputs become documented limits), 3536b83 was not sent for a sixth Codex round; the merge pass reviews it. In the worst remaining case a delivered message shows the dismissible "confirmation unavailable" or keeps waiting until its pane's target changes; no false confirmation beyond main's was found.

Every fix has a unit test that fails on the commit before it; bun run check fast passed on 3536b83.

@coderabbitai

coderabbitai Bot commented Oct 29, 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 7 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 353029c and 3536b83.

Files selected for processing: 12
  • DESIGN.md
  • changelog.d/pi-receipt-earlier-same-text.md
  • server/core/pending.test.ts
  • server/core/pending.ts
  • server/core/terminals.test.ts
  • server/core/terminals.ts
  • server/pending-input.contract.test.ts
  • server/pending-input.ts
  • server/pi-delivery.test.ts
  • server/pi-delivery.ts
  • shared/receipt-resume.ts
  • src/lib/receiptResume.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

Comment @coderabbitai help to get the list of available commands.

@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Merging 3536b83 (closes #2234 and #2055). A Pi send's receipt now confirms only from a same-text transcript record stamped at or after the pre-Enter capture; an earlier-stamped match settles as a dismissible "confirmation unavailable", never a false confirmation or a receipt stuck for good, and nothing is resent. #2055's items are done or dispositioned in the PR body. Queued input and receipts, so the merge pass reviewed it strictly beyond the lane's rounds (omo APPROVE twice; Codex five rounds, every MEDIUM fixed with a fail-before test): same-text sends back to back, whole-second stamps, the unavailable state across reconnect, other agents' receipts and the receipt-resume contract all held; 231 tests, typecheck clean. Known limits (Dori's decision, no follow-up issue: not something a user can realistically meet): (1) a same-text message submitted by another writer before Ovis's capture but stamped in the same millisecond confirms the receipt (server/pi-delivery.ts:252 compares with >=); (2) a wall clock set back between sends.

@devswha
devswha merged commit e9bd29a into main Oct 29, 2026
26 of 29 checks passed
@devswha
devswha deleted the fix/pi-receipts-followups branch October 29, 2026 05:10
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.

fix(chat): a same-text append can confirm a Pi receipt (from #2231 review) Queued-message Edit and Pi receipts: follow-ups from #2041

1 participant