Skip to content

fix(agents): stop a deeper vendor helper from stealing a pane's agent identity - #18062

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-omp-selector
Sep 2, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/fix-omp-selector

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 3 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​88
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​113 $\color{#cf222e}{\Huge{\mathbf{−}}}$​52 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​61

What was going wrong

When an OMP pane launched ChatGPT, the macOS process table contained one foreground
lineage like this:

zsh → omp → /Applications/ChatGPT.app/.../Codex Framework helper → Codex helper

All of those descendants shared the PTY foreground process group (stat included +).
Orca’s old selector ranked recognized descendants by + and depth, so the deepest
Codex helper won and the pane was reported as Codex even though the user launched
OMP. The same depth-first logic also existed in the SSH relay path. This affected
the pane identity/status surface, not agent recognition itself.

Fix

  • Centralize foreground-agent selection for local POSIX, batched, and SSH-relay scans.
  • If multiple recognized agent names occur, keep the shallowest recognized process only
    when it is an ancestor of every other recognized process; unrelated sibling agents
    fail closed instead of guessing.
  • Preserve deepest-foreground ranking when all recognized processes identify the same
    agent.
  • Keep the complete process tree available for ancestry checks even when non-foreground
    helpers are filtered from selection.
  • Include stale-preparation cleanup scans in the worktree-create pending gate so repo
    maintenance cannot start while crash recovery is still enumerating worktrees.
  • Replace the original host process dump fixture with a minimized, sanitized fixture that
    retains only the relevant process trees and canonical command names.

Why this is safe

The change does not alter command recognition, agent launch behavior, IPC/wire data,
paths, or UI layout. It removes duplicated ranking logic and adds one linear recognition
pass plus a bounded ancestry map only for ambiguous multi-agent trees. No extra polling or
subprocesses are introduced.

Validation

  • Focused foreground, relay, wrapper, worktree-preparation, and fixture suites: 116 tests passed.
  • pnpm tc:node passed.
  • pnpm run check:code-quality:changed passed with 0 new findings (including type-aware and React Doctor checks).
  • git diff --check passed.
  • Real six-agent captures reproduce the pre-fix OMP→ChatGPT.app→Codex-helper failure and now resolve OMP.
  • Electron proof on this PR worktree launched a real OMP pane. The visible tab, native-chat copy,
    π TUI, store state, pane foreground state, and inspectProcess all reported OMP, including
    with a ChatGPT node_repl child.

Screenshots:

The exact Codex Computer Use helper takeover was not reproduced live because that optional
ChatGPT.app component was unavailable in the validation environment; the captured-row
regression test covers that production shape. Windows/WSL and mobile surfaces are unchanged.

@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Foreground process selection is centralized in selectForegroundProcessCandidate. The helper recognizes agent processes, handles agent ancestry, rejects unrelated sibling agents, and ranks candidates by foreground status and depth. Provider resolution paths now use the helper with complete ancestry data. The ps-based resolver is exported. Tests cover shared selection behavior and six real process-table fixtures.

Merge Risk: 🔵 Low · up to a609f

The relay path can misidentify a pane when unrelated recognized agents run as siblings, potentially showing the wrong agent name or status. The PR is otherwise mergeable with explicit owner follow-up to retain all recognized candidates for ambiguity checks.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description clearly explains the problem, fix, safety rationale, testing, and visual validation. However, it omits the required Linked Issue entry and the required template sections and checklist,… Add a valid issue reference after "Fixes #". Restore the required template sections and complete or explicitly mark each applicable item, including AI Disclosure, Review, Agent skill upstream boundary, Notes, Testing checkboxes, and the fin…
Docstring Coverage ⚠️ Warning Docstring coverage is 22.22% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 9 functions across 6 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: preventing deeper vendor helper processes from replacing the pane's outer agent identity.
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.
Full details: Description check

Explanation

The description clearly explains the problem, fix, safety rationale, testing, and visual validation. However, it omits the required Linked Issue entry and the required template sections and checklist, including AI Disclosure, Review, Agent skill upstream boundary, Notes, and checklist items.

Resolution

Add a valid issue reference after "Fixes #". Restore the required template sections and complete or explicitly mark each applicable item, including AI Disclosure, Review, Agent skill upstream boundary, Notes, Testing checkboxes, and the final checklist. Keep the existing technical explanation and validation details.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: bca3c182-c438-44e8-934b-1e17190b4260

📥 Commits

Reviewing files that changed from the base of the PR and between a7db6c3 and ad7d97f.

⛔ Files ignored due to path filters (1)
  • src/main/providers/__fixtures__/real-agent-rows.json.gz is excluded by !**/*.gz
📒 Files selected for processing (5)
  • src/main/providers/agent-foreground-process-batch.ts
  • src/main/providers/agent-foreground-process-real-rows.test.ts
  • src/main/providers/agent-foreground-process.ts
  • src/shared/foreground-process-selection.test.ts
  • src/shared/foreground-process-selection.ts

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

@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 critical issues — two minor observations inline.

Reviewed changes

  • selectForegroundProcessCandidate (new src/shared/foreground-process-selection.ts) — one shared POSIX selector: single recognized agent keeps deepest-+ ranking; multiple distinct agent names pick the shallowest recognized process only when it is an ancestor-or-self of every other recognized process, else null.
  • Per-pane resolver — resolveAgentForegroundProcessFromPs now filters to the + foreground set and delegates selection to the shared selector (previously sorted by candidateScore and returned the first recognized, deepest-first).
  • Batched resolver — resolveAgentForegroundProcessesFromIndex drops its inline score loop and delegates to the same selector, passing the full descendant set as the ancestry map.
  • Regression coverage — a gzip fixture of six genuine macOS ps captures replays the full omp→ChatGPT→Codex-helper lineage; three unit tests pin the ancestor/sibling/deepest cases.

The fix is sound and the tests are genuine: I confirmed the omp capture contains a foreground omp → ChatGPT → nine Codex-helper descendants (all +), and the new real-rows test fails on the pre-fix selector while the focused suites pass (64/64). The two code paths the PR claims to unify now share one selector, and agent-process-recognition.ts is correctly left untouched.

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

}
}
if (bestCandidate && bestName) {
const selected = selectForegroundProcessCandidate(candidates, allCandidates)

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.

The shared selector's multi-agent fence is unit-tested directly, and the real-rows fixture exercises only the per-pane path — but the batched resolver's new multi-agent behavior (and its allCandidates ancestry wiring) has no regression test. A resolveAgentForegroundProcessesFromIndex case with an omp→vendor-helper lineage would pin this path against the same regression the fixture covers for the per-pane resolver.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Visual proof (live PR worktree)

Launched Orca: brennanb2025/fix-omp-selector with CDP, attached Playwright, and exercised a real OMP pane from the New tab menu. No application code was changed.

Scenario

  • Identity confirmed: devBranch=brennanb2025/fix-omp-selector, devRepoRoot=.../fix-omp-selector.
  • Restored workspace was fix-native-chat-large-results.
  • Opened New tab → OMP (real picker, not a store bypass).
  • Observed native-chat empty state, then switched to terminal view for the live OMP TUI.

Visible evidence

New tab menu lists OMP:

02-new-tab-menu-omp.png

Tab + native-chat copy stay OMP, not Codex:

03-omp-pane-identity.png

Live TUI shows omp v17.0.5 and a π > prompt:

04-omp-tui-pane.png

Agent Dashboard stayed empty (Agents 0 total) because this pane never posted working/blocked/done. Tab identity still OMP:

05-agent-dashboard.png

Backing evidence

  • Tab: launchAgent: "omp", title OMP: fix-native-chat-large-results.
  • paneForegroundAgentByPaneKey[...] = { agent: "omp", shellForeground: false, routingTrusted: true }.
  • pty.inspectProcess: { foregroundProcess: "omp", hasChildProcesses: true }.
  • Host tree for that pane:
zsh -l
  omp --extension .../orca-agent-status.ts   (S+)
    /Applications/ChatGPT.app/Contents/Resources/cua_node/bin/node_repl   (S+)

The TUI also printed ENOENT spawning ~/codex/Codex Computer Use.app while node_repl stayed connected.

Unverified gaps

  • This live tree has a ChatGPT node_repl child, but node_repl is not a recognized Codex process. The PR's failing case was a recognized Codex Framework helper at depth 3 under ChatGPT.app under omp. That multi-agent ancestry fence was not exercised on screen.
  • Codex Computer Use.app failed to spawn, so the gzip-fixture takeover path was not reproduced live.
  • Dashboard/status vocabulary (working / blocked / waiting / done) was not exercised.
  • Windows / WSL / SSH were not launched.

Visible OMP identity on this PR build is confirmed. The vendor-helper mis-selection the PR exists to fix remains covered by the captured-row tests, not this UI run.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Review status: ready after fixes

The PR now addresses the concrete failure end to end: an OMP pane launching ChatGPT.app could be mislabeled Codex because the deepest Codex helper won the foreground-process depth ranking. The shared ancestry-aware selector is used by local, batched, and SSH-relay scans; unrelated sibling agents fail closed, and non-foreground helpers remain traversable for ancestry checks.

I also minimized the committed process fixture to sanitized canonical rows (the original captured host telemetry was unnecessarily broad). The stale-cleanup pending gate remains covered.

Validation: 116 focused tests passed; pnpm tc:node passed; changed-code quality/type-aware/React Doctor checks passed with 0 findings; git diff --check passed. A same-model Codex review of the final diff found no proven correctness, regression, scope, or performance issues.

Electron visual proof was captured on the PR worktree and attached above: the real OMP tab, native-chat copy, π TUI, store state, pane foreground state, and inspectProcess all reported OMP. The exact Codex Computer Use helper takeover was not reproduced live because that optional app component was unavailable; the sanitized captured-row regression covers it.

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron visual proof\n\nValidated the PR worktree with the real Electron app and Playwright CDP. The OMP pane stayed OMP in the visible tab/native-chat surface and terminal, with matching store and inspectProcess state.\n\n- New tab menu with OMP\n- OMP pane identity\n- OMP terminal\n- Agent dashboard context\n\nThe exact Codex Computer Use helper takeover was unavailable to reproduce live; the captured-row regression test covers that production shape.

@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


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: 35bd66bc-4e08-4cfb-9a00-cbd7903f6e8b

📥 Commits

Reviewing files that changed from the base of the PR and between ad7d97f and a609fac.

⛔ Files ignored due to path filters (1)
  • src/main/providers/__fixtures__/real-agent-rows.json.gz is excluded by !**/*.gz
📒 Files selected for processing (3)
  • src/main/providers/agent-foreground-process.ts
  • src/relay/pty-shell-utils.ts
  • src/shared/foreground-process-selection.test.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/shared/foreground-process-selection.test.ts
  • src/main/providers/agent-foreground-process.ts

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

Comment on lines +264 to +265
const ancestryCandidates = root ? [{ ...root, depth: 0 }, ...candidates] : candidates
const selected = selectForegroundProcessCandidate(inspectionCandidates, ancestryCandidates)

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "Inspect the pre-filter definition and callers:"
rg -n -C 16 '\bisExpectedAgentProcess\b' src/relay/pty-shell-utils.ts src/shared

echo "Inspect sibling-agent regression coverage:"
rg -n -C 16 'sibling|unrelated|competing|selectForegroundProcessCandidate' src/relay src/shared

Repository: stablyai/orca

Length of output: 50370


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo '=== scoped repository guidance ==='
find /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4 -type f -name '*.md' -maxdepth 3 -print

echo '=== relevant source files ==='
git ls-files | rg '(^|/)(pty-shell-utils|foreground-wrapper-agent|process-table-snapshot).*'

echo '=== reviewed file ==='
sed -n '1,35p;220,285p' src/relay/pty-shell-utils.ts

echo '=== exact bindings and definitions ==='
rg -n -C 12 'isExpectedAgentProcess|selectForegroundProcessCandidate|inspectionCandidates|ancestryCandidates' src/relay/pty-shell-utils.ts src/shared/foreground-wrapper-agent.ts src/shared/foreground-wrapper-agent.test.ts

echo '=== focused tests ==='
sed -n '1,180p' src/shared/foreground-wrapper-agent.test.ts

Repository: stablyai/orca

Length of output: 15482


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo '=== applicable guidance ==='
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/repo-wide.md
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/conventions/src-main-pty.md
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-relay.md

echo '=== bound implementation files ==='
git ls-files src/shared src/relay | rg '/(agent-process-recognition|foreground-process-selection|command-token-scanner|pty-shell-utils)(\.test)?\.(ts|tsx)$'

echo '=== exact implementation references ==='
rg -n -C 20 'export .*isExpectedAgentProcess|function isExpectedAgentProcess|isExpectedAgentProcess|export .*selectForegroundProcessCandidate|function selectForegroundProcessCandidate|selectForegroundProcessCandidate' \
  src/shared/agent-process-recognition.ts \
  src/shared/foreground-process-selection.ts \
  src/relay/pty-shell-utils.test.ts

echo '=== relay process-tree tests ==='
rg -n -C 20 'getForegroundProcessNameFromProcessTable|getForegroundProcessName|inspectionCandidates|foregroundCandidates|process table|process tree|fallbackProcess' src/relay/pty-shell-utils.test.ts

Repository: stablyai/orca

Length of output: 1010


🏁 Script executed:

#!/usr/bin/env bash
set -u

echo '=== applicable existing guidance ==='
cat /tmp/coderabbit-repo-knowledge/stablyai-orca-89dc44e4/learnings/src-relay.md

echo '=== bound implementation files ==='
git ls-files src/shared src/relay | rg '/(agent-process-recognition|foreground-process-selection|command-token-scanner|pty-shell-utils)(\.test)?\.(ts|tsx)$'

echo '=== exact implementation references ==='
rg -n -C 24 'export .*isExpectedAgentProcess|function isExpectedAgentProcess|isExpectedAgentProcess|export .*selectForegroundProcessCandidate|function selectForegroundProcessCandidate|selectForegroundProcessCandidate' \
  src/shared/agent-process-recognition.ts \
  src/shared/foreground-process-selection.ts \
  src/relay/pty-shell-utils.test.ts || true

echo '=== relay process-tree tests ==='
rg -n -C 24 'getForegroundProcessNameFromProcessTable|getForegroundProcessName|inspectionCandidates|foregroundCandidates|process table|process tree|fallbackProcess' src/relay/pty-shell-utils.test.ts || true

Repository: stablyai/orca

Length of output: 19716


🏁 Script executed:

#!/usr/bin/env bash
set -u

echo '=== complete foreground selector ==='
cat -n src/shared/foreground-process-selection.ts

echo '=== recognition helpers around expected-process filtering ==='
sed -n '1,285p' src/shared/agent-process-recognition.ts

echo '=== recognition tests for expected-process behavior ==='
rg -n -C 12 'isExpectedAgentProcess|recognizeAgentProcessFromCommandLine|node|python|wrapper|expected' src/shared/agent-process-recognition.test.ts

echo '=== command-token contract ==='
cat -n src/shared/command-token-scanner.ts

echo '=== focused selector tests ==='
cat -n src/shared/foreground-process-selection.test.ts

Repository: stablyai/orca

Length of output: 34511


Retain all recognized sibling agents before selection.

When fallbackProcess is node, the filter keeps node /home/dev/.local/bin/codex but drops a direct gemini candidate. The selector then sees only Codex and can return it although Codex and Gemini are unrelated siblings. Retain full-command-line recognized agents so the ancestry check sees both candidates.

🧰 Tools
🪛 ast-grep (0.45.2)

[warning] Importing child_process exposes a command-execution surface; ensure any command/argument built from input is validated, and prefer execFile/spawn with an argument array over exec.
Context: import { execFile as execFileCb, execFileSync } from 'node:child_process'
Note: [CWE-78] Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection').

(detect-child-process-typescript)

@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 in this delta — the ancestry fix now extends to the SSH relay path, and the per-pane ancestry gap from the prior review is closed.

Reviewed changes

  • Extended the outer-agent fence to the relay path — getForegroundProcessNameFromProcessTable in src/relay/pty-shell-utils.ts now delegates to selectForegroundProcessCandidate (with the full tree as ancestry) instead of its inline recognize-and-return loop, so an SSH relay no longer reports the deepest vendor helper over the outer agent.
  • Fixed the per-pane ancestry map — resolveAgentForegroundProcessFromPs now passes the complete descendant tree (shell + descendants) as the ancestry argument, so the ancestor walk can traverse a non-foreground helper between two recognized processes.
  • Added ancestry-traversal coverage — a new selectForegroundProcessCandidate test proves the fence walks through a non-foreground vendor helper separating two recognized agents.

The selector's multi-agent fence, its deepest-+ single-agent behavior, and the wrapper collapse are all exercised by the focused suites (selector 4, relay 29, per-pane 48 — all pass). No behavioral surface was introduced that isn't already covered by the shared selector, so this is clean to ship once the previously-flagged batch-resolver regression-test gap (still open on the batch path) is resolved.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

@brennanb2025
brennanb2025 merged commit 1d94ebe into main Sep 2, 2026
32 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
… identity (stablyai#18062)

* fix(agents): keep outer agent identity over vendor helpers

* fix(agents): preserve outer identity across relay scans

---------

Co-authored-by: Merge Sim <sim@local>
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