Skip to content

fix(codex): keep /codex model scoped to the native binding - #128751

Merged
steipete merged 4 commits into
openclaw:mainfrom
chelsealong:fix/codex-model-outer-session-override
Aug 26, 2026
Merged

steipete merged 4 commits into
openclaw:mainfrom
chelsealong:fix/codex-model-outer-session-override

Conversation

@chelsealong

@chelsealong chelsealong commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #128718
Fixes #128976

Thanks @chelsealong for the original report, contributor implementation, and regression coverage.

Problem and root cause

/codex model incorrectly treated whichever outer session happened to be present in the command context as the owner of a conversation-bound Codex model. In a /codex bind conversation, that ambient session can belong to a different provider, runtime, or authentication profile, so the command silently rewrote unrelated ordinary-session routing.

The original binding-only patch fixed that leak but introduced #128976 for direct Codex sessions: their canonical desired model is the persistent SessionEntry, while the native binding describes the model actually loaded into the existing app-server thread. Updating only the binding lost the desired selection on the next turn and bypassed live-switch signaling, auth-profile reconciliation, and generation-safe thread lifecycle handling.

Architectural repair

Choose the owner exclusively from the authoritative target identity:

  • A persistent session identity updates its SessionEntry desired model, preserves liveModelSwitchPending and auth compatibility, and leaves the actual native binding unchanged until the existing lifecycle safely reconciles it.
  • A bound conversation or ephemeral session identity updates only its native binding. Ambient outer-session provider, model, runtime, and auth state remain untouched.
  • Bare /codex model reports the same authoritative owner. A conversation without a native model never falls back to an unrelated ambient session.

No new persistence, compatibility markers, lifecycle branches, or protocol surfaces are added. Production code is net negative: +23/-46; regression coverage is +147/-2.

Real native app-server proof

Executed against the actual installed Codex app server with an isolated temporary CODEX_HOME, file-only credential storage, all provider/GitHub credentials removed, and no operator gateway or home-directory state. This proves the real native protocol accepts a different model for a later turn in the same thread:

{
  "nativeAppServer": true,
  "isolatedHome": true,
  "credentials": "removed",
  "initialized": true,
  "threadStartRequestedModel": "gpt-5.6-sol",
  "threadStartReportedModel": "gpt-5.6-sol",
  "turnStartRequestedModel": "gpt-5.6-terra",
  "turnStartAccepted": true
}

The real OpenClaw command integration additionally dispatches /codex model against a bound conversation with a deliberately divergent outer provider/runtime/auth profile and verifies the native binding changes while every ambient outer-session field remains unchanged. Direct-session regressions verify desired-model persistence, stale native binding retention, live-switch signaling, compatible auth preservation, and incompatible auth cleanup.

Direct upstream contract inspection

Personally inspected the sibling openai/codex source before changing or approving behavior:

  • codex-rs/app-server-protocol/src/protocol/v2/turn.rs:197-199: a turn/start model override applies to that turn and subsequent turns.
  • codex-rs/app-server-protocol/src/protocol/v2/thread.rs:335-361: thread/resume carries thread-scoped model/provider overrides.
  • codex-rs/app-server/src/request_processors/thread_processor.rs:4133-4181: loaded threads with subscribers retain their current configuration; resume overrides are ignored until ownership is released. This is why prematurely overwriting the active binding would break OpenClaw's existing lifecycle reconciliation.
  • extensions/codex/src/app-server/thread-lifecycle.binding.test.ts:2091-2169: existing coverage protects same-generation resume and generation-changing thread rotation.

Verification

node scripts/run-vitest.mjs extensions/codex/src/conversation-control.test.ts extensions/codex/src/commands.test.ts extensions/codex/src/app-server/thread-lifecycle.binding.test.ts
Test Files: 3 passed; Tests: 316 passed

node scripts/run-vitest.mjs extensions/codex/src/conversation-control.test.ts extensions/codex/src/commands.test.ts
Test Files: 2 passed; Tests: 204 passed

node scripts/run-tsgo.mjs -p tsconfig.extensions.json --noEmit
PASS

node scripts/run-tsgo.mjs -p test/tsconfig/tsconfig.extensions.test.json --noEmit
PASS

node scripts/run-tsgo.mjs -p extensions/codex/tsconfig.json --noEmit --incremental --tsBuildInfoFile extensions/codex/dist/.boundary-tsc.tsbuildinfo
PASS after canonical plugin-SDK boundary artifact preparation

git diff --check
PASS

Fresh independent autoreview
PASS; no actionable findings

