Skip to content

fix(mobile): keep the foreground transcript when a nested CLI inherits the pane - #22866

Closed
innocarpe wants to merge 4 commits into
stablyai:mainfrom
innocarpe:fix/mobile-foreground-transcript
Closed

innocarpe wants to merge 4 commits into
stablyai:mainfrom
innocarpe:fix/mobile-foreground-transcript

Conversation

@innocarpe

@innocarpe innocarpe commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Orca Mobile showed a background Codex CLI transcript in place of the foreground Claude Code session.

Claude starts that Codex process with the foreground pane's ORCA_PANE_KEY. While the foreground turn was still active, the nested hook replaced the pane's provider session, and mobile chat follows that session.

While an inherited pane-key hook comes from the same terminal owner during an active foreground turn, Orca keeps the foreground provider session, model, and prompt. The nested event can still update activity, tool evidence, and output.

Focused fix

  • In scope: preserving foreground identity context while continuing to accept nested activity from the same terminal owner.
  • Out of scope: hiding a background pane the user opened themselves, and changing how mobile renders a session it was given.

Preserves

  • A nested done still does not mark the parent turn finished.
  • Another connection that collides on the same pane key can still take the pane.
  • After the foreground turn is done, a real agent switch on that pane still applies.
  • A different pane key is a different session.

Evidence

Vitest 4.1.11: 60 tests passed across server-ingest-remote.test.ts, server-hook-http-ingest.test.ts, agent-status-provider-session.test.ts, and useIpcEvents-agent-status-snapshot-replay.test.ts.

User-regression tradeoffs

While a foreground turn is still active, a second agent that inherited that pane key cannot replace the visible transcript. Its activity and output remain visible.

Fixes #22767

@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 broadened suppression drops a nested agent's non-done event entirely. That breaks src/main/agent-hooks/server-ingest-remote.test.ts — verified failing on this branch and passing on 646e9a5b — because the test pins the existing contract that nested tool progress still updates the row while identity stays pinned.

Reviewed changes

  • Suppression predicate broadened — shouldSuppressInheritedTerminalStatus now also suppresses non-done inherited hooks from the same terminal owner, not only done.
  • sameTerminalOwner threaded through all three call sites — the main server uses its WSL-aware owner comparison; the two renderer paths compare stored vs incoming connectionId.
  • Tests added — a nested Codex working no longer replaces the foreground Claude provider session, and a real agent switch is adopted once the foreground turn is done.

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

Comment thread src/shared/agent-status-identity.ts Resolved
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 28bc5d77-15bc-4d09-8d35-408ce2f7ee7c
📥 Commits

Reviewing files that changed from the base of the PR and between 4a1e860d607aaab38465c110bb4f733c5d70a894 and 9460f29.

📒 Files selected for processing (1)
  • src/main/agent-hooks/server-ingest-remote.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Inherited active-pane statuses retain the existing provider session, model, and prompt when the terminal owner matches and the incoming state is not done. Server and renderer status handling apply this condition. Regression tests cover matching and different connections, WSL-relayed status, and Codex updates after the foreground status is done.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: 🟡 Moderate · up to 9460f

A stale but still-running foreground session, or an inherited pane event from another worktree, may still show nested-agent context in the selected view. Resolve these ownership and freshness edge cases before merging.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 9460f

The change reduces accidental replacement of the foreground session and preserves the inspected completion and connection-switch behavior. Risk is limited, but consistent ownership handling across recovery and cross-worktree cases is not fully established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The inspected change affects context selection for an accepted status update addressing a pane key. It does not itself create hook admission, grant credentials or expand execution authority; broader exposure depends on the existing producers and admission controls.

Trust Boundaries and Controls

  • observed — Server terminal ownership rejects two supplied, unequal worktree identities before considering connection equality. Renderer retained-context ownership uses normalized connection equality, while its earlier admission gate rejects incompatible resolved connection ownership. The ownership definitions are therefore not identical.
  • inferred — The ownership difference alone does not demonstrate a new cross-worktree session leak on the ordinary synchronized path. The server already resolves inherited events to the foreground agent type before emission; an unchanged known type does not trigger renderer inherited-context retention. Divergent recovery state and alternative producers remain unverified.

