Skip to content

fix(codex): name the incompatible setting when a thread binding refuses rotation - #148530

Closed
DasX wants to merge 2 commits into
openclaw:mainfrom
DasX:fix/codex-binding-rotation-cause
Closed

DasX wants to merge 2 commits into
openclaw:mainfrom
DasX:fix/codex-binding-rotation-cause

Conversation

@DasX

@DasX DasX commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Refs #135310. This revision reapplies the diagnostic fix to the current staged-replacement lifecycle after merging main at a45979ee0f76. It does not restore the old lifecycle implementation.

Nine incompatibility checks currently report only rotating a stale thread binding when native ownership refuses replacement. If replacement is permitted but its later compare-and-swap fails, the diagnostic instead loses the cause as committing a fresh thread.

User Impact

The refusal identifies the changed setting: runtime identity, MCP configuration, web search, context-engine binding, user MCP configuration, network proxy configuration, plugin app configuration, dynamic tool loading mode, or dynamic tool catalog. The same staged cause also reaches a later replacement commit conflict.

Thread ownership and recovery behavior do not change. The existing guard, expected predecessor thread ID, mutation ordering, inventory preservation, subscription release, and rejection cleanup are unchanged. A genuinely fresh start without a staged replacement retains its existing conflict message.

Why This Change Was Made

rotateStaleBinding supplies the specific diagnostic operation. stageBindingReplacement captures it with the predecessor and passes it through the existing start context to startFreshCodexThread. The value is diagnostic metadata, not an authorization or configuration input. Other already-specific staging reasons also survive the commit boundary. The generic reason after an actually failed stale-thread resume remains generic.

The previous synthetic ownership regression now lives in the assignment-rotation suite rather than growing the oversized binding test file. A separate real-binary test is registered with the existing database-worker test owner.

Evidence

All evidence below is from this revision's local run, Linux x64, Node 24.21.0. Commands run serially in memory-limited units.

Before and after

With main's production code, the ownership regression and replacement-CAS regression both fail specifically because the operation is too generic. An additional test against the pinned real Codex 0.160.0 app-server reproduces the later conflict:

Expected: Codex thread binding changed while changing its dynamic tool loading mode: <thread-id>
Received: Codex thread binding changed while committing a fresh thread: <thread-id>

The temporary thread ID is replaced above. After the fix, all 10 tests in the assignment-rotation and new native-diagnostic suites pass, including the real-binary test.

The real-binary test starts actual native threads through the production OpenClaw lifecycle and persists the original binding through its SQLite store. It injects only a failed replacement-commit result. It verifies the specific conflict, unchanged original binding, still-readable predecessor thread, expected predecessor ID in the mutation, and deletion of only the uncommitted replacement. The native check passed in 1425 ms within the final suite run.

Verification

Final local verification on 116130492c085a37108bab211d087cd61acfb113 is green:

  • 287 tests in 9 files, two sequential shards, 151.788 s wall time:

    pnpm test \
      extensions/codex/src/app-server/thread-lifecycle.binding.test.ts \
      extensions/codex/src/app-server/thread-lifecycle.test.ts \
      extensions/codex/src/app-server/thread-lifecycle.configured-mcp-ownership.test.ts \
      extensions/codex/src/app-server/thread-lifecycle.app-inventory.test.ts \
      extensions/codex/src/app-server/thread-lifecycle.user-mcp-servers.test.ts \
      extensions/codex/src/app-server/thread-lifecycle.adoption.test.ts \
      extensions/codex/src/app-server/thread-lifecycle.native.test.ts \
      extensions/codex/src/app-server/thread-lifecycle.assignment-rotation.test.ts \
      extensions/codex/src/app-server/thread-lifecycle.rotation-cause.native.test.ts \
      --maxWorkers=1
  • npx oxlint --type-aware on all five changed TypeScript files: zero warnings and errors. The repository's SDK boundary declaration preparation was required first.

  • pnpm tsgo:extensions: exit 0, 330.074 s. This is the full production extensions graph, not the incomplete raw package graph.

  • pnpm check:line-cap-ratchet --base a45979ee0f7635a4bf9918a8ea648e6d0a415e51: pass.

  • pnpm check:max-lines-ratchet --base a45979ee0f7635a4bf9918a8ea648e6d0a415e51: pass.

  • node scripts/check-no-conflict-markers.mjs, oxfmt --check on all six changed files, and git diff --check: pass.

The local merge commit preserves the exact tested file tree. Publication is a normal fast-forward push from the previously published PR head, not a force push.

