Skip to content

fix(codex): attribute shared-daemon Codex hooks to the session's own worktree - #23411

Open
OrcaWin wants to merge 2 commits into
mainfrom
fix/worktree-ps-cross-worktree-prompt
Open

OrcaWin wants to merge 2 commits into
mainfrom
fix/worktree-ps-cross-worktree-prompt

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Sep 27, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 5 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​661 $\color{#cf222e}{\Huge{\mathbf{−}}}$​1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​660
Prod 12 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​428 $\color{#cf222e}{\Huge{\mathbf{−}}}$​42 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​386

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 ps showed 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-daemon per CODEX_HOME, because daemon_auto_start is stable and on by default. Every Codex TUI on that home connects to it over a unix socket. The daemon, not the TUI, runs the hooks.json commands, so every hook inherits the daemon's environment. That environment holds the ORCA_PANE_KEY / ORCA_WORKTREE_ID / ORCA_TAB_ID of 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=false only 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 is app-server … --managed-daemon, it adds a codex-shared-daemon marker. 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.ts reuses the OpenCode binder's host process sweep (sweepProcessIdentities). It flags each registered PTY whose shell has a live Codex client (native binary, npm codex.js launcher, or codex-<triple>; app-server is excluded). The pid→ppid walk moved from opencode-session-binder.ts into the new src/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 from server-ingest-normalization.ts before status, launch-token and transcript-polling code reads the stamp):

    1. Move the post to the Codex pane of the session cwd's deepest worktree. If several such panes tie and none is the stamped pane, drop the post.
    2. Keep the stamped pane when its worktree contains the cwd.
    3. If there is exactly one Codex pane on the host, use it, wherever it cd'd to.
    4. Drop the post when the cwd belongs to another pane's worktree, or when several Codex panes could own it.
    5. Otherwise keep the stamped pane.

    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 --version gives codex-cli 0.157.1; no Orca build needed)

Setup:

  • A temporary CODEX_HOME at /tmp/cxr/home with a fake model provider (no network, no auth).
  • A trusted UserPromptSubmit/SessionStart hook that logs its own ORCA_PANE_KEY/ORCA_WORKTREE_ID, its parent PID and the stdin payload.
  • Two TUIs driven through python pty, each started with a positional prompt:
    • A: cwd wtA, ORCA_PANE_KEY=tabA:..., ORCA_WORKTREE_ID=wt-MacOS. Started first.
    • B: cwd wtB, tabB, wt-StudentRegistration.

Hook log (/tmp/cxr/hooklog.jsonl):

ENV_PANE= tabA ENV_WT= wt-MacOS SessionStart cwd= /private/tmp/cxr/wtA prompt= None
ENV_PANE= tabA ENV_WT= wt-MacOS UserPromptSubmit cwd= /private/tmp/cxr/wtA prompt= MARKER_FROM_A_MacOS first prompt
ENV_PANE= tabA ENV_WT= wt-MacOS SessionStart cwd= /private/tmp/cxr/wtB prompt= None
ENV_PANE= tabA ENV_WT= wt-MacOS UserPromptSubmit cwd= /private/tmp/cxr/wtB prompt= MARKER_FROM_B_StudentRegistration

B's prompt carries A's pane key and worktree id.

  • The hook's parent PID was 28261 every time. That process is codex app-server --listen unix:// --managed-daemon (PPID 1). ps eww on the daemon shows ORCA_PANE_KEY=tabA / ORCA_WORKTREE_ID=wt-MacOS.
  • Variant with Orca's guard: with [features] daemon_auto_start = false set while the daemon was still running, B's hooks still ran as ENV_PANE= tabA ENV_WT= wt-MacOS ppid= 28261 ... prompt= MARKER2_B_with_autostart_false.
  • Control: after codex app-server daemon stop, with auto-start off, B's hooks ran as ENV_PANE= tabB ENV_WT= wt-StudentRegistration from the TUI's own process, so attribution was correct.
  • On the developer machine: the real Orca account-home daemon (PID 92301, Codex 0.157.0, started Sep 25 18:14) was still running even though that home's config now has daemon_auto_start=false. It carries ORCA_PANE_KEY=6f9b6e47-...:90586f09-... and ORCA_WORKTREE_ID=...np-CI-09-25.

2) Vitest reproduction through the real AgentHookServer HTTP ingest and the worktree ps row builder

pnpm vitest run src/main/runtime/codex-daemon-cross-worktree-prompt.repro.test.ts --silent=false (on main): 1 passed. It prints:

StudentRegistration: status "working", agents [{paneKey "tab-sr:1111...", state "working", prompt "LATEST MacOS prompt"}]
MacOS: status "inactive", agents []

This matches the user's report.

Regression test fails on main

I reverted every non-test file to its origin/main version, deleted the new modules, and ran pnpm vitest run src/main/agent-hooks/codex-shared-daemon-worktree-attribution.test.ts:

Tests  3 failed | 1 passed (4)
  • files each session under its own worktree, not the daemon starter pane failed. 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 it failed.
  • after an Orca restart, keeps the starter session before panes re-register failed.
  • The test that passes on main is the single-Codex codex -C ~/other case. 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:
    • A shell split in the other worktree: the post now moves to that worktree's Codex pane.
    • /Users/me/proj with a single Codex pane: the post stays on the stamped pane.
    • StudentRegistration holding only a shell: the post stays on the starter pane.
    • Panes without keys after a restart: the starter's own session is kept and the other worktree's session is dropped.
  • 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.
  • Real host ps check: a throwaway test (deleted afterwards) ran a process named codex under shell pid A and a plain sleep under shell pid B. runsCodexClient returned [true, false].

Checks run

  • pnpm tc: exit 0.
  • pnpm run check:code-quality:changed: 0 new findings across 17 changed files; the gate passed.
  • Pre-commit oxlint and oxfmt: 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.
    • The only failures are 4 tests in 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

  • Why not rely on 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.
  • Why not strip 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.
  • Why only panes that are running Codex: the first review round showed that counting every PTY in a worktree moved posts onto shells or dropped them when a worktree also had a shell split. Limiting candidates to panes with a live Codex client fixes both. This reuses the process sweep the OpenCode binder already has instead of adding a second one.
  • Why drop when unsure: wrong attribution is exactly the bug the user reported. Showing nothing is less misleading than showing another worktree's prompt.

Linked Issue

No GitHub issue. User report in the crash Slack channel (Orca 1.4.215, macOS): worktree ps showed 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 ps row-builder output above shows it directly.

Testing

  • I manually tested these changes locally (live Codex 0.157.1 reproduction on macOS, plus a check against the real host ps)
  • Automated tests added/updated (integration test through real HTTP ingest, attribution unit tests, process-sweep tests, hook-script tests)

Platforms: macOS, live and in tests. Linux shares the same POSIX script and ps sweep. On Windows the .cmd hook script has no daemon detection, so behavior there is unchanged from before. SSH: see Trade-offs.

Trade-offs

  • Extra ps calls. Daemon-run Codex posts now wait for a host process sweep, which is two ps calls on macOS/Linux. Posts within 1s share one result, and the wait is capped at 1.5s. Other hooks and other agents are unaffected.
  • When the sweep can't see the Codex client (a WSL pane's Linux processes, or a sweep that fails or times out), posts are only kept on the stamped pane, never moved. A session in another worktree is dropped rather than shown on the starter's row.
  • Several Codex panes share one worktree and none of them is the stamped pane: the post is dropped.
  • Several Codex panes exist and the session's cwd is outside every worktree: the post is dropped, because it cannot be told apart from the starter's.
  • Right after an Orca restart, non-starter worktrees show no Codex status until their panes register their keys again. Before this fix they showed the starter's wrong prompt instead.
  • SSH relay: it still keeps or drops by the stamped worktree. Over SSH, a Codex 0.157+ session launched into a directory outside its worktree loses status.
  • A Codex TUI started less than 1s after the last sweep may miss its first hook (typically 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:

    1. The first version counted every PTY in a worktree, not just Codex clients. A Codex pane plus a shell split dropped the post, and a single shell pane could receive it.
    2. Every 0.157+ hook was re-owned, so a correctly stamped single session with a cwd outside its worktree lost status.
    3. After an Orca restart, hydrated PTYs have no pane key, which dropped even the starter's own events.

    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/opencode after the refactor, and the relay dependency test. typecheck:node and oxlint were clean. No problems were found in these areas:

    • Other agents: only marked posts are touched.
    • Mixed script and listener versions.
    • Launch tokens.
    • Subagent transcript polling.
    • Folder workspaces: the ::workspace: suffix is handled.
    • Symlinked repo paths.
    • Keyless panes after a restart.
    • Slow or failed sweeps.
    • SSH relay.
    • WSL.
    • The agent-status-store rule.
    • AGENTS.md: no type assertions, concrete file names.

    Remaining known limits, none worse than before:

    • The Windows .cmd script has no daemon detection.
    • Two Codex panes in the same worktree may still share the starter's pane key, but the worktree row is correct.
    • A daemon started outside Orca has no ORCA_* environment, so its posts are handled as before.

Agent skill upstream boundary

  • Not applicable, or this change follows docs/reference/agent-skill-sharing-upstream-boundary.md and copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

  • Security: no new inputs are trusted. The marker only chooses between registered panes, and only the host's own ingest rewrites attribution.
  • Cross-platform: POSIX detection covers macOS and Linux. Windows is unchanged.
  • SSH: keep or drop only, as described under Trade-offs.
  • Mobile: it reads the same agent-status store and gets corrected rows.
  • Backwards compatibility: the marker is a new optional field.
  • Performance: the sweep is shared across posts within 1s and capped at 1.5s.

Checklist

  • This PR is small and focused (17 files: the core change plus moving the shared process-ancestry code out of the OpenCode binder so both use it)
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

m4air added 2 commits September 27, 2026 07:30
…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.

@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 — 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.ts walks up to four ancestors for app-server … --managed-daemon and stamps executor=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.ts decides keep / rebind / drop from the session's cwd against the registered Codex panes, applied in server-lifecycle.ts before normalization, disposition and transcript polling.
  • Codex-pane inventory from the host sweep. codex-client-panes.ts reuses sweepProcessIdentities to flag only panes with a live Codex client; the pid→ppid walk moved to pane-process-ancestry.ts and is now shared with the OpenCode binder.
  • Relay keep/drop. mergeRelayAgentHookRequest applies the same decision with no pane inventory.
  • Tests. Integration test through the real HTTP ingest and the worktree ps row 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.

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

Comment on lines +25 to +31
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')

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.

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.

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 0a69983d-f2ca-44b9-b7ba-efee1f34456a

📥 Commits

Reviewing files that changed from the base of the PR and between 27b823f and e6fc5ab.

📒 Files selected for processing (17)
  • src/main/agent-hooks/codex-shared-daemon-worktree-attribution.test.ts
  • src/main/agent-hooks/hook-post-command.ts
  • src/main/agent-hooks/pane-process-ancestry.ts
  • src/main/agent-hooks/server/server-ingest-normalization.ts
  • src/main/agent-hooks/server/server-lifecycle.ts
  • src/main/codex/codex-client-panes.test.ts
  • src/main/codex/codex-client-panes.ts
  • src/main/codex/codex-hook-script-shared-daemon.test.ts
  • src/main/codex/codex-hook-script.ts
  • src/main/opencode/opencode-session-binder.ts
  • src/relay/agent-hook-server.ts
  • src/shared/agent-hook-listener-relay-dependency.test.ts
  • src/shared/agent-hook-listener/codex-shared-daemon-attribution.test.ts
  • src/shared/agent-hook-listener/codex-shared-daemon-attribution.ts
  • src/shared/agent-hook-listener/hook-envelope.ts
  • src/shared/agent-hook-listener/opencode-session-correlation.ts
  • src/shared/agent-hook-types.ts

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


📝 Walkthrough

Walkthrough

Codex 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 e6fc5

The checked hook paths preserve daemon attribution and safely discard unattributable events. No identified issue currently prevents merging after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to e6fc5

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

  • Medium · security · inferred: When the session cwd matches no pane worktree, the sole detected Codex pane can receive a shared-daemon event without proof that it owns the session. A missed or stale observation of the actual client can therefore move its prompt and status to another worktree, rather than retaining the prior stamp or dropping the event.
Security review details

Security Blast Radius

  • inferred — Effective exposure is attribution of prompts and agent state among worktree rows within an installation, including hooks forwarded through its relay. The examined entrypoints require a hook token; the change does not establish cross-tenant reachability or a newly privileged network sink.

Security Findings and Attack Paths

  • inferred — An operator-controlled Codex session can report a cwd outside registered worktrees. If its actual pane is missed by the process observation while another pane is detected, the new sole-pane fallback can rewrite the event to that other pane; an accepted prompt or status can then appear under the wrong worktree. No unauthenticated request path or confirmed occurrence was established.

Trust Boundaries and Controls

  • observed — Hook tokens gate both HTTP handlers before normalization. Within that boundary the inherited daemon pane stamp is not treated as conclusive: local ingestion can replace it using cwd and process evidence, whereas relay ingestion only tests the stamped worktree against cwd and clears the pane key on a known mismatch.

Resilience and Maintainability Implications

  • observed — When relay has no pane inventory, an absent or unreadable stamped worktree root leaves the stamp in place; missing cwd does likewise. These fallbacks do not demonstrate an expanded relay attack path over prior stamp-based handling, but they limit the new protection. A dropped event cannot proceed through normal envelope parsing.

Hardening Proposals

  • proposed — Require positive session-to-pane evidence before rebinding an unmatched cwd to the sole observed client, or drop that case; carry pane/session generation or other ownership evidence through delayed ingestion so a stale process view cannot authorize a cross-worktree move.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 58.82% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 34 functions across 17 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely identifies the main change: correcting shared-daemon Codex hook attribution to the session's worktree.
Description check ✅ Passed The description is detailed and covers the user impact, mechanism, rationale, testing, platform considerations, trade-offs, and limitations. It states that no GitHub issue exists and provides the user…
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR

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.

@szsip239

Copy link
Copy Markdown
Contributor

Confirmed field case: two Codex panes in one worktree still lose the working row

Thanks 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 affected resumed Codex TUI displayed Working and produced output, but its sidebar agent row and yellow working indicator were absent. Only an older, completed sibling session appeared.
  • Session-scoped Codex logs identify the shared app-server --managed-daemon as the process executing the affected session. The TUI's own Orca pane/worktree environment was correct, but the daemon carried a different worktree's stamp.
  • A live Orca status-cache entry under that daemon-starter pane referenced a session whose transcript metadata had a different workspace cwd. This directly confirmed cross-workspace attribution, independently of title parsing.
  • The affected resumed tab had no launchAgent metadata. Its spinner-plus-session-name title therefore could not rescue the missing hook row. A comparison tab with launchAgent: codex did show a title-derived working indicator. The session-name language is not the cause.

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 function

Using 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' }

attributeCodexSharedDaemonHookBody then clears paneKey, and envelope normalization rejects the event. This safely avoids putting B's status on A, but does not restore B's working row. Merely being idle does not remove the sibling Codex process from these candidates.

The isolated replay verified four cases:

  1. Installed 1.4.215 normalizer: project-B prompt becomes a working event under project A's inherited stamp (bug reproduced).
  2. PR function, one Codex pane in B: event is correctly rebound to B.
  3. PR function, two Codex panes in B: event is dropped (remaining limitation reproduced).
  4. Unmarked/non-daemon post: unchanged.

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.

This branch has not been deployed

No deployments
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.

2 participants