Skip to content

fix(pi): resolve OMP tab identity from the outer wrapper, not the wrapped pi (#6364) - #9600

Merged
brennanb2025 merged 4 commits into
mainfrom
brennanb2025/fix-issue-6364-still
Jul 20, 2026
Merged

brennanb2025 merged 4 commits into
mainfrom
brennanb2025/fix-issue-6364-still

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

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 both omp and pi as agents. Foreground readers could select the wrapped Pi child. Restored or mirrored remote panes often have no launchAgent, 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

  • resolveOuterWrapperForegroundProcess now walks the selected process's real ppid ancestry and returns only an outer same-title-group ancestor. Sibling jobs cannot claim ownership, and malformed process-table cycles terminate safely.
  • Local POSIX, daemon-backed PTYs, SSH relay, and Windows CIM/WMIC readers use the same ancestry rule. Windows context filtering retains the full candidate tree so it cannot discard OMP before resolving a selected Pi descendant.
  • Recognized OMP fallbacks keep their zero-subprocess fast path. Only the ambiguous Pi fallback is enriched, using the existing globally deduplicated 500 ms process-table snapshot; daemon reads retain the resolved owner across its bounded 1 s refresh cadence.
  • Host mobile snapshots use a fresh retained hook identity for both the published tab title and 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:

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 outer omp; 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 from shell → omp → pi itself, 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

  • Invariant: foreground identity belongs to the selected process lineage; a same-group ancestor may own it, but a sibling may not.
  • Failure source: [Bug] Pasting images into an agent CLI not working using Remote Host #6364 / STA-944, especially restored Remote Host panes without launchAgent.
  • Oracle: POSIX, daemon-cadence, relay, Windows, sibling-lineage, context-filtering, zero-scan, and retained-hook title/status regression tests.
  • Performance budget: authoritative OMP reads perform no new subprocess work; ambiguous Pi reads reuse the bounded process-table cache; retained hook lookup runs once and is reused.
  • Residual gap: no live Remote Host repro binary/E2E was available, so the remote process tree and host publication path are covered deterministically.

Testing

  • 1,039/1,039 focused and adjacent tests pass across the shared resolver, process-table cache, local/Windows provider, daemon PTY, SSH relay, and host runtime.
  • 456/456 renderer PTY connection tests pass; the one failure seen only in a larger suite-order run was not reproducible alone or in its full file and touches no changed module.
  • Typecheck passes for node, CLI, and web projects.
  • Oxlint, commit-time React lint, formatting, reliability-gate manifest, max-lines ratchet, and git diff --check pass.
  • Full pnpm run lint is currently blocked by pre-existing switch-exhaustiveness errors in untouched src/main/daemon/daemon-server.ts and src/renderer/src/components/skills/skill-freshness-group.tsx.

…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.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds 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 pi processes, cross-group agents, shell rescans, Windows ancestry, cache timing, and retained omp status.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: resolving OMP tab identity from the outer wrapper instead of the wrapped pi.
Description check ✅ Passed The description is detailed and mostly template-aligned with summary, rationale, edge cases, and testing; screenshots, security audit, and notes are not explicit.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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: 1

🧹 Nitpick comments (1)
src/main/runtime/orca-runtime.ts (1)

22579-22588: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Update stale function reference in comment.

The comment references buildMobileSessionSnapshot, which appears to be a stale function name (likely renamed to toMobileSessionTabsResult, 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

📥 Commits

Reviewing files that changed from the base of the PR and between 99df415 and 0ac4822.

📒 Files selected for processing (8)
  • src/main/providers/agent-foreground-process.test.ts
  • src/main/providers/agent-foreground-process.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/relay/pty-shell-utils.test.ts
  • src/relay/pty-shell-utils.ts
  • src/shared/foreground-wrapper-agent.test.ts
  • src/shared/foreground-wrapper-agent.ts

Comment thread src/shared/foreground-wrapper-agent.ts Resolved

@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: 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 lift

Cross-bundle import violation.

Calling resolveWindowsAgentForegroundProcess here implies importing from src/main/... into src/relay. Based on learnings, src/relay is 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 on src/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.ts

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: f71d89df-2d4d-46bd-a044-5ac906ae4329

📥 Commits

Reviewing files that changed from the base of the PR and between 0ac4822 and e101d97.

📒 Files selected for processing (9)
  • src/main/providers/agent-foreground-process.test.ts
  • src/main/providers/agent-foreground-process.ts
  • src/main/providers/windows-agent-foreground-process.ts
  • src/main/runtime/orca-runtime.test.ts
  • src/main/runtime/orca-runtime.ts
  • src/relay/pty-shell-utils.test.ts
  • src/relay/pty-shell-utils.ts
  • src/shared/foreground-wrapper-agent.test.ts
  • src/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'

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.

📐 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

@brennanb2025
brennanb2025 merged commit f655ae3 into main Jul 20, 2026
8 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
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.

1 participant