Repository navigation
fix(native-chat): record a failed restart in the chat where the restart happens - #22742
brennanb2025 wants to merge 2 commits into
Conversation
…rt happens A restart that failed reached the chat only when a send asked for it. A pane coming into view (the hold) or provider-exit recovery that met the same failure only logged it, the hold RPC answered with the bare refusal code, and mobile never loaded the chat's history after a refused hold. The failure row is now written by the resume every asker shares, once per attempt, with tone 'error'; the send-only copy is deleted. The hold RPC carries the refusal's own message next to its code, mobile subscribes even when the hold is refused, and startup-failure rows carry the error tone too. A pane coming into view no longer respawns a chat whose last start failed, the rule provider-exit recovery already follows: the chat says why, and the next send retries. Without it every remount spawned a doomed child and wrote a row.
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughResume refusals are classified and recorded as error-status rows when applicable. Holds can avoid retrying a failed start, while sends use the shared refusal classification. The hold RPC preserves refusal messages and codes. The mobile hook continues subscription setup after a hold rejection and displays error status from session snapshots. Priority: ➖ Normal Merge Risk: 🔵 Low · up to Mobile can show a session as ready after a hold fails for an unexpected reason. Surface those failures; this is a bounded issue that does not prevent an explicit restart retry. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description provides detailed ELI5, change, rationale, testing, visual proof, compatibility, and checklist information. However, it does not provide the required linked issue; it explicitly states that no tracking issue exists despite the template requiring one.
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
…oes not restart it The row writer a failed start and a failed restart share also leaves the host session reading as one whose last child never finished starting, so a pane coming into view does not start a chat whose create or restart failed, and a chat this host cannot run says so once rather than once per view.
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 85155f74-4142-418a-bcac-5dfd12f02650
📒 Files selected for processing (19)
mobile/src/session/use-mobile-structured-agent-state-hold-refused.test.tsxmobile/src/session/use-mobile-structured-agent-state.tssrc/main/native-chat/agent-session-wire/structured-agent-session-dead-generation-settlement.tssrc/main/native-chat/agent-session-wire/structured-agent-session-hold-resume-race.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-hold-resume.tssrc/main/native-chat/agent-session-wire/structured-agent-session-holds.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-holds.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host-lifetime.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host.tssrc/main/native-chat/agent-session-wire/structured-agent-session-restart-failure-filing.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-resume-failure-row.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-resume-refusal.tssrc/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-send-preparation.tssrc/main/native-chat/agent-session-wire/structured-agent-session-start-failure-row.tssrc/main/native-chat/agent-session-wire/structured-agent-session-startup-failure-exit.test.tssrc/main/runtime/rpc/errors.tssrc/main/runtime/rpc/methods/structured-agent-session-hold.test.tssrc/main/runtime/rpc/methods/structured-agent-session-hold.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 2 remain after this review.
| // A refused hold still leaves the chat readable, and the host writes a real failure into it; | ||
| // a send restarts the agent itself. | ||
| const readable = held.catch((error: unknown) => { | ||
| console.warn('[structured-agent-session] hold failed:', error) | ||
| }) | ||
| void readable |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
sed -n '50,210p' mobile/src/session/use-mobile-structured-agent-state.ts
sed -n '1,130p' mobile/src/session/use-mobile-structured-agent-state-hold-refused.test.tsxRepository: stablyai/orca
Length of output: 8538
🏁 Script executed:
set -eu
printf '%s\n' '--- changed hunk ---'
git diff --unified=35 29480cd8cd35a1cf12f36bf056a7e280670c8c52 de715cc78003b6022eb9b537c60a2fd5a5c96c34 -- mobile/src/session/use-mobile-structured-agent-state.ts
printf '%s\n' '--- hook imports and definitions ---'
sed -n '1,125p' mobile/src/session/use-mobile-structured-agent-state.ts
printf '%s\n' '--- bound callAgentSession definitions/usages ---'
rg -n --glob '!node_modules' 'callAgentSession|agentSession\.hold|type .*AgentSession.*Action|reduceStructuredAgentSession' mobile src
printf '%s\n' '--- hook consumers and tests ---'
rg -n --glob '!node_modules' 'useMobileStructuredAgentState|status: .ready|status === .ready|state\.status' mobile/src mobile | head -240Repository: stablyai/orca
Length of output: 41107
🤖 get_repo_knowledge executed:
get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions
Length of output: 34460
🏁 Script executed:
set -eu
git diff --unified=35 29480cd8cd35a1cf12f36bf056a7e280670c8c52 de715cc78003b6022eb9b537c60a2fd5a5c96c34 -- mobile/src/session/use-mobile-structured-agent-state.ts
sed -n '1,125p' mobile/src/session/use-mobile-structured-agent-state.ts
rg -n --glob '!node_modules' 'callAgentSession|agentSession\.hold|reduceStructuredAgentSession|useMobileStructuredAgentState' mobile srcRepository: stablyai/orca
Length of output: 22744
🏁 Script executed:
set -eu
printf '%s\n' '--- hook imports and changed area ---'
sed -n '1,145p' mobile/src/session/use-mobile-structured-agent-state.ts
printf '%s\n' '--- exact helper and reducer references ---'
rg -n -C 5 --glob '!node_modules' 'callAgentSession|reduceStructuredAgentSession|agentSession\.hold' .
printf '%s\n' '--- base versus head changed behavior ---'
git diff --unified=20 29480cd8cd35a1cf12f36bf056a7e280670c8c52 de715cc78003b6022eb9b537c60a2fd5a5c96c34 -- mobile/src/session/use-mobile-structured-agent-state.tsRepository: stablyai/orca
Length of output: 41314
🏁 Script executed:
set -eu
printf '%s\n' '--- mobile RPC helper ---'
sed -n '1,180p' mobile/src/session/mobile-structured-agent-session-rpc.ts
printf '%s\n' '--- reducer definition and transitions ---'
sed -n '1,245p' src/shared/structured-agent-session-reducer.ts
printf '%s\n' '--- mobile session consumer ---'
sed -n '1,330p' mobile/src/session/use-mobile-structured-agent-session.ts
printf '%s\n' '--- relevant mobile hook/session tests ---'
sed -n '270,380p' mobile/src/session/use-mobile-structured-agent-session.test.tsx
sed -n '730,810p' mobile/src/session/use-mobile-structured-agent-session.test.tsx
printf '%s\n' '--- renderer comparable hold implementation/tests ---'
sed -n '1,180p' src/renderer/src/components/native-chat/use-structured-agent-session-hold.ts
sed -n '1,165p' src/renderer/src/components/native-chat/use-structured-agent-session-hold.test.tsx
printf '%s\n' '--- host hold handler ---'
sed -n '30,115p' src/main/runtime/rpc/methods/structured-agent-session-hold.tsRepository: stablyai/orca
Length of output: 42333
Surface non-refusal hold failures.
callAgentSession rejects for every unsuccessful RPC response, including authorization failures, and transport failures also reject. The new catch treats all of these failures as an intentional refusal, then starts agentSession.subscribe. If the subscription returns a snapshot, replacePage sets the state to ready without an error. The mobile consumer then exposes a ready session even though agentSession.hold failed.
Keep the read-only recovery for the host's hold-refusal code, but rethrow other hold errors so the existing error handler applies.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- One writer for the failed-restart row.
resumeHeldStructuredAgentSessionnow calls the newrecordFailedStructuredAgentSessionResumefor any non-transient refusal, so a surface hold, a send and provider-exit recovery all write the sametone: 'error'row; the send-onlyrecordFailedRestartis deleted. - Refusal classification extracted.
RESUME_REFUSAL_OUTCOMEmoves fromstructured-agent-session-send-preparation.tsintostructured-agent-session-resume-refusal.tsasstructuredAgentSessionResumeRefusalOutcome. - View holds stop respawning a failed start. New
lastStartFaileddep (hasProviderChild === false && providerChildPhase === 'starting') plus aresumeFailedStart: falsehold option suppress the resume for a surface coming into view;agentSession.holdopts in while sends, restart-dialog retries, recovery and workers keep restarting. - Typed hold refusal + real message on the wire.
StructuredAgentSessionHoldRefusedErrorcarries the refusal; the hold RPC rethrows{ code, message: refusal.message }, andAGENT_SESSION_WIRE_REFUSAL_CODESjoinsSTRUCTURED_RUNTIME_PASSTHROUGH_CODESsomapRuntimeErrorpreserves the code. - Startup-failure rows get
tone: 'error'in the dead-generation settlement. - Mobile subscribes after a refused hold, so the chat history with the failure row always loads.
- Tests: new host-level
structured-agent-session-resume-failure-row.test.ts, new mobileuse-mobile-structured-agent-state-hold-refused.test.tsx, plus updated expectations for per-attempt rows and the error tone.
I traced every writer of hasProviderChild / providerChildPhase and the row-writer call graph. lastStartFailed is true only for a childless failed start, so a view hold is suppressed exactly where intended and reopened/evicted sessions still resume on view; the two error-row writers are mutually exclusive, so no duplicate rows; and the failure row survives mapRuntimeError's structured branch as asserted. The tests assert exact row bodies and item counts, and the RPC test pins the exact { code, message }, so they would fail if the behavior regressed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — delta since the prior review at e52e990 (commit de715cc):
- Extracted start-failure writer. The row/publish logic moved out of
recordFailedStructuredAgentSessionResumeinto newrecordStructuredAgentSessionStartFailure(structured-agent-session-start-failure-row.ts);recordFailedStructuredAgentSessionResumenow delegates to it. - Marker broadened. The writer now sets
providerChildPhase = 'starting'whenever the session has no provider child, rather than only whenownerVerdict === 'exited'. This closes the earlier gap where a non-transient refusal with an unverifiable verdict would write a row but leave a view hold free to retry on every mount. Row text selection still keys onownerVerdict === 'exited'. - Two new host tests. A chat whose create made the conversation but not its agent is not started by the pane that opens it (the first send starts it, and exactly one error row is delivered); a chat this host cannot run says so once, not once per view.
The broadened condition is sound: recordFailedStructuredAgentSessionResume still returns early for transient refusals and for a missing record, and the resume only runs when ensureProviderChild saw no child, so !hasProviderChild is the state the marker describes. The new tests assert exact row bodies and per-view spawn counts, so they would fail if the marker regressed.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