The first rewritten head exposed one control-flow narrowing error in CI; the final corrective commit hoists the checked identity before its session-key guard, and all three formerly failing type/package-boundary checks now pass locally.

/codex model wrote the outer OpenClaw session model override (and marked
a pending live model switch) any time a session context was present,
even for a thread bound through /codex bind. In a dual-runtime setup
that let a Codex-scoped model change silently redirect the next turn
to a different configured runtime. The binding store is now the sole
owner of this selection; only /model may change the outer session
override.
@clawsweeper

clawsweeper Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@clawsweeper clawsweeper Bot added merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 24, 2026
@clawsweeper

clawsweeper Bot commented Aug 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed August 26, 2026, 1:25 AM ET / 05:25 UTC.

ClawSweeper review

What this changes

The PR makes /codex model update a direct session’s outer selection while updating only a bound conversation’s native Codex binding, and adjusts status output and regression tests for those two targets.

Regression provenance

Possible regression — probable (reviewed change; failure trace). No predecessor PR is attributed.

Merge readiness

⛔ Blocked until real behavior proof from a real setup is added - 3 items remain

Keep this PR open: the exact head now separates direct-session and bound-conversation ownership correctly in source, but it lacks real after-fix behavior proof and the required direct sibling Codex contract inspection was unavailable in this read-only, offline checkout.

Priority: P1
Reviewed head: bacf955f5c8b5dbd325bff4b35a6f74bc751c5c6

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The source-level ownership split and regressions are focused, but real behavior proof and independent upstream-contract inspection remain missing.
Proof confidence 🦪 silver shellfish (2/6) Needs real behavior proof before merge: The supplied Vitest results cover the owner boundary but do not show an after-fix native app-server/session run; add a redacted trace with no credentials, endpoints, or identifiers. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs real behavior proof before merge: The supplied Vitest results cover the owner boundary but do not show an after-fix native app-server/session run; add a redacted trace with no credentials, endpoints, or identifiers. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-main failure path: Current main forwards the ambient session whenever one exists, so a bound conversation reaches the SessionEntry mutation path before also patching its binding.
Exact-head ownership split: The PR head branches on the resolved binding identity: direct sessions update SessionEntry, while conversation bindings update only their native model and provider.
Lifecycle alignment: Direct-session lifecycle selection is derived from the runtime/session model, whereas bound conversations construct start/resume requests from binding.model and binding.modelProvider.
Findings None None.
Security None None.

How this fits together

The Codex plugin turns /codex model commands into either OpenClaw session selection or persisted native thread-binding state. The resulting selection is consumed by the normal Codex thread lifecycle when it starts or resumes a thread.

flowchart LR
  Command[Codex model command] --> Target[Resolve target identity]
  Target --> Kind{Direct session or bound conversation}
  Kind --> Session[Session model selection]
  Kind --> Binding[Native Codex binding]
  Session --> Lifecycle[Codex thread lifecycle]
  Binding --> AppServer[Codex app-server request]
  Lifecycle --> AppServer
Loading

Before merge

  • Add real behavior proof - Needs real behavior proof before merge: The supplied Vitest results cover the owner boundary but do not show an after-fix native app-server/session run; add a redacted trace with no credentials, endpoints, or identifiers. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The PR body still describes all targets as binding-only, but the exact head deliberately writes SessionEntry for direct sessions; that mismatch obscures the upgrade and ownership contract.
  • Resolve merge risk (P1) - The required direct Codex source check could not be performed because ../codex is absent and this environment cannot resolve GitHub; do not treat the quoted PR-body contract as an independent verification.
Agent review details

Security

None.

PR surface

Source -23, Tests +145. Total +122 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 23 46 -23
Tests 2 147 2 +145
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 170 48 +122

Review metrics

Metric Value Why it matters
Production versus test delta production +23/-46 (net -23); tests +147/-2 The patch removes the ambient-session forwarding path and adds coverage for direct-session and bound-conversation ownership.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #128718
Summary: This PR is the candidate repair for the bound-conversation outer-session mutation; the direct-session persistence report is an adjacent consequence addressed by the final ownership split.

Members:

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

Merge-risk options

Maintainer options:

  1. Prove the final ownership split (recommended)
    Before merge, provide a redacted after-fix trace showing a direct session resumes with its selected model and a bound conversation changes without altering its outer session.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Add a redacted after-fix app-server trace for direct-session and bound-conversation model changes, then update the PR body to describe the identity-specific ownership split.

Technical review

Best possible solution:

