Skip to content

fix(pi): isolate status ownership in new terminals - #22717

Merged
nwparker merged 3 commits into
stablyai:mainfrom
mmarabel:fix/pi-terminal-status-owner-env
Sep 25, 2026
Merged

nwparker merged 3 commits into
stablyai:mainfrom
mmarabel:fix/pi-terminal-status-owner-env

Conversation

@mmarabel

Copy link
Copy Markdown
Contributor

ELI5

Opening a new Pi terminal could leave Orca blind to its progress if another Pi had launched the terminal host. The new terminal inherited a flag saying the other Pi owned its status, so it never reported anything. New terminals now start without that flag; actual child agents inside the same terminal still stay quiet.

What Changed

  • Clear Pi, OMP, and Prime process-local status/title ownership markers when composing local, daemon, and SSH terminal environments, including SSH revival and late environment overrides.
  • Send the same three names through the existing envToDelete field on desktop and headless spawn routes, so a persistent older daemon or SSH relay cannot restore them from its own environment.
  • Preserve pane IDs, launch tokens, hook credentials, user settings, and the extension's nested-child/reload behavior.

Why

The ownership flag describes one agent process, not every terminal the host creates. Resetting it at the independent-terminal boundary fixes the leak without weakening the child-agent guard or adding process-tree checks. Clearing only the app's environment would miss a persistent daemon's inherited copy.

The live investigation found two fresh Pi panes with correct identities and receiver credentials, but no host agent rows. Their foreign owner belonged to a still-running Pi in another workspace. The installed extension registered 0 hooks with the leaked marker and 17 without it. Twelve new boundary regression cases failed before the fix and pass after it; three additional tests cover deletion requests to persistent daemons.

Linked Issue

Fixes #22716.

Related, distinct causes: #16109/#16631 handles an exited owner; #17267 handles a reused-pane launch-token fence; #20135 handles stale remote predecessor identity.

Visual Proof

N/A — No visual change to layout or components. This repairs host-side status production used by the existing UI. Before/after hook-registration and nested-child behavior are covered by automated tests; no user's desktop windows or running agents were modified.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated

Validated on Linux with ORCA_BACKGROUND_LAUNCH=1:

  • 318 tests passed across 17 suites, including all 15 new regression cases, existing local/daemon/SSH environment suites, Pi-family ownership/reload tests, title-marker suppression, and hook-server close/retirement/publication tests.
  • pnpm tc passed.
  • pnpm lint passed (two existing mobile prefer-array-flat-map warnings).
  • pnpm run check:code-quality:changed -- upstream/main passed with zero new findings across 11 files.
  • pnpm run build:relay passed for Linux/macOS/Windows x64 and arm64, plus WSL relays.
  • pnpm run build:electron-vite passed for main, preload, and renderer.

Native macOS/Windows execution, packaging, the full repository test suite, and end-to-end desktop checks remain CI coverage; cross-platform bundle builds are not claimed as native execution tests.

AI Disclosure

Implementation and review assisted by OpenAI GPT-6 Astra (max).

Review

  • Cross-platform/local/remote: pure environment-key deletion on the execution host; covers daemon and SSH revival paths without client-side PID assumptions. Folder workspaces need no Git-specific handling.
  • Agents/integrations: limited to Pi-family ownership flags; hooks, session identity, nested-child suppression, and other agents are unchanged.
  • Compatibility/security: reuses envToDelete; no new RPC fields, capabilities, or status precedence rules. Genuine nested agents still inherit the parent's marker through ordinary process spawning.
  • Performance/UI: three fixed-key deletions per environment pass, no new I/O or process probes; no UI styling changes.

Agent skill upstream boundary

  • Not applicable; no skill-installer source or content changed.

Notes

The paired execution host needs this fix to build clean new terminal environments. Existing running agents are not rewritten or restarted. An already-contaminated agent must be relaunched through the updated spawn path. No Git-provider behavior changes.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • Local checks above pass; CI covers full-suite/platform checks not run locally

@coderabbitai

coderabbitai Bot commented Sep 24, 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: fe491e29-5166-474d-ac41-644545c0fc78

📥 Commits

Reviewing files that changed from the base of the PR and between 524af05 and 3b7ba4c.

📒 Files selected for processing (1)
  • src/main/daemon/pty-subprocess/spawn-environment.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/daemon/pty-subprocess/spawn-environment.ts

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


📝 Walkthrough

Walkthrough

The change defines three Pi process-owner environment keys and removes them from daemon, local, IPC, runtime, and relay PTY environments. The IPC and runtime spawn options also add the keys to their environment deletion lists. Tests cover host and request environments, environment augmenters, daemon finalization, relay revival, and agent-status behavior.

Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 3b7ba

