Repository navigation
fix(native-chat): keep a child turn settling on an error Codex will not retry - #23808
Conversation
…ot retry #23801 removed the child-path reading of Codex's turn-ending `error` along with the import of the module #23682 deleted. That was the wrong half to remove: the primary journal path can rely on Codex's failed `turn/completed` arriving within ~32 ms, which is what #23682 established, but a child turn has no such guarantee, and without the error as its end the child's lifecycle row latches on `working` for the life of the session. Three tests assert exactly that and could not run, because the unresolved import had been skipping the unit matrix since #23682 merged. The reading is restored inline against `readCodexErrorWillRetry`, itself restored to `codex-structured-thread-facts.ts`, rather than by reviving the deleted module: its `thread-stopped-running` arm lost its only consumer when #23682 rewrote the primary path, so restoring the file would re-add dead code. Also drops `pr-workflow-parallelism.test.mjs`'s read of `.github/workflows/track-community-prs.yaml`, which #23796 deleted while leaving the assertion behind. Same failure class, and it fails the same shard.
a46dc46 to
9b8d9c6
Compare
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. 📝 WalkthroughWalkthroughCodex child-turn handling now recognizes errors that Codex will not retry and returns a failed turn-ending frame with the event’s turn ID. The frame type also permits a null turn ID and an unverifiable state. The parallelism test no longer loads the community PR tracking workflow or checks its runner. Priority: ⬇️ Low Merge Risk: 🔵 Low · up to An error without an explicit retry status could prematurely mark a child turn failed. The observed event examples use explicit statuses, so this is a bounded risk, but the error handling should distinguish a missing status before merging. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change restores failure reporting for background agents without adding a new external entry point or privilege. A limited uncertainty remains about how incomplete or unexpectedly ordered error notifications affect monitoring. Retained concerns
Security review detailsSecurity Blast Radius
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 💡 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.
ℹ️ No critical issues — two documentation nits inline.
Reviewed changes
- Restore child settlement on a fatal error —
readCodexChildTurnEndingagain maps anerrorwithwillRetry: falseto aturn-endedframe with statefailed, carrying the turn the error names; theturn-endedvariant'sturnIdwidens tostring | null. - Restore
readCodexErrorWillRetryincodex-structured-thread-facts.ts— verified byte-for-byte behaviorally identical to the version #23682 deleted (checkeddc8cf305, the commit before #23682);willRetrysits at the top level of the error params, matching the fixture. - Drop the dead workflow reference —
pr-workflow-parallelism.test.mjsno longer reads/asserts.github/workflows/track-community-prs.yaml, deleted by #23796; no remaining references.
The behavioral change is sound: the only consumer of turn-ended is CodexBackgroundTaskTracker.observe → executions.endTurn, the widened turnId is a safe widening with no consumer discriminating on null, and observeTurn already refuses to overwrite a newer running turn when a late error names a settled one (codex-child-work-evidence.test.ts:210). Error events reach the tracker (non-item canObserve passes) and the producer test drives the real adapter to the failed record. The two items below are doc-only.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
| * Codex hardcodes `willRetry: false` on an `error` that affects turn status, and `true` on a | ||
| * stream error it is about to retry, which ends nothing. | ||
| */ | ||
| export function readCodexErrorWillRetry(payload: unknown): boolean { |
There was a problem hiding this comment.
readCodexErrorWillRetry was inserted between the JSDoc for codexThreadStoppedRunning (lines 65-67) and its declaration, so that tagged-status comment now attaches to the new function and codexThreadStoppedRunning is left undocumented. Before #23682 this function sat after codexThreadStoppedRunning; restoring it there keeps the comment with its function.
| threadId: string | ||
| turnId: null | ||
| state: Extract<NativeChatSubagentState, 'unverifiable'> | ||
| turnId: string | null |
There was a problem hiding this comment.
The variant comment above (line 28) still reads "No turnId: the one it is running", but the restored error arm now supplies the turn the error names for the failed state, while only the thread/closed arm leaves it null. Worth refreshing so the two arms' turnId handling is unambiguous.
|
| /** `thread/status/changed` carries a TAGGED status (`{status:{type}}`), never a | ||
| * bare string. `idle` and `systemError` are the two arms that mean the thread | ||
| * is not running; `active` and `notLoaded` are not. */ | ||
| /** | ||
| * Codex hardcodes `willRetry: false` on an `error` that affects turn status, and `true` on a | ||
| * stream error it is about to retry, which ends nothing. | ||
| */ | ||
| export function readCodexErrorWillRetry(payload: unknown): boolean { | ||
| return record(payload)?.willRetry === true | ||
| } | ||
|
|
||
| export function codexThreadStoppedRunning(payload: unknown): boolean { |
There was a problem hiding this comment.
Status comment is misplaced The new JSDoc separates the
thread/status/changed comment from codexThreadStoppedRunning, making that comment appear to describe readCodexErrorWillRetry instead. Move the status comment directly above its function so callers can tell which payload contract applies to each reader.
| /** `thread/status/changed` carries a TAGGED status (`{status:{type}}`), never a | |
| * bare string. `idle` and `systemError` are the two arms that mean the thread | |
| * is not running; `active` and `notLoaded` are not. */ | |
| /** | |
| * Codex hardcodes `willRetry: false` on an `error` that affects turn status, and `true` on a | |
| * stream error it is about to retry, which ends nothing. | |
| */ | |
| export function readCodexErrorWillRetry(payload: unknown): boolean { | |
| return record(payload)?.willRetry === true | |
| } | |
| export function codexThreadStoppedRunning(payload: unknown): boolean { | |
| /** | |
| * Codex hardcodes `willRetry: false` on an `error` that affects turn status, and `true` on a | |
| * stream error it is about to retry, which ends nothing. | |
| */ | |
| export function readCodexErrorWillRetry(payload: unknown): boolean { | |
| return record(payload)?.willRetry === true | |
| } | |
| /** `thread/status/changed` carries a TAGGED status (`{status:{type}}`), never a | |
| * bare string. `idle` and `systemError` are the two arms that mean the thread | |
| * is not running; `active` and `notLoaded` are not. */ | |
| export function codexThreadStoppedRunning(payload: unknown): boolean { |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: a293b021-0407-4429-b8ce-a8be0ea43bec
📒 Files selected for processing (3)
config/scripts/pr-workflow-parallelism.test.mjssrc/main/codex/codex-background-task-frames.tssrc/main/codex/codex-structured-thread-facts.ts
💤 Files with no reviewable changes (1)
- config/scripts/pr-workflow-parallelism.test.mjs
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.
| function readCodexChildTurnEnding( | ||
| event: CodexBackgroundTaskEvent | ||
| ): CodexBackgroundTaskFrame | null { | ||
| if (event.method === 'error' && !readCodexErrorWillRetry(event.params)) { |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
#!/bin/bash
# Inspect error-event producers, fixtures, and assertions for the willRetry field.
rg -n -C 4 --glob '*.{ts,tsx,js,mjs,json}' \
"willRetry|method: ['\"]error['\"]|method === ['\"]error['\"]" srcRepository: stablyai/orca
Length of output: 19550
🏁 Script executed:
#!/bin/bash
set -eu
printf '%s\n' '--- changed file ---'
cat -n src/main/codex/codex-background-task-frames.ts | sed -n '1,110p'
printf '%s\n' '--- helper and event declarations ---'
rg -n -C 8 "function readCodexErrorWillRetry|type CodexBackgroundTaskEvent|interface CodexBackgroundTaskEvent|readCodexChildTurnEnding|CodexBackgroundTaskFrame" src/main/codex --glob '*.ts'
printf '%s\n' '--- direct callers ---'
rg -n -C 8 "readCodexChildTurnEnding|kind: 'turn-ended'|state: 'failed'|endTurn" src/main/codex --glob '*.ts'
printf '%s\n' '--- requested PR diff ---'
git diff --unified=12 2d358df8afdad61efa158b30dfc6308c35b8ab2d 9b8d9c6c6879e45f7fad321e75d17899bffda809 -- src/main/codex/codex-background-task-frames.ts src/main/codex/codex-structured-thread-facts.tsRepository: stablyai/orca
Length of output: 41777
Handle an absent willRetry value separately from false.
If an error payload omits willRetry, readCodexErrorWillRetry returns false, so this branch emits a failed turn-ended frame. End the child turn only when willRetry is explicitly false.
Suggested fix
- if (event.method === 'error' && !readCodexErrorWillRetry(event.params)) {
+ if (event.method === 'error' && readCodexErrorWillRetry(event.params) === false) {-export function readCodexErrorWillRetry(payload: unknown): boolean {
- return record(payload)?.willRetry === true
+export function readCodexErrorWillRetry(payload: unknown): boolean | null {
+ const value = record(payload)?.willRetry
+ return typeof value === 'boolean' ? value : null
}Resolves the conflict with #23808 in favour of this PR's model: a Codex child's turn ends on its own turn/completed, and the one ending without it is a closed thread. #23808's child error arm and readCodexErrorWillRetry (no other consumer) are dropped; its pr-workflow-parallelism.test.mjs fix is kept.

ELI5
When a background agent hits a fatal error, Codex sometimes never sends a "turn finished" message for it. Orca used to treat that error as the finish line. My previous PR (#23801) deleted that behaviour, which made background agents show a spinner forever. This puts it back. It also fixes a test that was reading a workflow file someone deleted.
What Changed
This corrects a mistake I made in #23801.
#23682 established that only
turn/completedends a Codex turn and deletedcodex-structured-journal-provider-verdicts.ts, but leftcodex-background-task-frames.tsimporting from it. In #23801 I resolved that by deleting the importer's branch. That was the wrong half.Before this PR: a child turn that ended on an
errorwithwillRetry: falseproduced no end frame at all, so the child's lifecycle row stayedworkingfor the rest of the session. After: it settles asfailedagain, exactly as three tests require.The distinction #23682 relied on does not transfer to children. Its own evidence is that Codex follows a turn-ending
errorwith a failedturn/completedfor the same turn within 0-32 ms — so on the primary journal path the error is redundant and strictly worse, because only the completion carries the duration and receipt time. A child turn has no such guarantee;turn/completedmay never arrive, and the error is its only end.Restored as a single predicate against
readCodexErrorWillRetry(itself restored tocodex-structured-thread-facts.ts, where #23682 also removed it) rather than by reviving the deleted module. That module's other arm,thread-stopped-running, lost its only consumer when #23682 rewrotecodex-structured-journal-translation.ts, so restoring the file wholesale would re-add dead code.Second, unrelated fix in the same PR:
pr-workflow-parallelism.test.mjsread.github/workflows/track-community-prs.yaml, which #23796 deleted while leaving the assertion in place. ItstrackingWorkflowbinding and the oneruns-onassertion are removed. They are together because both are the same failure class — a deletion that left a live reference — both land in the same unit shard, and both block every PR in the repo until they land.Why
Three tests document the behaviour and assert it directly:
codex-child-work-evidence.test.ts: settles a working child whose turn ended with no turn/completed, by an error naming its turn that Codex will not retry — and the sibling case naming no turncodex-structured-child-work-producer.test.ts: awillRetry: falseerror on a child thread recordsoutcome: 'failed'The deleted module's own doc comment said the same thing: without this frame "the running lifecycle row is a latch nothing re-derives and the chat reads working for the life of the session."
The alternative — keeping my deletion and updating the three tests — would trade a documented, tested, user-visible guarantee for a smaller diff. Restoring is the conservative direction, and it is the direction the tests point.
How this escaped review. The unresolved import broke four gates at once:
typecheck,pnpm build:orcad(all six Bunpersistenceplatforms),check:runtime-electron-ratchetinsidestatic analysis, and the esbuild pass behind Bun scope detection. Becausetestrequires bothstatic_analysisandtypecheckto succeed, no unit test ran on any PR between #23682 merging and #23801 merging. I checked two Codex test files for the error path before #23801 and found nothing; the three that do assert it are in files I did not check, and CI could not tell me. #23801 made the suite runnable again, which is how these surfaced.Linked Issue
No pre-existing issue. Third of three independent merge-time regressions found while auditing CI runner demand; the others are #23801 and #23802.
Visual Proof
N/A— no new UI surface. The user-visible effect is the restoration of prior behaviour: a background agent whose turn dies on a fatal error settles as failed instead of spinning indefinitely. There is no before/after to capture that is not already covered by the three named tests.Testing
Local, macOS:
pnpm exec vitest run --config config/vitest.config.ts src/main/codex/codex-child-work-evidence.test.ts src/main/codex/codex-structured-child-work-producer.test.ts— 34 passed (these were the 2 failing shards)pnpm exec vitest run --config config/vitest.config.ts config/scripts/pr-workflow-parallelism.test.mjs src/main/codex/— 145 files, 1731 passed, 12 skippedpnpm tc— exit 0oxlintandoxfmt --check— cleanI manually tested these changes locally
Automated tests added/updated, or explained why not below
No new test: the three existing tests are the regression coverage, they failed for exactly this change, and they now pass. Adding a fourth would duplicate them.
Cross-platform: pure TypeScript control flow, no platform-dependent behaviour. SSH/remote: the child-work path is shared by local and remote providers and is restored identically for both. Mobile: unaffected.
Review
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
Security: none. Cross-platform: none. Remote SSH: restores child settlement for remote providers too. Mobile: unaffected. Backwards compatibility: restores prior behaviour. Performance: one predicate per child event, as before #23801.
Worth a follow-up by #23682's author: this PR keeps the child path settling on the error because the tests require it, but if Codex really does always follow a child's turn-ending error with
turn/completed, the right end state is to delete this path and the three tests together, using the same captured app-server evidence #23682 was based on. I did not make that call here.Checklist
N/Awith reasonpnpm lint,pnpm typecheck,pnpm test, andpnpm buildpass (or CI will cover; local preferred)