Skip to content

fix(structured-sessions): don't pass an inherited pane identity to structured chat children - #26426

Closed
petersindex wants to merge 1 commit into
stablyai:mainfrom
petersindex:fix-structured-child-inherited-pane-identity
Closed

petersindex wants to merge 1 commit into
stablyai:mainfrom
petersindex:fix-structured-child-inherited-pane-identity

Conversation

@petersindex

@petersindex petersindex commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #26417

ELI5

Every Orca terminal carries a few variables that say which pane it is. If you start Orca itself from inside one of its own terminals (to restart a dev build, say), the new Orca process copies that pane's variables. Every Claude or Codex chat it opens then inherits them too, so the chat's status gets reported to that old terminal instead of its own workspace. The chat shows up as activity in an unrelated workspace. Now a chat never inherits another pane's identity.

What changed

  • Before: start Orca from an Orca terminal in workspace A, then open a Claude or Codex chat in workspace B. The chat's process carries A's ORCA_PANE_KEY, ORCA_TAB_ID, ORCA_WORKTREE_ID and ORCA_WORKSPACE_ID, so its hook status lands on A's pane.
  • After: the chat's process carries none of A's pane identity. It keeps its own ORCA_AGENT_SESSION_ID, ORCA_STRUCTURED_SESSION and CLI settings, and a registered worker keeps its own ORCA_TERMINAL_HANDLE.
  • Mechanism:
    • structuredSessionChildIdentityEnv builds every structured child's identity. Its doc comment already says it must never put a pane key in a child's environment, but it passed through whatever the app inherited. It now removes the inherited pane identity before adding the session's own values. That covers Claude, whose launch hands it the full environment.
    • Codex merges the app's environment under its overlay at spawn time, so codexStructuredChildEnvironment also puts the inherited keys in envToDelete. It leaves out any key the session sets itself, because envToDelete runs after the overlay and would otherwise wipe a registered worker's handle.
    • The key list (INHERITED_PANE_IDENTITY_ENV_KEYS) now lives once in spawn-env-keys.ts, beside the other inherited-env lists. Pi and ACP already stripped most of these keys with their own hand-written copies. They now use the shared list, which also adds ORCA_WORKSPACE_ID to both.

Why this approach

  • The terminal path already refuses a pane key it can't prove belongs to the spawn (spawn-env.ts), and ACP and Pi already strip one. Claude and Codex were the two structured paths without it, and both build their identity in structuredSessionChildIdentityEnv, so the fix goes there.
  • The list includes the scrub-safe aliases ORCA_AGENT_PANE and ORCA_AGENT_LAUNCH, which the issue doesn't mention. A stale alias would misattribute status the same way.
  • It removes only pane identity, not every ORCA_* variable: the session's id, marker, CLI path, user data path and hook port all have to reach the child.

Testing

  • On my Mac the bug is live in the test runner itself. The runner runs inside an Orca terminal, so its own environment carries ORCA_PANE_KEY, ORCA_TAB_ID, ORCA_WORKTREE_ID, ORCA_WORKSPACE_ID, ORCA_TERMINAL_HANDLE and ORCA_AGENT_PANE.
  • New tests:
    • structured-session-child-identity-env.test.ts: inherited pane identity is dropped, and a registered worker's own handle replaces an inherited one.
    • codex-structured-child-environment.test.ts: spawns a real child process through the Codex app-server connection, with the identity both in the app's environment and in the shell environment Codex launches with. The child reports it received none of it.
    • claude-structured-launch-resolution.test.ts: the real Claude launch resolver, given an inherited environment with the pane identity, produces a launch environment without it.
  • All four new tests fail on main and pass with this change.
  • Existing suites pass: src/main/acp, src/main/pi, src/main/codex, src/main/claude, src/main/ipc/pty and the structured identity tests (610 files). pnpm tc:node, oxlint, oxfmt and check:code-quality:changed pass.
  • Tested on macOS. The reporter is on Windows, and the change is plain environment handling with no platform branches. I haven't run it on Windows.
  • I didn't change claude-structured-* source, so I didn't run the real Claude CLI suite.

