Repository navigation
fix(codex): keep /codex model scoped to the native binding - #128751
Conversation
/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.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed August 26, 2026, 1:25 AM ET / 05:25 UTC. ClawSweeper reviewWhat this changesThe PR makes Regression provenancePossible 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 Review scores
Verification
How this fits togetherThe Codex plugin turns 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
Before merge
Agent review detailsSecurityNone. PR surfaceSource -23, Tests +145. Total +122 across 4 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest 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. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
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.
|
Addressed the P2 finding: 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. |
|
Addressed the remaining P1 ask: cloned 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. |
|
The latest review verdict is unchanged from what I already answered: this environment still has no live Codex app-server / provider credentials ( 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 |
|
Follow-up on the outstanding P1 ("pinned Codex app-server source could not be inspected directly"): this session had network access, cloned 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. |
|
Verified the new P1 finding directly and it's correct: for Not fixing it in this PR: a correct fix needs to tell an explicit |
|
Filed the outstanding P1 as a tracked follow-up: #128976 — Not folding it into this PR: it needs a precedence decision between an explicit |
|
No new code change here. The current ClawSweeper verdict is against sha |
Co-authored-by: chelsealong <[email protected]>
|
Merged via squash.
|
…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]>
Fixes #128718
Fixes #128976
Thanks @chelsealong for the original report, contributor implementation, and regression coverage.
Problem and root cause
/codex modelincorrectly treated whichever outer session happened to be present in the command context as the owner of a conversation-bound Codex model. In a/codex bindconversation, 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:
SessionEntrydesired model, preservesliveModelSwitchPendingand auth compatibility, and leaves the actual native binding unchanged until the existing lifecycle safely reconciles it./codex modelreports 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 modelagainst 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/codexsource before changing or approving behavior:codex-rs/app-server-protocol/src/protocol/v2/turn.rs:197-199: aturn/startmodel override applies to that turn and subsequent turns.codex-rs/app-server-protocol/src/protocol/v2/thread.rs:335-361:thread/resumecarries 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
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.