Skip to content

refactor(models): simplify picker and thinking projections - #130694

Merged
steipete merged 4 commits into
mainfrom
codex/model-consumer-cleanup
Aug 27, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/model-consumer-cleanup

Conversation

@steipete

@steipete steipete commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The chat model picker, tool-model selection, and Gateway thinking metadata repeat the same normalization/projection work in several branches. This maintainer-requested cleanup removes those parallel paths while preserving the models, labels, defaults, and controls operators see.

While diagnosing this PR's Doctor CI timeout, repeated lint execution exposed an existing registry-ownership bug in Crabbox, also reproduced in Codex: the plugin looked up a check through its own SDK module graph but registered it into the host's registry. With separate artifact-loader graphs, the second invocation registered the same ID again and threw instead of returning diagnostics.

Why This Change Was Made

Keep each decision with its existing owner: the UI prepares one retained catalog for picker options and label disambiguation; model references normalize directly from their stored strings; Gateway thinking metadata has one projection with optional request-local caching. Fast-mode provider matching scans the catalog once, retaining qualified-route precedence and refusing stale-provider fallback for ambiguous catalog matches.

Removed the transient override union/constructor, a caller-dominated server-ref fallback, repeated picker availability scans, and duplicate cached/uncached thinking projection. No new abstraction or dependency, public/config/default surface, persistence change, or provider catalog metadata change.

The Doctor repair passes lookup alongside registration through both bundled plugin artifacts, following the existing memory-core contract. It removes the runtime health-barrel back-edge. CUA and Policy already deduplicate explicit hosts and also support a separate implicit-global registration contract; those paths are unchanged. Codex's remaining broad model/runtime SDK imports are a separate cold-loading follow-up, not needed to repair registry ownership.

Production LOC: +91/-177 (net -86). Tests: +92/-45 (net +47). The Doctor portion adds eight net production lines to carry the actual host registry across the plugin boundary; the consumer cleanup removes 94. No pure moves or generated files. Release-note context is in this body; the final documentation-only commit removes the root changelog entry to follow current main's release-owned policy.

User Impact

No intended change to model selection. Nested IDs, legacy saved route aliases, unavailable models, ambiguous providers, session pins versus inherited defaults, and request-owned tool selection keep their existing contracts. Repeated Doctor lint now uses the same host registry for lookup and registration. Probe behavior, check selection, config, and stored data are unchanged. The provider fast-mode allowlist remains unchanged: replacing it requires authoritative route/auth-bound capability metadata, which is a separate follow-up, not something to infer from effective session configuration.

Evidence

  • Baseline: 291 tests across eight Gateway/UI files passed. Candidate: all 294 tests passed, including the expanded available/indeterminate/all-cold alias table and ambiguous nested-ID provider case. These are refactor-retention cases, not claimed bug regressions.
  • Gateway tests cover session/default projection, cached and uncached thinking, runtime policy, ACP ownership, serialization, and row-context reuse. UI tests cover reference resolution, picker availability, agent tool-model ownership, and session overrides.
  • Independent Codex autoreview of the complete patch: no actionable findings.
  • Freshly bundled Chromium proof: three E2E tests passed across chat model switching/reasoning synchronization and chat/Agents alias display. Before/after screenshots were visually inspected and contain only fixture data. The browser uses a mocked Gateway WebSocket; this is not authenticated provider inference.
  • Original consumer full changed gate passed. Expanded host tests: 26 core registration tests, all 19 Crabbox/Codex plugin tests, and all 25 whole-file Doctor lint tests passed. One earlier whole-file run timed out in deferred SQLite inspection; the retry passed with unchanged assertions and timeout. The repeat-call test was compressed into a loop after CI caught the file-length limit; its independent review and targeted lint passed.
  • Real built CLI proof: isolated doctor --lint --json --only crabbox/cloud-worker-profiles returns exactly one actionable missing-binary finding and exit 1; the Codex managed-app-server check accepts the installed pinned artifact and exits 0. Both built plugin APIs register once per independent host across repeated calls. No operator Gateway or private profile was used.
  • The expanded local changed gate passed through core/core-test/UI typechecks, Doctor contract closure, plugin boundaries, dead exports, and earlier guards. Both extension typecheck lanes are blocked locally by the absent unchanged @daytona/sdk dependency in the shared worktree install; no dependency reconciliation was performed. Exact-head hosted CI owns complete installed-dependency coverage.
  • All CI-artifact build phases completed, including 147 SDK export checks, 48 native-loaded control-plane closures and the rebuilt Control UI performance gate. The declaration step initially exhausted Node's default 4 GiB heap; resuming it and the remaining official phases with CI's existing --max-old-space-size=8192 budget passed. Runtime source is unchanged by the subsequent test-only loop commit.
  • Doctor regression proof: before the fix, the repeated real Crabbox lint case threw health check already registered: crabbox/cloud-worker-profiles; the Codex independent-host test registered twice instead of once. An additional built Codex artifact probe reproduced the duplicate registration. The unchanged whole Doctor lint file passed locally before adding the repeat-call regression; the CI timeout is not being described as a measured performance attribution.

