Skip to content

fix(codex): resume settled failures on a fresh client - #149000

Merged
obviyus merged 19 commits into
openclaw:mainfrom
MertBasar0:fix/148837-codex-systemerror-client-retire
Sep 16, 2026
Merged

obviyus merged 19 commits into
openclaw:mainfrom
MertBasar0:fix/148837-codex-systemerror-client-retire

Conversation

@MertBasar0

@MertBasar0 MertBasar0 commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #148837. After a settled native failure, changing instructions could make every later send refuse configuration reload without another provider request.

Why This Change Was Made

The resume owner retires the exact eligible client. Startup releases its lease, waits for confirmed physical shutdown, then resumes the same thread within that send. Unconfirmed shutdown stops with the binding preserved. Client retirement still has one writer: the existing shared-client lifecycle owner.

User Impact

Recovery preserves history and applies the new instructions. Active siblings and idle Incognito siblings veto replacement, preserving the target's existing refusal and their original client/thread. Original-policy Incognito continuation keeps its context. Saved idle siblings can cold-resume after replacement. Client-bound and supervised conversations remain excluded.

Evidence

A real native runtime behind registered Gateway chat.send, using a controlled HTTP 400, reproduces the original refusal. Candidate recovery completes with exactly one further request carrying the old marker and new instructions. The pre-correction source also fails the idle Incognito and delayed-exit controls.

node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server-isolated.config.ts src/gateway/server.codex-failure-recovery.test.ts

Compatibility

No schema, configuration, protocol or SDK change. Overlapping leases conservatively prevent recovery. Follow-up: active-sibling recovery needs a writer-release contract in shared-client-lifecycle.ts.

Consumers

All ordinary native sends use this resume path. Existing retained, claimed, routed and leased state supplies eligibility.

Invalidation

Only the exact failed client is retired. The binding and configuration fence survive replacement. Cancellation is checked before another acquisition.

Tests

Locally, all eight registered scenarios and 685 owner/startup tests pass on a fresh merge with main. The cancellation control checks that the old process is still alive after accepted chat.abort, then releases and joins its actual exit. Removing the physical-exit wait still fails the registered test. Both Gateway tests from this change and #149842 are selected exactly once, with runtime preparation retained.

The prior hosted run failed the cancellation control and startup's line cap. The fixture now holds the launcher's final resume until release, and the unchanged cleanup predicate lives with the existing cleanup operations. Local type-aware preflight and both line checks pass; hosted results for this revision are pending.

Production growth is 113 lines: cleanup +36, startup −9, runtime facts +26, routing facts +22, resume eligibility +25, status +4 and the internal replacement error +9. These compose existing owners without a second lifecycle or store. Growth accepted under the owner's standing acceptance (2026-09-15).

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 1:42 PM ET / 17:42 UTC (Revision 10).

ClawSweeper review

What this changes

The Codex plugin resumes eligible failed conversations on a fresh native process while preserving history, protecting sibling conversations, and testing recovery through Gateway chat requests.

Merge readiness

✅ Ready for maintainer review

This PR remains necessary: current main still has the reported recovery failure. The earlier client-bound and Incognito-sibling findings are addressed, and no remaining blocking defect was found.

Priority: P1
Reviewed head: 7d56169a839f8ba0d1e5f3665073cce5c12846e3

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused recovery fix with strong production-boundary evidence and resolved prior findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured PR records real Gateway chat.send and native Codex execution against an injected HTTP failure, followed by same-thread recovery with history and new instructions; the inspected eight-case fixture also covers sibling preservation, physical exit, explicit cancellation, and unconfirmed shutdown.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR records real Gateway chat.send and native Codex execution against an injected HTTP failure, followed by same-thread recovery with history and new instructions; the inspected eight-case fixture also covers sibling preservation, physical exit, explicit cancellation, and unconfirmed shutdown.
Evidence reviewed 10 items Current main still needs recovery: The fetched main revision resumes the existing client and retires it only for unsuccessful unsubscribe or an unknown policy-write outcome; it lacks the settled-failure replacement branch.
Native dependency contract inspected: The patch and its real-runtime proof depend directly on native thread/resume semantics. The sibling checkout is pinned to this SHA; its backing cache origin was verified as https://github.com/openai/codex.git. Native configuration reload explicitly requires ThreadStatus::Idle, while thread_status.rs preserves SystemError after a settled failure.
Replacement eligibility preserves existing boundaries: Replacement excludes client-bound and supervised conversations, overlapping leases and acquisitions, protected native children, retained ephemeral siblings, claimed siblings, and outstanding sibling routes or completion watchers. The existing configuration fence remains in place.
Findings None None.
Security None None.

How this fits together

The Codex plugin translates Gateway chat requests into native Codex conversations. Its startup and resume owners manage shared processes, conversation bindings, and configuration confirmation before a turn reaches the provider.

flowchart TD
  A[Chat request and current instructions] --> B[Conversation resume owner]
  B --> C{Settled failure and safe to replace?}
  C -->|No| D[Existing guarded resume]
  C -->|Yes| E[Retire client and release lease]
  E --> F{Physical exit confirmed?}
  F -->|Yes| G[Fresh client resumes saved conversation]
  F -->|No| H[Preserve binding and report failure]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +113, Tests +646, Other +3. Total +762 across 11 files.

View PR surface stats
Area Files Added Removed Net
Source 8 159 46 +113
Tests 2 646 0 +646
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 7 4 +3
Total 11 812 50 +762

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +113 lines; tests +645; test tooling +4 Production growth supports guarded replacement using existing lifecycle owners, with eight real-native Gateway scenarios covering recovery and preservation.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #148837
Summary: This PR is the candidate fix for the reported settled-failure configuration-refresh bug.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Technical review

Best possible solution:

Keep recovery within the existing resume and shared-client owners, preserving the saved conversation and configuration fence while leaving ineligible shared clients undisturbed.

Do we have a high-confidence way to reproduce the issue?

Yes. A settled HTTP 400 followed by changed instructions reaches the incompatible native reload condition; current source supports the mechanism and the report supplies a real-runtime reproduction, although this review did not execute it.

Is this the best way to solve the issue?

Yes. Bounded client replacement preserves the native configuration check and conversation identity, while explicit sibling and process-lifetime guards address the earlier unsafe retirement cases.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 3343ccd2a3f9.

Labels

Label justifications:

  • P1: A settled provider failure can leave subsequent sends unable to apply changed instructions, blocking continuation of an existing conversation.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR records real Gateway chat.send and native Codex execution against an injected HTTP failure, followed by same-thread recovery with history and new instructions; the inspected eight-case fixture also covers sibling preservation, physical exit, explicit cancellation, and unconfirmed shutdown.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR records real Gateway chat.send and native Codex execution against an injected HTTP failure, followed by same-thread recovery with history and new instructions; the inspected eight-case fixture also covers sibling preservation, physical exit, explicit cancellation, and unconfirmed shutdown.

Evidence

What I checked:

  • Current main still needs recovery: The fetched main revision resumes the existing client and retires it only for unsuccessful unsubscribe or an unknown policy-write outcome; it lacks the settled-failure replacement branch. (extensions/codex/src/app-server/thread-lifecycle-io.ts:108, 3343ccd2a3f9)
  • Native dependency contract inspected: The patch and its real-runtime proof depend directly on native thread/resume semantics. The sibling checkout is pinned to this SHA; its backing cache origin was verified as https://github.com/openai/codex.git. Native configuration reload explicitly requires ThreadStatus::Idle, while thread_status.rs preserves SystemError after a settled failure. (codex-rs/app-server/src/request_processors/thread_processor.rs:4257, 6b9826e3aa83)
  • Replacement eligibility preserves existing boundaries: Replacement excludes client-bound and supervised conversations, overlapping leases and acquisitions, protected native children, retained ephemeral siblings, claimed siblings, and outstanding sibling routes or completion watchers. The existing configuration fence remains in place. (extensions/codex/src/app-server/thread-lifecycle-io.ts:114, 7d56169a839f)
  • Physical shutdown precedes bounded retry: Startup releases its lease before awaiting closeAndWait, requires exited=true, permits at most one settled-failure replacement, and checks cancellation before another acquisition. Unconfirmed shutdown raises a preflight error without clearing the conversation binding. (extensions/codex/src/app-server/attempt-startup.ts:628, 7d56169a839f)
  • Recorded production-boundary recovery proof: The captured PR body, sourceRevision 6f3669f0a053f351b99f76a66db7fb5c0d51927d993faec7cd566e219e455f65, reports eight passing registered Gateway scenarios using the real native runtime and a loopback HTTP provider. The inspected fixture checks one additional provider request, unchanged native thread ID, historical content, replacement instructions, healthy reuse, sibling continuation, delayed exit, explicit chat.abort, and unconfirmed shutdown. The reviewer did not execute the fixture. (src/gateway/server.codex-failure-recovery.test.ts:28, 7d56169a839f)
  • Re-review continuity: The GitHub commit comparison against the immediately preceding reviewed head shows an unchanged retirement predicate moved to the cleanup owner and strengthened cancellation-fixture handling. Earlier client-bound and idle-ephemeral findings are resolved by the current eligibility guards. The previous completed review retained no outstanding findings or rank-up moves. (src/gateway/server.codex-failure-recovery.test.ts:490, 7d56169a839f)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (9 earlier review cycles; latest 8 shown)
  • reviewed 2026-09-15T10:44:31.688Z sha 62118883b056709d6e76c6213f6f72ff5339aea4 :: needs real behavior proof before merge. :: [P1] Exclude client-bound threads from unconditional retirement
  • reviewed 2026-09-15T13:07:10.574Z sha b943ed9 :: needs real behavior proof before merge. :: [P1] Exclude client-bound threads from the new retirement condition
  • reviewed 2026-09-15T17:41:49.268Z sha 644473f :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-15T18:44:37.459Z sha 65006d9 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-16T07:48:11.743Z sha 65006d9 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-16T12:39:23.489Z sha 65006d9 :: needs changes before merge. :: none
  • reviewed 2026-09-16T14:18:43.609Z sha cc5b05a :: blocked before merge. :: [P1] [P1] Preserve idle ephemeral siblings before retiring the client
  • reviewed 2026-09-16T16:10:31.097Z sha de17a2a :: needs maintainer review before merge. :: none

MertBasar0 and others added 2 commits September 15, 2026 15:46
…es handoff

Native thread/resume reloads configuration only for an idle thread. A thread
left in systemError by a settled provider failure is loaded but not idle, so it
silently ignores the overrides and never emits the notLoaded status change the
configuration fence waits for. The fence correctly refuses the unconfirmed
configuration, but resume cleanup only retires the client when the unsubscribe
fails or the handoff outcome is unknown. Here the unsubscribe succeeds and the
outcome is definite, so the same loaded client is preserved and every retry
repeats the identical refusal.

Carry the observed settled-systemError status to the cleanup site and retire the
client in that case, and cover it with a regression that fails when the
production change is reverted.

Co-Authored-By: Claude Opus 5 <[email protected]>
The explicit String() around an already-string message tripped
no-unnecessary-type-conversion in the core lint stripe. Use the
rejects.toThrow form the neighbouring cases already use.

Co-Authored-By: Claude Opus 5 <[email protected]>
@MertBasar0
MertBasar0 force-pushed the fix/148837-codex-systemerror-client-retire branch from 6211888 to b943ed9 Compare September 15, 2026 12:47
@MertBasar0

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@MertBasar0

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot removed the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Sep 15, 2026
@MertBasar0

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 16, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 16, 2026
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 16, 2026
@obviyus

obviyus commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-admin-merge
pr: 149000
head: de17a2a
scope: owner-review

@obviyus

obviyus commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

landpr-approve-admin-merge
pr: 149000
head: 7d56169
scope: owner-review

@obviyus
obviyus merged commit 6d410b5 into openclaw:main Sep 16, 2026
188 of 189 checks passed
@obviyus

obviyus commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Thanks @MertBasar0 and @compoodment!

Proof: After a controlled HTTP 400, the next send with changed instructions resumes the same conversation on a fresh client, keeps its history, and applies the new instructions. All eight recovery and sibling controls pass on Linux.

  • Bug: A settled failure made later instruction changes fail on every retry.
  • Fix: Retire an eligible failed client, confirm its physical exit, and resume the same thread within that send. Active and Incognito siblings remain protected.
Before After
Repeated reload refusal without another provider request. The changed-instructions send completes with the old context and new instructions.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
## What Problem This Solves

Fixes openclaw#148837. After a settled native failure, changing instructions could make every later send refuse configuration reload without another provider request.

## Why This Change Was Made

The resume owner retires the exact eligible client. Startup releases its lease, waits for confirmed physical shutdown, then resumes the same thread within that send. Unconfirmed shutdown stops with the binding preserved. Client retirement still has one writer: the existing shared-client lifecycle owner.

## User Impact

Recovery preserves history and applies the new instructions. Active siblings and idle Incognito siblings veto replacement, preserving the target's existing refusal and their original client/thread. Original-policy Incognito continuation keeps its context. Saved idle siblings can cold-resume after replacement. Client-bound and supervised conversations remain excluded.

## Evidence

A real native runtime behind registered Gateway `chat.send`, using a controlled HTTP 400, reproduces the original refusal. Candidate recovery completes with exactly one further request carrying the old marker and new instructions. The pre-correction source also fails the idle Incognito and delayed-exit controls.

```sh
node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-server-isolated.config.ts src/gateway/server.codex-failure-recovery.test.ts
```

## Compatibility

No schema, configuration, protocol or SDK change. Overlapping leases conservatively prevent recovery. Follow-up: active-sibling recovery needs a writer-release contract in shared-client-lifecycle.ts.

## Consumers

All ordinary native sends use this resume path. Existing retained, claimed, routed and leased state supplies eligibility.

## Invalidation

Only the exact failed client is retired. The binding and configuration fence survive replacement. Cancellation is checked before another acquisition.

## Tests

Locally, all eight registered scenarios and 685 owner/startup tests pass on a fresh merge with main. The cancellation control checks that the old process is still alive after accepted `chat.abort`, then releases and joins its actual exit. Removing the physical-exit wait still fails the registered test. Both Gateway tests from this change and openclaw#149842 are selected exactly once, with runtime preparation retained.

The prior hosted run failed the cancellation control and startup's line cap. The fixture now holds the launcher's final resume until release, and the unchanged cleanup predicate lives with the existing cleanup operations. Local type-aware preflight and both line checks pass; hosted results for this revision are pending.

Production growth is 113 lines: cleanup +36, startup −9, runtime facts +26, routing facts +22, resume eligibility +25, status +4 and the internal replacement error +9. These compose existing owners without a second lifecycle or store. Growth accepted under the owner's standing acceptance (2026-09-15).

Co-authored-by: Ayaan Zaidi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

extensions: codex gateway Gateway runtime P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Codex configuration refresh cannot recover a settled systemError thread

2 participants