Hardening Proposals

  • proposed — Define whether worktree identity is part of retained-context ownership, then align server and renderer ownership policy where that contract requires equivalence. This would reduce future control drift; it is not a verified vulnerability finding.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 5 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address issue [#22767]. For an inherited-pane event from the same terminal owner during an active turn, the server and renderer retain the foreground provider session, prompt, and model. R…
Out of Scope Changes check ✅ Passed The server, renderer, shared identity helper, and regression tests support issue [#22767]. The WSL relay handling preserves same-terminal ownership across relayed events. No unrelated changes appear i…
Title check ✅ Passed The title clearly identifies the mobile foreground-transcript fix for nested CLI sessions. It is specific and matches the main change.
Description check ✅ Passed The description explains the user impact, the change, its scope, preserved behavior, linked issue, and focused test results. It does not include visual proof or state N/A with a reason, and it does no…
  • Fix all pre-merge checks with AI

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.

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 587be35d-0428-4093-93a9-9beb6ed0e1a2

📥 Commits

Reviewing files that changed from the base of the PR and between 646e9a5 and 54cebf7c8b22d36abb79cf4c38b6c13c1c3c58d1.

📒 Files selected for processing (6)
  • src/main/agent-hooks/server-hook-http-ingest.test.ts
  • src/main/agent-hooks/server/server-status-update.ts
  • src/renderer/src/hooks/ipc-events/agent-status-event-applicator.ts
  • src/renderer/src/store/slices/agent-status-live-entry-builder.ts
  • src/renderer/src/store/slices/agent-status-provider-session.test.ts
  • src/shared/agent-status-identity.ts

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

Comment thread src/shared/agent-status-identity.ts Resolved
@innocarpe
innocarpe force-pushed the fix/mobile-foreground-transcript branch from 54cebf7 to 977e389 Compare September 26, 2026 04:04
@innocarpe

Copy link
Copy Markdown
Contributor Author

Sync update (977e389c3f)

Address review: a nested non-done hook on the same terminal keeps tool progress but no longer replaces the foreground providerSession. A nested done is still dropped. Worktree inequality and the 30-minute freshness window are unchanged.

@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

Changes since the prior pullfrog review: the second commit reworks how a nested hook is held back, replacing the whole-event suppression that broke the active-pane contract.

  • Split the inherited-hook predicate — shouldSuppressInheritedTerminalStatus drops the whole event only for a nested done; the new shouldRetainInheritedProviderSession pins the foreground providerSession while letting the nested hook's prompt/tool/lastAssistantMessage through.
  • Pinned the transcript at all three call sites — the main server substitutes previous.providerSession into sessionPinnedPayload, the renderer applicator rewrites the metadata source, and the live-entry builder keeps existing.providerSession and clears providerSessionChanged.
  • Fixed the WSL relay ownership comparison — the renderer now compares against the normalized ownershipConnectionId (null for a WSL relay) instead of the raw wsl: id, matching main's WSL-aware sameTerminalOwner.
  • Tests — added nested-working retention, different-connection replacement, post-done adoption, and a WSL-relay snapshot-replay case; the previously failing server-ingest-remote.test.ts:197 active-pane contract passes again.

Verified on the head commit: src/main/agent-hooks/ (101 files, 1049 passed), agent-status store slices (25 files, 211 passed), and ipc-events (15 files, 57 passed).

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

@woonys

woonys commented Oct 1, 2026

Copy link
Copy Markdown

Independent field repro on 1.4.217 (macOS host, iOS over LTE): Claude Code in a terminal pane ran codex exec -m gpt-6-astra via Bash at 04:06:49; at 04:07 mobile chat for that tab showed "Start a chat with Claude" while "Agent is working". session.tabs.list on the host returned the tab as agentType: "claude" with model: "gpt-6-astra" and the prompt Claude had passed to Codex. The Claude transcript itself was intact (nativeChat.readSession returned 40 messages once the next Claude hook restored providerSession).

One gap vs this diff: model and prompt still come from the nested Codex event, so the tab keeps showing gpt-6-astra and Codex's prompt even with providerSession pinned. It may be worth retaining those alongside providerSession when inheritedFromActivePane is true.

@innocarpe
innocarpe force-pushed the fix/mobile-foreground-transcript branch from 977e389 to 4a1e860 Compare October 4, 2026 09:01
@innocarpe

Copy link
Copy Markdown
Contributor Author

Thanks for the field repro. A nested event from the same terminal owner now retains the foreground pane's providerSession, model, and prompt in both the host status row and renderer store. The nested event can still update live activity and output, and a different connection can take over the identity context. I added regression coverage for the Claude → nested Codex sequence, checking that the Claude transcript/model/prompt stay paired while Codex output is retained, plus a different-connection takeover case. The focused suites pass (33 tests), and oxlint/oxfmt pass. I have not rerun the iOS-over-LTE scenario on a device.

@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

Retaining the foreground prompt for an inherited nested hook re-breaks server-ingest-remote.test.ts:197 — the exact pre-existing contract the previous commit restored. The suite is red on this head: 1 failed / 1193 passed.

Reviewed changes

Changes since the prior pullfrog review (977e389c): the follow-up commit 4a1e860 extends the inherited-hook retention from the provider session to the foreground model and prompt.

  • Widened inherited-context retention — shouldRetainInheritedProviderSession is renamed to shouldRetainInheritedPaneContext; the main server and the renderer live-entry builder now also keep previous.payload.model and previous.payload.prompt, not just providerSession.
  • Reordered promptInteractionKey — computed above commandCodeNewTurn, so a retained prompt is also treated as unchanged and does not trip command-code new-turn detection.
  • Extended the tests — the nested-Codex assertions now expect prompt: 'foreground claude' and model: 'claude-sonnet'.

ℹ️ Nitpicks

  • The PR body still says "A nested hook on the same terminal is now ignored for the whole turn", but the implementation only pins the foreground context and still applies the nested hook's tool progress and lastAssistantMessage. Update the description to match.

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

…s the pane

A background Codex CLI started from Claude inherits ORCA_PANE_KEY. While that
foreground turn is still active, the nested hook replaced the pane's provider
session, so mobile Chat UI followed the background transcript. Drop that hook
on the same terminal. A different connection may still take the pane, and a
real switch after the foreground turn is done is unchanged.
@innocarpe
innocarpe force-pushed the fix/mobile-foreground-transcript branch from 4a1e860 to 9460f29 Compare October 4, 2026 11:03

@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

Changes since the prior pullfrog review (4a1e860): the follow-up commit reconciles the stale nested-hook test with the intentional prompt-retention behavior.

  • Aligned the active-pane contract — server-ingest-remote.test.ts:197 is renamed to "…active pane context…" and now expects the foreground prompt: 'parent codex' instead of the nested prompt, matching the 4a1e860 behavior change; the nested toolName/toolInput still flow through, so the test still exercises the "activity/tool evidence keeps updating" contract.
  • Prior regression cleared — the four focused suites (60 tests) and the full src/main/agent-hooks/ directory (1165 passed / 11 skipped) are green on 9460f29. The PR body now documents the tradeoff.

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

@nwparker

Copy link
Copy Markdown
Contributor

Closing as superseded by merged #29264 and #29386. The merged implementation preserves the foreground session by rejecting inherited cross-provider updates at the execution host before status and cache mutation. It also retains an identified idle Claude process after Stop and checks exit/suspension before permitting a genuine provider replacement.

The #22767 path is covered by the real mobile transcript resolver and transcript reader over a paired client in three hidden Electron runs each on macOS and Linux; 197 focused tests passed. Proof and verification limits are recorded in #29386 and the issue closure. This PR's narrower field-preservation approach is no longer needed.

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.

[Bug]: Mobile shows background Codex CLI output instead of foreground Claude Code

3 participants