Skip to content

fix(native-chat): settling earlier sends after a restart no longer blocks starting a chat - #26577

Closed
brennanb2025 wants to merge 6 commits into
mainfrom
brennanb2025/chat-start-send-settlement-best-effort
Closed

brennanb2025 wants to merge 6 commits into
mainfrom
brennanb2025/chat-start-send-settlement-best-effort

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 8 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​666 $\color{#cf222e}{\Huge{\mathbf{−}}}$​74 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​592
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​157 $\color{#cf222e}{\Huge{\mathbf{−}}}$​116 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​41

ELI5

If Orca restarted while one of your chat messages was on its way to the agent, Orca can't tell whether it arrived. When you next use that chat, Orca checks the agent's own history and records the answer: delivered, or not delivered. If saving that answer failed (the database was busy, full or locked), Orca refused to restart the agent at all, so you couldn't keep chatting. Now the chat restarts normally. The old message just stays unconfirmed.

While fixing that, review found a second problem in the same check. A message that did reach the agent could be marked "not delivered", and sending it again would give the agent the same message twice. That no longer happens.

The problem

Native chat saves every message you send before handing it to the agent. After a crash or restart, a message that was handed over but never confirmed is marked unconfirmed. The next time the chat starts its agent (on your next send), Orca reads the agent's history for that conversation:

  • found in the history → marked delivered
  • absent from a history that provably covers it → marked not delivered, with "This message was not delivered. Send it again to continue."
  • anything else → stays unconfirmed

On main:

  1. A failed save blocked the user. Saving that delivered/not-delivered answer is bookkeeping about an earlier message, but its failure aborted the start: Orca stopped the agent it had just started and failed your new send. The chat showed "Your message was not sent." and "Claude couldn't restart. Send your message to try again." It kept failing as long as the save failed, and nothing in the log said why. Reproduced live on Windows (QA table below).
  2. A delivered message could be called "not delivered" (Claude chats). Orca reads Claude's history starting from the conversation's saved resume point, and every finished turn moves that point forward. If a message stayed unconfirmed past one start (history unreadable, a turn still running, or now problem 1), a later turn moved the resume point past it. The next check then didn't see the message and wrongly marked it not delivered, so sending it again duplicated it. Problem 1's obvious fix (don't fail the start) would have made this path more common, so both are fixed here.

User-facing change

  • The chat always starts. A failed save of an earlier message's status no longer stops the agent or refuses your send. Orca logs settling earlier sends against provider history failed and leaves that earlier message unconfirmed.
  • "Not delivered" only when it is true. Orca marks an absent message not delivered only when the history it read provably starts before that message was handed over. Otherwise the message stays unconfirmed.
  • Visible difference: some messages that used to show the red "This message was not delivered" now show as an ordinary sent message with no notice. That red line was sometimes wrong, and sending again then gave the agent a duplicate. An honest "unconfirmed" notice for these messages is a separate follow-up PR. Today the chat draws unconfirmed messages as plain sent messages, the same as main does for the unconfirmed cases it already has.
  • The common crash case is unchanged: you send a message, Orca crashes before Claude takes it, and on your next send it is still marked not delivered.

What changed (mechanism)

  • structured-agent-session-attach.ts: settling earlier messages against provider history is best effort. A failed write is caught and logged, and the start continues. The catch covers only that settlement. Ownership, the new agent's events, adopted history and the start's own result still fail the start as before. Writes are applied in memory only after SQLite commits (journal-row-writer.ts), so a failed write leaves the message unconfirmed both in memory and on disk. The list of unconfirmed messages returned to the client is now read straight from the journal.
  • journal-submission-reconciler.ts: one new rule before "not delivered". The history window carries where its start was set: the fence and host-clock time of the first link in the trailing run of identical resume points (resumePointStart, structured-agent-session-history-sample.ts). Each message carries the fence and time of its first handover (firstHandover, derived by the journal fold, never stored). Absence rejects a message only if it was handed over at a later fence than the start, or at the same fence strictly after the start's time; ties stay unconfirmed. New reason: history_start_unproven.
  • Nothing new is stored: no new persisted field, no schema change, no new wire field. firstHandover rides along in snapshots like the existing host-only acceptedSequence; the submission schema drops it and no client reads it.
  • attachJournal now requires the history window that performAttach samples before starting the agent. The lazy read inside it had no production caller.

Why this approach

  • Bookkeeping must not gate the user. Settling an earlier message's status protects nothing about the current start. Leaving it unconfirmed is the state Orca already uses when history can't be read, and Orca never resends on the user's behalf.
  • No latch, no retry loop. Nothing records "settlement owed". Every later start re-reads the unconfirmed messages and a fresh history sample. A message that is still unconfirmed blocks nothing: no queue hold, no Stop take-back, no "working" state, no command refusal. It ends when a later start can decide it, when its conversation's records are replaced (rewind or adoption), or when the chat is deleted.
  • Derive the order, don't store it. Fences order owners, and within one owner the same host clock stamps both the resume point move and the message handover. The alternative was ordering by journal rows. It was rejected because the resume point is saved before the journal records the turn that moved it, so a crash between the two writes would wrongly mark a delivered message not delivered.
  • The common pattern recovers interrupted work from durable records at a host-level boundary and lets a failure there propagate. Intended difference: Orca settles per chat when that chat next starts its agent, uses provider history only to narrow the answer, never resends, and treats a failed settlement as non-fatal, because the record is about an earlier message and not the start itself. Temporary difference: unconfirmed messages have no visible notice yet (follow-up PR above).

Known limits / not verified

  • Clock step. At the same fence, ordering uses the host's wall clock. If the system clock jumps backward by more than the time between handing a message over and the end of the next turn, and Orca then crashes before the chat starts again, a delivered message could still be marked not delivered. Not observed. Closing it exactly would need new stored state, which this PR avoids.
  • Messages that stay unconfirmed and show as plain sent messages until the follow-up PR, new with this PR:
    • N1: a later turn finished at the same fence at or after the message was handed over, including a queued or steered message the agent dropped.
    • N2: the resume point moved under a later owner before any start settled the message (after a failed save, an unreadable or inconsistent history read, or a still-running agent, followed by any finished turn). This also covers a delivered message whose "delivered" save failed.
    • N3: Claude's close/exit wrote a different resume point at the same fence after the handover.
    • Same as main: Codex (no history window), ACP agents (never a provable window), a Claude chat with no resume point yet, a forked, compacted or unreadable transcript, a still-running agent, messages with attachments, commands or several parts, and an ambiguous match.
  • The live QA injected the failure with a database trigger, not a real full disk or lock.
  • Live QA ran on Windows with Claude. macOS, Linux and SSH hosts run the same main-process code (settlement runs on the execution host, and its clock and journal are on that host) but were not exercised live.

Linked Issue

Found by the reviews of #26554 and #26555. Sibling: #26576 (stale-turn cleanup at start).

Visual Proof

Screenshots held locally pending owner review (they come from a real signed-in Claude session).

Live QA on Windows high spec with a real signed-in Claude and hidden windows. Each build ran on a fresh isolated profile. BEFORE = main e3639ef8d69; AFTER = b0c6c871627. Later commits change comments and pair the handover fence and time from the same first handover, which only matters for rows from September builds. Failure injected by adding an unconfirmed message to the test profile's journal plus a trigger that aborts only the save of that message's delivered/not-delivered answer.

Row BEFORE (main) AFTER (this PR)
Q1: the earlier message's status can't be saved; reopen the chat and send a new message Blocked: "Your message was not sent." and "Claude couldn't restart. Send your message to try again." No reply, and no log line naming the cause Works: Claude replies; log shows settling earlier sends against provider history failed … QA26577 injected failure; the earlier message stays unconfirmed
Control: same profile, trigger removed Claude replies; the never-sent message shows "This message was not delivered. Send it again to continue." n/a
Q2: no injected failure; reopen, send n/a The never-sent message shows "This message was not delivered…". After a quit, relaunch and reopen it still does, with one copy, and Claude never received it
Q3: Q1's profile after removing the trigger; send again n/a The earlier message stays unconfirmed (history_start_unproven: the agent started in Q1 had moved the resume point) and shows as a plain sent message. It is never resent. This is the expected cautious outcome until the follow-up PR

Real-home checks: Claude's settings, the Codex hooks and config, and ~/.orca hashes were unchanged before launch, after first use and after teardown.

Testing

  • I manually tested these changes locally

  • Automated tests added/updated, or explained why not below

  • Full-host restart tests on real SQLite:

    • The failure is injected inside the real transaction, so the real rollback runs, and the result is read back from disk.
    • A failed delivered/not-delivered save keeps the start working.
    • A failed save while re-attaching to a still-running agent does not stop that agent (on main it did).
    • A delivered Claude message stays unconfirmed after a later turn moves the history past it.
    • A truly undelivered message still settles as not delivered after a later restart when nothing moved.
  • Reconciler unit tests cover both directions: an earlier fence, the same fence before or after or at the same instant, and no start.

  • Mutation checks:

    • forcing the same-fence branch true turns 3 tests red;
    • forcing it false turns 12 red;
    • using the head link instead of the trailing run turns 4 red;
    • main's production files turn the original 3 failure tests red.
  • 8 changed test files (106 tests) pass, and 67 neighbouring restart, journal and attach test files pass (one more needs --expose-gc, an environment flag). Node typecheck and orca-ci-checks pass.

AI Disclosure

Review

Review summary posted as a PR comment.

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

brennanb2025 and others added 4 commits October 8, 2026 05:51
…ocks starting a chat

After a restart, starting or resuming a chat first settled the status of
sends from the previous run, and a failed settlement write failed the start.
Settlement is now best effort: unconfirmed sends keep showing as
unconfirmed and keep their replay protection, the failure is logged and
retried later, and the user's start proceeds.

Co-Authored-By: OpenAI Codex gpt-6.1-sol <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
…rovably starts before it

A send whose verdict failed to save stays unconfirmed; a later turn can move the
resume point the next restart reads from past it, and that history then reads the
delivered send as never sent. The reconciler now rejects an absent send only when
it was handed over at or after the fence of the owner that last moved that resume
point (derived from the record's chain head and the journal fold); otherwise it
stays unconfirmed. Presence still settles it.

Also: settlement failures are injected at the SQLite transaction in tests and
checked on disk; re-attaching to a running agent keeps it when a settlement fails;
docs on what a failed settlement leaves now say what is true.
…last moved

Round-1 dated the start from the chain head, but every later acquisition re-proves an
unmoved resume point as a new link, so one undecided attach left a truly undelivered send
unconfirmed forever. The start is now the first of the trailing links that carry the head's
handle, leaf included.

The same owner can also move the point past a send it handed over (a turn end after an
unrecorded accept), so at an equal fence the reconciler now rejects only when the point
moved strictly before the handover on that owner's clock; a tie stays unconfirmed.

attachJournal no longer samples history itself (only tests did, from the post-acquisition
record); callers pass the sampled window.
… and time together

A send handed over twice (legacy rows) paired its first handover's fence with its last
handover's time. Both now come from one derived firstHandover. Also drop a writer comment
about a pending retry path that no longer exists.
@OrcaWin

OrcaWin commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

Closing as superseded by merged #30580 (6059a5f).

I compared the complete production diff and all eight test changes. This PR makes provider-history reconciliation best effort and adds first-handover/history-start proof to prevent false “not delivered” results. #30580 deliberately removes that reconciliation mechanism, its adapter history hooks and the attach-time history read. Current attachJournal opens the journal and returns its unconfirmed messages directly: there is no recovery-verdict write to block starting the chat, and no transcript-absence inference to misclassify a delivered message.

The first-handover and history-window additions only support that removed mechanism, and the added tests cover it. No independent remaining scope needs salvaging here. Verified against current main; this PR's head is unchanged at 1e62f0e.

@OrcaWin OrcaWin closed this Oct 26, 2026
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.

2 participants