ELI5
When a chat's agent could not restart (for example, Claude is not signed in), you only saw why if you had just sent a message. Opening or switching to the chat tried the restart too, but a failure there was silent on desktop, showed a bare error code on the phone, and stopped the phone from loading the chat at all. Now every failed restart is written into the chat as one red error line with the real reason, whoever triggered it, and simply looking at the chat again no longer keeps retrying a start that already failed.
What Changed
Before
agent_session_operation_invalid) instead of the reason.After
tone: 'error'. The send-only copy is deleted. The status row a start leaves when its process dies after it was published (the startup-failure row) also getstone: 'error'.Mechanism
resumeHeldStructuredAgentSession(the shared resume behindensureProviderChild) now calls one writer,recordFailedStructuredAgentSessionResume, for any refusal that proves the chat cannot run right now. It makes the journal readable if the failed attach left none and publishes the row to subscribers. Refusals that only mean someone else is still settling the lease write nothing, same as before. The refusal classification moved with it from send preparation intostructured-agent-session-resume-refusal.ts.starting. A child that dies after it was published leaves exactly that state already. For a child that dies before it was published, the writer sets that phase on the session it made readable. Only the hold RPC (a surface coming into view) opts into the rule, through a newresumeFailedStart: falsehold option. Sends, restart-dialog retries and structured workers keep restarting.holds.holdthrows a typedStructuredAgentSessionHoldRefusedError. Its message is still the code, which is what the in-process restart ledger reads. The hold RPC handler maps it to{ code, message: refusal.message }, andmapRuntimeErrorpasses the agent-session refusal codes through with their message.Why
toneis an existing optional status field. The schema already admits it, the projection already passes it through, and the desktop renderer already drawserror. So this is a new value of a field older clients already handle, not a new row kind. A client that ignorestonestill shows the text.Differences from the common pattern
tone: 'error'. No field records the failure kind, and there is no separate session-level "last error". The in-memory host session's child phase stands in for that during the process lifetime.Linked Issue
No tracking issue. Out of scope, as follow-up context: Linear STA-8084 (provider "retrying" frames).
Visual Proof
N/A. No screenshots were captured for this change. The only visual change is that these rows use the existing error treatment in
NativeChatNoticeRow, which its current tests already cover. The behavior is covered by the host and wire tests below.Testing
I manually tested these changes locally
Automated tests added/updated, or explained why not below
New
structured-agent-session-resume-failure-row.test.ts, against the real host and record store:tone: 'error'row with the real reason to a subscriber.structured-agent-session-hold.test.ts(over the RPC dispatcher):{ code, message: <real reason> }.Updated tests:
tone: 'error'.Each new assertion was checked by deleting the core lines and seeing it fail for the stated reason, then restoring.
Mobile: new
use-mobile-structured-agent-state-hold-refused.test.tsxchecks that a refused hold still subscribes and shows the chat. It was not run locally because the mobile suite needs Expo installed. CI covers it.Local runs on macOS:
src/main/native-chat,src/main/runtime/rpc, the Claude structured runtime tests,src/sharedand the native-chat renderer tests all pass. The one exception isclaude-structured-real-cli/claude-tui-resume-real-binary, which already fail locally on main.AI Disclosure
Review
Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Author X handle: @BrennanKB5
Remote and version compatibility. Clients and hosts update independently, so here is what each mix does.
toneis an existing optional field. A new value reaches older clients, which render the text as before.structured_agent_session_unsupported) now arrive under their own code instead ofruntime_error.SSH and folder workspaces. All of this runs on the execution host that owns the session, so SSH-hosted chats behave the same. Nothing here depends on git.
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)