Proof boundaries

  • The real-binary test uses fresh temporary homes and state, an allowlisted child environment, a non-authenticated loopback-only provider configuration, and no model inference. It verifies that no auth file exists. No operator credentials or production state are copied.
  • The commit failure is fault-injected. This is real native thread creation and cleanup, not evidence of a naturally occurring concurrent production race.
  • The early native-ownership refusal is covered by a synthetic ownership fixture. This is not an account-backed, fully adopted supervised-session reproduction or a packaged-Gateway/UI proof.
  • The pinned dependency contract was checked directly: Codex 0.160.0 dynamic tool declarations. Namespaced functions carry type: function; defer_loading is serialized as deferLoading.

Maintainer question on the outstanding proof request: does this isolated real-binary lifecycle proof, together with the ownership and preservation regressions, suffice for this diagnostic-only change, or is a fully adopted supervised-session reproduction still required before merge?

…es rotation

Nine distinct rotation checks in startOrResumeThread passed the same operation
string, "rotating a stale thread binding", to clearCurrentBinding. The refusal
correctly preserved the thread but named none of the nine settings that could have
drifted, and at normal logging levels there was nothing else to distinguish them.

Give each check the cause its own debug line already reports. Three of the strings
are the ones the assertCodexBindingMayBeReplaced call directly above that check
already uses, so a refusal names one consistent cause whichever guard fires first.
assertCodexBindingMayBeReplaced and every control-flow path are unchanged.

The remaining generic string in thread-lifecycle-io.ts stays: it fires after a
failed thread/resume, where the binding really is stale.

Refs openclaw#135310
@clawsweeper

clawsweeper Bot commented Sep 14, 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 14, 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-09-14T20:53:49.605299Z ee6bffd PR opened
🔒 Security Review ✅ Completed 2026-09-14T20:56:22.742406Z ee6bffd PR opened
ℹ️ 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.

@clawsweeper

clawsweeper Bot commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 3, 2026, 4:32 AM ET / 08:32 UTC (Revision 2).

ClawSweeper review

What this changes

The Codex plugin names the incompatible setting in thread-replacement refusals and preserves that cause in later commit-conflict errors, with synthetic and real-binary regression coverage.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main. The new real-binary lifecycle evidence resolves the earlier proof blocker for this diagnostic-only change, and no blocking correctness or security finding remains.

Priority: P2
Reviewed head: 116130492c085a37108bab211d087cd61acfb113

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused diagnostic repair with sufficient real native lifecycle evidence and no blocking findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The captured after-fix run exercises production thread lifecycle and a real Codex 0.160.0 client on isolated Linux state, injecting replacement-commit failure and observing the specific cause, preserved SQLite binding, readable predecessor, and replacement-only deletion. Synthetic coverage supplements the early refusal; authenticated supervision is not required for this diagnostic-only change. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured after-fix run exercises production thread lifecycle and a real Codex 0.160.0 client on isolated Linux state, injecting replacement-commit failure and observing the specific cause, preserved SQLite binding, readable predecessor, and replacement-only deletion. Synthetic coverage supplements the early refusal; authenticated supervision is not required for this diagnostic-only change. No stored-data contract changes.
Evidence reviewed 11 items Verified introduced change: Reviewed the pinned base-to-head delta. Production changes pass cause-specific diagnostic strings and carry replacementOperation to the conflict constructor; guard conditions, replacement mutation, expected predecessor, and cleanup remain unchanged. The stale GitHub test merge was not used to infer merge effects.
Still needed on current main: Fetched main still stages the generic 'rotating a stale thread binding' operation for the nine incompatibility checks and does not carry replacementOperation. The relevant production modules have no differences between the pinned base and fetched main.
Latest release retains the defect: The latest release, v2026.9.8, still passes the generic stale-binding operation at all nine checks. Release source was inspected through GitHub's contents API.
Findings None None.
Security None None.

How this fits together

The Codex plugin connects OpenClaw sessions to native Codex threads. Its lifecycle compares saved bindings with current settings and either continues the thread, safely replaces it, or reports why replacement cannot proceed.

flowchart TD
  A[Session and current settings] --> C[Thread lifecycle]
  B[Saved thread binding] --> C
  C --> D[Compatibility and ownership checks]
  D --> E[Continue native thread]
  D --> F[Stage permitted replacement]
  D --> G[Specific refusal]
  F --> H[Commit replacement or report specific conflict]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +20, Tests +236. Total +256 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 40 20 +20
Tests 3 237 1 +236
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 277 21 +256

Review metrics

Metric Value Why it matters
Production versus regression growth production net +20 lines; tests net +235; test routing +1 Production growth carries diagnostic context through the existing lifecycle; most added coverage exercises real native creation, preservation, and cleanup.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #135310
Summary: This PR is the open candidate repair for the canonical diagnostic issue; earlier closed-unmerged proposals do not supersede it.

Members:

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

Technical review

Best possible solution:

