Skip to content

feat: configure Code Mode per model with inherited defaults - #132332

Merged
steipete merged 3 commits into
mainfrom
codex/code-mode-model-overrides
Aug 29, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/code-mode-model-overrides

Conversation

@steipete

@steipete steipete commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Operators could enable OpenClaw Code Mode globally or for an agent, but could not explicitly opt one model in or out independently of the provider catalog. The settings form also could not distinguish an inherited boolean from an explicit Off.

Why This Change Was Made

Adds the approved optional codeMode: boolean to shared and agent-specific model entries. Activation follows agent model → explicit agent setting → shared model → global default. Omission inherits, including a parent's Auto policy. Wildcard and bare-key Code Mode overrides are rejected at config validation; existing wildcard runtime policy remains valid. Model selection uses the logical provider/model for each attempt, including fallbacks; runtime selection and native Codex Code Mode are unchanged.

Production LOC: +124/-63 (net +61); tests: +557/-60. Growth implements the approved model override and tri-state UI while removing duplicate activation checks.

The shared tool-surface planner now owns activation. Catalog construction, client-tool additions, and execution no longer re-read the global switch and contradict an admitted model override or restart recovery. CLI mode flags and companion restrictions use an invocation override that wins over saved preferences while retaining limits and ordinary tool restrictions. Copilot uses the same owner.

User Impact

In Agent Defaults → Advanced → Models, each model now has Default / On / Off. Default removes the key; On/Off persist true/false. The Labs switch remains the global Auto/off default. Limits, aliases, parameters, streaming, and runtime settings are preserved.

Agent-specific model entries support the same config contract via Raw config or CLI. The existing Agent List generic form rejects its constrained map schema; repairing that editor is a separate follow-up, not claimed as fixed here. No new dependencies, persistence schema, or protocol version.

Evidence

  • Before the runtime change, the focused reproduction failed in seven cases, including real QuickJS execution after model opt-in with the global default off.
  • 851 tests across 28 files passed, covering model precedence, fallback identity, actual QuickJS execution, recovery, client tools, CLI, companion, Copilot, schema validation, and browser field round-trips. Type checking caught fixture signature/nullability errors; the full core-test type graph and a final 67-test rerun passed after correcting them.
  • Live isolated dev Gateway with real OpenAI Luna, Terra, and Sol: model On/global Off → exec; model Off/global Auto → read; Default/global Auto → exec; agent Off/shared model On → read; agent model On/agent Off → exec. Exact marker contents and persisted transcript tool calls verified. UI reload preserved Off; Default removed the key; timeout 7777 was retained. Normal operator Gateway untouched.
  • Real CLI --code-mode direct retained direct read despite saved model On; --code-mode code used exec despite all saved settings Off. Both completed with the exact marker.
  • Accepted ClawSweeper's ineffective-wildcard finding and added a shared model-map validator. Two new rejection cases failed before the repair; 132 focused config/schema/runtime tests pass after it. Maintainer approval and finding response.
  • Fresh independent Codex autoreview: no accepted/actionable findings, including the validation repair.
  • UI production build and performance budgets passed. The local full build compiled but its postbuild probe hit stale donor workspace-package exports; the same native probe passed all 49 built modules in the isolated runtime with checkout-owned packages. The first hosted run passed the runtime build and all behavior/UI jobs; only the two now-corrected test-type jobs failed. CI is rerunning on the corrected head before landing.
  • Config baseline regeneration adds two core paths and catches pre-existing visitor-access drift from feat(visitor-access): internal Cloudflare Access visitor plugin #132073 (+27 plugin paths); removing those rows reproduces the old plugin hash exactly.

Before:
Model settings before

After:
Model settings with Code Mode override

Final schema validation proof: real CLI rejects wildcard overrides in both model scopes; the actual Gateway settings UI shows the exact validation error and preserves the saved config. A fresh Sol request completed through exec on the final build. The complete remote changed-file gate passed; the final validation delta is checked separately.

