Repository navigation
Conversation
…e session's worktree Codex >= 0.157 runs every TUI's hooks inside one shared app-server daemon per CODEX_HOME, so the ORCA_* stamp on every hook post was the env of the pane that happened to start the daemon. worktree ps then showed another worktree's prompt and working state on that pane's row. The managed hook script now detects a --managed-daemon ancestor and marks the post; the hook server re-owns marked posts by the session's cwd (keep the stamp when its worktree holds the cwd, else the single pane of the session's deepest worktree, else drop). The SSH relay, which has no pane inventory, keeps or drops by the stamped worktree.
Review follow-up. Rebind targets are now panes with a live Codex client in their process tree (host sweep shared with the OpenCode binder, reused for 1s, 1.5s wait cap), so shell/dev-server splits no longer turn a rebind into a drop or inherit a session. A session whose cwd is outside every worktree stays with the only Codex pane (or the stamp when no rival Codex pane exists), restoring status for `codex -C <dir>`. Unkeyed panes hydrated at boot no longer drop the daemon starter's own events.
There was a problem hiding this comment.
ℹ️ No critical issues — one minor robustness suggestion inline, plus a platform-coverage question for the author to confirm.
Reviewed changes
Read the full 17-file diff and ran the five new test files (37/37 pass). What this PR does:
- Hook script marks daemon-run posts.
codex-hook-script.tswalks up to four ancestors forapp-server … --managed-daemonand stampsexecutor=codex-shared-daemon(new header on the raw-JSON transport, form field otherwise); daemon posts are deliberately never spooled. - Ingest re-owns marked posts.
codex-shared-daemon-attribution.tsdecides keep / rebind / drop from the session's cwd against the registered Codex panes, applied inserver-lifecycle.tsbefore normalization, disposition and transcript polling. - Codex-pane inventory from the host sweep.
codex-client-panes.tsreusessweepProcessIdentitiesto flag only panes with a live Codex client; the pid→ppid walk moved topane-process-ancestry.tsand is now shared with the OpenCode binder. - Relay keep/drop.
mergeRelayAgentHookRequestapplies the same decision with no pane inventory. - Tests. Integration test through the real HTTP ingest and the
worktree psrow builder, attribution unit tests, classifier/sweep tests, and a hook-script test.
I also verified the macOS ps invocation is not width-truncated when run from a command substitution (Apple's ps.c sets termwidth = UNLIMITED for a non-tty stdout, and args is a no-trunc last field), so the daemon match is not at risk from a long argv.
ℹ️ Windows keeps the pre-fix misattribution
The detection and re-ownership are POSIX-only; the .cmd script sets no executor marker and the listener re-owns only marked posts. The PR documents Windows as "unchanged from before", but if the managed daemon runs on Windows too then Codex 0.157+ sessions there still file onto the daemon-starter's worktree — the exact bug this fixes elsewhere. Worth confirming whether a Windows follow-up is planned so the platform gap is an explicit decision rather than implicit.
Technical details
# Windows parity for the shared-daemon attribution
## Affected sites
- `src/main/codex/codex-hook-script.ts` — `getManagedScript` win32 branch emits no `executor` marker.
- `src/shared/agent-hook-listener/codex-shared-daemon-attribution.ts` — re-ownership triggers only on `executor === 'codex-shared-daemon'`.
## Required outcome
- Either a Windows detection path (e.g. walking the process table through the sanctioned `windows-process-table.ts`) or an explicit statement that Windows Codex has no shared managed daemon / is out of scope.DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| const names = [row.executable, row.argv[0] ?? '', row.argv[1] ?? ''].map(baseName) | ||
| // Why the triple prefix: older npm builds ship `codex-<triple>`, and Linux `comm` truncates it. | ||
| const isCodex = names.some( | ||
| (name) => | ||
| name === 'codex' || name === 'codex.js' || /^codex-(?:x86_64|aarch64|arm64)/.test(name) | ||
| ) | ||
| return isCodex && !row.argv.includes('app-server') |
There was a problem hiding this comment.
isCodexClientProcess applies the same 'codex' / codex-<triple> / codex.js alternatives to argv[1], but only the npm launcher needs the argv[1] slot and its script name is codex.js; a native or codex-<triple> binary is already caught by executable/argv[0]. As written, any long-lived process whose first argument is literally codex (a tail -f codex, a local node codex) is counted as a Codex pane, and a second candidate in the same worktree flips a real session from rebind/keep to drop. Suggest restricting the argv[1] slot to codex.js while keeping the bare/triple names on executable/argv[0].
Technical details
# Narrow the argv[1] classifier slot
## Affected sites
- `src/main/codex/codex-client-panes.ts:25-31` — `names` includes `baseName(argv[1])`, then matches `'codex'`, `codex.js`, and `codex-(x86_64|aarch64|arm64)`.
## Required outcome
- The npm-launcher shape (`node …/codex.js`) still classifies as a Codex client.
- A process whose only Codex-looking token is a non-`codex.js` first argument does not.
## Suggested approach (optional)
- Match `codex` and the triple prefix against `executable`/`argv[0]` only; match `codex.js` in `argv[1]` (or anywhere in argv) for the launcher.|
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 configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (17)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthroughCodex hook scripts now mark posts made by the managed shared daemon. The local server detects Codex client panes and attributes daemon posts using cwd and worktree data. Relay ingestion applies attribution using request headers without a pane inventory. Tests cover process detection, both request transports, worktree matching, ambiguous ownership, and restart scenarios. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to The checked hook paths preserve daemon attribution and safely discard unattributable events. No identified issue currently prevents merging after normal checks. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to The change addresses prompts appearing on the wrong worktree, but attributing a session to the only detected Codex pane can itself put a prompt on the wrong worktree when process detection is incomplete. Hook requests remain token-gated; this is a worktree-attribution risk, not evidence of a newly open network endpoint. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 2📝 Generate docstrings 💡
🛠️ Fix failing CI checks 💡
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 |
Confirmed field case: two Codex panes in one worktree still lose the working rowThanks for this fix. I confirmed the shared-daemon attribution failure on macOS, Orca 1.4.215, Codex 0.158.0, and checked the attribution code at e6fc5ab. This is additional evidence for the documented same-worktree limitation, not a claim that this PR introduced the problem. Observed on the installed release (read-only inspection):
The actual topology matters: project A supplied the daemon stamp; project B had two live Codex processes in separate panes—one idle older 0.156.1 session and the affected resumed 0.158.0 session. Neither B pane was the stamped pane. Focused replay against this PR's actual functionUsing synthetic identities/paths only: const a = 'tab-a:11111111-1111-4111-8111-111111111111'
const b1 = 'tab-b1:22222222-2222-4222-8222-222222222222'
const b2 = 'tab-b2:33333333-3333-4333-8333-333333333333'
const wtA = 'repo-a::/synthetic/project-a'
const wtB = 'repo-b::/synthetic/project-b'
attributeCodexDaemonHook({
cwd: '/synthetic/project-b',
stampedPaneKey: a,
stampedWorktreeId: wtA,
panes: [
{ paneKey: a, worktreeId: wtA, runsCodexClient: true },
{ paneKey: b1, worktreeId: wtB, runsCodexClient: true },
{ paneKey: b2, worktreeId: wtB, runsCodexClient: true }
]
}) // { kind: 'drop' }
The isolated replay verified four cases:
These were focused function-level checks using the pinned PR source (TypeScript syntax/import adaptation only), not a full build or live UI test of this PR. No production hooks were injected and no running session was interrupted. Could this topology be explicitly covered in the regression/acceptance tests, with either a positive session-to-pane ownership fix here or a linked follow-up? The desired result is that the active resumed B session remains visible as working without assigning its status to the idle sibling. I agree that guessing between candidates would be unsafe; the safe-drop behavior should remain until ownership is proven. As currently implemented, this PR fixes the single-candidate case but should not be considered an end-to-end fix for this reported two-pane configuration. |

ELI5
Newer Codex versions run one shared helper program in the background, and every Codex window talks to it. The helper runs Orca's "report what Codex is doing" script for all of those windows. It does that while still wearing the name tag of whichever Orca window started it first. So when you typed a prompt in worktree B, Orca read the name tag and filed the prompt under worktree A.
With this fix, the script notices when the shared helper is the one running it and says so. Orca then ignores the name tag and asks which Codex window the session really belongs to. It goes by the folder the session is working in and by which Orca panes actually have Codex running. If Orca can't tell for sure, it shows nothing for that report instead of showing it on the wrong worktree.
Description
Source: a user report in the crash channel (Orca 1.4.215, macOS).
worktree psshowed one worktree's Codex prompt as the active prompt of a different worktree.Before: with Codex running in two worktrees, A (started first) and B, B's prompts, tool calls and "done" events all showed on A's row. A's row read "working" with B's latest prompt, and B's row showed no agent. Typing into terminals was not affected.
After: each Codex session's status and prompt appear on the row of the worktree that session is working in. If Orca cannot tell which pane owns a session, the event is dropped rather than put on the wrong row.
Mechanism:
Root cause. Codex 0.157 and later starts one shared
codex app-server --managed-daemonperCODEX_HOME, becausedaemon_auto_startis stable and on by default. Every Codex TUI on that home connects to it over a unix socket. The daemon, not the TUI, runs thehooks.jsoncommands, so every hook inherits the daemon's environment. That environment holds theORCA_PANE_KEY/ORCA_WORKTREE_ID/ORCA_TAB_IDof the pane that first started the daemon. Orca's hook script posts those values, and the hook server files the event under them without checking them.Why the existing guard didn't help. PR fix(codex): Codex 0.157+ starts in Orca-managed homes instead of failing with SUN_LEN #22878 sets
daemon_auto_start=falseonly when the socket path is too long. That flag only stops a new daemon from starting. A TUI still connects to a daemon that is already running (verified live below). Daemons also keep running after Orca restarts and upgrades.Change 1: the hook script marks daemon-run posts.
src/main/codex/codex-hook-script.ts(POSIX) walks up to 4 parent processes. If one isapp-server … --managed-daemon, it adds acodex-shared-daemonmarker. The marker travels in its own header and form field (hook-envelope.ts,agent-hook-types.ts), so older listeners ignore it and a new listener treats an old script's posts as before.Change 2: only marked posts are re-owned, and only onto panes running Codex. The new
src/main/codex/codex-client-panes.tsreuses the OpenCode binder's host process sweep (sweepProcessIdentities). It flags each registered PTY whose shell has a live Codex client (native binary, npmcodex.jslauncher, orcodex-<triple>;app-serveris excluded). The pid→ppid walk moved fromopencode-session-binder.tsinto the newsrc/main/agent-hooks/pane-process-ancestry.ts, and both features use it.Change 3: decision order (
src/shared/agent-hook-listener/codex-shared-daemon-attribution.ts, called fromserver-ingest-normalization.tsbefore status, launch-token and transcript-polling code reads the stamp):The SSH relay has no pane inventory, so it only keeps or drops by the stamped worktree. A moved post takes the target pane's launch token, and Codex subagent transcript polling uses the moved post.
Fix evidence
1) Live reproduction with real Codex 0.157.1 (
codex --versiongivescodex-cli 0.157.1; no Orca build needed)Setup:
CODEX_HOMEat/tmp/cxr/homewith a fake model provider (no network, no auth).UserPromptSubmit/SessionStarthook that logs its ownORCA_PANE_KEY/ORCA_WORKTREE_ID, its parent PID and the stdin payload.wtA,ORCA_PANE_KEY=tabA:...,ORCA_WORKTREE_ID=wt-MacOS. Started first.wtB,tabB,wt-StudentRegistration.Hook log (
/tmp/cxr/hooklog.jsonl):B's prompt carries A's pane key and worktree id.
28261every time. That process iscodex app-server --listen unix:// --managed-daemon(PPID 1).ps ewwon the daemon showsORCA_PANE_KEY=tabA/ORCA_WORKTREE_ID=wt-MacOS.[features] daemon_auto_start = falseset while the daemon was still running, B's hooks still ran asENV_PANE= tabA ENV_WT= wt-MacOS ppid= 28261 ... prompt= MARKER2_B_with_autostart_false.codex app-server daemon stop, with auto-start off, B's hooks ran asENV_PANE= tabB ENV_WT= wt-StudentRegistrationfrom the TUI's own process, so attribution was correct.daemon_auto_start=false. It carriesORCA_PANE_KEY=6f9b6e47-...:90586f09-...andORCA_WORKTREE_ID=...np-CI-09-25.2) Vitest reproduction through the real
AgentHookServerHTTP ingest and theworktree psrow builderpnpm vitest run src/main/runtime/codex-daemon-cross-worktree-prompt.repro.test.ts --silent=false(on main): 1 passed. It prints:This matches the user's report.
Regression test fails on main
I reverted every non-test file to its
origin/mainversion, deleted the new modules, and ranpnpm vitest run src/main/agent-hooks/codex-shared-daemon-worktree-attribution.test.ts:files each session under its own worktree, not the daemon starter panefailed. The StudentRegistration row expected[{paneKey: tab-sr:1111..., state: 'working', prompt: 'LATEST StudentRegistration prompt'}]and received[], because main files the prompt on the MacOS starter pane.drops a session outside every worktree when two Codex panes could own itfailed.after an Orca restart, keeps the starter session before panes re-registerfailed.codex -C ~/othercase. It checks that the fix does not break that case.Passes on the branch
src/main/agent-hooks/codex-shared-daemon-worktree-attribution.test.ts: 4/4 passed.src/shared/agent-hook-listener/codex-shared-daemon-attribution.test.ts: 22/22 passed, including each probe the reviewers used:/Users/me/projwith a single Codex pane: the post stays on the stamped pane.src/main/codex/codex-client-panes.test.ts(new): 6/6 passed.src/main/codex/codex-hook-script-shared-daemon.test.ts(new): covers the script's daemon detection.pscheck: a throwaway test (deleted afterwards) ran a process namedcodexunder shell pid A and a plainsleepunder shell pid B.runsCodexClientreturned[true, false].Checks run
pnpm tc: exit 0.pnpm run check:code-quality:changed: 0 new findings across 17 changed files; the gate passed.pnpm vitest run src/main/codex src/main/opencode src/main/agent-hooks src/shared/agent-hook-listener src/relay/agent-hook-server.test.ts: 352 files passed.src/main/codex/codex-prompt-registry-retention.test.ts. They throw "The test runner must enable --expose-gc". This PR does not touch that file, and the error comes from the local test-run setup, not from this change.Why
daemon_auto_start=false: it doesn't stop a TUI from connecting to a daemon that is already running. Daemons outlive Orca restarts and upgrades. It would also turn off a Codex feature that is on by default.ORCA_*from the daemon's environment: Orca doesn't control the environment of a daemon that is already running. Without those values the posts can't be attributed at all.Linked Issue
No GitHub issue. User report in the crash Slack channel (Orca 1.4.215, macOS):
worktree psshowed one worktree's Codex prompt as another worktree's active prompt.Visual Proof
N/A: no UI code changed. The visible effect is which worktree row gets the Codex status and prompt, and the
worktree psrow-builder output above shows it directly.Testing
ps)Platforms: macOS, live and in tests. Linux shares the same POSIX script and
pssweep. On Windows the.cmdhook script has no daemon detection, so behavior there is unchanged from before. SSH: see Trade-offs.Trade-offs
pscalls. Daemon-run Codex posts now wait for a host process sweep, which is twopscalls on macOS/Linux. Posts within 1s share one result, and the wait is capped at 1.5s. Other hooks and other agents are unaffected.SessionStart). Its later hooks attribute correctly.Adversarial review
2 loops, each with a new reviewer. Final result: clean.
Loop 1 (not clean, 3 findings). The reviewer confirmed the root cause live: the daemon argv matches the script's pattern and the hooks inherit the starter's
ORCA_*values. The reviewer also confirmed the regression tests fail on main and pass on the branch. The three findings were:All three were fixed in e6fc5ab (Codex-client-only candidates via the reused process sweep, the new decision order, and handling for keyless panes) and are covered by tests.
Loop 2 (clean; 2 nits only). The reviewer confirmed again that the tests fail on main (3 of 4) and pass on the branch (4 of 4). 294 tests passed across the new tests,
src/main/opencodeafter the refactor, and the relay dependency test.typecheck:nodeand oxlint were clean. No problems were found in these areas:::workspace:suffix is handled.Remaining known limits, none worse than before:
.cmdscript has no daemon detection.ORCA_*environment, so its posts are handled as before.Agent skill upstream boundary
docs/reference/agent-skill-sharing-upstream-boundary.mdand copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.Notes
Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)