Keep one lifecycle owner that reports the specific incompatibility through refusal and replacement failure while preserving native ownership and existing cleanup.

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

Yes, from source: a deferred-tool loading mismatch reaches the generic replacement operation on current main. The contributor also records before/after real-binary conflict evidence; this review did not execute it.

Is this the best way to solve the issue?

Yes. Supplying specific causes at the existing checks and carrying that metadata to the existing conflict error is a narrow repair without competing policy or state ownership.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This fixes a bounded diagnostic defect that obscures incompatible settings while the existing ownership guard preserves the thread.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured after-fix run exercises production thread lifecycle and a real Codex 0.160.0 client on isolated Linux state, injecting replacement-commit failure and observing the specific cause, preserved SQLite binding, readable predecessor, and replacement-only deletion. Synthetic coverage supplements the early refusal; authenticated supervision is not required for this diagnostic-only change. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured after-fix run exercises production thread lifecycle and a real Codex 0.160.0 client on isolated Linux state, injecting replacement-commit failure and observing the specific cause, preserved SQLite binding, readable predecessor, and replacement-only deletion. Synthetic coverage supplements the early refusal; authenticated supervision is not required for this diagnostic-only change. No stored-data contract changes.

Label justifications:

  • P2: This fixes a bounded diagnostic defect that obscures incompatible settings while the existing ownership guard preserves the thread.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured after-fix run exercises production thread lifecycle and a real Codex 0.160.0 client on isolated Linux state, injecting replacement-commit failure and observing the specific cause, preserved SQLite binding, readable predecessor, and replacement-only deletion. Synthetic coverage supplements the early refusal; authenticated supervision is not required for this diagnostic-only change. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured after-fix run exercises production thread lifecycle and a real Codex 0.160.0 client on isolated Linux state, injecting replacement-commit failure and observing the specific cause, preserved SQLite binding, readable predecessor, and replacement-only deletion. Synthetic coverage supplements the early refusal; authenticated supervision is not required for this diagnostic-only change. No stored-data contract changes.

Evidence

What I checked:

  • Verified introduced change: Reviewed the pinned base-to-head delta. Production changes pass cause-specific diagnostic strings and carry replacementOperation to the conflict constructor; guard conditions, replacement mutation, expected predecessor, and cleanup remain unchanged. The stale GitHub test merge was not used to infer merge effects. (extensions/codex/src/app-server/thread-lifecycle-run.ts:237, 116130492c08)
  • Still needed on current main: Fetched main still stages the generic 'rotating a stale thread binding' operation for the nine incompatibility checks and does not carry replacementOperation. The relevant production modules have no differences between the pinned base and fetched main. (extensions/codex/src/app-server/thread-lifecycle-run.ts:258, 5df82fa43619)
  • Latest release retains the defect: The latest release, v2026.9.8, still passes the generic stale-binding operation at all nine checks. Release source was inspected through GitHub's contents API. (extensions/codex/src/app-server/thread-lifecycle-run.ts:594, fc23bc864e45)
  • Unchanged preservation boundary: The existing replacement guard interpolates the supplied operation into both native-ownership and supervision refusals. The patch does not alter this guard or its authorization inputs. The thread guide documents preserved native ownership and fail-closed continuation. (extensions/codex/src/app-server/session-binding-record.ts:610, 116130492c08)
  • After-fix real native lifecycle proof: The captured PR body reports Linux x64, Node 24.21.0, pinned Codex 0.160.0, a before-fix generic conflict, and an after-fix pass in 1425 ms at the reviewed head. The inspected harness calls production startOrResumeThread with a real isolated app-server client and SQLite binding store, injects only replacement-commit failure, checks the specific diagnostic and unchanged binding, reads the predecessor through the real client, and verifies deletion targets only the replacement. This is bounded native lifecycle proof, not an authenticated supervised-session or naturally occurring race claim. (extensions/codex/src/app-server/thread-lifecycle.rotation-cause.native.test.ts:138, 116130492c08)
  • Previous review disposition: The previous review had no code findings and requested actual after-fix Codex output with preserved binding. The updated captured body supplies real-binary lifecycle evidence beyond the earlier synthetic server responses. Synthetic coverage separately checks the early ownership refusal and preserved assignments; a fully adopted supervised reproduction is unnecessary for this unchanged guard and diagnostic-only patch. (extensions/codex/src/app-server/thread-lifecycle.assignment-rotation.test.ts:169, 116130492c08)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Colton-Harris: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; 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 (1 earlier review cycle)
  • reviewed 2026-09-14T20:55:44.768Z sha ee6bffd :: needs real behavior proof before merge. :: none

@DasX

DasX commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

Status on the remaining before-merge item, so it does not sit open without an answer.

