Repository navigation
fix(native-chat): make prompt cancellation recoverable - #20339
brennanb2025 wants to merge 9 commits into
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
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 (1)
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review. 📝 WalkthroughWalkthroughThe 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 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)
✅ Passed checks (1 passed)
Full details: Description checkExplanation 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.
✨ 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 |
There was a problem hiding this comment.
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 winKeep cancellation reachable for pending approvals.
When
prompt.body.kind === 'approval',NativeChatStructuredSessionunmountsNativeChatComposerand passes onlyonChoosetoNativeChatApprovalCard. Choosing an approval option callsrespondToApproval, notcontroller.cancel, which maps toagentSession.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
📒 Files selected for processing (8)
mobile/src/session/MobileNativeChatView.test.tsmobile/src/session/MobileNativeChatView.tsxsrc/renderer/src/components/native-chat/NativeChatMessageList.tsxsrc/renderer/src/components/native-chat/NativeChatMessageList.turn-indicator.test.tsxsrc/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsxsrc/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsxsrc/renderer/src/components/native-chat/NativeChatStructuredSession.tsxsrc/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.
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
- Desktop foreground-activity gate —
NativeChatMessageListgainsshowLiveTurnActivity(defaulttrue) that gates only theNativeChatTurnActivityLine;NativeChatStructuredSessionpassesprompt === null, so the pending interaction owns the foreground while the turn row (activeTurnIsWorking) and live tool rows stay live. - Mobile parity —
MobileNativeChatViewcomputeshasPendingStructuredInteractionand gates only theListFooterComponentturn status; Stop, per-turn working state, and background-task status are untouched. - Regression coverage — desktop tests for pending question/approval driving
showLiveTurnActivityand preserving cancel/background work, plus aNativeChatMessageListtest 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.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes (since prior review)
- Approval-card cancellation —
NativeChatApprovalCardgains an optionalonCancelrendered as an iconXbutton, with the title column switched toflex-1so it stays clear of the button.NativeChatStructuredSessionwires it tocontroller.cancel(controller.turnId), restoring a cancel affordance for the approval state where the composer — and its Stop button — is hidden. - Coverage — new
NativeChatApprovalCard.test.tsxasserts the button invokesonCancel, and the structured-session approval test now drivesonCancelthrough tocontroller.cancel('turn-approval'). - Scoping —
onCancelis optional, so the legacyNativeChatInteractiveCardrender path keeps its current behavior.pnpm tc:weband mobilepnpm typecheckpass; desktop suite is 45 tests, mobile 19.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
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: c21b6080-d30d-46d2-a60b-b17e4dffa58b
📒 Files selected for processing (4)
src/renderer/src/components/native-chat/NativeChatApprovalCard.test.tsxsrc/renderer/src/components/native-chat/NativeChatApprovalCard.tsxsrc/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsxsrc/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.
| onCancel={() => { | ||
| if (controller.turnId) { | ||
| void controller.cancel(controller.turnId) | ||
| } | ||
| }} |
There was a problem hiding this comment.
🩺 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.
QA evidence (desktop Electron + iOS Simulator)Hidden Electron identity: Claude (AskUserQuestion) — pass for pending-question ownership:
Codex (
Gaps
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 |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: c075d327-3d99-454e-b2bd-ea64ba2b366d
📒 Files selected for processing (63)
mobile/src/session/mobile-session-route-parity.test.tsmobile/src/session/mobile-structured-agent-session-test-fixtures.tsmobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-native-chat-session-lane.tsmobile/src/session/use-mobile-session-native-chat-dictation.tsmobile/src/session/use-mobile-structured-agent-session-cancel.tsmobile/src/session/use-mobile-structured-agent-session.test.tsxmobile/src/session/use-mobile-structured-agent-session.tsmobile/src/transport/host-status-gates.tsmobile/src/transport/runtime-capability-probe.test.tsmobile/src/transport/runtime-capability-probe.tssrc/main/claude/claude-host-prompt-cancellation.tssrc/main/claude/claude-structured-control-actions.test.tssrc/main/claude/claude-structured-inbound-control.test.tssrc/main/claude/claude-structured-inbound-control.tssrc/main/claude/claude-structured-prompt-replies.tssrc/main/claude/claude-structured-prompt-types.tssrc/main/claude/claude-structured-session-acquisition.tssrc/main/claude/claude-structured-session-adapter-turns.test.tssrc/main/claude/claude-structured-session-adapter.tssrc/main/claude/claude-structured-session-cancel.tssrc/main/codex/codex-persistent-command-retention.test.tssrc/main/codex/codex-structured-journal-contracts.tssrc/main/codex/codex-structured-journal-prompts.tssrc/main/codex/codex-structured-journal-settlement.tssrc/main/codex/codex-structured-journal-sink.tssrc/main/codex/codex-structured-journal-translation-settlement.test.tssrc/main/codex/codex-structured-journal-translation-turn-boundaries.tssrc/main/codex/codex-structured-journal-translation.tssrc/main/codex/codex-structured-prompt-replies.test.tssrc/main/codex/codex-structured-prompt-replies.tssrc/main/codex/codex-structured-prompt-turn-settlement.tssrc/main/codex/codex-structured-session-acquire.tssrc/main/codex/codex-structured-session-adapter.tssrc/main/codex/codex-structured-session-cancel.test.tssrc/main/native-chat/agent-session-journal/journal-prompt-cancellation.tssrc/main/native-chat/agent-session-journal/journal-row-writer.tssrc/main/native-chat/agent-session-journal/journal-store.tssrc/main/native-chat/agent-session-wire/structured-agent-session-adapter-router.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-adapter-router.tssrc/main/native-chat/agent-session-wire/structured-agent-session-adapter.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host-test-harness.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-mutation-plans.tssrc/main/native-chat/agent-session-wire/structured-agent-session-prompt-cancellation.tssrc/main/native-chat/agent-session-wire/structured-agent-session-stale-turn-verdict.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-stale-turn-verdict.tssrc/main/native-chat/agent-session-wire/structured-agent-session-turns.tssrc/main/runtime/rpc/methods/structured-agent-session.test.tssrc/renderer/src/components/native-chat/NativeChatApprovalCard.tsxsrc/renderer/src/components/native-chat/NativeChatStructuredSession.test-harness.tsxsrc/renderer/src/components/native-chat/NativeChatStructuredSession.test.tsxsrc/renderer/src/components/native-chat/NativeChatStructuredSession.tsxsrc/renderer/src/components/native-chat/use-structured-agent-session-mutate.tssrc/renderer/src/components/native-chat/use-structured-agent-session-prompt-cancel.test.tsxsrc/renderer/src/components/native-chat/use-structured-agent-session.test.tsxsrc/renderer/src/components/native-chat/use-structured-agent-session.tssrc/renderer/src/runtime/structured-agent-session-client.test.tssrc/renderer/src/runtime/structured-agent-session-client.tssrc/shared/agent-session-operation-ledger.tssrc/shared/protocol-version.tssrc/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.
| if (prompt.turnId === null && turnId && prompt.threadId === threadId) { | ||
| prompt.turnId = turnId | ||
| } |
There was a problem hiding this comment.
🩺 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.
| 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 | |
| } | |
| } |
There was a problem hiding this comment.
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 optionalprompt: {itemId, expectedRevision}(andturnIdbecomes optional when a prompt identifies the turn), with a newagent-session.prompt-cancel.v1capability advertised without a protocol bump. - Host prompt settlement —
performCancelresolves the prompt group, interrupts the owning turn, then CAS-revises each still-pending row tocancelledwith the caller's attribution;settledOutcome/recoverUnknownFromDurableStatemake a confirmed cancellation survive a lost status write. - Claude cancellation —
ClaudeHostPromptCancellationsuppresses the providerprompt-cancelledevent 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;
collectCodexTurnPromptCancellationsterminalizes them onturn/completed, and the adapter maps the logical turn to the provider child viacompactions.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.openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
|
Too many files changed for review (101 files, 100 file limit). Bypass the limit by tagging |
There was a problem hiding this comment.
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 95e2596f-619d-41e7-bec6-b45b767f6e96
📒 Files selected for processing (67)
mobile/src/session/mobile-session-route-parity.test.tsmobile/src/session/mobile-structured-prompt-cancellation.test.tsmobile/src/session/mobile-structured-prompt-cancellation.tsmobile/src/session/use-mobile-native-chat-controller.test.tsmobile/src/session/use-mobile-native-chat-controller.tsmobile/src/session/use-mobile-session-native-chat-dictation.tsmobile/src/session/use-mobile-structured-agent-session-cancel.tsmobile/src/session/use-mobile-structured-agent-session.test.tsxmobile/src/transport/host-status-gates.test.tsmobile/src/transport/host-status-gates.tsmobile/src/transport/runtime-capability-probe.tsmobile/src/transport/unvalidated-rpc-request-port-inventory.tssrc/main/claude/claude-host-prompt-cancellation.tssrc/main/claude/claude-journal-prompt-groups.tssrc/main/claude/claude-structured-control-actions.test.tssrc/main/claude/claude-structured-journal-translation.test.tssrc/main/claude/claude-structured-journal-translation.tssrc/main/claude/claude-structured-prompt-replies.tssrc/main/claude/claude-structured-session-adapter-turns.test.tssrc/main/claude/claude-structured-session-adapter.tssrc/main/claude/claude-structured-session-cancel.tssrc/main/claude/claude-structured-session-state.tssrc/main/codex/codex-prompt-cancellation-registry.tssrc/main/codex/codex-structured-journal-prompts.tssrc/main/codex/codex-structured-journal-settlement.tssrc/main/codex/codex-structured-journal-sink.tssrc/main/codex/codex-structured-journal-translation-turn-boundaries.tssrc/main/codex/codex-structured-notification-retry.tssrc/main/codex/codex-structured-prompt-cancellation-settlement.test.tssrc/main/codex/codex-structured-prompt-replies.test.tssrc/main/codex/codex-structured-prompt-replies.tssrc/main/codex/codex-structured-prompt-turn-settlement.tssrc/main/codex/codex-structured-provider-events.tssrc/main/codex/codex-structured-session-adapter.tssrc/main/codex/codex-structured-session-cancel.test.tssrc/main/codex/codex-structured-session-prompt-cancellation.tssrc/main/codex/codex-structured-session-state.tssrc/main/codex/codex-structured-turn-cancellation.tssrc/main/native-chat/agent-session-journal/journal-prompt-body-bounds.test.tssrc/main/native-chat/agent-session-journal/journal-prompt-body-bounds.tssrc/main/native-chat/agent-session-journal/journal-prompt-cancellation.tssrc/main/native-chat/agent-session-journal/journal-row-writer.test.tssrc/main/native-chat/agent-session-journal/journal-row-writer.tssrc/main/native-chat/agent-session-journal/journal-store.test.tssrc/main/native-chat/agent-session-journal/journal-store.tssrc/main/native-chat/agent-session-wire/structured-agent-session-adapter.tssrc/main/native-chat/agent-session-wire/structured-agent-session-grouped-prompt.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host-mutations.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host-prompt-cancellation.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-host.tssrc/main/native-chat/agent-session-wire/structured-agent-session-mutation-admission.tssrc/main/native-chat/agent-session-wire/structured-agent-session-mutation-plans.tssrc/main/native-chat/agent-session-wire/structured-agent-session-operation-settlement.tssrc/main/native-chat/agent-session-wire/structured-agent-session-prompt-cancellation.tssrc/main/native-chat/agent-session-wire/structured-agent-session-send-idempotency.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-turn-cancellation.tssrc/main/native-chat/agent-session-wire/structured-agent-session-turns.test.tssrc/main/native-chat/agent-session-wire/structured-agent-session-turns.tssrc/main/runtime/agent-session-record-operation-settlement.test.tssrc/main/runtime/agent-session-record-operation-settlement.tssrc/main/runtime/agent-session-record-store.tssrc/renderer/src/components/native-chat/use-structured-agent-session-prompt-cancel.test.tsxsrc/renderer/src/components/native-chat/use-structured-agent-session.tssrc/shared/agent-session-journal-schemas.tssrc/shared/agent-session-journal-types.tssrc/shared/agent-session-operation-ledger.test.tssrc/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.
| resolvedBy: resolution.resolvedBy ?? null, | ||
| resolvedAt: resolution.resolvedAt ?? null, | ||
| ...(resolution.settlementId ? { settlementId: resolution.settlementId } : {}) |
There was a problem hiding this comment.
🩺 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/sharedRepository: 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 500Repository: 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 500Repository: 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 500Repository: 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.
| Number.isSafeInteger(settlement.runtimeFence) && | ||
| (settlement.runtimeFence as number) > 0 && |
There was a problem hiding this comment.
🗄️ 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 -60Repository: 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 -320Repository: 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"
doneRepository: 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 -260Repository: 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.
There was a problem hiding this comment.
ℹ️ 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 —
performCancelnow persists apreparedsettlement before interrupting the provider, flushes the journal, persistsprovider-confirmed, then CAS-settles the durable prompts;resumePromptCancellationsettles a retry from the journal proof (settlementId === prompt-cancel:<op>) without interrupting twice, andresumeAtCurrentFencere-admits provider-confirmed retries under the current ledger fence. - Codex cancellation deferral —
CodexStructuredTurnCancellationblocks and holds the providerturn/completeduntil the interrupt is confirmed, then releases it exactly once with the settlement merged in, socollectCodexTurnPromptCancellationsstamps the caller'ssettlementId/resolvedBy/resolvedAtonto the durable row. - Settlement write guard —
AgentSessionRecordStore.recordOperationOutcomeIfCurrentlets anunsettledwrite advancepending → unknownwhile apendingwrite only overwritespending, so the generic error path can no longer downgrade a prepared/confirmed settlement. - Claude prompt groups and journal bounds —
ClaudeJournalPromptGroupsreplaces per-prompt tombstones with settlement-stamped cancelled bodies;cancelledJournalPromptBodydeep-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.getretry.
openrouter/deepseek/deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏
| return cancelJournalPromptsAtRevisions(this.rowWriter, () => this.state, input) | ||
| } | ||
|
|
||
| hasAppliedSettlement(settlementId: string): boolean { |
There was a problem hiding this comment.
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.
Final-head Electron QA (
|
Final review status (
|
|
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. |
There was a problem hiding this comment.
ℹ️ 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.jsongainscomponents.native-chat.approval.cancel(954e78a) anden-runtime-required.jsongains its generated mirror (6abdeca). No other production change; the card's call site still readscomponents.native-chat.question.cancel.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| "allow": "Allow", | ||
| "deny": "Deny" | ||
| "deny": "Deny", | ||
| "cancel": "Cancel" |
There was a problem hiding this comment.
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.There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the one commit since the prior pullfrog review at 6abdeca.
- Ambiguous retry kept recoverable —
resumePromptCancellationnow returnsnullwhen a retry's provider cancel reportscancelled: falseand the journal holds no cancellation proof, instead of returning acancelled: falsesuccess that settled the ledger row assucceeded. The operation staysunknownwith itspreparedsettlement, the client retry reuses the same operation id, and a later provider confirmation can still settle it — matching the existingsetOption"unknown outcome is not a successful replay" precedent. - Regression coverage — a new host test drives a lost interrupt reply followed by a
cancelled: falseretry and asserts theagent_session_operation_unknownrefusal with the prepared settlement retained; it fails against the prior success return.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
Final-head Electron QA (
|
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run re-reviewed the one commit since the prior pullfrog review at 4b6cb77.
- Retained ambiguous cancellation identity —
requestStructuredAgentSessionMutationnow routes bothagentSession.conversationCommandandagentSession.cancelrefusals throughagentSessionRefusalOperationState, so anagent_session_operation_unknowncancel returnsunknownanduseMobileStructuredAgentSessionCancelkeeps the same client operation id for the retry instead of deleting it and minting a new one. Conversation-command behavior is unchanged: onlyagent_session_operation_unknownmaps tounknownfor either method. - Added regression coverage — a new
use-mobile-structured-agent-session-cancel.test.tsxdrives an ambiguous refusal into a retry (same operation id) and asettled-rejectedrefusal into a retry (fresh id), plus a success case that releases the id. The ambiguous case fails against the prior classification.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Review status: PASS — ready to merge, with the residual validation gaps below.
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. |
There was a problem hiding this comment.
✅ 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 newclearCodexPromptTurnhelper) forgets provider requests bound to a settled(threadId, turnId), wired throughCodexJournalTranslatorDeps.clearPromptTurnintoacquisition.prompts.clearTurn. - Turn-bound prompt identity —
bindPromptItemIdgains an optionalturnId; 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 —
settleCodexJournalTurnalways calls its lifecycle batch (empty batches are a no-op inpartitionJournalLifecycleMutations) so it can cancel the pending journal prompts and clear the provider registry even when there is no other row to write;collectCodexTurnPromptCancellationsnow receives an explicitpendingPromptsplus the receipt fields. - Shared lifecycle writer and prompt-byte accounting —
appendLifecycleMutationsmoved to the sink asappendCodexLifecycleMutations;promptBytes/retainedPromptBytesmoved tocodex-prompt-registry-bounds.tsascodexPromptBytes/codexRetainedPromptBytes. - Coverage — new tests assert that a turn completing while an approval or question is pending writes a
cancelledrow and callsclearPromptTurn, and thatclearTurndrops 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.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
|
Conflict resolution is complete and pushed at 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:
The PR is currently |
|
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. |



















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