Repository navigation
A resent chat message gets its recorded answer, never an early refusal or a made-up record - #25158
Conversation
… early refusal or a made-up record The host now looks a resent send id up before preparing the session. A row that settled refused answers with its refusal before the chat is opened. A resend whose chat cannot be opened or made ready answers unknown instead of a refusal. A /clear in flight refuses only ids the ledger does not hold. A send row now records the journal epoch it was admitted into. An unsettled row with nothing written in that same epoch runs for the first time; under a later epoch the host answers unknown instead of reconstructing a submission it never had. The host advertises agent-session.send-answers-proof.v1.
…d is answered before any write A send (and /compact) settles its ledger row `succeeded` in the same SQLite transaction as the submission or queued draft that accepts it, so a row still `pending` proves nothing was written and a resend runs it for the first time. The unknown-before-run mark and the per-row journal epoch go. A resent id is answered from its row and the journal before preparation starts an agent and before any write transaction: a recorded refusal with nothing opened; otherwise the conversation is opened (no agent start for a send) and replayed, and a conversation that will not open answers unknown.
…fuses only a send's first run An id the ledger refuses (expired, conflict, invalid, capacity) is answered as admission would, with no journal read, preparation or write, so a closed chat or a read-only store answers it too. A re-read after the replay open that comes back refused returns that refusal. Whether a /clear is in flight is read when a send arrives and applied in the send's preparation for a first run only: an id the ledger holds by the send's turn, including one whose earlier attempt was queued ahead of the clear, is answered from its record. MutationPlan makes settlesWithWrite and settledOutcome exclusive; the capability text no longer promises a refused id never sends.
Review summaryThe problem. When a chat message's answer gets lost, Orca resends it under the same id until the host answers. The planned fix for failed sends will trust that answer: a refusal hands the text back, and "unknown" means keep resending. That only works if the host never refuses a message it already holds, and never makes up a record. Before this PR it could do both:
What changes for you.
How the review changed the PR. Three review rounds, plus a readiness checklist at the end.
Deferred (P3 / follow-ups):
Residual risk, stated in the body. On macOS, a power cut can roll back the last few committed database writes after the agent already received a message. A resend would then send it again. This risk is new with the choice to send a never-written message on resend; before, such a message was stuck instead. Verified:
Not verified:
|
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 🧰 Additional context used📚 Code guidelines (1)No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (26)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughJournal receipts now write operation outcomes in the same transaction as accepted journal rows. Send and conversation-command plans use write-based settlement. Mutation admission and replay paths recheck ledger and journal state, and send preparation distinguishes admission from replay. The change also updates clear-in-flight send handling, adds resend and transaction tests, and advertises a runtime capability for send-outcome proof. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to Resent chat messages now get their recorded answer, and a send's success record is committed with its message. No concrete merge-blocking issue was found. The author documents one rare macOS power-loss edge case, which can redeliver a message. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to Recording a message and its accepted outcome now happen together, while resends resolve recorded results before attempting another send. No new security weakness was established in the reviewed paths. End-to-end access controls and mixed-version behavior remain partially verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the full 26-file diff at f63fb59f61, tracing the new replay-before-admit path, the JournalOperationReceipt write/commit mechanism, and the /clear arrival gate against their call sites and tests.
- Replay answered before any write —
answerRecordedOperationanswers a recorded id from the ledger row (afailedrow with its recorded refusal, with nothing opened), runs the plan's replay-only preparation, re-evaluates the ledger, and only falls through to a first run when nothing durable landed.agentSessionLedgerRefusalde-dupes the refusal shape. - A send's success commits with its message —
JournalOperationReceiptstages the ledger settlement inside the journal transaction and adopts it after COMMIT;sendPlan/conversationCommandPlanmove frommarkUnknownBeforeRuntosettlesWithWrite, so a send that threw before writing leaves apendingrow that reruns on resend instead of a fabricatedunknown. /clearrefuses only a first run — the controller passesarrival.clearInFlight;sendPreparationapplies it only on theadmitpath, so a recorded id is answered behind the clear.sendPlan.replaynow also reruns apendingrow.- Capability —
agent-session.send-answers-proof.v1is advertised (additive, no protocol bump); nothing reads it yet, matching the PR's plan.
I verified two things that could have been regressions and found neither: the receipt's write/committed run in one synchronous step at both call sites, so a store transact on its own microtask queue cannot interleave and adopt() cannot clobber a newer published; and the extra prepareSession('replay') on the rerun branch only reaches idempotent side effects (ensureAgent, finishOwedStop, openConversationForWrite), with every mutateStructuredAgentSession caller passing a preparation so the old inline replay block remains a consistent fallback.
The author-stated residuals (macOS power-loss rollback, outcomeUnknown for an unreadable chat) are deliberate trade-offs, not defects.
deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
…-history Conflict: journal-row-writer.ts. Main's send ledger receipt (#25158) writes inside the same append transaction as the row and the chat status this PR stores, and is adopted after COMMIT before the PR's committed() observers. journal-store.ts stays within its length limit by inlining the tombstone's item key.