Provenance: Crabbox's mismatch came from #124995 (code author, PR author, and merger @steipete; August 18, 2026). Codex's matching pattern came from #124137 (code author Jason / PR author and merger @fuller-stack-dev; August 16, 2026). This PR repairs the host boundary without changing the existing version probe. Direct upstream source inspection checked codex-rs/cli/src/main.rs:98-113 at d47e5cc0e2bbd35774dff15c83570519735d2ac4, where the CLI enables Clap's version option.

ClawSweeper follow-through: the latest review at 06:25 UTC on the final head found no actionable patch defects. Its remaining rank-up requests are complete: exact-head CI passed on 995fc460b6797e0fb84d267025a586752a54cef0, and the lead personally inspected the unchanged upstream Codex version contract in codex-rs/cli/src/main.rs. The review worker lacked that sibling checkout; the maintainer verification did not. The CI guard initially hit a 120-second Git fetch timeout; its targeted unchanged retry passed. The built command owner also passes twice in the same process for each affected check: Crabbox returns exit 1 / one finding / one check on both calls; Codex returns exit 0 / zero findings / one check on both calls. Separate real CLI parser runs pass. The stored-data detector is not applicable: there is no schema, serialized field, or persistence behavior change. Independent Codex autoreviews of the consumer cleanup, complete Doctor repair, final test-loop cleanup, and documentation-only changelog removal are clean.

Focused command:

node scripts/run-vitest.mjs src/gateway/session-utils.test.ts src/gateway/session-utils.perf.test.ts src/gateway/session-utils-model.acp-owner.test.ts src/gateway/server.sessions.thinking-e2e.test.ts ui/src/lib/chat/model-ref.test.ts ui/src/lib/chat/model-select-state.test.ts ui/src/lib/agents/index.test.ts ui/src/lib/sessions/session-model-override.test.ts

Best-fix judgment: consolidate the existing owners, rather than introduce a cross-layer model registry or duplicate provider policy in the UI. Core runtime selection, plugin metadata, auth boundaries, and persisted values are unchanged. Code inspection covered the complete production owners and their chat/session/Agents callers, Gateway row construction and thinking handlers, adjacent tests, and model metadata stores. No authenticated provider inference is claimed for this behavior-neutral consumer refactor.

Before: fixture catalog aliases in the chat picker

After: the same catalog labels and routes

After: saved model switch updates supported reasoning

@steipete steipete self-assigned this Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 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 app: web-ui App: web-ui gateway Gateway runtime size: M maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 04:42
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 2:25 AM ET / 06:25 UTC.

ClawSweeper review

What this changes

The PR simplifies model picker and Gateway thinking projections, and makes bundled Crabbox and Codex Doctor registrars query the core registry they write to.

Regression provenance

