Skip to content

fix(native-chat): keep a child turn settling on an error Codex will not retry - #23808

Merged
nwparker merged 1 commit into
mainfrom
nwparker/restore-codex-provider-verdict
Sep 29, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/restore-codex-provider-verdict

Conversation

@nwparker

@nwparker nwparker commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 1 0 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​25 $\color{#cf222e}{\Huge{\mathbf{−}}}$​7 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​18

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/completed ends a Codex turn and deleted codex-structured-journal-provider-verdicts.ts, but left codex-background-task-frames.ts importing 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 error with willRetry: false produced no end frame at all, so the child's lifecycle row stayed working for the rest of the session. After: it settles as failed again, 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 error with a failed turn/completed for 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/completed may never arrive, and the error is its only end.

Restored as a single predicate against readCodexErrorWillRetry (itself restored to codex-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 rewrote codex-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.mjs read .github/workflows/track-community-prs.yaml, which #23796 deleted while leaving the assertion in place. Its trackingWorkflow binding and the one runs-on assertion 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 turn
  • codex-structured-child-work-producer.test.ts: a willRetry: false error on a child thread records outcome: '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 Bun persistence platforms), check:runtime-electron-ratchet inside static analysis, and the esbuild pass behind Bun scope detection. Because test requires both static_analysis and typecheck to 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 skipped

  • pnpm tc — exit 0

  • oxlint and oxfmt --check — clean

  • I 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

  • 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: 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

  • This PR is small and focused
  • 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)

…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.
@nwparker
nwparker force-pushed the nwparker/restore-codex-provider-verdict branch from a46dc46 to 9b8d9c6 Compare September 29, 2026 06:28
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

📝 Walkthrough

Walkthrough

Codex 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 9b8d9

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 Review

Security architecture risk: 🔵 Low · up to 9b8d9

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

  • Low · reliability · inferred: If a retryable child error lacks a boolean retry marker, the new classifier treats it as terminal. For a running child, that can mark the turn failed and remove it from working-task monitoring. Source comments describe explicit retry markers, but the upstream schema was not independently established.
Security review details

Security Blast Radius

  • inferred — The changed outcome affects child-turn state and its published work evidence, not primary-turn settlement. The authenticity of upstream Codex notifications was outside the available source evidence.

Trust Boundaries and Controls

  • observed — Primary-thread events cannot enter the new child-ending branch. An ending without a current child execution produces no endTurn transition, and settled child turns resist later working events.

Resilience and Maintainability Implications

  • inferred — Explicit retryable errors remain outside child-ending handling. For incomplete retry metadata, the newly introduced terminal classification could instead hide continuing child work from working-task monitoring; whether supported provider events can take that path is unresolved.

Hardening Proposals

  • proposed — Confirm the supported provider contract for retry-marker presence and error ordering before relying on ambiguous errors to remove a child from monitoring.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 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 identifies the primary change: restoring child-turn settlement when Codex emits an error that it will not retry.
Description check ✅ Passed The description is complete and detailed. It explains the user impact, implementation, rationale, linked regression context, visual-proof status, testing, compatibility considerations, and checklist s…
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 💡 1
📝 Generate docstrings 💡
  • 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.

@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 — two documentation nits inline.

Reviewed changes

  • Restore child settlement on a fatal error — readCodexChildTurnEnding again maps an error with willRetry: false to a turn-ended frame with state failed, carrying the turn the error names; the turn-ended variant's turnId widens to string | null.
  • Restore readCodexErrorWillRetry in codex-structured-thread-facts.ts — verified byte-for-byte behaviorally identical to the version #23682 deleted (checked dc8cf305, the commit before #23682); willRetry sits at the top level of the error params, matching the fixture.
  • Drop the dead workflow reference — pr-workflow-parallelism.test.mjs no 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.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using 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 {

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.

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

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.

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.

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 4/5

[Medium risk] Adjusts how child conversation turns end on errors.

The PR appears safe to merge; the remaining issue is a non-blocking documentation placement error.

Findings

  1. P2 Status comment is misplaced ▶

Summary

The PR restores settlement of child Codex turns on non-retryable errors and removes a test reference to a deleted workflow.

  • Child error frames can again settle a working child as failed when no turn/completed arrives.
  • The workflow parallelism test no longer reads or asserts on the removed community-PR workflow.

Reviews (1) · Last reviewed commit: "fix(native-chat): keep a child turn sett..."

Comment on lines 65 to 76
/** `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 {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 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.

Suggested change
/** `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!

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: a293b021-0407-4429-b8ce-a8be0ea43bec

📥 Commits

Reviewing files that changed from the base of the PR and between 2d358df and 9b8d9c6.

📒 Files selected for processing (3)
  • config/scripts/pr-workflow-parallelism.test.mjs
  • src/main/codex/codex-background-task-frames.ts
  • src/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)) {

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.

🎯 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['\"]" src

Repository: 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.ts

Repository: 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
}

@nwparker
nwparker merged commit 25d9c57 into main Sep 29, 2026
42 checks passed
@nwparker
nwparker deleted the nwparker/restore-codex-provider-verdict branch September 29, 2026 06:42
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
Brings #23808, which restores the Codex child-turn end on an error Codex
will not retry (the child path has no guaranteed turn/completed), plus a
README badge update. No overlap with #23059's files.
brennanb2025 added a commit that referenced this pull request Sep 29, 2026
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.
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.

1 participant