The inspected terminal-creation paths prevent inherited Pi status ownership markers from reaching new terminals. No actionable merge risk was identified.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: isolating Pi status ownership in new terminals.
Description check ✅ Passed The description includes all required sections, explains the user impact and implementation, links issue #22716, documents testing and platform coverage, and records the remaining CI coverage.
Linked Issues check ✅ Passed The PR meets the coding requirements in #22716. Local PTY creation strips the Pi, OMP, and Prime process-local ownership markers before and after environment overrides. Desktop, headless, daemon, and …
Out of Scope Changes check ✅ Passed The changes remain within #22716. Production changes isolate the specified process-local ownership markers at local, daemon, headless, SSH, and revival boundaries. Supporting tests verify the required…
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 11 files.

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.

@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

  • Strip Pi ownership at every spawn boundary — New PI_PROCESS_OWNER_ENV_KEYS / stripPiProcessOwnerEnv (src/main/pty/pi-process-owner-env.ts) removes ORCA_PI_STATUS_OWNED, ORCA_PRIME_AGENT_STATUS_OWNED, and ORCA_PI_TITLE_MARKER_OWNED from the daemon (createDaemonPtyEnvironment + finalizeDaemonPtyEnvironment), local provider (buildLocalPtySpawnEnvironment + enforceLocalPtySpawnEnvironmentOverrides), and relay (PtyHandler.buildSpawnEnv, shared by spawn and revive).
  • Cross-version deletion requests — The same three keys are merged into envToDelete on both IPC and headless runtime spawn routes, so a persistent older daemon or SSH relay applies the deletion from its own inherited environment through the pre-existing envToDelete field.
  • Tests — Four new suites cover host/request/late-augmenter sources across all three boundaries, plus a daemon extension-harness case that confirms the owner still registers, a child sharing its env stays suppressed, and reload keeps ownership. provider-dispatch.test.ts pins the exact SSH envToDelete set.

I traced the ownership semantics in agent-status-handler-source.ts:127 and titlebar-extension-source.ts:109: the marker is only inherited through ordinary process spawning from a running agent, which this change never touches — the strip only removes keys from the fresh terminal env object. All key lists are complete (no other ORCA_*OWNED env markers exist; OMP session ownership is in-process via globalThis), and every spawn path I enumerated (local, daemon create/finalize/rescrub, relay spawn/revive, headless runtime, SSH request) is covered. The finalize helpers do not re-introduce the keys, so strip ordering holds.

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

@mmarabel

Copy link
Copy Markdown
Contributor Author

Local validation is green: 318 tests across 17 suites, typecheck, full lint, changed-code quality, app build, and all six relay bundle targets. The follow-up commits only document the environment boundaries; executable code is unchanged.

GitHub has the fork workflows waiting for maintainer approval (PR Checks, PR test LoC, and Computer-use e2e). Could a maintainer approve the pending runs? The current contributor account cannot approve upstream workflows.

@nwparker

Copy link
Copy Markdown
Contributor

Maintainer review: traced local, daemon, headless IPC, SSH spawn/revive, and late environment overrides. The deletion request uses the existing envToDelete contract, including older persistent hosts; ordinary Pi subagent spawning still inherits ownership and stays suppressed. Cross-checked Pi's subagent launcher in local pi-mono. No remaining correctness findings or unresolved inline bot threads.

The local verification covered 879 tests across 105 suites (including both Pi fixes), node typecheck, and changed-code quality; the new ownership/history regressions failed before the fixes. Approved the pending fork workflow runs and am waiting for CI before merge. Native Windows execution is covered by CI, not claimed from the local macOS run.

@nwparker

Copy link
Copy Markdown
Contributor

The full changed-spec lane passed 19/20 tests; its sole failure was ssh-docker-reconnect-pane-restore timing out after reconnect while waiting for top's "load average" text (line 115). I ran that exact spec independently on both revisions:

This is an intermittent reconnect-test failure; no failing Pi ownership behavior was reproduced. All eight unit shards, static analysis, typecheck, packaging, shell contracts, relay integration, managed hooks, and native Linux/Windows/macOS smoke checks passed. The separate remaining Docker SSH suite is still running.

@nwparker

Copy link
Copy Markdown
Contributor

Final maintainer disposition: the remaining Docker SSH suite passed (job 107904378087). All inline bot comments are addressed; no code findings remain. Merging the reviewed head 3b7ba4c with the original reconnect-test timeout documented above and a successful isolated rerun on that exact head and on base. No admin override requested.

@nwparker
nwparker merged commit 7a71e20 into stablyai:main Sep 25, 2026
40 of 41 checks passed
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:] Pi status is suppressed in new terminals by an inherited live owner PID

2 participants