Keep direct sessions owned by SessionEntry and bound conversations owned by their native binding, update the PR description to that final contract, and add a redacted after-fix app-server trace for both target kinds.

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

Yes, from source: current main forwards an ambient session for a bound conversation, while the PR’s identity branch prevents that write; focused regressions cover both ownership targets. A real app-server trace remains absent.

Is this the best way to solve the issue?

Yes, conditionally: identity-based ownership matches the two lifecycle consumers, but the final PR description and a real after-fix trace must confirm that contract before merge.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3d37bb4cbaa6.

Labels

Label justifications:

  • P1: Incorrect model ownership can silently route or preserve the wrong model for the next Codex turn.
  • merge-risk: 🚨 compatibility: The patch changes which persisted owner records an existing user's model selection.
  • merge-risk: 🚨 auth-provider: Direct-session provider and compatible auth-profile updates remain part of the changed model path.
  • merge-risk: 🚨 session-state: The patch changes the relationship between SessionEntry state and persisted native thread bindings.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The supplied Vitest results cover the owner boundary but do not show an after-fix native app-server/session run; add a redacted trace with no credentials, endpoints, or identifiers. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

Likely related people:

  • steipete: The current identity-specific ownership branch is blamed to this PR-head commit, and this person authored the two latest commits shaping the final behavior. (role: recent area contributor; confidence: high; commits: 568be428ecb9, bacf955f5c8b; files: extensions/codex/src/conversation-control.ts, extensions/codex/src/command-handler-actions.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add a redacted native app-server trace for a direct session and a bound conversation.
  • Update the PR body so it describes the exact-head identity-specific ownership behavior.
  • Re-run review where the required sibling Codex source is available.

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 (5 earlier review cycles)
  • reviewed 2026-08-24T14:23:28.451Z sha 9eada49 :: needs real behavior proof before merge. :: [P2] Read /codex model status from the binding
  • reviewed 2026-08-24T15:15:04.228Z sha 69a4f2e :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-24T15:40:55.176Z sha 69a4f2e :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-24T22:21:00.759Z sha 69a4f2e :: needs real behavior proof before merge. :: [P1] Carry the binding model into direct-session resume
  • reviewed 2026-08-26T04:29:13.020Z sha 568be42 :: needs real behavior proof before merge. :: none

The no-argument /codex model status read still preferred the outer
SessionEntry override over the native binding, so it could report a
stale model that diverged from what /codex model just wrote to the
binding. Read the binding first and fall back to the outer session
model only when no binding exists yet.
@chelsealong

Copy link
Copy Markdown
Contributor Author

Addressed the P2 finding: /codex model (no args) status now reads the native binding first and only falls back to the outer session model when no binding exists yet (extensions/codex/src/command-handler-actions.ts:340-361), so it no longer reports a stale outer override after this PR's write-path fix. Added a regression covering divergent outer-session/binding state and updated the one pre-existing test that had been asserting the old (buggy) priority. node scripts/run-vitest.mjs extensions/codex/src/commands.test.ts extensions/codex/src/conversation-control.test.ts → 202/202 passed; typecheck (tsgo:extensions, tsgo:extensions:test) and lint/format on touched files are clean. Pushed as 69a4f2e.

On the "real behavior proof" ask: I don't have a live Codex app-server / provider credential in this environment, so I can't produce a real-session trace here — flagging that instead of faking it. The Vitest coverage above is what I can supply from this checkout.

@chelsealong

Copy link
Copy Markdown
Contributor Author

Addressed the remaining P1 ask: cloned openai/codex and inspected the pinned @openai/[email protected] source directly at tag rust-v0.148.0 (3ba0f71) for the app-server model/provider contract (Codex hard gate). ThreadStartParams/ThreadResumeParams (codex-rs/app-server-protocol/src/protocol/v2/thread.rs:59-63) carry model/model_provider only as per-request fields, and thread_processor.rs:1061-1118/:175-176 fold them into ConfigOverrides scoped to that one thread's Session only — the Codex app-server protocol has no cross-thread/outer-session model concept at all. That confirms the outer SessionEntry write this PR removes was purely OpenClaw-side, with nothing on the Codex side to preserve. Full citations added to the PR body under "Codex app-server contract verification".

The live real-session trace ask is still not producible here (no live Codex app-server credentials in this environment) — noted in the previous comment and unchanged.

@chelsealong

Copy link
Copy Markdown
Contributor Author

The latest review verdict is unchanged from what I already answered: this environment still has no live Codex app-server / provider credentials (~/.openclaw/credentials/ doesn't exist here), so I still can't produce a real dual-runtime session trace — not faking one.

On the other P1 item in this latest verdict ("pinned Codex app-server source could not be inspected directly ... in this review environment"): that's the reviewer's own sandbox lacking network access to clone openai/codex, not a gap on my end — I already did that inspection and cited exact file/line evidence in the PR body under "Codex app-server contract verification" (posted in my 15:33 UTC comment above).

@chelsealong

Copy link
Copy Markdown
Contributor Author

Follow-up on the outstanding P1 ("pinned Codex app-server source could not be inspected directly"): this session had network access, cloned openai/codex fresh, confirmed tag rust-v0.148.0 resolves to the already-cited commit 3ba0f71, and re-read all three cited passages directly. Added the exact quoted source lines (not just file/line refs) to the PR body under "Direct quotes (re-verified in a follow-up session with network access)" so the contract is checkable without cloning anything. All three citations match exactly.

The live app-server session-trace ask is unchanged and still not producible here — no Codex credentials in this environment, as noted in earlier comments.

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Aug 24, 2026
@chelsealong

Copy link
Copy Markdown
Contributor Author

Verified the new P1 finding directly and it's correct: for kind: "session" targets, /codex model now only patches the native binding, but nothing consumes binding.model as the actual resume model. thread-lifecycle-run.ts:315-317 resolves the start/resume model as params.runtimeModelId ?? params.params.modelId — the outer session's model — and thread-model-selection.ts:57-67 reads binding.model only as a modelProvider fallback (when it happens to equal the requested model), never as the model itself. So for the common non-/codex bind case the command reports success but the next native turn keeps using the outer model.

Not fixing it in this PR: a correct fix needs to tell an explicit /codex model override apart from the routine per-turn sync that already overwrites binding.model from the actual thread response after every turn (run-attempt-finalize.ts:389). Making the direct lifecycle prefer binding.model unconditionally would make a later ordinary /model change silently stop affecting the Codex thread — that's new persisted precedence state and a resume-ownership design decision, not a mechanical patch, and it would push this PR well past its 120-added-line budget (currently 91/120 for the whole diff). Leaving this open for a follow-up rather than rushing a partial fix here.

@chelsealong

Copy link
Copy Markdown
Contributor Author

Filed the outstanding P1 as a tracked follow-up: #128976 — /codex model on a direct session-kind binding is overwritten on the very next turn because thread-lifecycle-run.ts:315-321 resolves the resume model from the outer runtime/session model, not binding.model (only used as a modelProvider fallback in thread-model-selection.ts), and thread-lifecycle-io.ts:286/:609 then re-persist that outer model onto the binding after every start/resume.

Not folding it into this PR: it needs a precedence decision between an explicit /codex model override and the routine per-turn sync that already overwrites binding.model from the actual thread response every turn — a design change, not a mechanical patch, and out of this PR's diff budget. Details and citations are in #128976. The live app-server session-trace ask remains not producible in this environment (no Codex credentials here), unchanged from earlier comments.

@chelsealong

Copy link
Copy Markdown
Contributor Author

No new code change here. The current ClawSweeper verdict is against sha 69a4f2e09f16, which is still the branch HEAD — both open asks from that verdict were already answered in this thread: the P1 (carry the binding model into direct-session resume) is tracked as follow-up #128976 with the reasoning for why it needs a separate precedence decision rather than a mechanical patch in this PR; the live app-server trace remains infeasible in this environment (~/.openclaw/credentials still doesn't exist here, reconfirmed just now). Nothing has changed since those replies, so requesting @clawsweeper re-review to pick up the current state.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 26, 2026
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 26, 2026
@steipete
steipete merged commit 2c9bcf3 into openclaw:main Aug 26, 2026
123 of 124 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…128751)

* fix(codex): keep /codex model scoped to the native binding

/codex model wrote the outer OpenClaw session model override (and marked
a pending live model switch) any time a session context was present,
even for a thread bound through /codex bind. In a dual-runtime setup
that let a Codex-scoped model change silently redirect the next turn
to a different configured runtime. The binding store is now the sole
owner of this selection; only /model may change the outer session
override.

* fix(codex): make /codex model status binding-owned

The no-argument /codex model status read still preferred the outer
SessionEntry override over the native binding, so it could report a
stale model that diverged from what /codex model just wrote to the
binding. Read the binding first and fall back to the outer session
model only when no binding exists yet.

* fix(codex): preserve authoritative model selection ownership

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

* fix(codex): retain session identity narrowing

---------

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

Labels

extensions: codex merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence.

Projects

None yet

2 participants