Skip to content

fix(native-chat): make prompt cancellation recoverable - #20339

Closed
brennanb2025 wants to merge 9 commits into
brennanb2025/native-chat-hide-working-uifrom
brennanb2025/native-chat-hide-working
Closed

brennanb2025 wants to merge 9 commits into
brennanb2025/native-chat-hide-working-uifrom
brennanb2025/native-chat-hide-working

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 33 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2444 $\color{#cf222e}{\Huge{\mathbf{−}}}$​178 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2266
Prod 65 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​2285 $\color{#cf222e}{\Huge{\mathbf{−}}}$​428 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1857

Summary

Stacked on #20496, this PR keeps structured prompt cancellation correct after the foreground UI state has disappeared.

It moves cancellation ownership to the execution host and provider adapters, carries exact session/thread/turn/item/revision identity, persists provider-confirmation receipts before revision-aware journal settlement, and adds capability-gated transport plus bounded mobile recovery. This preserves cancellation across reconnects/process interruption and prevents stale retries from settling a newer prompt.

Scope

This PR intentionally contains the reliability/infrastructure half of the change. The presentation-only activity-row suppression is in #20496.

Validation

  • Desktop/host, wire, journal, provider, renderer, and mobile regression coverage passed
  • Typechecks and changed-code quality checks passed
  • CI passed static analysis, typecheck, cross-version wire compatibility, mobile verify, macOS/Windows packaging, all test shards, and aggregate verify
  • Exact-head Electron QA covered real Claude cancellation/recovery, Codex question continuation, and Grok legacy question continuation

Remaining evidence gaps

Live SSH/relay disconnect injection, physical-device battery measurement, separate Codex prompt cancellation, and a permission-gated approval card remain unexercised scenarios; no proven defects were found.

@coderabbitai

coderabbitai Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 61b3b0c5-16ee-40e4-880c-c3e009a72235

📥 Commits

Reviewing files that changed from the base of the PR and between 8749513 and cd149a2.

📒 Files selected for processing (1)
  • src/main/native-chat/agent-session-wire/structured-conversation-command.test.ts

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


📝 Walkthrough

Walkthrough

The change adds structured prompt cancellation across native chat, runtime capabilities, Claude, Codex, and journal layers. Pending prompts can be cancelled by item ID and revision when supported. Turn-only cancellation remains available as a fallback. Provider adapters preserve settlement metadata and recover interrupted cancellations. Journal writes support bounded lifecycle batches, replay-safe settlement, stale-prompt cleanup, and cancellation receipts. Native chat hides generic live activity while a prompt card is pending.

Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to cd149

The test correction is safe, but unresolved approval-cancellation and durable-settlement issues still pose material risks to cancellation behavior and resource usage. Resolve them before merging.

🚥 Pre-merge checks | ✅ 1 | ❌ 4

❌ Failed checks (4 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 15.07% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 73 functions across 76 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The description explains the implementation and validation, but it omits most required template sections, including ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing checkboxes, Notes, and … Use the repository template. Add the required sections, include a linked issue in the required format, provide visual proof or state N/A with a reason, and complete the testing and checklist items.
Linked Issues check ⚠️ Warning The description references #20496 as a stacked pull request, but it does not provide the required linked issue entry or identify the issue this pull request fixes. Add the applicable linked issue using the required Linked Issue section and format, such as Fixes #12345``.
Out of Scope Changes check ⚠️ Warning The description states that presentation-only activity-row suppression is in #20496, but the changeset includes activity suppression in mobile, renderer, and session components. Move the presentation-only activity suppression changes to #20496, or update the scope and description to explain why those changes belong in this pull request.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: making native-chat prompt cancellation recoverable.
Full details: Description check

Explanation

The description explains the implementation and validation, but it omits most required template sections, including ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing checkboxes, Notes, and Checklist.

  • 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.

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)
src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx (1)

387-387: 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Keep cancellation reachable for pending approvals.

When prompt.body.kind === 'approval', NativeChatStructuredSession unmounts NativeChatComposer and passes only onChoose to NativeChatApprovalCard. Choosing an approval option calls respondToApproval, not controller.cancel, which maps to agentSession.cancel. Add an approval cancel action or retain an accessible stop control.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: e24f707f-0c5e-4c70-b23f-a224b16a14a1

📥 Commits

Reviewing files that changed from the base of the PR and between ef6eeab and 8762468.

📒 Files selected for processing (8)
  • mobile/src/session/MobileNativeChatView.test.ts
  • mobile/src/session/MobileNativeChatView.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageList.tsx
  • src/renderer/src/components/native-chat/NativeChatMessageList.turn-indicator.test.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session.test.tsx

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

@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

  • Desktop foreground-activity gate — NativeChatMessageList gains showLiveTurnActivity (default true) that gates only the NativeChatTurnActivityLine; NativeChatStructuredSession passes prompt === null, so the pending interaction owns the foreground while the turn row (activeTurnIsWorking) and live tool rows stay live.
  • Mobile parity — MobileNativeChatView computes hasPendingStructuredInteraction and gates only the ListFooterComponent turn status; Stop, per-turn working state, and background-task status are untouched.
  • Regression coverage — desktop tests for pending question/approval driving showLiveTurnActivity and preserving cancel/background work, plus a NativeChatMessageList test proving the live tool row survives suppression; mobile tests for both prompt kinds and restoration once the prompt clears. All assertions are exact and fail against the pre-change behavior.

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

@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 (since prior review)

  • Approval-card cancellation — NativeChatApprovalCard gains an optional onCancel rendered as an icon X button, with the title column switched to flex-1 so it stays clear of the button. NativeChatStructuredSession wires it to controller.cancel(controller.turnId), restoring a cancel affordance for the approval state where the composer — and its Stop button — is hidden.
  • Coverage — new NativeChatApprovalCard.test.tsx asserts the button invokes onCancel, and the structured-session approval test now drives onCancel through to controller.cancel('turn-approval').
  • Scoping — onCancel is optional, so the legacy NativeChatInteractiveCard render path keeps its current behavior. pnpm tc:web and mobile pnpm typecheck pass; desktop suite is 45 tests, mobile 19.

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c21b6080-d30d-46d2-a60b-b17e4dffa58b

📥 Commits

Reviewing files that changed from the base of the PR and between 8762468 and 9497661.

📒 Files selected for processing (4)
  • src/renderer/src/components/native-chat/NativeChatApprovalCard.test.tsx
  • src/renderer/src/components/native-chat/NativeChatApprovalCard.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx

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

Comment on lines +249 to +253
onCancel={() => {
if (controller.turnId) {
void controller.cancel(controller.turnId)
}
}}

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

Cancel the approval’s owning turn instead of gating on controller.turnId. The UI renders every pending approval, but controller.turnId becomes null when the journal has no running turn record. In that state, clicking the cancel control issues no agentSession.cancel request, so the pending provider turn can remain active. Resolve the approval item’s owning turn and pass that ID to controller.cancel.

@brennanb2025

brennanb2025 commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor Author

QA evidence (desktop Electron + iOS Simulator)

Hidden Electron identity: Orca: brennanb2025/qa-pr20339-grok (isDev: true, worktree /Users/brennanbenson/orca/workspaces/orca/qa-pr20339-grok, HEAD 9497661e81c077a1b3b84ff556e47205d33347ee). CDP 127.0.0.1:9333, ORCA_BACKGROUND_LAUNCH=1. Real Claude and Codex structured chats were launched from the New tab menu (Chat UI enabled). No source committed.

Claude (AskUserQuestion) — pass for pending-question ownership:

  • While the question card was pending, generic Working/Thinking + timer/spinner were absent; the live Running AskUserQuestion tool row stayed; Cancel (X) was present and the options were actionable.
  • Answering Tea resolved the prompt (Resolved · Answered on desktop-renderer). A second question (Red/Blue) was answered while instructing the same turn to continue; the turn kept going (count 1–8, TURN_STILL_ACTIVE) then settled as Worked for 30s. Live Working after answer was too fast to screenshot.

Claude pending question owns composer; no Working/Thinking

Claude second pending question still hides Working

Claude first question resolved after Tea

Claude second turn continued after answer then settled

Codex (request_user_input) — structured-question card not elicited:

  • Two genuine prompts asked Codex to use its native user-input/question tool. Codex replied that the input tool is unavailable in this structured-chat mode. A later file-write ran without an approval card (auto-allowed). Pending-question Stop/Cancel therefore could not be exercised on Codex.

Codex structured chat: question tool unavailable; no approval card

Gaps

  • Codex pending structured question / Cancel-while-pending: not exercised (tool unavailable in structured mode).
  • Approval card + distinct Cancel: not elicited (Claude was not asked to hit a permission gate; Codex writes auto-allowed).
  • Live Working row immediately after a still-active answer: not captured (remaining work finished in ~2s).
  • Native iOS: blocked. iPhone 17 Pro (iOS 26.5) + this worktree Metro (8084) loaded the installed com.stably.orca.mobile dev client and redboxed: Cannot find native module 'OrcaNotificationDismissal'. Did not substitute Expo web / Electron / mocks.

iOS Simulator redbox: missing OrcaNotificationDismissal

Codex Plan-mode follow-up (one additional UI attempt): the native-chat Codex composer exposed only Model and Effort. No Plan/Mode picker was present. Typing /plan opened skill autocomplete, not a Plan-mode command. The session also showed Provider exited: recorded pid absent on host. request_user_input remains unavailable in this structured Default-mode session.

@coderabbitai coderabbitai 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.

Actionable comments posted: 3


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: c075d327-3d99-454e-b2bd-ea64ba2b366d

📥 Commits

Reviewing files that changed from the base of the PR and between 9497661 and a2ee201.

📒 Files selected for processing (63)
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/session/mobile-structured-agent-session-test-fixtures.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-native-chat-session-lane.ts
  • mobile/src/session/use-mobile-session-native-chat-dictation.ts
  • mobile/src/session/use-mobile-structured-agent-session-cancel.ts
  • mobile/src/session/use-mobile-structured-agent-session.test.tsx
  • mobile/src/session/use-mobile-structured-agent-session.ts
  • mobile/src/transport/host-status-gates.ts
  • mobile/src/transport/runtime-capability-probe.test.ts
  • mobile/src/transport/runtime-capability-probe.ts
  • src/main/claude/claude-host-prompt-cancellation.ts
  • src/main/claude/claude-structured-control-actions.test.ts
  • src/main/claude/claude-structured-inbound-control.test.ts
  • src/main/claude/claude-structured-inbound-control.ts
  • src/main/claude/claude-structured-prompt-replies.ts
  • src/main/claude/claude-structured-prompt-types.ts
  • src/main/claude/claude-structured-session-acquisition.ts
  • src/main/claude/claude-structured-session-adapter-turns.test.ts
  • src/main/claude/claude-structured-session-adapter.ts
  • src/main/claude/claude-structured-session-cancel.ts
  • src/main/codex/codex-persistent-command-retention.test.ts
  • src/main/codex/codex-structured-journal-contracts.ts
  • src/main/codex/codex-structured-journal-prompts.ts
  • src/main/codex/codex-structured-journal-settlement.ts
  • src/main/codex/codex-structured-journal-sink.ts
  • src/main/codex/codex-structured-journal-translation-settlement.test.ts
  • src/main/codex/codex-structured-journal-translation-turn-boundaries.ts
  • src/main/codex/codex-structured-journal-translation.ts
  • src/main/codex/codex-structured-prompt-replies.test.ts
  • src/main/codex/codex-structured-prompt-replies.ts
  • src/main/codex/codex-structured-prompt-turn-settlement.ts
  • src/main/codex/codex-structured-session-acquire.ts
  • src/main/codex/codex-structured-session-adapter.ts
  • src/main/codex/codex-structured-session-cancel.test.ts
  • src/main/native-chat/agent-session-journal/journal-prompt-cancellation.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-adapter-router.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter-router.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-mutation-plans.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-prompt-cancellation.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-stale-turn-verdict.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-stale-turn-verdict.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-turns.ts
  • src/main/runtime/rpc/methods/structured-agent-session.test.ts
  • src/renderer/src/components/native-chat/NativeChatApprovalCard.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSession.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session-mutate.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-prompt-cancel.test.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session.test.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session.ts
  • src/renderer/src/runtime/structured-agent-session-client.test.ts
  • src/renderer/src/runtime/structured-agent-session-client.ts
  • src/shared/agent-session-operation-ledger.ts
  • src/shared/protocol-version.ts
  • src/shared/rpc-contract/structured-agent-session-params.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/renderer/src/components/native-chat/NativeChatApprovalCard.tsx

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

Comment on lines +242 to +244
if (prompt.turnId === null && turnId && prompt.threadId === threadId) {
prompt.turnId = turnId
}

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.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Preserve the registry byte limit when backfilling turnId.

register checks promptBytes while turnId can still be null. This mutation can later attach a large translator-supplied turnId without rechecking MAX_CODEX_PROMPT_REGISTRY_BYTES.

Repeated fallback bindings can make retained memory exceed the registry limit. Check the added byte count before assigning prompt.turnId. Leave the turn identity unset when the value exceeds the limit.

Proposed fix
     if (prompt.turnId === null && turnId && prompt.threadId === threadId) {
-      prompt.turnId = turnId
+      const addedBytes = Buffer.byteLength(turnId, 'utf8')
+      if (this.retainedPromptBytes() + addedBytes <= MAX_CODEX_PROMPT_REGISTRY_BYTES) {
+        prompt.turnId = turnId
+      }
     }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (prompt.turnId === null && turnId && prompt.threadId === threadId) {
prompt.turnId = turnId
}
if (prompt.turnId === null && turnId && prompt.threadId === threadId) {
const addedBytes = Buffer.byteLength(turnId, 'utf8')
if (this.retainedPromptBytes() + addedBytes <= MAX_CODEX_PROMPT_REGISTRY_BYTES) {
prompt.turnId = turnId
}
}

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

Important

The new Codex turn-completion collector re-settles prompts that an explicit cancel already terminalized, dropping the caller attribution (resolvedBy/resolvedAt) on the durable row and potentially flipping a provider-resolved prompt to cancelled.

Reviewed changes

  • Prompt CAS target on agentSession.cancel — the cancel schema gains an optional prompt: {itemId, expectedRevision} (and turnId becomes optional when a prompt identifies the turn), with a new agent-session.prompt-cancel.v1 capability advertised without a protocol bump.
  • Host prompt settlement — performCancel resolves the prompt group, interrupts the owning turn, then CAS-revises each still-pending row to cancelled with the caller's attribution; settledOutcome/recoverUnknownFromDurableState make a confirmed cancellation survive a lost status write.
  • Claude cancellation — ClaudeHostPromptCancellation suppresses the provider prompt-cancelled event on a confirmed interrupt and keeps it as the fallback when the provider refuses; traced with no double-emit and no pending-after-confirmed interleaving.
  • Codex cancellation — prompts bind to their owning provider turn; collectCodexTurnPromptCancellations terminalizes them on turn/completed, and the adapter maps the logical turn to the provider child via compactions.providerTurnId.
  • Client gating — desktop probes the capability with a pinned pairing revision and targets the displayed prompt revision; mobile gates on host capabilities and threads the result through the structured session.

ℹ️ Mobile host gate no longer fails open on a refused status.get

useHostStatusGates used to settle with empty capabilities on a failed status.get, which cleared statusPending and let HostProtocolGate render the host with conservative feature gates. The shared startRuntimeStatusProbe now retries on failure and never calls back, so a first-load permanent failure holds the whole host tree behind the compatibility spinner rather than failing open. If the retry is intended, this is fine — worth confirming it cannot strand a host whose status.get is permanently refused.

Technical details
# Mobile host-status gates drop the fail-open branch

## Affected sites
- `mobile/src/transport/host-status-gates.ts:44-75` — the effect now returns `startRuntimeStatusProbe(...)`; the previous `!response.ok` / `catch` settles with empty capabilities are gone.
- `mobile/src/components/HostProtocolGate.tsx:32-35` — `holdBack` keeps the host tree unmounted while `statusPending` is true on first load.

## Required outcome
- Confirm whether a `status.get` refused for the life of a connection should retry indefinitely or settle conservatively so the host UI can render.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@greptile-apps

greptile-apps Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

Too many files changed for review (101 files, 100 file limit).

Bypass the limit by tagging @greptile-apps to review.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 95e2596f-619d-41e7-bec6-b45b767f6e96

📥 Commits

Reviewing files that changed from the base of the PR and between a2ee201 and 8749513.

📒 Files selected for processing (67)
  • mobile/src/session/mobile-session-route-parity.test.ts
  • mobile/src/session/mobile-structured-prompt-cancellation.test.ts
  • mobile/src/session/mobile-structured-prompt-cancellation.ts
  • mobile/src/session/use-mobile-native-chat-controller.test.ts
  • mobile/src/session/use-mobile-native-chat-controller.ts
  • mobile/src/session/use-mobile-session-native-chat-dictation.ts
  • mobile/src/session/use-mobile-structured-agent-session-cancel.ts
  • mobile/src/session/use-mobile-structured-agent-session.test.tsx
  • mobile/src/transport/host-status-gates.test.ts
  • mobile/src/transport/host-status-gates.ts
  • mobile/src/transport/runtime-capability-probe.ts
  • mobile/src/transport/unvalidated-rpc-request-port-inventory.ts
  • src/main/claude/claude-host-prompt-cancellation.ts
  • src/main/claude/claude-journal-prompt-groups.ts
  • src/main/claude/claude-structured-control-actions.test.ts
  • src/main/claude/claude-structured-journal-translation.test.ts
  • src/main/claude/claude-structured-journal-translation.ts
  • src/main/claude/claude-structured-prompt-replies.ts
  • src/main/claude/claude-structured-session-adapter-turns.test.ts
  • src/main/claude/claude-structured-session-adapter.ts
  • src/main/claude/claude-structured-session-cancel.ts
  • src/main/claude/claude-structured-session-state.ts
  • src/main/codex/codex-prompt-cancellation-registry.ts
  • src/main/codex/codex-structured-journal-prompts.ts
  • src/main/codex/codex-structured-journal-settlement.ts
  • src/main/codex/codex-structured-journal-sink.ts
  • src/main/codex/codex-structured-journal-translation-turn-boundaries.ts
  • src/main/codex/codex-structured-notification-retry.ts
  • src/main/codex/codex-structured-prompt-cancellation-settlement.test.ts
  • src/main/codex/codex-structured-prompt-replies.test.ts
  • src/main/codex/codex-structured-prompt-replies.ts
  • src/main/codex/codex-structured-prompt-turn-settlement.ts
  • src/main/codex/codex-structured-provider-events.ts
  • src/main/codex/codex-structured-session-adapter.ts
  • src/main/codex/codex-structured-session-cancel.test.ts
  • src/main/codex/codex-structured-session-prompt-cancellation.ts
  • src/main/codex/codex-structured-session-state.ts
  • src/main/codex/codex-structured-turn-cancellation.ts
  • src/main/native-chat/agent-session-journal/journal-prompt-body-bounds.test.ts
  • src/main/native-chat/agent-session-journal/journal-prompt-body-bounds.ts
  • src/main/native-chat/agent-session-journal/journal-prompt-cancellation.ts
  • src/main/native-chat/agent-session-journal/journal-row-writer.test.ts
  • src/main/native-chat/agent-session-journal/journal-row-writer.ts
  • src/main/native-chat/agent-session-journal/journal-store.test.ts
  • src/main/native-chat/agent-session-journal/journal-store.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-adapter.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host-prompt-cancellation.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-host.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.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-prompt-cancellation.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-send-idempotency.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-turn-cancellation.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-turns.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-turns.ts
  • src/main/runtime/agent-session-record-operation-settlement.test.ts
  • src/main/runtime/agent-session-record-operation-settlement.ts
  • src/main/runtime/agent-session-record-store.ts
  • src/renderer/src/components/native-chat/use-structured-agent-session-prompt-cancel.test.tsx
  • src/renderer/src/components/native-chat/use-structured-agent-session.ts
  • src/shared/agent-session-journal-schemas.ts
  • src/shared/agent-session-journal-types.ts
  • src/shared/agent-session-operation-ledger.test.ts
  • src/shared/agent-session-operation-ledger.ts
💤 Files with no reviewable changes (1)
  • mobile/src/transport/unvalidated-rpc-request-port-inventory.ts
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/main/claude/claude-structured-control-actions.test.ts
  • src/main/claude/claude-structured-session-adapter.ts
  • src/main/claude/claude-structured-session-cancel.ts
  • src/main/codex/codex-structured-prompt-replies.ts
  • src/main/claude/claude-structured-session-adapter-turns.test.ts
  • src/main/codex/codex-structured-journal-sink.ts
  • mobile/src/transport/runtime-capability-probe.ts

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

Comment on lines +40 to +42
resolvedBy: resolution.resolvedBy ?? null,
resolvedAt: resolution.resolvedAt ?? null,
...(resolution.settlementId ? { settlementId: resolution.settlementId } : {})

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.

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the schemas and producers for explicit length bounds.
rg -n -C4 \
  'clientOperationId|promptCancellationSettlementId|resolvedBy|settlementId' \
  src/main/native-chat src/main/claude src/main/codex src/shared

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

for file in \
  src/main/native-chat/agent-session-journal/journal-prompt-body-bounds.ts \
  src/main/native-chat/agent-session-journal/journal-prompt-cancellation.ts \
  src/main/native-chat/agent-session-journal/journal-row-schema.ts \
  src/main/codex/codex-structured-turn-cancellation.ts \
  src/main/codex/codex-structured-session-adapter.ts \
  src/main/codex/codex-structured-provider-events.ts
do
  echo "===== $file ====="
  sed -n '1,220p' "$file"
done

echo "===== cancellation callers ====="
rg -n -C5 \
  'cancelPromptsAtRevisions|resolvedBy:|settlementId:|callerKey:' \
  src/main/native-chat/agent-session-journal \
  src/main/native-chat/agent-session-wire \
  src/main/codex \
  -g '*.ts' \
  | head -n 500

Repository: stablyai/orca

Length of output: 50369


🤖 get_repo_knowledge executed:

get_repo_knowledge stablyai/orca /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings

Length of output: 19007


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "===== cancellation construction sites ====="
rg -n -C8 \
  'cancelCodexStructuredSessionTurn|cancelJournalPromptsAtRevisions|JournalPromptCancellationInput|settlementId.*resolvedBy|resolvedBy.*settlementId' \
  src/main/codex src/main/native-chat \
  -g '*.ts' \
  | head -n 700

echo "===== cancellation settlement creation ====="
rg -n -C10 \
  'settlementId|resolvedBy' \
  src/main/codex/codex-structured-session-prompt-cancellation.ts \
  src/main/codex/codex-structured-notification-retry.ts \
  src/main/codex/codex-structured-session-state.ts \
  src/main/native-chat/agent-session-wire \
  -g '*.ts' \
  | head -n 700

echo "===== lifecycle row admission and writer contract ====="
sed -n '80,145p' src/main/native-chat/agent-session-journal/journal-row-builders.ts
sed -n '1,130p' src/main/native-chat/agent-session-journal/journal-lifecycle-batch-appender.ts
rg -n -C8 \
  'MAX_JOURNAL_LIFECYCLE_BATCH_BYTES|serializedLifecycleBatchFits|isJournalRow|appendLifecycleBatch' \
  src/main/native-chat/agent-session-journal \
  -g '*.ts' \
  | head -n 500

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "===== lifecycle row builder ====="
sed -n '80,140p' src/main/native-chat/agent-session-journal/journal-row-builders.ts
sed -n '1,90p' src/main/native-chat/agent-session-journal/journal-lifecycle-batch-appender.ts

echo "===== prompt cancellation implementation ====="
cat src/main/codex/codex-structured-session-prompt-cancellation.ts
rg -n -C12 \
  'promptCancellationId|promptCancellationResolvedBy|promptCancellationResolvedAt|cancelTurn\\s*=' \
  src/main/native-chat src/main/codex \
  -g '*.ts' \
  | head -n 500

echo "===== resolvedBy and settlementId production values ====="
rg -n -C6 \
  'resolvedBy: (request|input|context|caller)|settlementId: (input|request|context)|promptCancellationId:' \
  src/main/native-chat src/main/codex \
  -g '*.ts' \
  | grep -vE 'test\\.ts|\\.test\\.ts' \
  | head -n 500

Repository: stablyai/orca

Length of output: 49581


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "===== mutation envelope and caller validation ====="
rg -n -C10 \
  'clientOperationId|callerKey|MAX_.*(OPERATION|CALLER)|operation.*(length|byte)|caller.*(length|byte)' \
  src/main/native-chat/agent-session-wire \
  src/shared \
  -g '*.ts' \
  | grep -vE 'test\\.ts|\\.test\\.ts' \
  | head -n 700

echo "===== cancellation settlement helpers and context ====="
rg -n -C12 \
  'promptCancellationSettlementId|type AgentSessionPromptCancelSettlement|resolvedBy: string|resolvedBy\\??: string|settlePromptCancellation|performCancel' \
  src/main/native-chat/agent-session-wire \
  -g '*.ts' \
  | grep -vE 'test\\.ts|\\.test\\.ts' \
  | head -n 700

echo "===== all production calls into cancelledJournalPromptBody ====="
rg -n -C12 \
  'cancelledJournalPromptBody\\(' \
  src/main \
  -g '*.ts' \
  | grep -vE 'test\\.ts|\\.test\\.ts'

Repository: stablyai/orca

Length of output: 50371


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "===== production cancellation helper and turn context ====="
rg -n -C8 \
  'promptCancellationSettlementId|resolvedBy: request.callerKey|resolvedBy: ctx.resolvedBy|type AgentSessionPromptCancelSettlement|settlePromptCancellation' \
  src/main/native-chat/agent-session-wire \
  -g '*.ts' -g '!*.test.ts'

echo "===== production clientOperationId declarations and checks ====="
rg -n -C5 \
  'clientOperationId' \
  src/main/native-chat/agent-session-wire \
  -g '*.ts' -g '!*.test.ts'

echo "===== production callerKey declarations and checks ====="
rg -n -C5 \
  'callerKey' \
  src/main/native-chat/agent-session-wire \
  -g '*.ts' -g '!*.test.ts' \
  | sed -n '1,350p'

Repository: stablyai/orca

Length of output: 50370


Bound cancellation receipt metadata before serialization.

cancelledJournalPromptBody bounds prompt content but copies resolvedBy and settlementId unchanged. The cancellation path derives settlementId from clientOperationId and resolvedBy from callerKey, without a byte-length check. The compact fallback retains both fields, so an oversized value can exceed the 256 KiB prompt-body limit. A sufficiently large value can also make journalLifecycleBatchRowBuilder throw journal_lifecycle_batch_byte_bound_exceeded. Add admission validation or a bounded representation for these receipt fields.

Comment on lines +264 to +265
Number.isSafeInteger(settlement.runtimeFence) &&
(settlement.runtimeFence as number) > 0 &&

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.

🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 4 'runtimeFence' src/main/runtime src/main/native-chat --type=ts -g '!**/*.test.ts' | head -120

# Initial fence assignment and any bump logic
ast-grep run --pattern 'runtimeFence: $VAL' --lang typescript src/main | head -60

Repository: stablyai/orca

Length of output: 13274


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- runtimeFence assignments and uses ---'
rg -n -C 5 'runtimeFence|nextFence|isPromptCancelSettlement|performCancel|resumePromptCancellation' src/main src/shared -g '*.ts' -g '!**/*.test.ts' | head -260

printf '%s\n' '--- lease and record declarations/validators ---'
rg -n -C 8 'interface .*Lease|type .*Lease|AgentSessionLease|lease:|runtimeFence' src/shared src/main/runtime src/main/native-chat -g '*.ts' -g '!**/*.test.ts' | head -320

Repository: stablyai/orca

Length of output: 50369


🤖 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: 30210


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- files containing the lease fence symbol ---'
rg -l 'runtimeFence|nextFence|AgentSessionLease|isPromptCancelSettlement' src/shared src/main/runtime src/main/native-chat -g '*.ts' -g '!**/*.test.ts' | sort

printf '%s\n' '--- shared lease declarations and validators ---'
for f in $(rg -l 'runtimeFence|AgentSessionLease|isPromptCancelSettlement' src/shared -g '*.ts' -g '!**/*.test.ts' | sort); do
  echo "### $f"
  rg -n -C 10 'runtimeFence|nextFence|AgentSessionLease|isPromptCancelSettlement|isAgentSession.*Record|isAgentSession.*Row' "$f"
done

printf '%s\n' '--- runtime construction and fence bump paths ---'
for f in $(rg -l 'runtimeFence|nextFence' src/main/runtime src/main/native-chat -g '*.ts' -g '!**/*.test.ts' | sort); do
  echo "### $f"
  rg -n -C 8 'runtimeFence|nextFence' "$f"
done

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- explicit fence assignments ---'
rg -n -C 6 'runtimeFence[[:space:]]*:' src/main src/shared -g '*.ts' -g '!**/*.test.ts' | head -240

printf '%s\n' '--- minimum fence assignments ---'
rg -n -C 6 'minimumNextFence|nextAgentSessionFence\(' src/main src/shared -g '*.ts' -g '!**/*.test.ts' | head -220

printf '%s\n' '--- record store lease creation and validation ---'
sed -n '1,260p' src/main/runtime/agent-session-record-store.ts
sed -n '260,620p' src/main/runtime/agent-session-record-store.ts

printf '%s\n' '--- operation ledger persistence and reload ---'
sed -n '1,340p' src/shared/agent-session-operation-ledger.ts
rg -n -C 10 'isAgentSessionOperationRow|operation.*row|discard|filter|load|restore|resumePromptCancellation' src/main src/shared -g '*.ts' -g '!**/*.test.ts' | head -280

printf '%s\n' '--- cancellation flow ---'
rg -n -C 12 'function performCancel|performCancel|resumePromptCancellation|runtimeFence: ctx\.fence|promptCancelSettlement' src/main/native-chat src/shared -g '*.ts' -g '!**/*.test.ts' | head -260

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '%s\n' '--- zero and non-derived fence assignments ---'
rg -n 'runtimeFence[[:space:]]*:[[:space:]]*[^a-zA-Z]' src/main src/shared -g '*.ts' -g '!**/*.test.ts'
rg -n -C 12 'runtimeFence[[:space:]]*:[[:space:]]*(0|1|request|args|input|fence)' src/main src/shared -g '*.ts' -g '!**/*.test.ts'

printf '%s\n' '--- reservation admission ---'
sed -n '1,260p' src/main/runtime/agent-session-reservation-admission.ts

printf '%s\n' '--- operation store loading and row filtering ---'
for f in src/main/runtime/agent-session-record-store-file.ts src/main/runtime/agent-session-record-store-security.ts src/main/runtime/agent-session-store-transaction-queue.ts; do
  if test -f "$f"; then
    echo "### $f"
    rg -n -C 14 'operations|isAgentSessionOperationRow|unreadable|discard|filter|load|parse|state' "$f"
  fi
done

printf '%s\n' '--- cancellation implementation ---'
sed -n '1,240p' src/main/native-chat/agent-session-wire/structured-agent-session-turn-cancellation.ts
rg -n -C 18 'resumePromptCancellation|performCancel' src/main/native-chat src/main/runtime -g '*.ts' -g '!**/*.test.ts'

Repository: stablyai/orca

Length of output: 50369


Keep the lease and settlement fence invariants consistent.

createAgentSessionRecord starts at runtimeFence: 1, and normal transitions only increase it. However, isAgentSessionLease accepts a persisted fence of 0. Such a lease can reach performCancel, which persists ctx.fence; isPromptCancelSettlement then rejects the settlement because it requires > 0. On reload, parseState rejects the store containing that invalid operation row, so resumePromptCancellation cannot recover it. Enforce the positive-fence invariant when loading leases and migrate existing zero-fence records.

@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 critical issues — one minor suggestion inline.

Reviewed changes

This run re-reviewed the delta since the prior pullfrog review at a2ee201: the "make prompt cancellation recoverable" commit.

  • Recoverable host cancellation — performCancel now persists a prepared settlement before interrupting the provider, flushes the journal, persists provider-confirmed, then CAS-settles the durable prompts; resumePromptCancellation settles a retry from the journal proof (settlementId === prompt-cancel:<op>) without interrupting twice, and resumeAtCurrentFence re-admits provider-confirmed retries under the current ledger fence.
  • Codex cancellation deferral — CodexStructuredTurnCancellation blocks and holds the provider turn/completed until the interrupt is confirmed, then releases it exactly once with the settlement merged in, so collectCodexTurnPromptCancellations stamps the caller's settlementId/resolvedBy/resolvedAt onto the durable row.
  • Settlement write guard — AgentSessionRecordStore.recordOperationOutcomeIfCurrent lets an unsettled write advance pending → unknown while a pending write only overwrites pending, so the generic error path can no longer downgrade a prepared/confirmed settlement.
  • Claude prompt groups and journal bounds — ClaudeJournalPromptGroups replaces per-prompt tombstones with settlement-stamped cancelled bodies; cancelledJournalPromptBody deep-bounds text/options with a compact fallback; oversized cancellations split into atomically-committed, uniquely-suffixed batches.
  • Client gating parity — desktop and mobile both fall back to turn-only cancellation when the prompt-cancel capability is false or the probe fails, and the mobile host gate fails compatibility open while keeping feature gates pending during the bounded status.get retry.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

return cancelJournalPromptsAtRevisions(this.rowWriter, () => this.state, input)
}

hasAppliedSettlement(settlementId: string): boolean {

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.

This method is unused, and its key no longer matches what the prompt-cancellation path writes: partitionJournalLifecycleMutations records one settlement id per chunk (<base>:1/N), and the reducer stores those suffixed ids in appliedSettlementIds (journal-lifecycle-batch-appender.ts:45). So hasAppliedSettlement(base) would return false after every chunk of a split settlement has applied. Either drop it or have it compare against the chunk ids.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final-head Electron QA (cd149a293a396b6d1e28ec1915b26b4340100d63)

Hidden Electron identity: Orca: pr20339-qa (isDev: true, branch brennanb2025/native-chat-hide-working). CDP 127.0.0.1:9334, ORCA_BACKGROUND_LAUNCH=1, isolated user-data. Identity confirmed via window.api.app.getIdentity() before testing. Genuine Claude and Codex structured chats were launched from the New tab menu after Chat UI settings were enabled. No mocks, seeded cards, renderer-store fabrication, or journal injection. No source committed.

Claude (AskUserQuestion) — pass for pending-question ownership, cancel, and recovery:

  • Real question card appeared (For this QA check, pick a drink. / Tea / Coffee). Live Running AskUserQuestion tool row stayed. Generic Working / Thinking / timer were absent. The card Cancel (X) was available (the composer Stop control is replaced while the card owns that region).
  • Invoking Cancel removed the pending prompt (Cancelled · Cancelled on desktop-renderer) and stopped the turn (Worked for 1m 0s, Cancellation requested.).
  • A subsequent ordinary turn completed normally (PONG, Worked for 1s).

Claude pending question card; no Working/Thinking

Claude cancelled receipt then subsequent PONG

Codex (request_user_input) — structured question card not elicited:

  • First genuine prompt settled empty in 5s with no card.
  • Second genuine prompt: Codex replied TOOL_UNAVAILABLE The missing tool is request_user_input.
  • A subsequent ordinary turn still completed (PONG, Worked for 1s). Pending-question Stop/Cancel could not be exercised because no card appeared.

Codex first turn: no question card

Codex: request_user_input unavailable

Codex subsequent ordinary turn completed

Approval — not elicited:

  • Harmless Claude Bash write (printf qa-ok > /tmp/pr20339-qa-probe.txt && cat …) auto-allowed (Done — output was qa-ok) with no Allow/Deny card. Did not fabricate an approval.

Claude Bash auto-allowed; no approval card

Gaps

  • Codex pending structured question / Cancel-while-pending: not exercised (request_user_input unavailable in this structured Chat UI session).
  • Approval card + distinct Cancel: not elicited (Claude Bash auto-allowed; Codex question tool unavailable).

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final review status (cd149a293a396b6d1e28ec1915b26b4340100d63)

This supersedes the earlier QA status notes. The branch is clean, matches the pushed PR head, is mergeable, and all required GitHub checks are green.

  • Review/fix loop: one meaningful test defect was fixed: the crash-recovery fault injection now mocks recordOperationOutcomeIfCurrent, so the regression test exercises the intended conditional-settlement failure. Independent same-model re-reviews returned CLEAN; no product scope was added.
  • Architecture: the failure came from transient UI turn state diverging from durable prompt state. The final design removes that mechanism: the execution host resolves exact provider-owned session/thread/turn/item/revision identity, provider confirmation is persisted before revision-aware compare-and-set settlement, and the renderer only suppresses the redundant Working/Thinking presentation. The mechanism matches established structured-interaction ownership and lifecycle patterns without a material deviation.
  • Compatibility/performance: the wire change is additive and capability-gated; host ownership is preserved for local, SSH, relay, git-worktree, and folder-workspace use. No hot scans, subprocess fanout, polling, render-loop work, listener leaks, or unbounded retention were found. Mobile capability recovery is bounded to one request/timer with cleanup.
  • Automated validation: focused matrices passed (246 desktop/host + 70 mobile); the independent readiness suites passed (254 desktop + 57 mobile). pnpm tc, mobile TypeScript --noEmit, and changed-code quality checks passed. CI passed static analysis, typecheck, cross-version wire compatibility, mobile verify, macOS/Windows packaging, all 8 test shards, and aggregate verify.
  • Real UI validation: hidden exact-head Electron runs exercised genuine Claude AskUserQuestion pending/cancel/recovery, genuine Codex request_user_input answer/continuation, and genuine Grok ask_user_question answer/continuation through its legacy lane. The PR description contains the exact-head screenshots.
  • Native mobile: a rebuilt iOS Simulator app exercised a genuine Claude question, verified that generic Working/Thinking was absent while the prompt was pending, cancelled via mobile Stop, and completed a subsequent PONG turn. Screenshot attachment was blocked only by local macOS Accessibility/Screen Recording permissions; no web/mock substitute is claimed.
  • Readiness: final checklist verdict PASS — P0: none, P1: none, P2: none. Security/supply-chain, functional correctness, architectural fit, compatibility/remoting/mobile, and performance/resources were judged separately.

Remaining evidence gaps: no live SSH/relay disconnect fault ladder, physical-device battery measurement, separately cancelled Codex prompt, or permission-gated approval card (the attempted approval flow auto-allowed). These are unverified scenarios, not proven defects.

Status: no proven in-scope blockers remain.

@brennanb2025 brennanb2025 changed the title fix(native-chat): hide activity while awaiting input fix(native-chat): make prompt cancellation recoverable Sep 13, 2026
@brennanb2025
brennanb2025 changed the base branch from main to brennanb2025/native-chat-hide-working-ui September 13, 2026 19:08
@brennanb2025

Copy link
Copy Markdown
Contributor Author

The change is now split into a stacked pair:

Earlier comments describing the combined diff are superseded by this split. The reliability work remains intentionally stacked because it depends on the UI PR's cancellation entry point.

@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 critical issues — one minor suggestion inline.

Reviewed changes

This run re-reviewed the two commits since the prior pullfrog review at 8749513: the approval cancellation label catalog entries.

  • Catalogued an approval cancel label — en.json gains components.native-chat.approval.cancel (954e78a) and en-runtime-required.json gains its generated mirror (6abdeca). No other production change; the card's call site still reads components.native-chat.question.cancel.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

"allow": "Allow",
"deny": "Deny"
"deny": "Deny",
"cancel": "Cancel"

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.

The new components.native-chat.approval.cancel entry is never read. The approval card's cancel button was switched to components.native-chat.question.cancel in a2ee201, and nothing references the new key (or its en-runtime-required.json mirror), so both additions are dead weight in the translator source and the boot bundle. Either point the approval card back at approval.cancel or drop the two entries.

Technical details
# Unreferenced `native-chat.approval.cancel` key

## Affected sites
- `src/renderer/src/i18n/locales/en.json:17239` — new `approval.cancel` entry, no call site.
- `src/renderer/src/i18n/en-runtime-required.json:2613-2615` — generated mirror of the same key.
- `src/renderer/src/components/native-chat/NativeChatApprovalCard.tsx:43` — reads `components.native-chat.question.cancel`.

## Required outcome
- The approval cancel label has exactly one source key, referenced by the card.

## Suggested approach (optional)
- If approval should own its own label: revert `NativeChatApprovalCard.tsx:43` to `components.native-chat.approval.cancel` (value is identical, so behavior is unchanged).
- Otherwise: remove the `approval.cancel` entries from both catalogs.

@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

This run re-reviewed the one commit since the prior pullfrog review at 6abdeca.

  • Ambiguous retry kept recoverable — resumePromptCancellation now returns null when a retry's provider cancel reports cancelled: false and the journal holds no cancellation proof, instead of returning a cancelled: false success that settled the ledger row as succeeded. The operation stays unknown with its prepared settlement, the client retry reuses the same operation id, and a later provider confirmation can still settle it — matching the existing setOption "unknown outcome is not a successful replay" precedent.
  • Regression coverage — a new host test drives a lost interrupt reply followed by a cancelled: false retry and asserts the agent_session_operation_unknown refusal with the prepared settlement retained; it fails against the prior success return.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Final-head Electron QA (4b6cb7784b7b3585d75fb365238a3a6bb9f1a361)

Hidden Electron identity: Orca: brennanb2025/grok-electron-pr20339-exact (isDev: true, devRepoRoot /Users/brennanbenson/orca/workspaces/orca/grok-electron-pr20339-exact, worktree grok-electron-pr20339-exact). CDP 127.0.0.1:9334, renderer 127.0.0.1:5174, ORCA_BACKGROUND_LAUNCH=1, isolated user-data. Identity confirmed via window.api.app.getIdentity() before testing. The imported workspace head was 4b6cb7784b7b3585d75fb365238a3a6bb9f1a361. Chat UI + structured native chat were enabled from Settings. Genuine Grok (legacy Chat UI) and Claude (structured Claude Chat) sessions were launched from the New tab menu. No mocks, seeded cards, renderer-store fabrication, or journal injection.

Claude structured (AskUserQuestion) — pass for pending-question cancel and recovery

  • Real question card appeared (For this QA check, pick a drink. / Tea / Coffee) with live Running AskUserQuestion. Generic Working / Thinking were absent. Card Cancel was available.
  • Cancel settled the prompt (Cancelled · Cancelled on desktop-renderer, Cancellation requested., Worked for 41s).
  • A subsequent ordinary turn completed (PONG then Worked for 3s; Claude replied that the question was rejected / no drink selected).

Claude pending question card

Claude cancelled receipt

Claude PONG recovery

Grok native Chat UI (ask_user_question, terminal-backed / not structured)

  • Real question card appeared (For this QA check, pick a drink. / Tea / Coffee). Card Cancel dismissed the card and restored the composer.
  • A subsequent PONG user message was accepted by the composer. Host sidebar status remained Waiting for input on the original ask_user_question during this run; no completed Grok assistant recovery turn was observed.

Grok pending question card

Grok after cancel + PONG sent; still waiting

Identity / empty app before repo add

Attached hidden instance

Gaps

  • Codex pending structured question / Cancel-while-pending: not exercised in this run.
  • Permission-gated approval card: not elicited.
  • Grok host-status settlement after card Cancel: unproven (UI card dismissed; sidebar still waiting).
  • Live SSH/relay disconnect injection: not exercised.

@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

This run re-reviewed the one commit since the prior pullfrog review at 4b6cb77.

  • Retained ambiguous cancellation identity — requestStructuredAgentSessionMutation now routes both agentSession.conversationCommand and agentSession.cancel refusals through agentSessionRefusalOperationState, so an agent_session_operation_unknown cancel returns unknown and useMobileStructuredAgentSessionCancel keeps the same client operation id for the retry instead of deleting it and minting a new one. Conversation-command behavior is unchanged: only agent_session_operation_unknown maps to unknown for either method.
  • Added regression coverage — a new use-mobile-structured-agent-session-cancel.test.tsx drives an ambiguous refusal into a retry (same operation id) and a settled-rejected refusal into a retry (fresh id), plus a success case that releases the id. The ambiguous case fails against the prior classification.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: PASS — ready to merge, with the residual validation gaps below.

  • Updated head: bd71aa3659dcb884cc0af35e32781f14e69a14e0.
  • Fixed the mobile cancellation retry bug by routing agentSession.cancel through the shared refusal-state classifier. An ambiguous agent_session_operation_unknown keeps the durable operation ID for a safe retry; settled refusals and successful cancellation release it.
  • Regression coverage is in the dedicated mobile cancellation suite. Focused mobile tests, 18 desktop compatibility tests, mobile/workspace typechecks, changed-code quality, direct lint, formatting, and max-lines checks passed. The final readiness pass found no proven P0/P1/P2 issues, and PR CI is green.
  • Electron/CDP screenshots and question/cancel evidence: fix(native-chat): make prompt cancellation recoverable #20339 (comment)

Remaining gaps are untested live SSH/relay/network fault injection, Windows/WSL, live iOS/Android, provider end-to-end cancellation, and additional Electron flows (Codex pending-question, approval, and live relay fault injection). The final mobile-only fix does not change the desktop renderer behavior covered by the existing Electron evidence.

@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

This run re-reviewed the merge commit since the prior pullfrog review at bd71aa3, which folds the base branch's new Codex prompt-settlement commits into the PR.

  • Registry fallback on settled turns — CodexPromptRegistry.clearTurn (via the new clearCodexPromptTurn helper) forgets provider requests bound to a settled (threadId, turnId), wired through CodexJournalTranslatorDeps.clearPromptTurn into acquisition.prompts.clearTurn.
  • Turn-bound prompt identity — bindPromptItemId gains an optional turnId; the translator now passes the pending prompt's turn and the registry adopts it when the request was registered without one, so a turn completion can match prompts Codex did not stamp with a turn at registration time.
  • Turn-completion settlement runs unconditionally — settleCodexJournalTurn always calls its lifecycle batch (empty batches are a no-op in partitionJournalLifecycleMutations) so it can cancel the pending journal prompts and clear the provider registry even when there is no other row to write; collectCodexTurnPromptCancellations now receives an explicit pendingPrompts plus the receipt fields.
  • Shared lifecycle writer and prompt-byte accounting — appendLifecycleMutations moved to the sink as appendCodexLifecycleMutations; promptBytes/retainedPromptBytes moved to codex-prompt-registry-bounds.ts as codexPromptBytes/codexRetainedPromptBytes.
  • Coverage — new tests assert that a turn completing while an approval or question is pending writes a cancelled row and calls clearPromptTurn, and that clearTurn drops only prompts belonging to the settled turn/thread.

Two prior minor inline threads (AgentSessionJournal.hasAppliedSettlement unused / base-id mismatch, and the unreferenced native-chat.approval.cancel key) are untouched by this delta and remain open.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Conflict resolution is complete and pushed at 448e6c821b.

The current #20496 base was merged into #20339 while preserving #20339’s child-thread ownership, bounded prompt identity handling, and cancellation settlement receipts, together with #20496’s turn-aware prompt fallback and turn-scoped registry cleanup. No unrelated product scope was added.

Validation is clean:

  • Focused Codex lifecycle/cancellation suite: 86/86 tests passed
  • pnpm tc:node and pnpm tc:web passed
  • Changed-code quality, type-aware quality, React Doctor, formatting, and pre-commit gates passed
  • GitHub CI passed, including static analysis, typecheck, package, Windows package, all 8 test shards, cross-version compatibility, and pullfrog

The PR is currently MERGEABLE. Because it is stacked, merge #20496 first, then merge #20339.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Superseded by #20601.

The replacement uses a simpler ownership model: the session journal is the only durable UI/history source, provider-local registries own live callbacks, and answer/cancel contend for one exact callback claim after the host validates the prompt item and revision. Older hosts retain turn-only cancellation through capability downgrade.

This also resolves the remaining review concerns by removing the old durable settlement-receipt/base-ID path entirely, avoiding the unused approval-label addition, preserving Claude prompts as durable cancelled rows, and keeping provider callback cleanup bounded across completion, exit, and close.

Focused host/provider, desktop, mobile, and mixed-version wire tests pass, and hidden Electron QA exercised a real Claude question through the actual Cancel control. Closing this PR in favor of #20601.

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.

Native chat shows Working while awaiting structured input

1 participant