Possible regression — probable (reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open. No actionable patch defect was found; the repair is not on current main, and the protected maintainer-owned PR remains assigned while exact-head checks are incomplete.

Priority: P3
Reviewed head: 995fc460b6797e0fb84d267025a586752a54cef0

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and well-covered, with useful built-behavior evidence; exact-head CI and direct Codex source confirmation remain before merge.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: Not applicable to this maintainer-authored PR; the body nevertheless records built CLI output and UI evidence for the changed paths.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable to this maintainer-authored PR; the body nevertheless records built CLI output and UI evidence for the changed paths.
Evidence reviewed 8 items Current-main registry split: Current main reads a check from the plugin-SDK registry but registers it through the supplied core host, so separately loaded artifacts can observe a different registry before the core registry rejects the duplicate.
Candidate owner-boundary repair: The PR removes the artifact-local value lookup and performs both lookup and registration through the injected host registry.
Core caller preserves the shared registry: The bundled artifact loader passes both core registry functions to Codex and configured worker-provider registrars, retaining plugin ownership without a new SDK surface.
Findings None None.
Security None None.

Live Verification

Command: pnpm openclaw doctor --help

Result: PASS (completed)

$ node scripts/run-node.mjs doctor --help
[openclaw] Building TypeScript (dist is stale: missing_build_stamp - build stamp missing).
[openclaw] Building bundled plugin assets.
[canvas] build: node scripts/bundle-a2ui.mjs
[log] ‹DIR›/a2ui.bundle.js  chunk │ size: 399.96 kB
[log] ‹DIR›/a2ui-v0.9.bundle.js  chunk │ size: 615.66 kB
[log]
[success] rolldown v1.2.0 Finished in 99.79 ms
[diffs] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts curated
[diffs-language-pack] build: node --import tsx ../../scripts/build-diffs-viewer-runtime.mts full
[discord] build: node --import tsx ../../scripts/build-discord-activity-sdk.mts
[tsdown-build] invocation 1/2 finished in 0.7s
node_modules/playwright-core/lib/coreBundle.js (65821:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65821:29 ]
       │
 65821 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/playwright-core/lib/coreBundle.js (65828:28) [EVAL] Use of direct ˋevalˋ function is strongly discouraged as it poses security risks and may cause
issues with minification.
       ╭─[ node_modules/playwright-core/lib/coreBundle.js:65828:29 ]
       │
 65828 │               const value = eval(ˋ(${expr})ˋ);
       │                             ──┬─
       │                               ╰─── Use of direct ˋevalˋ here.
       │
       │ Help: Consider using indirect eval. For more information, check the documentation: https://rolldown.rs/guide/troubleshooting#avoiding-direct-eval
───────╯

node_modules/web-tree-sitter/web-tree-sitter.js (2343:30) [EVAL] Use of direct ˋev
… output truncated …
e)
  --fix                          Apply recommended repairs (alias for --repair) (default: false)
  --force                        Apply aggressive repairs (overwrites custom service config) (default: false)
  --generate-gateway-token       Generate and configure a gateway token (default: false)
  --github-issue                 With --session-sqlite recover: prepare and optionally create an openclaw/openclaw issue (default: false)
  -h, --help                     Display help for command
  --json                         Emit JSON; bare --json runs advisory read-only health checks (default: false)
  --lint                         Run read-only health checks and report findings (default: false)
  --no-workspace-suggestions     Disable workspace memory system suggestions
  --non-interactive              Run without prompts (safe migrations only) (default: false)
  --only ‹id›                    With --lint: run only the specified check id (repeatable) (default: [])
  --post-upgrade                 Emit plugin-compat findings only (machine-readable with --json) (default: false)
  --repair                       Apply recommended repairs without prompting (default: false)
  --session-sqlite ‹mode›        Run session SQLite migration mode (dry-run|import|validate|inspect|compact|restore|recover)
  --session-sqlite-agent ‹id›    With --session-sqlite: inspect one agent
  --session-sqlite-all-agents    With --session-sqlite: inspect configured and discovered agent stores (default: false)
  --session-sqlite-store ‹path›  With --session-sqlite: inspect one session store
  --severity-min ‹level›         With --lint: drop findings below this severity (info|warning|error)
  --skip ‹id›                    With --lint: skip a specific check id (repeatable) (default: [])
  --state-sqlite ‹mode›          Run shared state SQLite maintenance mode (compact)
  --yes                          Accept defaults without prompting (default: false)

Docs: docs.openclaw.ai/cli/doctor

Assertions:

  • PASS expect_output: --lint

How this fits together

Control UI derives model controls from Gateway sessions and the model catalog, while Gateway projects thinking choices for session responses. Doctor loads plugin-owned diagnostics through the core health registry and returns findings to the CLI.

flowchart LR
  A[Gateway sessions and model catalog] --> B[Control UI model controls]
  A --> C[Gateway thinking projection]
  D[Bundled plugin registrar] --> E[Core health registry]
  E --> F[Doctor lint command]
  B --> G[Operator model selection]
  C --> G
  F --> H[Diagnostic findings]
Loading

Before merge

  • Resolve merge risk (P1) - The unchanged native Codex --version contract could not be independently source-checked because the required sibling checkout is absent; do not treat that external-contract proof as reviewed until a maintainer verifies it.
Agent review details

Security

None.

PR surface

Source -86, Tests +47. Total -39 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 9 91 177 -86
Tests 6 92 45 +47
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 183 222 -39

Review metrics

Metric Value Why it matters
Production versus test LOC production +91/-177 (net -86); tests +92/-45 (net +47) The registry boundary requires small production growth, while the overall patch removes more production code and adds focused retention coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/codex/src/doctor.ts, migration/backfill/repair: extensions/crabbox/doctor-health-api.ts, migration/backfill/repair: extensions/crabbox/src/doctor.ts, serialized state: src/gateway/session-utils-model.ts, vector/embedding metadata: src/gateway/session-utils-model.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the single host-registry path and merge only after exact-head checks are green and the Codex native-version contract is confirmed from upstream source.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the single host-registry path and merge only after exact-head checks are green and the Codex native-version contract is confirmed from upstream source.

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

Yes, source-reproducible: current main reads through an artifact-local registry and writes through the core host registry, so a repeated same-process Doctor registration can hit the duplicate-ID rejection path.

Is this the best way to solve the issue?

Yes for the owned repair: passing the core host lookup alongside registration restores one registry authority without adding a new config, persistence, or plugin SDK contract.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P3: This is a behavior-preserving projection cleanup plus a bounded Doctor repeat-registration repair.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Not applicable to this maintainer-authored PR; the body nevertheless records built CLI output and UI evidence for the changed paths.

Evidence

What I checked:

  • Current-main registry split: Current main reads a check from the plugin-SDK registry but registers it through the supplied core host, so separately loaded artifacts can observe a different registry before the core registry rejects the duplicate. (extensions/codex/src/doctor.ts:210, 3aef4d546c70)
  • Candidate owner-boundary repair: The PR removes the artifact-local value lookup and performs both lookup and registration through the injected host registry. (extensions/codex/src/doctor.ts:212, 995fc460b679)
  • Core caller preserves the shared registry: The bundled artifact loader passes both core registry functions to Codex and configured worker-provider registrars, retaining plugin ownership without a new SDK surface. (src/flows/bundled-health-checks.ts:128, 995fc460b679)
  • Behavioral regression coverage: The added Codex host test covers repeated registration per independent host; the Doctor command test invokes the actual bundled registration flow twice; loader tests verify both injected functions reach each artifact. (src/commands/doctor-lint.test.ts:451, 995fc460b679)
  • Model projection equivalence: The refactor preserves raw-versus-qualified behavior, one retained picker catalog, qualified-route precedence, and optional request-local thinking caching; tests cover aliases, availability states, nested IDs, and ambiguous providers. (ui/src/lib/chat/model-select-state.ts:190, 995fc460b679)
  • Current main has not absorbed the refactor: Current main still contains the tagged override union and separate uncached thinking branch, so this PR remains necessary rather than superseded. (ui/src/lib/chat/model-ref.ts:47, 3aef4d546c70)

Likely related people:

  • steipete: Authored the reviewed PR and the related merged Crabbox Doctor work cited by the PR context. (role: recent Doctor-boundary contributor; confidence: high; commits: 995fc460b679, b82d07f46649; files: extensions/crabbox/src/doctor.ts, src/flows/bundled-health-checks.ts)
  • fuller-stack-dev: The PR context identifies the merged Codex managed-app-server check as the adjacent feature history. (role: related Codex Doctor feature contributor; confidence: medium; commits: eb174bcaffd4; files: extensions/codex/src/doctor.ts)
  • ruel225: Available shallow-history blame attributes the current-main pre-change projection and registry lines to this commit, though deeper provenance is unavailable locally. (role: current-main source provenance; confidence: low; commits: cd321938f6de; files: ui/src/lib/chat/model-select-state.ts, src/gateway/session-utils-model.ts)

Rank-up moves

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

  • Let exact-head CI finish, then verify the unchanged native Codex --version contract from the required upstream source checkout.

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 (2 earlier review cycles)
  • reviewed 2026-08-27T04:49:34.566Z sha 66ca54e :: needs maintainer review before merge. :: none
  • reviewed 2026-08-27T05:42:29.974Z sha 9c21254 :: needs maintainer review before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

The consumer refactor remains unchanged. CI investigation exposed an existing split-registry bug in the Crabbox Doctor path and its Codex sibling; the added commit carries the host lookup alongside registration, following memory-core. Both regressions were demonstrated before repair, and the expanded plugin/host tests pass. The PR description records the original CI timeout, remaining local whole-file timing retry, independent review, provenance, and the unchanged persistence boundary. Exact-head CI and final built-CLI proof remain required before landing.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

@steipete
steipete merged commit cf8b58c into main Aug 27, 2026
360 of 432 checks passed
@steipete
steipete deleted the codex/model-consumer-cleanup branch August 27, 2026 06: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 Aug 28, 2026
…130694)

* refactor(models): simplify picker and thinking projections

* fix(doctor): keep bundled checks in the host health registry

* test(doctor): consolidate repeated lint invocation

* docs: keep Doctor release context in the PR body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui commands Command implementations extensions: codex extensions: crabbox gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

1 participant