Repository navigation
fix(pi): resolve OMP tab identity from the outer wrapper, not the wrapped pi (#6364) - #9600
Conversation
…pped pi (#6364) OMP runs as a `shell → omp → pi` process tree and Orca recognizes both `omp` and `pi` as distinct agents. The foreground-process readers scored the deepest `+` foreground descendant, so they returned the wrapped `pi` engine instead of the `omp` the user actually launched — and because the sampled `+` frame moves between omp and pi across command boundaries, the read oscillated and the tab icon/label flickered OMP↔Pi. It surfaced on Remote Host / SSH (only in a worktree, only while working) where a mirrored/restored pane has no client-side launchAgent to anchor identity, so the (host-read) foreground was the only pi/omp signal — and it was wrong. Fix the detection at its source so foregroundAgent is trustworthy everywhere (local tab icon, exit detection, and the remote mirror): - Add `resolveOuterWrapperForegroundProcess` (src/shared/foreground-wrapper-agent.ts): when the recognized foreground winner shares a `titleIdentityGroup` with a shallower recognized ancestor, return the shallowest — the outer wrapper. Stable regardless of which of omp/pi holds the foreground at the sample; bare Pi and cross-group reads (Codex, etc.) are unchanged. - Wire it into both readers: local `agent-foreground-process.ts` and the SSH relay `pty-shell-utils.ts`. Also harden the relay's fallback short-circuit so a pi-compatible process reported by node-pty rescans for the omp wrapper instead of trusting `pi` raw (never downgrading below the fallback). Also unify the host-side publish path onto the shared owner resolver: the mobile session snapshot builders now resolve pane ownership via `resolvePaneAgentOwner` ({launchAgent, hookAgent}) instead of a bespoke `launchAgent ?? foregroundAgent`, so the host stops being a divergent fourth identity path and the hook's host-stamped identity survives when launchAgent is dropped on a mirrored pane. Tests: unit coverage for the wrapper resolver, `shell→omp→pi` ps trees for both readers (outer omp, oscillating-frame, bare pi, node-pty pi fallback), and a host-snapshot regression that keeps an OMP hook labeled OMP when the wrapped pi child owns the foreground.
📝 WalkthroughWalkthroughAdds shared logic to resolve outer wrappers when embedded agents share a synthetic identity group. Unix, Windows, relay, and daemon PTY foreground detection now use this resolver. Runtime pane ownership considers launch metadata and hook agent identities before foreground fallbacks. Tests cover wrapped and unwrapped 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches📝 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.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)
22579-22588: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueUpdate stale function reference in comment.
The comment references
buildMobileSessionSnapshot, which appears to be a stale function name (likely renamed totoMobileSessionTabsResult, where the matching logic now resides).♻️ Proposed refactor
- // `pi` of a shell→omp→pi tree and oscillates. See buildMobileSessionSnapshot. + // `pi` of a shell→omp→pi tree and oscillates. See toMobileSessionTabsResult.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f1ff246c-9703-4987-a53c-d02194435e11
📒 Files selected for processing (8)
src/main/providers/agent-foreground-process.test.tssrc/main/providers/agent-foreground-process.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/relay/pty-shell-utils.test.tssrc/relay/pty-shell-utils.tssrc/shared/foreground-wrapper-agent.test.tssrc/shared/foreground-wrapper-agent.ts
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/relay/pty-shell-utils.ts (1)
260-273: 📐 Maintainability & Code Quality | 🔴 Critical | 🏗️ Heavy liftCross-bundle import violation.
Calling
resolveWindowsAgentForegroundProcesshere implies importing fromsrc/main/...intosrc/relay. Based on learnings,src/relayis bundled separately for remote deployments, and importing app-side modules from the main bundle breaks the separate relay bundle.Please ensure that Windows-specific process resolution logic needed by the relay is either duplicated, moved to
src/shared, or handled without depending onsrc/main.Run the following script to verify the import paths in this file:
#!/bin/bash # Verify if src/main is imported into src/relay/pty-shell-utils.ts rg "from '\.\./main/" src/relay/pty-shell-utils.tsSource: Learnings
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: f71d89df-2d4d-46bd-a044-5ac906ae4329
📒 Files selected for processing (9)
src/main/providers/agent-foreground-process.test.tssrc/main/providers/agent-foreground-process.tssrc/main/providers/windows-agent-foreground-process.tssrc/main/runtime/orca-runtime.test.tssrc/main/runtime/orca-runtime.tssrc/relay/pty-shell-utils.test.tssrc/relay/pty-shell-utils.tssrc/shared/foreground-wrapper-agent.test.tssrc/shared/foreground-wrapper-agent.ts
🚧 Files skipped from review as they are similar to previous changes (4)
- src/main/providers/agent-foreground-process.ts
- src/main/runtime/orca-runtime.test.ts
- src/shared/foreground-wrapper-agent.test.ts
- src/main/runtime/orca-runtime.ts
| execFile: execFileMock | ||
| })) | ||
|
|
||
| import { resetWindowsProcessRowsSnapshotForTests } from '../main/providers/windows-foreground-process-rows' |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟠 Major | ⚖️ Poor tradeoff
Cross-bundle import violation in test.
This imports resetWindowsProcessRowsSnapshotForTests from src/main into a src/relay test file. Based on learnings, src/relay modules must remain isolated from src/main to preserve the separate relay bundle architecture. While this is a test file, bridging the boundary here violates architectural hygiene and could complicate test environment isolation.
Consider mocking the required Windows process row behavior or providing a shared testing utility instead of reaching into the main bundle.
Source: Learnings
…pped pi (stablyai#6364) (stablyai#9600) * fix(pi): resolve OMP tab identity from the outer wrapper, not the wrapped pi (stablyai#6364) OMP runs as a `shell → omp → pi` process tree and Orca recognizes both `omp` and `pi` as distinct agents. The foreground-process readers scored the deepest `+` foreground descendant, so they returned the wrapped `pi` engine instead of the `omp` the user actually launched — and because the sampled `+` frame moves between omp and pi across command boundaries, the read oscillated and the tab icon/label flickered OMP↔Pi. It surfaced on Remote Host / SSH (only in a worktree, only while working) where a mirrored/restored pane has no client-side launchAgent to anchor identity, so the (host-read) foreground was the only pi/omp signal — and it was wrong. Fix the detection at its source so foregroundAgent is trustworthy everywhere (local tab icon, exit detection, and the remote mirror): - Add `resolveOuterWrapperForegroundProcess` (src/shared/foreground-wrapper-agent.ts): when the recognized foreground winner shares a `titleIdentityGroup` with a shallower recognized ancestor, return the shallowest — the outer wrapper. Stable regardless of which of omp/pi holds the foreground at the sample; bare Pi and cross-group reads (Codex, etc.) are unchanged. - Wire it into both readers: local `agent-foreground-process.ts` and the SSH relay `pty-shell-utils.ts`. Also harden the relay's fallback short-circuit so a pi-compatible process reported by node-pty rescans for the omp wrapper instead of trusting `pi` raw (never downgrading below the fallback). Also unify the host-side publish path onto the shared owner resolver: the mobile session snapshot builders now resolve pane ownership via `resolvePaneAgentOwner` ({launchAgent, hookAgent}) instead of a bespoke `launchAgent ?? foregroundAgent`, so the host stops being a divergent fourth identity path and the hook's host-stamped identity survives when launchAgent is dropped on a mirrored pane. Tests: unit coverage for the wrapper resolver, `shell→omp→pi` ps trees for both readers (outer omp, oscillating-frame, bare pi, node-pty pi fallback), and a host-snapshot regression that keeps an OMP hook labeled OMP when the wrapped pi child owns the foreground. * fix(pi): harden wrapper foreground ownership * fix(pi): preserve OMP ownership in daemon foreground reads * fix(pi): retain OMP owner when process scans fail
Summary
Fixes the OMP → Pi tab-icon/label flicker reported in #6364 (STA-944). The Remote Host beta report saw an OMP pane alternate OMP↔Pi while the agent was working because Orca exposed OMP's wrapped Pi engine as the pane owner.
Root cause
OMP runs as
shell → omp → pi, and Orca recognizes bothompandpias agents. Foreground readers could select the wrapped Pi child. Restored or mirrored remote panes often have nolaunchAgent, so that unstable foreground identity reached the tab directly.The first implementation also selected any shallower same-group process. That did not prove ownership: an unrelated/background OMP sibling could claim a foreground bare-Pi lineage.
Fix
resolveOuterWrapperForegroundProcessnow walks the selected process's realppidancestry and returns only an outer same-title-group ancestor. Sibling jobs cannot claim ownership, and malformed process-table cycles terminate safely.agentStatus, so an OMP hook cannot publish an OMP status beside a Pi title. The retained-row lookup is shared rather than duplicated.Prior fixes and why this one closes the remaining gap
The earlier fixes were valid for the signal path each one covered, but OMP identity was still being decided independently at several layers:
launchAgentwas absent.launchAgent: 'omp', preventing later Pi-compatible renderer title/hook/status frames from overriding that owner.processAgentsignal by re-owning it to a durable launch/hook owner. Its documented residual was a restored pane with nolaunchAgent, live/completed hook, or hibernated session: with no owner anchor, a raw foregroundpiread could still win.This PR closes that exact residual at the source instead of asking another renderer rule to reinterpret an already-wrong value. When the host selects the wrapped
pi, it follows that process's real parent chain and resolves the outeromp; the same rule now feeds local, daemon, relay, and Windows readers. The daemon retains that resolved owner across bounded refresh/degraded scans, and Remote Host publishes title and status from one retained owner. Therefore a launchless/hookless restored pane can recover OMP ownership fromshell → omp → piitself, while bare Pi and unrelated sibling jobs remain Pi.The regression coverage combines every previously protected OMP case with the formerly unprotected case: a restored/launchless Remote Host pane receiving Pi foreground evidence from a real OMP ancestor chain. This is why #9600 closes the escape hatch left by the earlier PRs rather than moving the same ambiguity to another identity layer.
Reliability contract
launchAgent.Testing
git diff --checkpass.pnpm run lintis currently blocked by pre-existing switch-exhaustiveness errors in untouchedsrc/main/daemon/daemon-server.tsandsrc/renderer/src/components/skills/skill-freshness-group.tsx.