Repository navigation
fix(native-chat): an unfinished tool call too big for one cleanup write no longer breaks a chat for good - #26576
brennanb2025 wants to merge 3 commits into
Conversation
…esuming a chat's agent Starting or resuming a chat's agent ran cleanup of turns left over from a previous run with no error handling, so a failed cleanup write failed the user's start. The cleanup is now best effort: its failure is logged and retried on a later start, and the start proceeds. Co-Authored-By: OpenAI Codex gpt-6.1-sol <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
…te no longer stops a chat starting, reopening or settling after exit When an agent dies mid-turn, Orca rewrites what it left running (its turn, open tool calls, pending prompts) in batch rows capped at 1.5 MB. A single leftover item larger than that, such as a tool call whose whole input was journaled, could never fit, so the cleanup failed on every attempt: the start or resume failed, a reopened chat kept the dead turn running (sends queued behind it forever), and the exit cleanup gave up. The settle now writes such an item as an ordinary item revision, the same row kind the live session wrote it with, so the cleanup always lands. The attach-time cleanup fails the start again when it cannot be written (as before this branch), instead of leaving the dead turn running behind a started agent.
Review summaryThe problem. When a chat's agent stops in the middle of a step, Orca marks whatever it left running as interrupted. That covers the turn, any open tool calls, and pending approvals. These marks are saved in groups capped at 1.5 MB. A single leftover item over that cap can never be saved, so the cleanup failed on every attempt and the chat stayed stuck for good:
What changes for the user. That chat now reopens with the old step shown as interrupted and the approval shown as cancelled. The composer is back, and the next message goes straight to the agent. This is rare today, because no agent normally writes an item that large. A Claude tool input tops out around 0.4–0.7 MB under its output cap. But if it ever happens, main never recovers. How the design changed during review. The first version of this PR let a chat's start continue when the cleanup failed. Review showed that this traded a visible, retryable failure for a silent one. The dead turn stayed "working", so new messages queued behind it forever, and nothing would ever clear it. The PR now fixes why the cleanup fails instead.
Fixed in review
Deferred (follow-ups, none needed for this fix)
Refuted: a suspected 17-byte gap in the group size estimate. The estimate sizes every number at maximum width, which leaves at least 36 bytes spare. What was verified
Not verified
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (8)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review. 📝 WalkthroughWalkthroughRecovered journal settlement now checks whether a single mutation fits within a recovered lifecycle batch. It writes an oversized single-item mutation with Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The oversized cleanup case can settle without leaving the chat stuck. No identified issue prevents merging after normal checks. 🚥 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 |
|
Closing as superseded: a merged PR already covers this change. Merged #26664 (ded0144) says 'Supersedes #26576'. It commits a dead generation's settlement in one transaction, with an oversize item written as an ordinary row with its full body. That is the same failure, (Stale-PR cleanup 2026-10-20, approved by Brennan. Reopen if something here is still missing on main.) |
ELI5
What you saw: a chat whose agent quit in the middle of a step could become stuck for good. On reopening, it showed "Working for 3m 23s" above "Orca on Local Mac stopped unexpectedly while this response was in progress." and kept counting. Sometimes the old approval card ("Allow the tool?") took the composer's place, so there was nowhere to type. Otherwise, every message failed with "Your message was not sent." and "OMP couldn't restart. Send your message to try again.", and retrying never helped. Restarting Orca didn't help either.
Why: when an agent quits mid-step, Orca later marks what it left unfinished as interrupted. It saves those marks in groups, and a group can hold at most 1.5 MB. If one unfinished item is bigger than that (for example a tool call with a huge input), the marks can never be saved, and the chat stays half-cleaned forever.
Now: a too-big item is saved on its own, the way it was first saved, so the cleanup always finishes. The same chat reopens with the old step shown as "Edited 1 file · 1 interrupted", the approval as "Cancelled", the composer available, and the next message goes straight to the agent.
This is a defensive fix for a rare case. No agent produces an item that size in normal use today: a Claude tool input is limited by its 128k-token output cap to roughly 0.4–0.7 MB. Reaching 1.5 MB would take unusual content or a higher future cap. If it does happen, though, main never recovers, which is why it is worth closing.
What Changed
Before: when an agent stopped mid-turn (Orca restarted, the agent crashed or exited), Orca rewrote what it had left running: the turn, open tool calls, pending approvals and questions. These rewrites go into journal "lifecycle batch" rows, and each row is capped at 1.5 MB. A single leftover item over the cap could not fit any row, so this cleanup failed on every attempt, in each of the three places it runs:
After: all three cleanups go through one shared writer (
appendSettlementMutationsinstructured-agent-session-dead-generation-settlement.ts). It splits the rewrites into batch rows as before. When one item is too large for any batch row, it is written as an ordinary item row instead, the same kind of row the live agent used to write that item in the first place. So the cleanup stores nothing larger than the journal already holds, and it always lands:The size check is a small exported predicate in
journal-lifecycle-batch-partition.ts. It reuses the partitioner's own size and version accounting, and the partitioning result is unchanged.A genuine storage failure (disk full, the database locked by another process) still fails the start, as on main. In that case the start's own essential writes would fail too. Failing visibly, so the user can retry, is better than starting with the old turn stuck as "working" behind the new agent.
Why
The 1.5 MB cap exists because a batch row can hold up to 200 changes. Item rows have no such cap, and the oversized body was already written once as an item row while the agent was live. Writing its final state the same way closes the gap instead of adding a second guard.
Alternatives considered:
The common pattern also settles a dead session's unfinished work before new work starts, and fails closed when it cannot. This change keeps that ordering and that failure policy.
Linked Issue
Found by review of the native-chat "bookkeeping must never block the user" work (#26554). No separate issue.
Visual Proof
Before (base e3639ef), the chat reopened with an approval left over: stuck "Working", no composer

Before, with no approval left over: every send fails with "OMP couldn't restart"

After (this PR), the same chat reopened: old step interrupted, approval cancelled, composer back

After: a new message is sent and answered

After: still fine after quitting and relaunching Orca, and a third message is answered

Testing
On macOS, using real temporary SQLite journals with a scripted agent:
The first three fail on main with
journal_lifecycle_batch_byte_bound_exceeded(or with the old turn left running) and pass here. The related restart, reopen and exit suites pass too.Also run: Node typecheck, and
orca-ci-checks(lint, code quality, localization, guards).Manual QA in the Electron app on macOS, using hidden test windows, isolated test profiles and an OpenAI-compatible stand-in model (no credentials). The setup:
Writetool call with a ~1.6 MB input. Some runs also had a pending approval.What happened:
journal_lifecycle_batch_byte_bound_exceeded.Not exercised by hand:
AI Disclosure
Review
See the review summary comment.
Agent skill upstream boundary
Notes
Follow-ups, not in this PR:
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)