Skip to content

fix(codex): stop model fallback when native threads are active - #181204

Merged
steipete merged 4 commits into
mainfrom
fix/codex-active-thread-not-model-fallback
Oct 23, 2026
Merged

steipete merged 4 commits into
mainfrom
fix/codex-active-thread-not-model-fallback

Conversation

@steipete

@steipete steipete commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #181046

Related: #176177 (broader change that also includes this typed error; it can drop that hunk after this lands)

What Problem This Solves

Fixes unnecessary model fallback when a Codex thread is still claimed by active work and a policy change needs to release it.

User Impact

OpenClaw preserves the thread and stops the fallback chain instead of attempting another model against the same busy thread. Wait for or stop the active work before retrying. The actionable diagnostic remains available under the existing error-detail settings; this change does not add public channel copy. No configuration or migration is required.

Why This Change Was Made

Use the existing global AgentHarnessPreflightError contract at the refusal producer, as the fallback owner already treats it as a coordination failure. Apply the same classification to the session-retirement sibling and remove manual adoption's duplicate plain-error check so its existing typed authority check owns the refusal. The warm-thread and retirement messages are unchanged; adoption retains the canonical wait-for-completion guidance.

Thanks to @Stronggenetics for the typed-error idea in #176177. This separates that narrow correction from its broader native-tool catalog changes, following the coordination-error approach in #179347.

Evidence

  • Source/history confirmation on main 718bd3d69d293d992212bf1c4cc685d9551ddfc2: thread-lifecycle-warm.ts:215 throws an ordinary Error; the fallback runner advances unknown failures but stops global harness preflight errors.

  • The real warm-thread lifecycle regression requires an unscoped AgentHarnessPreflightError, the original message, unchanged binding, and successful reuse under the original policy. Existing core fallback tests own the one-attempt/no-fallback contract for this public error type. Adoption and session-retirement cases now require typed refusals too.

  • Local execution gap: host Node 26.12.0 is below the required 26.12.1, so pnpm install was refused. Per maintainer policy, local tests (including red/green runs), lint, formatting, and typecheck are deferred to PR CI. No local passing-test or timing claim. Live Gateway/channel e2e was skipped per maintainer policy.

  • git diff --check passes. Simplification removed a duplicate claim check without adding new error classes, codes, fallback policy, or state. Exact numstat: production +9/-9 (net 0), tests +11/-3, docs +5/-0.

  • Independent Codex branch autoreview through P2 completed scoped-clean: no actionable findings. This is static review, not runtime proof.

  • Merged fresh main 08b5a12ddd5173d2ef5e3e4668c94f748c77efb5 without conflicts. The corrected patch is unchanged after integration; current head is 498bb5772caa1fc09dadcf0d4103465a1599a763. Fresh full-candidate P0–P2 autoreview is scoped-clean with no actionable findings.

  • Initial-head CI (b96e5b6) passed the composed lifecycle-to-fallback regression (96 ms) and the adoption/retirement suites, but rejected its direct core import from an extension test. The follow-up keeps the regression on the public preflight contract; production is unchanged. The failed boundary job is 120203614256.

  • Review scope: main already returns generic copy for this ordinary ownership error when external error details are disabled (agent-runner-failure-reply.ts and renderCodexAppServerFailureCopy). Curated non-verbose channel copy is a separate improvement; this PR preserves the existing diagnostic-disclosure behavior while fixing fallback classification.

  • Current-head CI is green: run 39891710031 completed successfully on 498bb5772caa1fc09dadcf0d4103465a1599a763 (28 successful jobs, 29 skipped). Lint, formatting, production/test types, boundary checks, and the CI gate pass. All 110 cases in the three changed suites pass; key CI case timings are 53 ms (warm refusal/reuse), 131 ms (claimed manual adoption), and 22 ms (retirement refusal). No local wall-time measurement is claimed under the host policy.

steipete and others added 2 commits October 22, 2026 18:54
Classify claimed-thread refusals as global harness preflight failures and
reuse the existing adoption authority check instead of its plain-error
duplicate. Preserve actionable guidance and native thread ownership.

Extend existing lifecycle coverage through the model fallback runner.
Local test/lint execution is deferred to PR CI per maintainer host policy.

Fixes #181046.
Typed-error idea also appears in #176177 by @Stronggenetics.

Co-authored-by: Stronggenetics <[email protected]>
@clawsweeper

clawsweeper Bot commented Oct 23, 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.

@steipete
steipete marked this pull request as ready for review October 23, 2026 02:17
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T02:52:38.923684Z 498bb57 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation extensions: codex size: XS labels Oct 23, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b96e5b61a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Classifies busy Codex thread refusals as global preflight failures so model fallback stops.

Example: The native thread warm-background-policy-thread has active work when plugin policy changes.

  • Before: The ownership refusal can trigger another model attempt against the same busy thread.
  • After: The refusal stops fallback and preserves the original binding for reuse.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, correct patch with meaningful lifecycle coverage and passing CI; confidence remains bounded by synthetic runtime evidence.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; supplied evidence exercises the real lifecycle and transport client against a synthetic app-server, with exact-head CI passing.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A busy native Codex thread triggers misleading model switching even though changing models cannot release its ownership.