Visual Proof

N/A: the change is to the environment a chat's child process starts with, and the tests check that environment directly, including through a real spawned child.

Follow-up (not in this PR)

ACP sessions also inherit the app's ORCA_TERMINAL_HANDLE when the session has no registered handle. Fixing that needs the same rule Codex uses here, but it changes an exact envToDelete assertion in ACP's OpenCode tests, so I've kept this PR to Claude and Codex. I can send that as a separate PR.

AI review

  • Cross-platform: plain env-key deletion, no platform branches.
  • SSH / remote: structured sessions run on the execution host; nothing here changes what crosses the relay.
  • Performance: a handful of key deletions per chat launch.
  • Security: removes values that should never reach the child; adds no new inputs.
  • Backwards compatibility: no wire or schema change.
  • Agents and integrations: covers every structured agent child. Claude and Codex go through structuredSessionChildIdentityEnv, and Pi and the ACP agents (Grok, OpenCode, OMP) use the shared key list. Terminal agents are unchanged.

X: @petersindex

…ructured chat children

When Orca itself is started from one of its own terminals, the app process
carries that pane's ORCA_PANE_KEY, ORCA_TAB_ID, ORCA_WORKTREE_ID,
ORCA_WORKSPACE_ID, launch token, their scrub-safe aliases and its terminal
handle. Structured Claude and Codex children inherited all of it, so their
hook status landed on that unrelated pane.

structuredSessionChildIdentityEnv now drops the inherited pane identity before
adding the session's own values, which covers Claude. Codex merges the app's
env under its overlay at spawn, so it also deletes the inherited keys there,
sparing a registered worker's own handle. The key list lives once in
spawn-env-keys.ts, and Pi and ACP reuse it instead of their own copies.

Fixes stablyai#26417
@coderabbitai

coderabbitai Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fd4bc9c2-7c9c-4a58-817e-8383f41fb508
📥 Commits

Reviewing files that changed from the base of the PR and between 00a8250 and 74120e1.

📒 Files selected for processing (8)
  • src/main/acp/acp-launch-specs.ts
  • src/main/claude/claude-structured-launch-resolution.test.ts
  • src/main/codex/codex-structured-child-environment.test.ts
  • src/main/codex/codex-structured-child-environment.ts
  • src/main/ipc/pty/host-env/spawn-env-keys.ts
  • src/main/pi/rpc-launch.ts
  • src/main/runtime/structured-session-child-identity-env.test.ts
  • src/main/runtime/structured-session-child-identity-env.ts

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


📝 Walkthrough

Walkthrough

The change centralizes inherited pane identity keys and removes inherited identity from structured child environments. ACP and Pi use the shared key list in their child deletion rules. Codex now returns inherited identity keys for deletion and also removes the visuals directory key when visuals are absent. Tests cover identity cleanup and retention of session-specific values.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 74120

The intended Claude and Codex identity cleanup is supported by the inspected launch paths. No established issue currently blocks merging.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.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 Issue #26417 requires structured Claude and Codex children to reject inherited pane identity and retain session identity. structuredSessionChildIdentityEnv removes the shared pane-identity keys and …
Out of Scope Changes check ✅ Passed The shared key list and its adoption in Pi and ACP centralize the same inherited pane-identity rule. The added ORCA_WORKSPACE_ID protection addresses the same misattribution risk. These changes supp…
Title check ✅ Passed The title clearly and concisely describes the primary change: preventing structured chat children from inheriting pane identity.
Description check ✅ Passed The description is detailed and covers the user impact, implementation, rationale, linked issue, testing, visual proof, and known follow-up work. It omits the formal checklist and agent-skill boundary…
  • Fix all pre-merge checks with AI
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@nwparker

nwparker commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded — the linked issue (#26417) has been resolved on main by #27204 (v1.4.225). Thanks for the contribution!

@nwparker nwparker closed this Nov 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants