Skip to content

feat: per-model code-mode capability flags with an "auto" master-switch tier - #114695

Merged
steipete merged 5 commits into
mainfrom
feat/code-mode-model-flags-a9ff
Jul 27, 2026
Merged

steipete merged 5 commits into
mainfrom
feat/code-mode-model-flags-a9ff

Conversation

@steipete

@steipete steipete commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

tools.codeMode.enabled is all-or-nothing today: true forces the compact code-mode surface onto every tool-capable run, including models that do not write short orchestration programs reliably, and false leaves the savings on the table for models that clearly benefit. Operators who mix strong hosted models with weaker or local ones have no way to say "use code mode where it wins, normal tools elsewhere".

Why This Change Was Made

Adds a per-model capability flag to the model catalog compat surface (compat.codeMode: "preferred" | "capable", absent = capable) and an additive "auto" tier on the master switch. "auto" engages code mode only for catalog-preferred models, resolved at the two run engagement gates (embedded attempt prep and the harness tool-surface bridge) where the prepared model row is already in hand — no request-time catalog rediscovery. true/false behavior is byte-identical to before, the shipped default stays false, and the flag is provider-owned catalog metadata: values live in each provider plugin's manifest/catalog and core reads only the generic compat field. For OpenAI models the flag matters only when a run resolves to the OpenClaw embedded runtime; default OpenAI routing to the Codex-style harness surface is unchanged.

Live verification surfaced one latent bug this PR also fixes: the Anthropic plugin's hand-built forward-compat model rows (used when the runtime prefers plugin-resolved modern models, including env-key-only runs with an empty model registry) silently dropped catalog compat metadata. The row now carries registry compat when present and falls back to a lazily indexed manifest compat lookup, with regression tests in extensions/anthropic/forward-compat-generation.test.ts.

Codex boundary check for the touched stream wrapper (createCodexNativeWebSearchWrapper in src/llm/providers/stream-wrappers/openai.ts): the sibling Codex source defines the provider-native web_search ToolSpec payload entry in codex-rs/tools/src/tool_spec.rs (WebSearch variant, #[serde(rename = "web_search")]). This PR does not change that payload contract; it only adds an OpenClaw-side signal (openclawCodeModeToolSurface stream option) so the provider-family wrapper skips native web-search injection consistently when an "auto"-engaged run owns the tool surface — the same skip that enabled: true already triggers via config.

The "auto" tier makes catalog annotations a runtime input for opted-in operators; the owner has accepted ownership of the initial preferred-model list and future catalog corrections as provider-owned policy. Flipping the default from false to "auto" is a deliberate one-line owner follow-up, intentionally not part of this PR.

User Impact

Operators can set tools.codeMode: "auto" (or enabled: "auto") and get code-mode token savings (~30-50% total-token reduction at equal-or-better pass rates in A/B evals) on catalog-preferred models — the recent anthropic, gpt-5.5+, gemini-3.x, deepseek-v4, kimi-k3, MiniMax-M3, glm-5.1/5.2, and mimo-v2.5 lines — while unflagged and Ollama-served models keep normal tool exposure. Existing true/false configs behave exactly as before, including the fail-closed promise when the QuickJS runtime is unavailable. The Labs toggle reads "auto" as on instead of silently narrowing it. Docs cover the new tier, the catalog flag semantics, the shipped preferred list, the OpenAI routing caveat, and tier-choice guidance.

Evidence

Real behavior proof (isolated OPENCLAW_STATE_DIR, dev CLI openclaw agent --local, deliberately invalid provider keys so runs stop at the provider 401 after the tool surface is assembled; no credentials or private endpoints involved):

tools.codeMode: "auto" + catalog-preferred model (anthropic/claude-opus-5) — code mode engages:

[agent/embedded] code-mode: cataloged 30 tools behind exec/wait
[provider-transport-fetch] [model-fetch] response provider=anthropic api=anthropic-messages model=claude-opus-5 status=401 ...

Side-by-side under one identical tools.codeMode: "auto" config (Tool Search enabled as the positive control signal for the non-code-mode surface):

# auto + catalog-preferred model (anthropic/claude-opus-5): code mode owns the surface
[agent/embedded] code-mode: cataloged 30 tools behind exec/wait
[provider-transport-fetch] [model-fetch] start provider=anthropic api=anthropic-messages model=claude-opus-5 method=POST url=https://api.anthropic.com/v1/messages ...

# auto + unflagged model (google/gemini-2.5-flash, explicit config row without the flag): normal surface kept
[agent/embedded] tool-search: cataloged 34 tools behind compact prompt surface
[provider-transport-fetch] [model-fetch] start provider=google api=google-generative-ai model=gemini-2.5-flash method=POST url=https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:streamGenerateContent ...

tools.codeMode: true + the same unflagged model — force-on still engages:

[agent/embedded] code-mode: cataloged 34 tools behind exec/wait

Focused local runs (trusted source, linked-worktree wrapper):

node scripts/run-vitest.mjs src/agents/code-mode-runtime.test.ts src/agents/harness/tool-surface-bridge.test.ts packages/model-catalog-core/src/model-catalog-normalize.test.ts
 Test Files  3 passed — incl. new master-switch resolution table, auto/preferred gate cases, catalog compat normalization

node scripts/run-vitest.mjs src/config/schema.test.ts src/config/zod-schema.agent-defaults.test.ts
 Test Files  2 passed (101 tests) — new: accepts "auto"/{enabled:"auto"}, rejects "on"/{enabled:"always"}

node scripts/run-vitest.mjs extensions/anthropic  (full extension suite, 14 files)
 Test Files  14 passed — incl. new forward-compat compat-carry regression tests

node scripts/run-vitest.mjs extensions/openai/provider-catalog.contract.test.ts extensions/google/provider-catalog.test.ts extensions/deepseek extensions/moonshot/provider-catalog.test.ts extensions/xiaomi extensions/zai extensions/minimax/model-definitions.test.ts src/plugins/manifest-registry.test.ts src/llm/providers/stream-wrappers/openai.test.ts
 all shards passed

node scripts/run-vitest.mjs ui/src/pages/labs/labs-page.test.ts
 Test Files  1 passed — new: "auto" reads as enabled in Labs
  • node scripts/check-changed.mjs (delegated to Blacksmith Testbox): green, exit 0 (all lanes incl. formatting, ratchets, boundaries)
  • node scripts/run-tsgo.mjs core/extensions/root test lanes and tsconfig.extensions.json: clean
  • Autoreview (Codex, gpt-5.6-sol, --mode uncommitted, run per commit): clean each round — "no accepted/actionable findings reported"
  • node scripts/generate-docs-map.mjs --check — up to date

Branch drift: this PR intentionally does not chase moving main; merge drift is advisory in this repo, GitHub blocks real conflicts, and the land flow validates hosted CI on the exact head.

ClawSweeper rank-up notes: the preferred/unflagged comparison above is the requested after-fix side-by-side. A harness-path (plugin tool-bridge) runtime transcript is intentionally skipped: the only bundled consumer is the Copilot bridge, which requires live GitHub Copilot session auth; its gate is the same isCodeModeEngagedForModel helper proven above and is covered by the tool-surface-bridge unit table. The initial preferred-model policy and catalog-correction ownership are sponsored by the repository owner (this PR implements the owner-approved list, including the explicit decision to keep claude-sonnet-4-6 out of the preferred tier).

@steipete
steipete marked this pull request as ready for review July 27, 2026 18:58
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 4:33 PM ET / 20:33 UTC.

ClawSweeper review

What this changes

Adds tools.codeMode: "auto" and model-catalog compat.codeMode metadata so OpenClaw chooses Code Mode only for provider models marked preferred, while preserving explicit on and off behavior.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 5 items remain

Keep this PR open for maintainer product review and one more real-runtime proof pass. The implementation is a coherent additive opt-in path, and the existing true/false default remains unchanged, but the new provider-owned preferred-model policy and both changed tool-surface paths need maintainer confirmation and observable after-fix evidence. Likely related people: steipete is the feature’s current area contributor (medium confidence).

Priority: P2
Reviewed head: ddd073f98e569badd85d4615735c06db1a02bd15
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The patch is well-scoped and covered by focused tests, while partial rather than complete real-runtime evidence keeps it below merge-ready confidence.
Proof confidence 🦐 gold shrimp (3/6) Needs stronger real behavior proof before merge: The PR body now includes useful redacted embedded live output, but it does not visibly establish the unflagged normal-tool result or the changed harness-path behavior; add redacted terminal/live output and remove private details before posting. 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 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body now includes useful redacted embedded live output, but it does not visibly establish the unflagged normal-tool result or the changed harness-path behavior; add redacted terminal/live output and remove private details before posting. 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 4 items Additive configuration and per-model gate: The branch expands the Code Mode master switch to true, false, or "auto"; the new helper engages "auto" only when the prepared model has compat.codeMode: "preferred".
Both runtime tool-surface gates use prepared model metadata: The embedded attempt preparation and harness bridge both call the same per-model engagement helper, avoiding request-time catalog discovery.
Catalog contract and provider propagation coverage: The branch validates preferred normalization, config-schema acceptance, embedded behavior, harness behavior, and Anthropic’s forward-compatible dynamic rows retaining catalog compatibility metadata.
Findings None None.
Security None None.

How this fits together

Code Mode changes the tool surface exposed to an agent run: normal tools are compacted behind exec and wait. The selected provider model’s catalog metadata now feeds the embedded-run and harness tool-surface gates, which determine whether a request receives Code Mode or normal tools.

flowchart LR
  Config[Operator Code Mode setting] --> Gate[Per-model engagement gate]
  Catalog[Provider model catalog metadata] --> Gate
  Gate --> Embedded[Embedded agent tool surface]
  Gate --> Harness[Provider harness tool surface]
  Embedded --> Output[Code Mode or normal tools]
  Harness --> Output
  Output --> Request[Provider request]
Loading

Decision needed

Question Recommendation
Should OpenClaw adopt the proposed provider-owned compat.codeMode: "preferred" model list as supported policy for the new opt-in tools.codeMode: "auto" setting? Sponsor the scoped auto tier: Approve the opt-in tier with the proposed catalog-owned preferred list, retaining false as the default and requiring runtime proof before merge.

Why: The patch is mechanically additive, but choosing which provider models receive a different model-facing tool surface is ongoing product and provider-policy ownership rather than a purely technical correction.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body now includes useful redacted embedded live output, but it does not visibly establish the unflagged normal-tool result or the changed harness-path behavior; add redacted terminal/live output and remove private details before posting. 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) - "auto" is a new public configuration value whose behavior depends on provider-maintained catalog annotations; an incorrect preferred-model entry can change an opted-in operator’s tool surface after an OpenClaw update.
  • Resolve merge risk (P1) - The live evidence in the PR body demonstrates one embedded preferred-model path, but not the harness bridge or a visible normal-tools result for an unflagged auto-selected model.
  • Complete next step (P2) - The remaining blockers are maintainer acceptance of a new provider-policy contract and contributor-supplied real behavior proof, not a narrow mechanical repair suitable for automation.
Agent review details

Security

None.

PR surface

Source +123, Tests +158, Docs +91. Total +372 across 36 files.

View PR surface stats
Area Files Added Removed Net
Source 25 158 35 +123
Tests 8 159 1 +158
Docs 3 96 5 +91
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 36 413 41 +372

Review metrics

Metric Value Why it matters
Public configuration values 1 added value: "auto" The new master-switch tier changes an opted-in operator’s runtime behavior and therefore needs fresh-install and upgrade-safe review.
Catalog capability field 1 added field: compat.codeMode Provider model metadata now affects which model-facing tool surface an opted-in run receives.

Merge-risk options

Maintainer options:

  1. Add cross-surface runtime proof (recommended)
    Before merge, show redacted after-fix runs for a preferred model entering Code Mode and an unflagged model retaining normal tools, including the harness path when it is used.
  2. Accept catalog-policy ownership
    A maintainer may approve the proposed preferred-model set as an intentionally provider-owned, opt-in behavior policy.
  3. Pause pending policy scope
    Pause the PR if maintainers do not want catalog annotations to control an operator-selected tool-surface mode yet.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Add redacted real-runtime transcripts for preferred and unflagged `tools.codeMode: "auto"` runs, including a harness-path scenario where applicable; verify the normal tool surface is retained for the unflagged case.

Technical review

Best possible solution:

Keep false as the shipped default, approve the provider-owned preferred-model policy explicitly, and add redacted real-runtime evidence for both the preferred Code Mode outcome and the unflagged normal-tool outcome on the changed execution surfaces.

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

Not applicable as a bug reproduction: this is a feature PR. The PR body supplies a credible embedded live-run path, but the full changed behavior still needs cross-surface runtime observation.

Is this the best way to solve the issue?

Unclear: the shared per-model gate and provider-owned metadata are a maintainable design, but maintainers must first accept the preferred-model policy and the runtime proof should cover both modified tool-surface paths.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded, opt-in runtime and configuration enhancement with limited blast radius.
  • merge-risk: 🚨 compatibility: The new public configuration value changes tool-surface selection for operators who opt into "auto".
  • merge-risk: 🚨 auth-provider: Provider-resolved model catalog metadata now controls whether the run receives the embedded Code Mode surface.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body now includes useful redacted embedded live output, but it does not visibly establish the unflagged normal-tool result or the changed harness-path behavior; add redacted terminal/live output and remove private details before posting. 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:

  • Additive configuration and per-model gate: The branch expands the Code Mode master switch to true, false, or "auto"; the new helper engages "auto" only when the prepared model has compat.codeMode: "preferred". (src/agents/code-mode-runtime.ts:207, ddd073f98e56)
  • Both runtime tool-surface gates use prepared model metadata: The embedded attempt preparation and harness bridge both call the same per-model engagement helper, avoiding request-time catalog discovery. (src/agents/harness/tool-surface-bridge.ts:95, ddd073f98e56)
  • Catalog contract and provider propagation coverage: The branch validates preferred normalization, config-schema acceptance, embedded behavior, harness behavior, and Anthropic’s forward-compatible dynamic rows retaining catalog compatibility metadata. (extensions/anthropic/forward-compat-generation.test.ts:47, ddd073f98e56)
  • Current PR proof is only partly observable across changed surfaces: The PR body includes a redacted embedded Anthropic terminal result showing an auto-preferred run engages Code Mode, but it does not provide an observable after-fix harness-path result or a transcript showing the unflagged auto run’s retained normal tool surface. (ddd073f98e56)

Likely related people:

  • steipete: The current PR’s five commits implement the Code Mode switch, provider catalog annotations, and Anthropic propagation repair, making this the strongest available routing signal in the supplied review context. (role: recent area contributor; confidence: medium; commits: 4bb984eff756, ddd073f98e56; files: src/agents/code-mode-runtime.ts, src/agents/harness/tool-surface-bridge.ts, extensions/anthropic/register.runtime.ts)

Rank-up moves

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

  • Add redacted after-fix output that visibly compares a preferred auto run with an unflagged auto run.
  • Include a harness-path runtime result if the changed harness bridge is reachable for the selected provider/model.
  • Obtain maintainer sponsorship for the initial preferred-model policy.

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 (3 earlier review cycles)
  • reviewed 2026-07-27T19:03:22.051Z sha 82ed838 :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-27T19:52:58.612Z sha 89ba78e :: needs real behavior proof before merge. :: none
  • reviewed 2026-07-27T20:01:59.212Z sha 9fd5bde :: needs real behavior proof before merge. :: none

@steipete
steipete force-pushed the feat/code-mode-model-flags-a9ff branch from 82ed838 to efa47fd Compare July 27, 2026 19:44
@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 Jul 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 27, 2026
@steipete
steipete merged commit 7394262 into main Jul 27, 2026
134 of 136 checks passed
@steipete
steipete deleted the feat/code-mode-model-flags-a9ff branch July 27, 2026 20:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 28, 2026
…ch tier (openclaw#114695)

* feat(tools): per-model code-mode capability flags and auto master-switch tier

* feat(anthropic): flag claude-sonnet-4-6 as code-mode preferred

* revert(anthropic): drop claude-sonnet-4-6 from the code-mode preferred set

* test(anthropic): type the manifest compat field in the catalog contract test

* fix(anthropic): carry catalog compat onto hand-built forward-compat model rows
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 docs Improvements or additions to documentation extensions: anthropic extensions: copilot extensions: deepseek extensions: google extensions: minimax extensions: moonshot extensions: openai extensions: xiaomi extensions: zai gateway Gateway runtime maintainer Maintainer-authored PR 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. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant