Skip to content

fix(codex): decide the store and the Kiro guard from the read made now - #2782

Merged
devswha merged 2 commits into
mainfrom
fix/issue-2774
Nov 4, 2026
Merged

devswha merged 2 commits into
mainfrom
fix/issue-2774

Conversation

@devswha

@devswha devswha commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes #2774.

#2764 lets a Chat command poll hand its own pane.process_info read to the Codex transcript lookup. The pane can change between that read and the lookup, and two decisions still rested on the earlier read. A review of this branch found two more cases of the same kind, which also exist on main; they are fixed here too.

What was wrong

  1. Store choice (Command outcomes: Codex lookups trust a stale poll read for store choice and the Kiro guard #2774 item 1). The earlier read names Codex A (store A). A leaves and Codex B starts with another CODEX_HOME. placed stayed true, so nothing checked B against store A, and a screen match could show A's conversation in B's pane, and bind it there.
  2. Kiro guard (Command outcomes: Codex lookups trust a stale poll read for store choice and the Kiro guard #2774 item 2). When the earlier read saw a plain Codex and the pane became a Kiro wrapper before the lookup, codexAgentInfo skipped the nested guard, which allowed the weaker short-exchange match.
  3. Same as 1 without a poll read (found in this branch's review, also on main). paneCodexHomePlaced makes its own read before openRollouts makes the next, so the same swap applied to every caller.
  4. A failed guard read (found in this branch's review, also on main). When agent.get labels the pane Codex and herdr fails the process read that decides the guard, the pane was taken for a plain one, and the next read could then prove a nested Codex the guard had missed.

Change (server/codex.ts, server/conversation.ts)

  • codexTranscriptPath takes homeFromEarlierRead. resolveTranscript sets it whenever a Codex process placed the store (placed && !codexHome). The first Codex of the fresh read must then write to that store (processCodexHome ?? defaultCodexHome(), the rule paneCodexHomePlaced places by), or the lookup returns null and the terminal stands in.
  • codexAgentInfo reads the pane's processes itself again, after agent.get, and never takes the caller's read. It returns that read as processRead, and openRollouts reuses it, so the Kiro guard and the rollout binding rest on the same fresh read. A Codex command poll still makes 2 pane.process_info calls, as the test from fix(outcome): reuse the poll's process read in Codex, omp and gjc lookups #2764 pins.
  • If the guard's read failed and the pane is not nested already, codexTranscriptPath returns null. An answer that came back without process facts is asked again, as on main.
  • The queued-question reader in server/prompt.ts checks the store the same way (paneCodexHomePlaced, then homeFromEarlierRead).
  • codexOpenRollout and the other callers that pass nothing behave as before, apart from the store check in 3.

Not changed: a Codex with no CODEX_HOME whose own HOME differs from the server's still counts as writing to the default store. Telling them apart means reading HOME in processCodexHome, which every caller uses. The same review also noted a LOW: the agent_not_found fallback makes 3 process reads per poll. Neither is in this PR.

Tests (server/codex-processes.test.ts)

Five new tests use the file's fake herdr socket. The two store tests use real sleep processes with their own CODEX_HOME. Each test fails without its part of the fix (the promise resolves to the other store's rollout):

  • the store an earlier read's Codex keeps, once another Codex runs there (1)
  • the Kiro guard, when the pane became a wrapper after an earlier read saw a plain Codex (2)
  • the store the lookup's own first read chose, with no poll read handed down (3)
  • a failed guard read followed by one that shows the wrapper (4); the harness gained failedReads to fail a chosen process read
  • an answer without process facts for agent.get's read, then the wrapper: the nested Codex still resolves (the regression the review found in the first version)

Validation

  • bun run check fast at the final head: passed (unit: 11184 pass, 0 fail, 44 skip). At 41a29af: passed (unit: 11183 pass, 0 fail, 44 skip; typecheck, build and generated files ok).
  • The 4 new tests, run against this branch's code before each part of the fix (the 2 earlier ones against fix(outcome): reuse the poll's process read in Codex, omp and gjc lookups #2764's head 700fea6, the 2 later ones against the first version of this fix): each failed, the promise resolving to the other store's rollout. With the fix, each passes; looped 30 times, 0 failures.
  • bun test server/codex-processes.test.ts server/outcome.test.ts server/conversation.test.ts server/codex.test.ts server/dsh-http.test.ts: 551 pass, 0 fail, 3 runs in a row. One earlier run had a single failure that did not come back.
  • Skipped: bun run check full.

A Chat poll's earlier process read could choose a store another Codex started since does not use, or miss a Kiro wrapper the pane runs now. The Codex seen now must write to the store an earlier read chose (the caller's or the lookup's own), agent.get's own process read decides the Kiro guard and serves the rollout binding, and a failed read there shows no conversation. Fixes #2774.
@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 14 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration
Commits

Reviewing files that changed from the base of the PR and between 7240c80 and e5b7578.

Files selected for processing: 5
  • changelog.d/codex-command-lookup-fresh-read.md
  • server/codex-processes.test.ts
  • server/codex.ts
  • server/conversation.ts
  • server/prompt.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

…the queued-question reader's store

Review of #2782: reusing agent.get's read when herdr gave no process facts hid a nested Codex the next read proves; the queued-question reader chose its store without the check.
@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Review round on 41a29af: the omo review was CLEAR. A Codex (Terra) adversarial review reproduced four MEDIUMs; one was introduced by this PR, and three also happen on main.

Fixed in the next commit:

  1. Introduced here: an answer without process facts was reused. If herdr answered agent.get's read with no process_info, openRollouts took that empty answer, so a nested Codex the next read would prove was never seen, and a Kiro pane main resolves showed no conversation. Fixed: openRollouts reuses the read only when it has process facts (agent.processRead?.info), and otherwise asks again, as on main. New test: asks again when herdr answers the lookup's own read without process facts, and resolves the nested Codex then fails without the fix.
  2. On main: the queued-question reader in server/prompt.ts skipped the store check. It chose the store with paneCodexHome and then called codexTranscriptPath without saying that a process placed it. Fixed: it now uses paneCodexHomePlaced and passes homeFromEarlierRead, as resolveTranscript does. No new test covers this path; the check itself is covered by the store tests.

Left out, both on main and both in processCodexHome, which every caller uses:

  1. An environment read that fails counts as the default store. readProcessCodexHome returns null both for an unset CODEX_HOME and for a read that failed (for example EACCES), so a replacement Codex whose environment cannot be read passes the check when the earlier store was the default. Telling the two apart changes that helper's contract.
  2. The 30-second environment cache is keyed by pid and argv, without the process's start time. A Codex that reuses a pid with the same argv within 30 s reads the old home. Reproduced by simulating the reuse, not with a real reused pid.

@devswha

devswha commented Nov 4, 2026

Copy link
Copy Markdown
Owner Author

Merge note: merged on the omo review (CLEAR at this head), Codex Terra (no HIGH; reproduced findings fixed, the rest in the PR comments or follow-up issues) and green required checks (Integration and browser passed). Jobs still shown as in progress or queued were stuck by GitHub's Actions incident (steps already succeeded) or are non-required macOS jobs waiting for runners. For contract changes, review findings and resolutions are in the PR comments.

@devswha
devswha merged commit 7922416 into main Nov 4, 2026
17 of 20 checks passed
@devswha
devswha deleted the fix/issue-2774 branch November 4, 2026 16:41
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.

Command outcomes: Codex lookups trust a stale poll read for store choice and the Kiro guard

1 participant