Skip to content

A resent chat message gets its recorded answer, never an early refusal or a made-up record - #25158

Merged
brennanb2025 merged 5 commits into
mainfrom
brennanb2025/chat-send-id-checked-first
Oct 4, 2026
Merged

brennanb2025 merged 5 commits into
mainfrom
brennanb2025/chat-send-id-checked-first

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 9 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​584 $\color{#cf222e}{\Huge{\mathbf{−}}}$​160 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​424
Prod 17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​372 $\color{#cf222e}{\Huge{\mathbf{−}}}$​114 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​258

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:

  • It could refuse it before looking the id up (for example "the chat can't be loaded" or "wait for /clear to finish"), even when it already held the message.
  • If Orca failed or quit between accepting a message and writing it into the chat, every resend got a made-up "delivery unknown" record. That message was never sent and could never be confirmed.

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.

  1. Refusals made before the id is looked up. admitAndRunAgentSessionMutation reads the ledger (the host's per-id record of operations) first. For a call with a prepareSession step, 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 /clear runs, 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.
  2. A made-up record. The host marked a send's record "unknown" in one database write, then wrote the message in a second one. If the run threw or Orca quit between the two, the record stayed "unknown" with nothing in the chat. Every resend then got a fabricated unknown submission with reason durable_send_submission_missing (structured-agent-session-replay-outcome.ts:36-56, structured-agent-session-mutation-plans.ts:101-124).
    • What you see today: the message says "Message delivery is unconfirmed." with Retry.
    • Retry resends the same id and gets the same made-up answer, so it can never succeed.
    • The message is never sent. Other windows and the phone never show it, because no record of it exists in the chat.

What changes for you

Situation Before After
Orca failed or quit after accepting a message but before writing it; the app resends it "Message delivery is unconfirmed." + a Retry that never succeeds; the message is never sent The resend sends it, once, under the same id. It counts as your own message, as the original would have: it starts the agent's turn and lifts a Stop or restart pause on queued messages
You resend a message the host already refused Same refusal, but the host first reopened the chat (and, with a rewind in doubt, could start the agent) Same refusal, answered from the record with nothing opened or started
The app resends a message the host holds while a rewind is in doubt The host started the agent first; if that failed, the resend was refused Answered from the chat; no agent is started
The app resends a message while you run /clear Refused at once: "Wait for the conversation operation to finish.", even if its first attempt was still queued ahead of the clear and then got written Waits its turn behind the clear. A message the host holds, including one whose first attempt was queued ahead of the clear, gets its record. One that was never written gets the same "Wait for the conversation operation to finish."
A brand-new message during /clear Refused at once Refused with the same words, once the clear has finished
The app resends a message the host holds, but the chat can't be loaded right now Refused with "Unable to load this chat" (the phone puts the text back in the composer) "Orca couldn't confirm…, check the chat" (the existing words for an unknown outcome); the same id is kept on both desktop and phone
A brand-new message into a chat that can't load Refused Unchanged: refused

Older clients only get answer shapes they already handle: a real submission, or agent_session_operation_unknown with 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

  1. A resend is answered first, and writes nothing.

    • An id the ledger refuses (expired, conflicting, malformed) is answered right after the lookup, with nothing opened and nothing written. So is a recorded id that settled refused.
    • Any other recorded id is answered after the operation's own "replay" preparation, from the ledger row and the chat's history, with no write transaction.
      • For a send, /compact and /clear, that preparation only opens the chat: no agent is started. A chat that can't be opened answers agent_session_operation_unknown / outcomeUnknown, never a refusal.
      • The other mutations (Stop, prompt answers, options, thread goal, rewind) still run their own preparation first, as before. See "Differences" below.
    • Only an id that turns out never to have run continues as a first run: full preparation, the ledger write, then the run.
  2. 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.

    • The new JournalOperationReceipt lets a journal write carry a ledger update in the same transaction.
    • AgentSessionStoreTransactions.receipt stages that update. It writes the ledger row inside the journal's transaction and publishes it to memory only after COMMIT.
    • performSend attaches the receipt to the message's write, and the queued path attaches it to the queued draft's insert.
    • This replaces the old "mark unknown, then write" order: markUnknownBeforeRun is removed, and send and /compact now use settlesWithWrite.
    • So a send's record is pending exactly while nothing has been written. A run that throws before the write leaves it pending, and the resend runs it as its first run.
    • A refusal coming back after the success has already committed (only an in-memory update failing after the write) is now thrown, which proves nothing. Before, it was recorded as a refusal on top of a message that was already written.
  3. Replay with nothing in the chat. pending reruns. A succeeded record whose message a later rebuild of the chat's history dropped keeps today's answer: recorded, delivery unknown, never run again. So do unknown records written by earlier builds; these expire within a day.

  4. /clear in flight. The controller notes on arrival whether a /clear is 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.

  5. Capability agent-session.send-answers-proof.v1, advertised by the host. Its comment says how a client may read the refusals agentSession.send returns:

    • outcomeUnknown / resultLost: resend under the same id.
    • rewindUnconfirmed: settled; nothing was written.
    • "expired": only the transcript can tell.
    • A conflict, a reused message id, or "not attached": proves nothing about this message.
    • Any other returned refusal: the chat holds no message under that id and none is in flight. A resend of that same id may still run as a new send, so a client that hands the text back must not resend the old id.
    • A thrown error, including a thrown refusal, proves nothing.

    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 (mutateStructuredAgentSession serializes 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

  • One transaction instead of re-deriving. A first version kept "mark unknown, then write" and decided a stuck record later, by checking whether the chat's history had been rebuilt since. That depended on every place a send can write, on the retention windows of other tables, and on rows never being dropped inside one copy of the history. Committing the success with the write leaves nothing to re-derive: a record is never "unknown" any more.
  • Rerun, not "unknown", for a send that provably wrote nothing. Answering "unknown" there would keep the client resending for a day and then hand the text back with "couldn't confirm". Running it is safe because nothing could have delivered it, and its record still dedupes later resends.
  • Considered: an in-memory set of running ids, to answer "still in progress". The per-chat queue already makes that state impossible to observe.

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.

  • For a send: lookup first, recorded refusal answered before any work, receipt committed with the effect. These match the common pattern.
  • Only a send and /compact commit 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.
  • Other mutations still run their own preparation before replaying. That can finish a Stop left owed, or, for rewind and thread goal, start the agent. Temporary: a follow-up gives every replay one shared open-only step and drops the 'replay' preparation mode.
  • The receipt row is placed (as 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. pending with nothing written always means "never ran", so it is resolved by running.
  • A resend whose chat can't be read answers "unknown", not an error. Intended: an error would let the client hand back text for a message the host may hold, which could duplicate it.
  • Receipts last 24 hours plus clock skew, not forever. Intended, unchanged: past that window a resend is refused as expired and never run again.
  • Residual: power loss on macOS. macOS fsync doesn'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):
    • a refused record is answered without reopening the chat;
    • an unreadable chat answers "unknown" for a held id and still refuses a new id;
    • a resend during /clear replays, while a new id is refused after the clear;
    • a resend fired while its original is mid-write gets the original's submission, with one delivery;
    • a resend with a rewind in doubt is answered with no agent started;
    • a resend on a database a newer Orca wrote (read-only here) is answered;
    • a queued send commits its record with the queued draft.
  • structured-agent-session-resend-ledger-refusal.test.ts (new):
    • an expired id is answered "expired" with the chat closed, and on a read-only database;
    • a record that expires while the chat opens is answered "expired";
    • a resend whose first attempt was queued ahead of a /clear gets that attempt's submission;
    • an expired id resent during a /clear is answered "expired".
  • structured-agent-session-send.test.ts:
    • a send whose separate ledger write fails still has its record committed with the message;
    • a send that threw before writing runs once when resent;
    • records from a rebuilt history answer as recorded and never redeliver.
  • structured-agent-session-send-preparation.test.ts: a pending record with no live agent reruns and starts the agent once; an older build's unknown record starts nothing.
  • agent-session-store-transactions.test.ts: a receipt shows in memory only once committed, and a rolled-back one is never published.
  • Ablations: each change was reverted one at a time against the committed tree, then restored. Each made at least one of the tests above fail. The reverted changes:
    • the receipt never writing, or never being published after COMMIT;
    • a throw marking the record unknown again;
    • a resend going through the first-run preparation;
    • dropping the recorded-refusal shortcut, the per-chat serialization, or the early answer for ledger refusals;
    • applying the /clear refusal on arrival again;
    • forcing a rerun when the re-read row is refused.
  • 275 test files (2,373 tests) across the agent-session journal, wire and runtime suites, plus the two cross-version agent-session suites. The cross-version suites check that a send from this build is accepted by the newest release and vice versa. They don't exercise the changed resend answers: "older clients handle these answers" rests on reading their code, plus the phone's existing test for an unknown refusal.
  • tsc for the node, web and CLI projects through the shared typecheck gate; oxlint, oxfmt and the changed-code quality check.
  • Not run: the real-Claude CLI suite (no src/main/claude/claude-structured-* file changed), the mobile typecheck (no mobile file changed), Windows, SSH.

Notes

  • SSH / remote: host-side only. Answers keep shapes every client already handles, and the capability is optional. The ledger and the journals are in the host's own database, so nothing new crosses the wire.
  • Folder workspaces: no git assumptions.
  • Performance: a send now commits two database transactions where it did four (the "unknown" mark and the separate success write are gone). A resend that is answered from its record writes nothing.
  • Deferred:
    • For a resend into a chat that can't load, the words say "check the chat", and the phone no longer puts the text back. The planned client change owns those words.
    • A /clear or /compact resend still opens the chat to answer.

… 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.
@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review summary

The 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:

  • it refused some resends before looking the id up (chat not loaded, agent start failed, /clear running);
  • a message Orca accepted but never wrote got a made-up "delivery unknown" answer forever. Desktop showed "Message delivery is unconfirmed." with a Retry that could never succeed, and the message was never sent.

What changes for you.

  • A message Orca accepted but never wrote is now sent when it is resent, once.
  • A resend of a message the host holds is answered from its record. That holds while a rewind is in doubt, while /clear runs, and on a database a newer Orca wrote. It is never refused first.
  • A brand-new message sent during /clear is still refused with the same words. It now waits for the clear to finish before being refused, instead of being refused at once.
  • Nothing in the chat UI changed. The host advertises a new capability that the planned client change will gate on.

How the review changed the PR. Three review rounds, plus a readiness checklist at the end.

  • Round 1 replaced the first design, which stamped each record with the chat's history version and checked it later. Now a send's "accepted" record is committed in the same database transaction as the message itself, so a record is never left "unknown". A resend is also answered from its record before any preparation or database write. These two changes removed:
    • a gap where a withdrawn queued message could be sent again;
    • a 24-hour resend loop the planned client would have hit;
    • a stuck /compact case;
    • an undetected journal-repair risk.
  • Round 1 also tightened the capability text, which overstated what a refusal proves (thrown refusals, rewindUnconfirmed, conflicts).
  • Round 2 fixed one P2: a resend during /clear could be refused while its own first attempt was still queued ahead and then got written. The /clear refusal now applies only to a message's first run, after the lookup, so that resend gets its record. Ledger refusals (expired and the like) are now answered right after the lookup.
  • Round 3 checked only the round-2 changes: no P0–P2. It found two comment fixes, both done.
  • Readiness checklist (SSH, crash/retry/growth, security, performance, correctness, compatibility, cross-platform, organization): pass, nothing at P0–P2.

Deferred (P3 / follow-ups):

  • A resend into a chat that can't load says "Orca couldn't confirm…, check the chat", and the phone no longer puts that text back in the composer. The planned client change owns those words.
  • Other mutations (Stop, prompt answers, options, thread goal, rewind) still run their own preparation before answering a resend. Follow-up: one shared open-only step for every replay, which also removes the 'replay' preparation mode.
  • Simplifications: on the rare replay-then-run path the answer is resolved three times and the chat prepared twice. The journal writer also takes both a hook and a receipt.
  • A held send whose rerun keeps throwing (rather than refusing) is retried on each client resend until its record expires. That needs a repeated unusual failure.

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:

  • 275 related test files (2,373 tests), plus the two cross-version agent-session suites.
  • Each part of the fix was reverted one at a time (ablations), and each revert turned at least one test red.
  • Node, web and CLI typechecks through the shared gate; lint and format on the changed files.

Not verified:

  • No app QA. The changed paths need injected faults (Orca failing between accepting and writing a message, an unreadable or read-only database, a rewind in doubt, a resend racing /clear), and no rendered UI changed. They are covered by host tests against a real SQLite journal.
  • Not run: the real-Claude CLI suite (no Claude structured-session file changed), the mobile typecheck (no mobile file changed), Windows, SSH.
  • The cross-version suites check that sends are accepted across versions, but don't exercise the changed resend answers. "Older clients handle these answers" rests on reading their code.

@brennanb2025
brennanb2025 marked this pull request as ready for review October 4, 2026 08:57
@coderabbitai

coderabbitai Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

🧰 Additional context used
📚 Code guidelines (1)
AGENTS.md — auto-discovered

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 37cd8cfa-bf33-4cd8-a0a8-e54d5b28faa2
📥 Commits

Reviewing files that changed from the base of the PR and between ce07786 and f63fb59.

📒 Files selected for processing (26)
  • src/main/native-chat/agent-session-journal/journal-queued-messages.ts
  • src/main/native-chat/agent-session-journal/journal-row-writer.ts
  • src/main/native-chat/agent-session-journal/journal-store.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-mutation-admission.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-mutation-plans.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-operation-settlement.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-operation-settlement.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-queued-command.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-queued-messages.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-replay-outcome.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-resend-answer.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-resend-ledger-refusal.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-restart-failure-filing.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-restart-interruption-test-harness.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-restart-ownership.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-send.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-turns.ts
  • src/main/native-chat/agent-session-wire/structured-conversation-command-controller.ts
  • src/main/runtime/agent-session-record-store.ts
  • src/main/runtime/agent-session-store-transactions.test.ts
  • src/main/runtime/agent-session-store-transactions.ts
  • src/shared/agent-session-mutation-envelope.ts
  • src/shared/protocol-version.ts

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


📝 Walkthrough

Walkthrough

Journal 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 f63fb

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 Review

Security architecture risk: 🔵 Low · up to f63fb

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
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The demonstrated exposure is send and command state within the executing host's session store, with downstream provider delivery. The changed global replay lookup spans caller identities, but a differing session or payload is subject to fingerprint conflict rejection. This containment does not establish transport authentication or tenant authorization.

Trust Boundaries and Controls

  • observed — Attacker-supplied operation identifiers are checked for validity, future skew, fingerprint reuse, age, and capacity. Replay bypasses execution only when returning a recorded answer; an unwritten operation still pays normal admission before running. These are replay and execution controls, not substitutes for caller authorization.

Resilience and Maintainability Implications

  • observed — Mutation entry uses per-session serialization. Direct sends check for an existing submission, queued insertion preserves an existing draft, and replay follows a consumed draft's handoff or withdrawn state instead of automatically creating another delivery. These controls support failure containment across repetition and recovery.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 46.88% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 26 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: resent messages receive their recorded answer instead of an early refusal or an invented outcome. It is specific and relevant, though longer than preferre…
Description check ✅ Passed The description explains the problem, user-visible behavior, implementation, trade-offs, testing, and visual-proof status in detail. The template’s Linked Issue section is not completed, and several t…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 — answerRecordedOperation answers a recorded id from the ledger row (a failed row 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. agentSessionLedgerRefusal de-dupes the refusal shape.
  • A send's success commits with its message — JournalOperationReceipt stages the ledger settlement inside the journal transaction and adopts it after COMMIT; sendPlan/conversationCommandPlan move from markUnknownBeforeRun to settlesWithWrite, so a send that threw before writing leaves a pending row that reruns on resend instead of a fabricated unknown.
  • /clear refuses only a first run — the controller passes arrival.clearInFlight; sendPreparation applies it only on the admit path, so a recorded id is answered behind the clear. sendPlan.replay now also reruns a pending row.
  • Capability — agent-session.send-answers-proof.v1 is 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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025
brennanb2025 merged commit b99d28e into main Oct 4, 2026
59 checks passed
brennanb2025 added a commit that referenced this pull request Oct 4, 2026
…-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.
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