ELI5
When a chat message is sent and the answer gets lost (the connection drops, the window reloads), Orca sends the same message again under the same id until the host answers. The host keeps a record per id, so a resend can't deliver a message twice.
Before this change, the host could answer a resend in two wrong ways:
Now the host answers a resend from its record before doing anything else. It also writes a send's "accepted" record in the same database write as the message itself, so a message that was never written is simply sent when it is resent, once.
Problem
The planned fix for failed sends lets the chat decide what to do from the host's answer alone. A refusal would mean "not sent, here is your text back". "Unknown" would mean "keep resending the same id". That only works if every answer the host gives is true. Today some aren't.
admitAndRunAgentSessionMutationreads the ledger (the host's per-id record of operations) first. For a call with aprepareSessionstep, though, it runs that step even when the ledger says "replay this id". It then needs a database write before it answers. So a resend of a message the host already holds can be refused by the preparation step: "chat not attached", "Unable to load this chat", a failed agent start for a rewind still in doubt, or a write refused on a database a newer Orca wrote (structured-agent-session-mutation-admission.ts:95-160,structured-agent-session-send-preparation.ts:57-151). Separately, while a/clearruns, every send is refused with "Wait for the conversation operation to finish" before the host looks at the id. A client that hands text back on such a refusal would duplicate a message the host already had.unknownsubmission with reasondurable_send_submission_missing(structured-agent-session-replay-outcome.ts:36-56,structured-agent-session-mutation-plans.ts:101-124).What changes for you
/clear/clearOlder clients only get answer shapes they already handle: a real submission, or
agent_session_operation_unknownwith an existing reason. Nothing in the chat UI is changed by this PR. The planned client change will read the new capability below.The change
A resend is answered first, and writes nothing.
/compactand/clear, that preparation only opens the chat: no agent is started. A chat that can't be opened answersagent_session_operation_unknown/outcomeUnknown, never a refusal.A send's success is committed with the message itself. The ledger and every chat journal (the stored chat history) live in one SQLite database on one connection.
JournalOperationReceiptlets a journal write carry a ledger update in the same transaction.AgentSessionStoreTransactions.receiptstages that update. It writes the ledger row inside the journal's transaction and publishes it to memory only after COMMIT.performSendattaches the receipt to the message's write, and the queued path attaches it to the queued draft's insert.markUnknownBeforeRunis removed, and send and/compactnow usesettlesWithWrite.pendingexactly while nothing has been written. A run that throws before the write leaves itpending, and the resend runs it as its first run.Replay with nothing in the chat.
pendingreruns. Asucceededrecord whose message a later rebuild of the chat's history dropped keeps today's answer: recorded, delivery unknown, never run again. So dounknownrecords written by earlier builds; these expire within a day./clearin flight. The controller notes on arrival whether a/clearis running. A send that arrived during one is refused only if it reaches its first run, which happens in the chat's queue, after the lookup. A send that arrived before the clear still runs.Capability
agent-session.send-answers-proof.v1, advertised by the host. Its comment says how a client may read the refusalsagentSession.sendreturns:outcomeUnknown/resultLost: resend under the same id.rewindUnconfirmed: settled; nothing was written.Nothing reads the capability yet. The planned client change gates on it so it never trusts an older host's refusals.
Why "still in progress" is not a new answer: a chat's mutations run one at a time (
mutateStructuredAgentSessionserializes per session), and every check that could refuse a resend now runs in that queue, after the lookup. So a resend is handled only after its original has finished, and gets the original's real answer. A test pins this by firing the resend while the original's write is held open; removing the serialization turns that test red.Why this approach
Differences from the common pattern
The common pattern checks a per-command receipt before doing anything else. It answers a rejected receipt with "previously rejected", and replays an accepted one from what it stored. It writes the receipt in the same transaction as the command's effects.
/compactcommit their receipt with their effect. Stop, prompt answers, options and the other mutations still record their outcome after running. Intended: their effect is a call to the agent process, which can't share a database transaction. Their records keep the existing "unknown" handling.'replay'preparation mode.pending) before the run and committed with the effect, instead of only with the effect. Intended: the placed row reserves the id and enforces the per-client capacity before any work, as it did before.pendingwith nothing written always means "never ran", so it is resolved by running.fsyncdoesn't flush the drive cache under this database's sync settings (journal-database.ts), so a power cut can roll back the last few committed writes. That could include a message and its success record, after the agent already received it. A rerun would then send it again. This risk is new with the choice to rerun a send that has nothing written. Before, such a message got the made-up "unknown" answer and was never sent again, so it was stuck instead. Intended, as a stated residual risk: it needs a power cut in the seconds between delivery and the next checkpoint, plus a lost answer for that exact message.Visual Proof
N/A: this changes no rendered UI. Each changed path needs an injected fault: Orca failing between accepting a message and writing it, a chat database that fails to open or is read-only, a rewind left in doubt, or a resend landing during
/clear. None can be reproduced reliably by clicking in the app. They are covered against the real host and a real SQLite chat journal in the tests below. What the user sees for each answer is the existing client handling, unchanged here.Testing
structured-agent-session-resend-answer.test.ts(new, 7 tests):/clearreplays, while a new id is refused after the clear;structured-agent-session-resend-ledger-refusal.test.ts(new):/cleargets that attempt's submission;/clearis answered "expired".structured-agent-session-send.test.ts:structured-agent-session-send-preparation.test.ts: apendingrecord with no live agent reruns and starts the agent once; an older build'sunknownrecord starts nothing.agent-session-store-transactions.test.ts: a receipt shows in memory only once committed, and a rolled-back one is never published./clearrefusal on arrival again;tscfor the node, web and CLI projects through the shared typecheck gate;oxlint,oxfmtand the changed-code quality check.src/main/claude/claude-structured-*file changed), the mobile typecheck (no mobile file changed), Windows, SSH.Notes
/clearor/compactresend still opens the chat to answer.