Repository navigation
fix(mobile): retire a structured operation id the host has refused - #20868
Conversation
`agentSession.cancel` kept its client operation id whenever the outcome came back unknown. One of those unknowns is not transport doubt: when the host answers `agent_session_operation_unknown` it has decided about that id and will not run it again, because cancel's mutation plan recovers no unknown ledger row. Every later Stop on that turn re-sent the same refused id, so Stop stayed unusable until the row expired. The RPC layer collapsed both cases into a bare `unknown`, discarding the difference between "the effect is in doubt" and "the host answered about this id". It now reports the second case, and cancel spends the id there while still replaying under genuine transport doubt. `agentSession.conversationCommand` deliberately keeps its id: its plan sets `recoverUnknownFromDurableState`, so a reused id can still replay or rerun.
|
Run failed. View the logs →
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe RPC mutation result now marks Priority: ⬇️ Low Merge Risk: ⚪ Minimal · up to The cancellation retry behavior retires host-refused operation IDs and preserves transport-uncertain IDs as intended. No merge-blocking risk remains. 🚥 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 |
Mobile + Electron QA (PR worktree)Native iOS Simulator QA on iPhone 17 Pro / iOS 26.5 with Metro from this worktree, plus a background CDP launch of this branch ( What was exercised
What was not reproduced liveThe second-tap fix needs the host to settle cancel as Android was not booted ( ScreenshotsLoaded app: PR Electron instance (CDP, background): Paired Host 14 + this worktree: Grok composer on the PR worktree: Live turn with Stop: Screenshots were inspected for pairing codes / tokens / QR before attach. Not committed. |
Review status: cleanPR #20868 was reviewed against
Verdict: the code review is clean and the PR is ready to land once the failed |
…tablyai#20868) `agentSession.cancel` kept its client operation id whenever the outcome came back unknown. One of those unknowns is not transport doubt: when the host answers `agent_session_operation_unknown` it has decided about that id and will not run it again, because cancel's mutation plan recovers no unknown ledger row. Every later Stop on that turn re-sent the same refused id, so Stop stayed unusable until the row expired. The RPC layer collapsed both cases into a bare `unknown`, discarding the difference between "the effect is in doubt" and "the host answered about this id". It now reports the second case, and cancel spends the id there while still replaying under genuine transport doubt. `agentSession.conversationCommand` deliberately keeps its id: its plan sets `recoverUnknownFromDurableState`, so a reused id can still replay or rerun.






ELI5
On mobile, when Stop came back unconfirmed, pressing Stop again did nothing — and kept doing nothing for the rest of that turn. Orca was re-sending an identifier the host had already refused. It now reuses that identifier only when reusing it can actually help.
Before / After
The wording on screen does not change. What changes is what the second tap does.
Setup: the agent is working, you tap Stop, and the host's ledger row for that cancel settled
unknown.The banner holds about 4s and then clears; it falls back to a bottom toast when the composer is not on screen.
What Changed
requestStructuredAgentSessionMutationmapped the host refusalagent_session_operation_unknownonto a bare{ status: 'unknown' }— the same value it returns when the transport lost the reply. Those are two different facts:agent_session_operation_unknown— the host has answered about that id and will not run it againThe unknown result now carries
hostReportedOperationUnknown, andagentSession.cancelspends its id in that case. Transport doubt still retains it.Two production files and one new test. No wire change: this reads a refusal code the host already sends.
Why
Whether reusing an id helps is decided by that method's mutation plan.
resolveAgentSessionReplayOutcomerefuses a same-id retry against anunknownledger row unless the plan setsrecoverUnknownFromDurableStateorrerunWhenReplayMissing.cancelPlansets neither, so the refusal repeats for as long as the host's ledger row survives —agentSessionOperationExpiryputs that at roughly a day after admission, after which the same id is refused asagent_session_operation_expiredinstead, which is a settled answer and finally releases it. The retained id was a latch with nothing behind it re-deriving the truth, self-healing only after about 24h.Deliberately not changed, each checked rather than assumed:
agentSession.conversationCommandkeeps its id. Its plan does setrecoverUnknownFromDurableState, so a reused id can replay or rerun. I made the same change there, and the existing test pinning that behaviour caught it as a regression; it is reverted.use-mobile-structured-agent-session.tsis correct as written. Those plans recover nothing either, so keeping the id would strand the user. Rotating is safe there because prompt responses are guarded byexpectedRevision(agent_session_item_revision_stale) andsetOptionis idempotent by value.AgentSessionSendResultcarries asubmission, so there is no dispatch state for it to read.Linked Issue
STA-7472.
Scope note: that ticket's original P1 — mobile silently acknowledging an unknown send — shipped in #20133. This PR fixes a different and narrower defect found while auditing what remained, and the two other items listed on the ticket turn out not to be defects (see Why above). The ticket is worth re-scoping and re-prioritising rather than closing.
Visual Proof
No pixels change: the banner and its wording are identical before and after, so a screenshot pair would show the same image twice. The user-facing difference is behavioural and is tabulated under Before / After above.
Not run in the app — flagging that rather than claiming N/A. Reproducing it live requires the host to throw mid-cancel so the ledger row settles
unknown; the before/after above is derived from the cancel and replay paths, and is covered by tests rather than by a recording.Testing
pnpm --dir mobile exec vitest run src/session— 167 files / 1604 tests passEvery new test ablated at the final head:
both production files reverted to base: 2 of the 4 new tests fail, and the 2 guard arms still pass (so the file is not uniformly red)
only the cancel change reverted, keeping the RPC flag: 1 fails, 3 pass — the cancel change is independently load-bearing
I manually tested these changes locally — no; see Visual Proof
Automated tests added/updated
Notes
The host half of this mechanism was traced by reading the plan and replay code, not by running it. How often
performCancelactually throws is unmeasured, and that frequency is what decides this bug's real priority — it bounds how often a user meets a dead Stop.