Repository navigation
refactor(models): preserve selected identities and centralize thinking policy - #150509
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 16, 2026, 11:09 PM ET / September 17, 2026, 03:09 UTC (Revision 2). ClawSweeper reviewWhat this changesPreserves selected model identities across commands, replies, and session listings while consolidating thinking settings and provider catalog preparation. Merge readiness⛔ Blocked before merge - 1 item remains Keep open with no blocking findings. Current main still contains the repeated normalization this PR addresses. The updated compatibility explanation and inspected readers resolve the previous migration concern. Priority: P2 Review scores
Verification
How this fits togetherModel selection combines configured defaults, saved session choices, and provider catalogs before dispatching agent turns. Its results also supply model pickers and session displays. flowchart TD
A[Configured defaults] --> D[Model selection]
B[Saved session choices] --> D
C[Provider catalogs] --> D
D --> E[Selected model identity]
E --> F[Provider thinking policy]
F --> G[Agent execution]
E --> H[Pickers and session displays]
Before merge
Agent review detailsSecurityNone. PR surfaceSource -272, Tests +491, Docs +18. Total +237 across 79 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep parsing at selection boundaries, preserve prepared identities downstream, and derive thinking behavior from the selected provider and runtime. Do we have a high-confidence way to reproduce the issue? Yes, from source: current-main command selection normalizes already selected references again, and the regression fixtures expose chained-alias and literal-ID collisions. No runtime reproduction was executed here. Is this the best way to solve the issue? Yes. Reusing existing readers and provider policy removes competing normalization paths while retaining legacy parsing and persisted formats. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9ca2d1dfcd16. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
e195e6f to
2a86fee
Compare
|
Merged via squash.
|
…g policy (openclaw#150509) * refactor(models): centralize selection and thinking policy * test(models): reuse command normalization helpers
…150128) Model resolution, both spawn paths, catalog publication, aliases, and Doctor change together so unsupported selections cannot bypass the shared decision. Most added lines are regression tests. ## What Problem This Solves A saved `Grok → xai/auto` alias could create a child that the native API rejected. A custom provider name could also make retired native `auto` appear usable in the picker. Provider recognition and an endpoint URL were being treated as model support. Refs #115617, #142136. ## Why This Change Was Made Spawn and prepared aliases use the existing model resolver. Catalog publication and Doctor consume the same compiled retirement rules for the selected route. The catalog uses main's shared projection owner from #150509. Prepared aliases have one writer; Doctor keeps its existing config and session writers. ## User Impact Unsupported explicit choices fail before child creation with recovery guidance. Automatic choices retain their primary and fallback order. Picker views omit known retired routes; the admin inventory retains saved definitions. Custom endpoints and logical provider/account choices remain intact. ## Compatibility Native IDs need a definition, catalog support, or provider-owned resolution. This deliberately replaces #125931's endpoint-only inference: previously accepted unlisted native IDs need explicit definitions when their provider cannot resolve them. Custom/local endpoints, authored private models, and models supplied by native runtimes remain supported. Doctor repairs known retirements, preserves account pins and allowlists, and retains unresolved choices with guidance. It does not invent definitions for unverified IDs. No new configuration keys, schema, or protocol changes. ## Evidence - The real Gateway regression fails with the browse filter removed and passes with it restored: retired native `personal/auto` disappears, while custom endpoint and admin inventory controls remain intact. Command: `node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server.models-native-retirement.test.ts`. - Final package `08e2f6002888` passed upgrades driven by published 2026.9.3 and 2026.9.4, followed by candidate startup and existing/new/custom conversations. Both preserved the seven original transcript events. All 26 Doctor commands passed, including repeated repair, logical native aliases, custom models, account pins, and allowlists. - Both upgraded fixtures passed all 10 Telegram Test Server controls: retired/unknown rejection, native/custom/friendly-alias completion, and correct picker buttons. The previously missing 2026.9.3 custom-model reply is now observed. - Four final-build Gateway cases passed: native account/history continuity, saved-token selection, a new reply across a 60-second process freeze, and recovery after a settled failure. Each matched exactly one intended test and left no child processes. - Source coverage includes 172 model/Doctor/Gateway tests, 220 affected fixture tests, and focused delivery, hook, lifecycle, and compaction checks; these counts overlap. Production/test types, lint, formatting, size limits, assertion limits, exports, architecture, and test registration checks passed. Limits: updater tests use `--no-restart` followed by separate candidate startup. The first 2026.9.3 update hit its shipped 30-second package-scan limit; the retained installation was verified intact, and one normal retry after a measured 11-second scan succeeded. Telegram uses the real Test Server with local model fixtures. An extra final-package fallback run completed through the Gateway and Telegram accepted its sends, but the recorder timed out before capturing user-side receipt; that run is not counted as passed. Earlier `b12d66a91bc1` fallback runs retain their original identity and successful observations. ## Consumers Visible/background spawn, prompt aliases, model materialization, picker publication, and Doctor use the shared support facts. No public SDK contract changes. ## Invalidation Existing config, catalog, account, and plugin owners control freshness. Alias hints belong to the prepared turn snapshot. Admission rechecks freshness after asynchronous resolution. ## Tests Coverage includes native/custom/private models, selected routes, namespace identity, pins, fallback order, stale generations, and repeated Doctor repair. A separate follow-up answer defect from #149223 remains behind #126263's task-ownership prerequisite; its assertion remains active and this PR does not claim to fix it. ## Screenshots Packaged comparison at `b12d66a91bc1`: native Personal Auto is removed, while custom Private Auto remains. | Before | After | | --- | --- | |  |  | Final-package model-list responses match both pictured comparisons. The native metadata remains readable: model name, 1M context, and Medium thinking. | Before | After | | --- | --- | |  |  | <details> <summary>Production changes: +705 lines</summary> The added code implements shared admission, native alias support, and Doctor repair. It adds no state manager or configuration surface. | File | Net | Responsibility | | --- | ---: | --- | | `cli-runner/helpers.ts` | +4 | Pass prepared aliases | | `cli-runner/prepare.ts` | 0 | Use async prompt preparation | | `cli-runner/prompt-context.ts` | +33 | Capture the existing prepared owner | | `model.configured-fallback.ts` | +10 | Apply shared support rules | | `model.configured-overrides.ts` | +60 | Validate selected transport support | | `model.provider-hooks.ts` | -55 | Defer hook binding through the existing resolver | | `model.provider-hooks.types.ts` | +31 | Keep existing hook types separate | | `model.provider-transport.ts` | +35 | Relocate existing transport resolution | | `model.registry-resolution.ts` | -40 | Remove competing resolution paths | | `model.static-catalog-row.ts` | +36 | Relocate existing row conversion | | `model.static-catalog.ts` | +64 | Reuse canonical native metadata | | `model.static-catalog.types.ts` | +2 | Keep donor facts in the existing cache | | `model.ts` | +13 | Share resolution and recovery errors | | `prepared-compaction-runtime.ts` | +1 | Pass prepared aliases | | `attempt-system-prompt-prepare.ts` | +1 | Pass prepared aliases | | `model-catalog-visibility.ts` | +20 | Filter retirement after route projection | | `model-runtime-choice.ts` | +224 | Share admission across spawn paths | | `openclaw-tools.ts` | 0 | Use current session configuration | | `prepared-model-runtime.configured-completion.ts` | +88 | Prepare aliases without inventing catalog rows | | `prepared-model-runtime.full-catalog.ts` | +9 | Publish captured alias facts | | `prepared-model-runtime.types.ts` | +2 | Represent derived alias facts | | `materialize-model.ts` | +4 | Share final route validation | | `subagent-spawn-child-plan.ts` | -96 | Remove separate admission checks | | `subagent-spawn-deps.ts` | -3 | Remove obsolete dependency surface | | `subagent-spawn-plan.ts` | +42 | Consume shared admission | | `subagent-spawn.runtime.ts` | -1 | Remove obsolete argument | | `system-prompt-config.ts` | -2 | Render supplied facts only | | `sessions-spawn-visible.ts` | 0 | Use common async admission | | `commands-models.ts` | -4 | Use captured retirement metadata | | `commands-system-prompt.ts` | +8 | Capture prompt facts before rendering | | `model-runtime-normalization.ts` | +9 | Relocate existing normalization | | `codex-route-session-repair.ts` | 0 | Use the session repair module | | `retired-model-ref-repair.ts` | +8 | Use selected-route retirement policy | | `retired-session-model-repair.ts` | +59 | Relocate existing session repair | | `models-list-result.ts` | +1 | Pass captured metadata | | `manifest-model-suppression.ts` | +136 | Compile native retirement policy once | | `manifest-model-suppression.types.ts` | +6 | Carry effective route facts | </details> Co-authored-by: Ayaan Zaidi <[email protected]>
…penclaw#150128) Model resolution, both spawn paths, catalog publication, aliases, and Doctor change together so unsupported selections cannot bypass the shared decision. Most added lines are regression tests. ## What Problem This Solves A saved `Grok → xai/auto` alias could create a child that the native API rejected. A custom provider name could also make retired native `auto` appear usable in the picker. Provider recognition and an endpoint URL were being treated as model support. Refs openclaw#115617, openclaw#142136. ## Why This Change Was Made Spawn and prepared aliases use the existing model resolver. Catalog publication and Doctor consume the same compiled retirement rules for the selected route. The catalog uses main's shared projection owner from openclaw#150509. Prepared aliases have one writer; Doctor keeps its existing config and session writers. ## User Impact Unsupported explicit choices fail before child creation with recovery guidance. Automatic choices retain their primary and fallback order. Picker views omit known retired routes; the admin inventory retains saved definitions. Custom endpoints and logical provider/account choices remain intact. ## Compatibility Native IDs need a definition, catalog support, or provider-owned resolution. This deliberately replaces openclaw#125931's endpoint-only inference: previously accepted unlisted native IDs need explicit definitions when their provider cannot resolve them. Custom/local endpoints, authored private models, and models supplied by native runtimes remain supported. Doctor repairs known retirements, preserves account pins and allowlists, and retains unresolved choices with guidance. It does not invent definitions for unverified IDs. No new configuration keys, schema, or protocol changes. ## Evidence - The real Gateway regression fails with the browse filter removed and passes with it restored: retired native `personal/auto` disappears, while custom endpoint and admin inventory controls remain intact. Command: `node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway.config.ts src/gateway/server.models-native-retirement.test.ts`. - Final package `08e2f6002888` passed upgrades driven by published 2026.9.3 and 2026.9.4, followed by candidate startup and existing/new/custom conversations. Both preserved the seven original transcript events. All 26 Doctor commands passed, including repeated repair, logical native aliases, custom models, account pins, and allowlists. - Both upgraded fixtures passed all 10 Telegram Test Server controls: retired/unknown rejection, native/custom/friendly-alias completion, and correct picker buttons. The previously missing 2026.9.3 custom-model reply is now observed. - Four final-build Gateway cases passed: native account/history continuity, saved-token selection, a new reply across a 60-second process freeze, and recovery after a settled failure. Each matched exactly one intended test and left no child processes. - Source coverage includes 172 model/Doctor/Gateway tests, 220 affected fixture tests, and focused delivery, hook, lifecycle, and compaction checks; these counts overlap. Production/test types, lint, formatting, size limits, assertion limits, exports, architecture, and test registration checks passed. Limits: updater tests use `--no-restart` followed by separate candidate startup. The first 2026.9.3 update hit its shipped 30-second package-scan limit; the retained installation was verified intact, and one normal retry after a measured 11-second scan succeeded. Telegram uses the real Test Server with local model fixtures. An extra final-package fallback run completed through the Gateway and Telegram accepted its sends, but the recorder timed out before capturing user-side receipt; that run is not counted as passed. Earlier `b12d66a91bc1` fallback runs retain their original identity and successful observations. ## Consumers Visible/background spawn, prompt aliases, model materialization, picker publication, and Doctor use the shared support facts. No public SDK contract changes. ## Invalidation Existing config, catalog, account, and plugin owners control freshness. Alias hints belong to the prepared turn snapshot. Admission rechecks freshness after asynchronous resolution. ## Tests Coverage includes native/custom/private models, selected routes, namespace identity, pins, fallback order, stale generations, and repeated Doctor repair. A separate follow-up answer defect from openclaw#149223 remains behind openclaw#126263's task-ownership prerequisite; its assertion remains active and this PR does not claim to fix it. ## Screenshots Packaged comparison at `b12d66a91bc1`: native Personal Auto is removed, while custom Private Auto remains. | Before | After | | --- | --- | |  |  | Final-package model-list responses match both pictured comparisons. The native metadata remains readable: model name, 1M context, and Medium thinking. | Before | After | | --- | --- | |  |  | <details> <summary>Production changes: +705 lines</summary> The added code implements shared admission, native alias support, and Doctor repair. It adds no state manager or configuration surface. | File | Net | Responsibility | | --- | ---: | --- | | `cli-runner/helpers.ts` | +4 | Pass prepared aliases | | `cli-runner/prepare.ts` | 0 | Use async prompt preparation | | `cli-runner/prompt-context.ts` | +33 | Capture the existing prepared owner | | `model.configured-fallback.ts` | +10 | Apply shared support rules | | `model.configured-overrides.ts` | +60 | Validate selected transport support | | `model.provider-hooks.ts` | -55 | Defer hook binding through the existing resolver | | `model.provider-hooks.types.ts` | +31 | Keep existing hook types separate | | `model.provider-transport.ts` | +35 | Relocate existing transport resolution | | `model.registry-resolution.ts` | -40 | Remove competing resolution paths | | `model.static-catalog-row.ts` | +36 | Relocate existing row conversion | | `model.static-catalog.ts` | +64 | Reuse canonical native metadata | | `model.static-catalog.types.ts` | +2 | Keep donor facts in the existing cache | | `model.ts` | +13 | Share resolution and recovery errors | | `prepared-compaction-runtime.ts` | +1 | Pass prepared aliases | | `attempt-system-prompt-prepare.ts` | +1 | Pass prepared aliases | | `model-catalog-visibility.ts` | +20 | Filter retirement after route projection | | `model-runtime-choice.ts` | +224 | Share admission across spawn paths | | `openclaw-tools.ts` | 0 | Use current session configuration | | `prepared-model-runtime.configured-completion.ts` | +88 | Prepare aliases without inventing catalog rows | | `prepared-model-runtime.full-catalog.ts` | +9 | Publish captured alias facts | | `prepared-model-runtime.types.ts` | +2 | Represent derived alias facts | | `materialize-model.ts` | +4 | Share final route validation | | `subagent-spawn-child-plan.ts` | -96 | Remove separate admission checks | | `subagent-spawn-deps.ts` | -3 | Remove obsolete dependency surface | | `subagent-spawn-plan.ts` | +42 | Consume shared admission | | `subagent-spawn.runtime.ts` | -1 | Remove obsolete argument | | `system-prompt-config.ts` | -2 | Render supplied facts only | | `sessions-spawn-visible.ts` | 0 | Use common async admission | | `commands-models.ts` | -4 | Use captured retirement metadata | | `commands-system-prompt.ts` | +8 | Capture prompt facts before rendering | | `model-runtime-normalization.ts` | +9 | Relocate existing normalization | | `codex-route-session-repair.ts` | 0 | Use the session repair module | | `retired-model-ref-repair.ts` | +8 | Use selected-route retirement policy | | `retired-session-model-repair.ts` | +59 | Relocate existing session repair | | `models-list-result.ts` | +1 | Pass captured metadata | | `manifest-model-suppression.ts` | +136 | Compile native retirement policy once | | `manifest-model-suppression.types.ts` | +6 | Carry effective route facts | </details> Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes selected models being renamed, reset, or assigned another model's thinking settings when aliases and saved choices pass through multiple selection paths.
User Impact
Pinned and configured models retain their literal identity across commands, replies, heartbeats, session lists, and pickers. Thinking defaults, supported controls, and execution levels follow the selected model's provider and runtime. No new configuration, schema, dependency, or migration is required.
Why This Change Was Made
Model resolution now happens once at its owner, and callers carry the prepared provider/model tuple forward. Bare defaults still use prepared runtime hooks without triggering manifest discovery. Thinking selection produces requested intent, support, and the execution level from one profile; Anthropic and Vertex use their existing provider-owned policy.
Catalog projections share their row cache while login readiness is checked on publication. OpenCode metadata refresh and account discovery share one lifecycle owner, preserving Zen's current-snapshot resolution, Go's seed-only resolution, and per-call credentials. Private transport wrappers and duplicate Responses policy preparation are removed; shipped transport adapters remain supported.
Production code is 256 lines smaller overall. Tests cover the removed paths and the failures discovered during the cutover, including namespace collisions, chained aliases, captured metadata, exact allowlists, locked selections, stale heartbeat origins, native runtime ownership, and empty/null thinking controls.
Upgrade Compatibility
Persisted session/config formats are unchanged. The three Doctor edits pass an already resolved default provider/model tuple into existing policy checks; retirement decisions and writes retain their existing owners. Session fields, serializers, schema, override writers, and shared legacy readers are unchanged. Existing rows still recover missing provenance or parse raw model references once. Reply coverage includes missing source/origin fields, fallback notices, user/auth pin preservation, and heartbeat fallback recovery; new cases distinguish literal IDs that previously collided during repeated normalization.
The focused compatibility run passed all 230 tests across stored model overrides, model-override provenance, retired-model repairs and ordering, and both Doctor health-check suites. No migration is needed because this change neither adds nor rewrites persisted data.
Evidence
openrouter/autoidentity.openclaw/ci-gatepassed on head2a86feeba88a3760e2b6b603adc5c48d71fe6167.kimi/k3,opencode/kimi-k3,opencode-go/gpt-5.6-luna, andanthropic/claude-opus-4-6, including file-read tool calls.