Reason: The maintainer-authored direction corrects an established classification defect using existing owners and contracts.

Merge readiness

✅ Ready for maintainer review

This PR narrowly fixes a current-main fallback bug. No actionable findings remain, and exact-head CI passes.

Priority: P2
Reviewed head: 498bb5772caa1fc09dadcf0d4103465a1599a763

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped Gateway fallback-stop scenario or pre-fix failing run is supplied; the recorded validation policy deliberately uses CI and production-lifecycle harness coverage.
Agent review details

How this fits together

The Codex plugin prepares native threads before agent execution; its errors reach the core model-fallback runner, which decides whether another model should be attempted.

flowchart TD
  A[Agent turn] --> B[Codex thread preparation]
  B --> C[Existing ownership guards]
  C --> D[Global preflight refusal]
  D --> E[Model fallback stops]
  C --> F[Compatible thread reuse]
Loading

Technical review

Best possible solution:

Use the existing global preflight error at busy-thread refusals while preserving the binding and ownership guards.

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

Current-main source establishes the protected-thread trigger, plain-error refusal, and fallback continuation; this read-only review ran no target code.

Is this the best way to solve the issue?

The producer-side classification is the smallest complete correction: the fallback owner already supports global preflight errors, and manual adoption already has the required typed claim check.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 5dce97b1362f.

Provenance checked

  • Warm-thread ownership refusal keeps the original intent (f5f44fa: Preserve native history and follow the physical thread owner across connection changes instead of releasing active work.)
  • Session-retirement claim refusal keeps the original intent (0924fd9: Reclaim deleted-session bindings while checking active native claims before destructive mutation.)
  • Manual-adoption duplicate claim check keeps the original intent (0924fd9: Refuse configuration adoption while competing work owns the native thread; the remaining authority callback enforces the same refusal with the canonical typed error.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f5f44fa adds extensions/codex/src/app-server/thread-lifecycle-warm.ts:129 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f5f44faeca4e; files: extensions/codex/src/app-server/thread-lifecycle-warm.ts)
  • Jacqueline Henriksen: Raw commit 31f23a5 adds extensions/codex/src/app-server/thread-lifecycle-warm.ts:365 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 31f23a54ecaa; files: extensions/codex/src/app-server/thread-lifecycle-warm.ts)
  • Dallin Romney: Raw commit 92eba62 adds extensions/codex/src/app-server/thread-lifecycle-warm.ts:156 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 92eba62bdfd7; files: extensions/codex/src/app-server/thread-lifecycle-warm.ts)

PR surface

Source 0, Tests +8, Docs +5. Total +13 across 7 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 3 9 9 0
Tests 3 11 3 +8
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 25 12 +13

Root-cause cluster

Relationship: same_root_cause
Canonical: #181046
Summary: This PR isolates the busy-thread fallback correction from a broader open Codex change.

Members:

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦪 silver shellfish: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A bounded coordination-error classification bug causes misleading model fallback and avoidable attempts during an already-blocked thread transition.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-23T02:34:19.097Z sha b96e5b6 :: needs changes before merge. :: [P2] Remove the extension test's direct core import | [P2] Provide public recovery copy for the typed ownership refusals

Reviewed October 22, 2026, 11:08 PM ET / October 23, 2026, 03:08 UTC (Revision 2).

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Oct 23, 2026
@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@steipete
steipete merged commit 20aecc9 into main Oct 23, 2026
136 of 137 checks passed
@steipete
steipete deleted the fix/codex-active-thread-not-model-fallback branch October 23, 2026 03:46
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 23, 2026
…law#181204)

* fix(codex): stop model fallback when native threads are active

Classify claimed-thread refusals as global harness preflight failures and
reuse the existing adoption authority check instead of its plain-error
duplicate. Preserve actionable guidance and native thread ownership.

Extend existing lifecycle coverage through the model fallback runner.
Local test/lint execution is deferred to PR CI per maintainer host policy.

Fixes openclaw#181046.
Typed-error idea also appears in openclaw#176177 by @Stronggenetics.

Co-authored-by: Stronggenetics <[email protected]>

* test(codex): keep active-thread regression on the public contract

---------

Co-authored-by: Stronggenetics <[email protected]>
RomneyDa added a commit that referenced this pull request Oct 28, 2026
* fix(codex): stop model fallback when native threads are active

Classify claimed-thread refusals as global harness preflight failures and
reuse the existing adoption authority check instead of its plain-error
duplicate. Preserve actionable guidance and native thread ownership.

Extend existing lifecycle coverage through the model fallback runner.
Local test/lint execution is deferred to PR CI per maintainer host policy.

Fixes #181046.
Typed-error idea also appears in #176177 by @Stronggenetics.

Co-authored-by: Stronggenetics <[email protected]>

* test(codex): keep active-thread regression on the public contract

---------

Co-authored-by: Stronggenetics <[email protected]>

(cherry picked from commit 20aecc9)

Co-authored-by: Stronggenetics <[email protected]>
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit e7cb8efb85614e20e168c2060229b17955cfe475)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: codex P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XS 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.

Codex active-thread rejection incorrectly triggers model fallback

1 participant