@clawsweeper

clawsweeper Bot commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime commands Command implementations agents Agent runtime and tooling extensions: copilot size: L maintainer Maintainer-authored PR labels Aug 29, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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. labels Aug 29, 2026
@clawsweeper

clawsweeper Bot commented Aug 29, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 29, 2026, 12:04 AM ET / 04:04 UTC.

ClawSweeper review

What this changes

Adds per-model OpenClaw Code Mode on/off overrides, inherited activation precedence, CLI invocation overrides, Control UI tri-state selection, and documentation.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open: the prior P2 blocker remains. A valid provider-wildcard model entry can persist codeMode, but activation only reads an exact selected model key, silently falling back to the inherited setting.

Priority: P2
Reviewed head: 1fe61be2d3baa93813a93263c36ac0fb8c9883d6

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The feature has focused coverage and a concrete, fixable configuration-contract defect.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: repository state identifies a MEMBER-authored PR, so the external-contributor real-behavior-proof gate does not apply.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: repository state identifies a MEMBER-authored PR, so the external-contributor real-behavior-proof gate does not apply.
Evidence reviewed 5 items Introduced acceptance path: The introduced model-entry schema accepts codeMode for every string-keyed model entry, including valid provider/* entries.
Exact-only runtime lookup: Activation normalizes the selected provider/model and reads only that exact map key; it has no wildcard lookup.
Existing wildcard contract: Current main documents provider/* as valid model-map entries, while the PR documentation says codeMode is exact-model-only; validation must enforce that distinction.
Findings 1 actionable finding [P2] Reject Code Mode overrides on wildcard model entries
Security None None.

How this fits together

Agent configuration supplies a selected provider/model to the tool-surface planner, which chooses either direct tools or the compact OpenClaw Code Mode controls. The resulting surface is used by embedded runs and the Copilot bridge.

flowchart LR
  A[Operator configuration] --> B[Selected provider and model]
  B --> C[Activation resolver]
  C --> D[Tool-surface planner]
  D --> E[Code Mode controls]
  D --> F[Direct tool surface]
  E --> G[Embedded agent run]
  F --> G
Loading

Before merge

  • Reject Code Mode overrides on wildcard model entries (P2) - models accepts documented provider/* rows, and this schema now accepts codeMode on them. Activation only looks up the exact selected provider/model key in code-mode-runtime.ts, so an operator can save openai/*: { codeMode: true } and silently receive the inherited default. Reject this field on wildcard rows (the documented contract) and add a regression case.
  • Resolve merge risk (P1) - Existing configurations using a valid provider/* row can save a Code Mode choice that never takes effect, creating a silent configuration mismatch.
  • Complete next step (P2) - The remaining blocker is a narrow, mechanical validation mismatch with a clear owner-boundary repair.

Findings

  • [P2] Reject Code Mode overrides on wildcard model entries — src/config/zod-schema.agent-runtime.ts:893
Agent review details

Security

None.

PR surface

Source +43, Tests +483, Docs +58, Generated 0. Total +584 across 44 files.

View PR surface stats
Area Files Added Removed Net
Source 27 102 59 +43
Tests 13 543 60 +483
Docs 2 78 20 +58
Config 0 0 0 0
Generated 2 5 5 0
Other 0 0 0 0
Total 44 728 144 +584

Review metrics

Metric Value Why it matters
Configuration surface 1 optional boolean across 2 model maps The new persisted activation override must distinguish exact models from supported provider wildcards.
Production versus tests production +102/-59; tests +543/-60; docs +83/-25 The feature adds a cross-cutting activation policy while supplying substantial focused coverage.

Stored data model

Persistent data-model change detected: serialized state: src/gateway/session-companion-ask.ts, serialized state: src/gateway/session-companion-policy.ts, unknown-data-model-change: src/config/schema.help.models.ts, unknown-data-model-change: src/config/schema.help.runtime.ts, vector/embedding metadata: src/config/schema.help.models.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Enforce exact model keys (recommended)
    Reject codeMode on provider/* rows and add regression coverage, preserving wildcard support for the settings that actually implement it.

Technical review

Best possible solution:

Make the documented exact-model contract enforceable by rejecting codeMode on wildcard rows and covering that rejection alongside exact-key precedence.

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

Yes, in source: set global Code Mode off and agents.defaults.models["openai/*"].codeMode on; the schema accepts it but the exact selected model lookup ignores it.

Is this the best way to solve the issue?

No. The intended exact-only behavior is documented, but it is not enforced at the config boundary; reject wildcard codeMode values rather than accepting a no-op.

Full review comments:

  • [P2] Reject Code Mode overrides on wildcard model entries — src/config/zod-schema.agent-runtime.ts:893
    models accepts documented provider/* rows, and this schema now accepts codeMode on them. Activation only looks up the exact selected provider/model key in code-mode-runtime.ts, so an operator can save openai/*: { codeMode: true } and silently receive the inherited default. Reject this field on wildcard rows (the documented contract) and add a regression case.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.99

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 20997195bc47.

Labels

Label justifications:

  • P2: A saved setting can silently fail for a documented valid configuration shape, but the defect is bounded to wildcard model entries.
  • merge-risk: 🚨 compatibility: Merging would expose a new persisted config field whose accepted wildcard form does not match runtime behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🌊 off-meta tidepool and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: Not applicable: repository state identifies a MEMBER-authored PR, so the external-contributor real-behavior-proof gate does not apply.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/config/zod-schema.agent-defaults.test.ts src/agents/code-mode.config.test.ts.
  • [P1] node scripts/run-vitest.mjs ui/src/components/config-form-map-integrity.browser.test.ts.
  • [P1] node scripts/check-changed.mjs -- src/config/zod-schema.agent-defaults.ts src/config/zod-schema.agent-runtime.ts src/config/zod-schema.agent-defaults.test.ts src/agents/code-mode.config.test.ts.

What I checked:

Likely related people:

  • steipete: Current feature hunks and the preceding Code Mode implementation history are attributed to this author. (role: recent Code Mode and configuration contributor; confidence: high; commits: c1607722e41d, 5b6ef55fc796; files: src/agents/code-mode-runtime.ts, src/config/zod-schema.agent-runtime.ts, src/agents/tool-surface-plan.ts)

Rank-up moves

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

  • Reject wildcard codeMode entries and add exact-versus-wildcard validation coverage.

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-08-29T03:54:42.307Z sha c160772 :: found issues before merge. :: [P2] Reject Code Mode on wildcard model entries

@steipete

Copy link
Copy Markdown
Contributor Author

Maintainer confirmation: the optional per-model codeMode boolean, its inheritance order, and the Default/On/Off settings control are explicitly approved for this PR. Omission inherits; true/false override activation only. No new store schema or persisted session format is introduced.

Accepted the wildcard finding. Both model maps now share one validation owner that rejects an authored Code Mode value on wildcard or bare model keys, with an error at the offending codeMode field. Existing provider-wildcard runtime settings remain valid. This preserves the approved exact-model contract rather than silently adding another activation tier.

The rejection regressions failed before the repair and now pass for both agent/default scopes and both boolean values. The real CLI reproduced the earlier acceptance; I am rebuilding the dev Gateway to verify the corrected CLI and settings error path before landing. The two earlier CI fixture type errors are also corrected, with all core-test type jobs green on the current pushed head.

@steipete
steipete merged commit 1b2ce27 into main Aug 29, 2026
260 checks passed
@steipete
steipete deleted the codex/code-mode-model-overrides branch August 29, 2026 04:21
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

* feat: configure Code Mode per model with inherited defaults

* test: type Code Mode invocation fixtures precisely

* fix: reject ineffective model Code Mode overrides
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling app: web-ui App: web-ui commands Command implementations docs Improvements or additions to documentation extensions: copilot gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant