Repository navigation
fix(agents): stop a deeper vendor helper from stealing a pane's agent identity - #18062
Conversation
📝 WalkthroughWalkthroughForeground process selection is centralized in Merge Risk: 🔵 Low · up to 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)
✅ Passed checks (3 passed)
Full details: Description checkExplanation 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.
✨ Finishing Touches 💡 1📝 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
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: bca3c182-c438-44e8-934b-1e17190b4260
⛔ Files ignored due to path filters (1)
src/main/providers/__fixtures__/real-agent-rows.json.gzis excluded by!**/*.gz
📒 Files selected for processing (5)
src/main/providers/agent-foreground-process-batch.tssrc/main/providers/agent-foreground-process-real-rows.test.tssrc/main/providers/agent-foreground-process.tssrc/shared/foreground-process-selection.test.tssrc/shared/foreground-process-selection.ts
Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.
There was a problem hiding this comment.
ℹ️ No critical issues — two minor observations inline.
Reviewed changes
selectForegroundProcessCandidate(newsrc/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, elsenull.- Per-pane resolver —
resolveAgentForegroundProcessFromPsnow filters to the+foreground set and delegates selection to the shared selector (previously sorted bycandidateScoreand returned the first recognized, deepest-first). - Batched resolver —
resolveAgentForegroundProcessesFromIndexdrops 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
pscaptures 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
| } | ||
| } | ||
| if (bestCandidate && bestName) { | ||
| const selected = selectForegroundProcessCandidate(candidates, allCandidates) |
There was a problem hiding this comment.
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.
Visual proof (live PR worktree)Launched Scenario
Visible evidenceNew tab menu lists OMP: Tab + native-chat copy stay OMP, not Codex: Live TUI shows Agent Dashboard stayed empty ( Backing evidence
The TUI also printed Unverified gaps
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. |
Review status: ready after fixesThe 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; 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 |
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
|
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Team
Run ID: 35bd66bc-4e08-4cfb-9a00-cbd7903f6e8b
⛔ Files ignored due to path filters (1)
src/main/providers/__fixtures__/real-agent-rows.json.gzis excluded by!**/*.gz
📒 Files selected for processing (3)
src/main/providers/agent-foreground-process.tssrc/relay/pty-shell-utils.tssrc/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.
| const ancestryCandidates = root ? [{ ...root, depth: 0 }, ...candidates] : candidates | ||
| const selected = selectForegroundProcessCandidate(inspectionCandidates, ancestryCandidates) |
There was a problem hiding this comment.
🎯 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/sharedRepository: 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.tsRepository: 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.tsRepository: 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 || trueRepository: 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.tsRepository: 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)
There was a problem hiding this comment.
ℹ️ 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 —
getForegroundProcessNameFromProcessTableinsrc/relay/pty-shell-utils.tsnow delegates toselectForegroundProcessCandidate(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 —
resolveAgentForegroundProcessFromPsnow 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
selectForegroundProcessCandidatetest 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.
DeepSeek Pro (free via Pullfrog for OSS) | 𝕏
… 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>





What was going wrong
When an OMP pane launched ChatGPT, the macOS process table contained one foreground
lineage like this:
All of those descendants shared the PTY foreground process group (
statincluded+).Orca’s old selector ranked recognized descendants by
+and depth, so the deepestCodex 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
when it is an ancestor of every other recognized process; unrelated sibling agents
fail closed instead of guessing.
agent.
helpers are filtered from selection.
maintenance cannot start while crash recovery is still enumerating worktrees.
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
pnpm tc:nodepassed.pnpm run check:code-quality:changedpassed with 0 new findings (including type-aware and React Doctor checks).git diff --checkpassed.π TUI, store state, pane foreground state, and
inspectProcessall reported OMP, includingwith a ChatGPT
node_replchild.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.