The review asks for after-fix evidence from a real OpenClaw/Codex setup showing the specific refusal and the preserved binding. I tried to produce that on the host I have and could not, so this PR does not claim it.

What is available here: the pinned Codex CLI (@openai/codex 0.153.4) and the codex plugin, enabled and current.
What is missing: any OpenAI credential at all. The agent auth profile store holds profiles: {} on every agent, the Codex home has no auth.json, models.providers.openai carries no key, and the service unit exports no OpenAI variables.

Reaching the changed refusal needs a persisted thread binding produced by a real Codex session. That needs a login, which I am not going to perform to manufacture a proof. I am also not going to hand-write a binding into a session file and call the result a real setup, because the hand-written part would be precisely the part under review.

So, plainly:

  • Proven. The refusal text is produced by the real startOrResumeThread path through the native-model-ownership branch, with synthetic server responses. That is the test already in this PR, and it is what the review has already seen.
  • Not proven. The same refusal observed in a live OpenClaw/Codex install, and the supervision branch of assertCodexBindingMayBeReplaced.
  • Unchanged. Control flow. assertCodexBindingMayBeReplaced is untouched; the nine call sites pass a cause-specific operation string instead of nine identical ones. A binding that refused rotation before refuses it identically now, with a message that names which setting changed.

For a maintainer who does have a working Codex login, the reproduction is short: bind a thread, change one incompatible setting (the dynamic tool loading mode is the cleanest, since it is the only possible cause on that path once native model ownership is in play), start again, and read the refusal.

If that evidence is required before this can land, this PR is blocked on someone else's environment, not on more work here. I would rather say that than pad the body with a substitute.

@DasX

DasX commented Sep 14, 2026

Copy link
Copy Markdown
Contributor Author

On the two earlier proposals the review flags as same_root_cause: I read both closures, and neither was a rejection of the repair.

#135413 and #137972 were closed by their own author on 2026-09-04 for a mechanical reason. @gaoanze888 says it plainly in the closing comment on #137972: #135413's base was over 1300 commits behind main, main had since refactored thread-lifecycle-run.ts, and cherry-picking the stale whole-file blob overwrote that refactor, which is what failed the type, snapshot, boundary and dependency checks. The same comment ends:

The PR's actual change is sound and still applicable: 9 clearCurrentBinding("rotating a stale thread binding") calls → specific reasons. Main's current thread-lifecycle-run.ts still has all 9 calls. But they must be re-applied onto main's c[urrent file]

This branch is that re-application, written against cbc5d7e03cd and since rebased, touching only the nine string arguments and adding one test. No whole-file replacement, so the refactor that broke the earlier attempt is intact.

On the remaining before-merge item: I cannot supply it and would rather say so than pad the PR. Real-setup evidence needs a Codex App Server with a materialized supervised thread, and there is none on the machine this was developed on. The Limitations section already records that the supervised branch of assertCodexBindingMayBeReplaced was not exercised and that the test drives the native-model-ownership branch instead, which renders the same operation string through the same helper.

If a maintainer with a live Codex setup wants to confirm it, the shortest path is the issue's own reproduction: adopt a supervised binding, change only the persisted dynamicToolsContainDeferred, and continue the thread. Before this change the refusal reads while rotating a stale thread binding; after it, while changing its dynamic tool loading mode.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 3, 2026
roboclaw-bot added a commit that referenced this pull request Nov 2, 2026
…191522)

Name the incompatible setting in the existing thread-rotation refusal using
the label already available at the comparison owner. Rotation conditions and
native binding preservation stay unchanged.

The focused lifecycle regression fails on main's generic message and passes
with the fix (7 cases). Validated on Crabbox with touched-file lint/format;
independent autoreview found no actionable P0-P2 findings. The separate 10-line
allocation covers the net regression growth in the existing ownership table.

Supersedes #148530, thanks @DasX.

Co-authored-by: Peik S. <[email protected]>
@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @DasX for diagnosing this and working through the refusal cases. The smaller replacement landed in #191522 (ccac42b): it uses the setting label already known by the comparison owner, with a regression that fails on main and passes after the fix. Your co-author credit is preserved. Closing this as superseded by the merged replacement.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 3, 2026
…penclaw#191522)

Name the incompatible setting in the existing thread-rotation refusal using
the label already available at the comparison owner. Rotation conditions and
native binding preservation stay unchanged.

The focused lifecycle regression fails on main's generic message and passes
with the fix (7 cases). Validated on Crabbox with touched-file lint/format;
independent autoreview found no actionable P0-P2 findings. The separate 10-line
allocation covers the net regression growth in the existing ownership table.

Supersedes openclaw#148530, thanks @DasX.

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

Labels

extensions: codex P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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.

2 participants