Skip to content

fix(mobile): retire a structured operation id the host has refused - #20868

Merged
brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-mobile-stop-retires-refused-operation-id
Sep 15, 2026
Merged

brennanb2025 merged 1 commit into
mainfrom
brennanb2025/fix-mobile-stop-retires-refused-operation-id

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

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.

Before After
First Stop tap Banner above the composer: "Stop unconfirmed — check chat before retrying". The turn keeps running. Identical.
Tap Stop again The same banner. Orca re-sends the id the host already refused, so the host returns the same refusal — the turn cannot be stopped, and every later tap repeats it. The retry goes out under a fresh id, so the host admits it as a new cancel. The turn stops, or you get a real answer instead of the same refusal.
Getting Stop working again Wait for the turn to end on its own, or ~24h for the host's ledger row to expire. Not needed.
Separate case: the reply was lost in transit and the host never answered Retry reuses the id, so it stays a replay rather than a second cancel. Correct. Unchanged — still reuses the id.

The banner holds about 4s and then clears; it falls back to a bottom toast when the composer is not on screen.

What Changed

requestStructuredAgentSessionMutation mapped the host refusal agent_session_operation_unknown onto a bare { status: 'unknown' } — the same value it returns when the transport lost the reply. Those are two different facts:

  • transport doubt — the host may never have seen the request, so the id must be reused to keep the retry a replay
  • agent_session_operation_unknown — the host has answered about that id and will not run it again

The unknown result now carries hostReportedOperationUnknown, and agentSession.cancel spends 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. resolveAgentSessionReplayOutcome refuses a same-id retry against an unknown ledger row unless the plan sets recoverUnknownFromDurableState or rerunWhenReplayMissing. cancelPlan sets neither, so the refusal repeats for as long as the host's ledger row survives — agentSessionOperationExpiry puts that at roughly a day after admission, after which the same id is refused as agent_session_operation_expired instead, 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.conversationCommand keeps its id. Its plan does set recoverUnknownFromDurableState, 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.
  • The prompt/option rotation in use-mobile-structured-agent-session.ts is 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 by expectedRevision (agent_session_item_revision_stale) and setOption is idempotent by value.
  • The generic mutation mapper still reports any ok RPC as accepted. Only AgentSessionSendResult carries a submission, 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 pass
  • Mobile typecheck clean
  • Changed-code quality gate: 0 findings across all checks

Every 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 performCancel actually throws is unmeasured, and that frequency is what decides this bug's real priority — it bounds how often a user meets a dead Stop.

`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.
@pullfrog

pullfrog Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Run failed. View the logs →

Pullfrog  | Rerun failed job ➔ | View workflow run | via Pullfrog | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai

coderabbitai Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

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: f6748b0b-d519-4822-a72d-4eee34a7d212

📥 Commits

Reviewing files that changed from the base of the PR and between 9ab0a18 and de9a0d3.

📒 Files selected for processing (3)
  • mobile/src/session/mobile-structured-agent-session-cancel.ts
  • mobile/src/session/mobile-structured-agent-session-rpc.ts
  • mobile/src/session/mobile-structured-operation-id-retirement.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The RPC mutation result now marks agent_session_operation_unknown refusals with hostReportedOperationUnknown. Cancellation handling uses this distinction when updating operation IDs. Tests verify that host refusals use fresh IDs on subsequent cancels, while transport-level uncertainty replays the same ID and retains the ledger entry.

Priority: ⬇️ Low

Merge Risk: ⚪ Minimal · up to de9a0

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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly and concisely describes the main change: retiring a structured operation ID after the host refuses it.
Description check ✅ Passed The description is detailed and covers the problem, implementation, rationale, linked issue, visual behavior, testing, and scope. It does not use the exact N/A wording requested for Visual Proof and…
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

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.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

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 (ORCA_BACKGROUND_LAUNCH=1, port 9333). Identity: Orca: brennanb2025/fix-mobile-stop-retires-refused-operation-id.

What was exercised

  • Orca Mobile loaded (not Expo launcher / redbox).
  • Paired to the PR Electron instance; opened worktree #20868.
  • Started a Grok turn and captured the live Stop control in surrounding native UI.
  • mobile-structured-operation-id-retirement.test.ts: 4/4 passed.

What was not reproduced live

The second-tap fix needs the host to settle cancel as agent_session_operation_unknown. A healthy turn does not throw mid-cancel, so the "Stop unconfirmed" banner and fresh-id retry were not observed. That matches the PR Visual Proof note. Emulator Stop taps also did not land after the transcript filled the AX 500-node cap; Stop visibility is screenshot-proven, cancel success is not.

Android was not booted (adb not on PATH; no device attached).

Screenshots

Loaded app:

01-orca-mobile-loaded.png

PR Electron instance (CDP, background):

02-electron-pr-instance.png

Paired Host 14 + this worktree:

03-paired-host14-workspace.png

Grok composer on the PR worktree:

05-grok-composer-ready.png

Live turn with Stop:

06-grok-stop-visible.png

Screenshots were inspected for pairing codes / tokens / QR before attach. Not committed.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: clean

PR #20868 was reviewed against origin/main (62c5037). The same-model, high-effort adversarial review found no proven P0/P1/P2 issues, so no code changes or push were needed.

  • Readiness checklist passed at both the start and end with zero findings.
  • Validation passed: 5,096 mobile tests (6 skipped), focused retirement tests (4/4), mobile typecheck, mobile lint, changed-code quality, and git diff --check.
  • Native QA ran on an iPhone 17 Pro / iOS 26.5 with Metro from this branch. The PR Electron worktree was launched in the background with CDP identity verification, paired to the simulator, and the running native Stop control was captured. Screenshot and QA evidence.
  • The host-refused agent_session_operation_unknown second-tap path was not reproduced live because a healthy cancel does not throw mid-ledger; the emulator accessibility tree also capped out before a reliable Stop tap. The four new tests cover the fresh-id versus transport-doubt behavior, and this gap is documented in the QA comment.
  • The pullfrog check is red because its reviewer timed out after one hour; this is an external review timeout, not a product test failure. The other code-relevant checks are green or correctly skipped.

Verdict: the code review is clean and the PR is ready to land once the failed pullfrog check is rerun or explicitly waived.

@brennanb2025
brennanb2025 merged commit e7206f6 into main Sep 15, 2026
22 of 23 checks passed
ivanvykopal pushed a commit to ivanvykopal/orca that referenced this pull request Sep 20, 2026
…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.
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