Repository navigation
Conversation
prepareModelPolicy re-parsed the already-resolved defaultModel as provider/model text, which split model ids containing slashes (for example "zai-org/GLM-5.2-TEE") into a bogus provider/model pair. The mis-resolved configuredDefault then failed to match the current selection in resolveInitialModelSelection, so fresh sessions on independently-configured agents were replaced with the allowlist's first model. Build defaultRef with normalizeModelRef on the resolved provider/model pair instead, and add regression coverage for exact allowlists that omit a slash-containing primary. Fixes openclaw#149796
|
🦞👀 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: needs maintainer review before merge. Reviewed October 6, 2026, 10:10 PM ET / October 7, 2026, 02:10 UTC (Revision 12). ClawSweeper reviewWhat this changesAdds two reply-pipeline tests ensuring fresh sessions retain slash-containing primary model IDs when a legacy exact allowlist omits them. Merge readiness✅ Ready for maintainer review Keep open: current main fixes the production behavior, but this PR retains useful, discriminating regression coverage. The latest change resolves the prior mock-export finding; no blocking patch defect remains. Priority: P2 Review scores
Verification
How this fits togetherReply model selection combines agent configuration, model policy, and stored session choices to select the provider and model used for a turn. These tests protect fresh-session selection before provider execution. flowchart TD
A[Agent primary model] --> D[Reply model selection]
B[Exact model allowlist] --> D
C[Prepared model catalog] --> D
D --> E{Configured primary retained}
E --> F[Selected provider and model]
F --> G[Provider execution]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceTests +90. Total +90 across 1 file. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Retain focused coverage at the reply-selection boundary so later identity or policy refactors cannot silently replace an agent's configured primary. Do we have a high-confidence way to reproduce the issue? No current-main failure is established: source and supplied Gateway observations preserve the configured primaries. Historical-hunk reversal provides a concrete failing control for the proposed regression cases. Is this the best way to solve the issue? Yes: testing the existing reply-selection entry point protects the reported configuration without restoring redundant production code or adding a test-only API. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 07e9a2519420. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (11 earlier review cycles; latest 8 shown)
|
`src/auto-reply/reply/model-selection.test.ts` is grandfathered by the line-cap ratchet (2527 counted lines against a 1000 cap), so CI rejected the added cases as growth: src/auto-reply/reply/model-selection.test.ts: 2527 -> 2579 counted lines (cap 1000) The same two cases now live in `model-selection.exact-allowlist.test.ts`, which drives `createModelSelectionState()` with the allowlist and the resolved pair and supplies its own prepared catalog instead of mocking the catalog runtime. The grandfathered file is unchanged from the base, so no coverage was trimmed.
…ssion-primary-model
…ssion-primary-model
…ssion-primary-model
…ssion-primary-model
…ssion-primary-model # Conflicts: # src/agents/model-selection-shared.ts
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Verified on A built Gateway using the reported one-entry exact allowlist (
All three completed with
Additional verification: Contributor credit remains intact. No production fix or changelog change is needed in this test-only PR. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Updated head: The first CI run identified a new mock-export guard violation in this test's auth-runtime mock. The mock now spreads This follow-up changes only the test mock. Production code, build inputs, Gateway configuration, and provider execution are unchanged, so the three-agent built-Gateway proof and single gpt-5-mini live call remain applicable. No additional paid call was made. |
|
Landed in f06e9b1. Thanks @xydigitLybnnnn! Current main already starts each agent on its own slash-containing primary under an exact allowlist (checked on a built Gateway with your reported config); this test fails if that identity-preservation fix is reverted, so it now guards #149796. |
…enclaw#150423) Guard that agents with slash-containing model.primary values keep their own primary for fresh sessions when agents.defaults.models is an exact allowlist, instead of starting on the allowlist's first model. Main already fixes the behavior; this pins it. Fixes openclaw#149796. Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Issue #149796 — in a gateway with several independently configured agents, every fresh session initialized on the allowlist's first model instead of the agent's own
model.primary, andsession.startedalready recorded the wrong model, with nomodelOverride/modelOverrideSourceand no fallback provenance (no preceding 429/error, no[model-fallback/decision]entry).Reported shape:
agents.defaults.modelsused as an exact allowlist containing onlychutes/deepseek-ai/DeepSeek-V3.2-TEE, while each agent has a slash-containing primary:Every agent resolved to
chutes/deepseek-ai/DeepSeek-V3.2-TEE, including agents whose primary is not in their fallback chain. Model ids with a slash are normal for Chutes/OpenRouter-style providers, so the bug hit all of them at once.Root cause
prepareModelPolicy()insrc/agents/model-selection-shared.tsbuiltdefaultRefby re-parsingparams.defaultModelas provider/model text:defaultModelis already the model id of the resolved provider/model pair —createModelSelectionState()receivesdefaultProviderplus the model id, andbuildAllowedModelSet()callers pass the same split (for examplesrc/commands/doctor/shared/retired-model-ref-repair.tspassescurrentModel.defaultRef.provider/currentModel.defaultRef.model).parseModelRef()splits at the first slash, sozai-org/GLM-5.2-TEEbecame providerzai-org+ modelGLM-5.2-TEE.resolveInitialModelSelection()keeps the current selection only whenallows(current)is true orcurrentequalsconfiguredDefault(the prepareddefaultRef). The mis-resolved ref never matched, so selection fell through to the first allowed catalog entry.Status of this PR: test-only, guarding an upstream fix that has no coverage
This PR started as a one-expression fix plus its regression test. While it was open,
upstream/mainlanded #150509 (90567a8bfd4, refactor(models): preserve selected identities and centralize thinking policy), which rewrites this same selection path and, as a side effect, fixes the defect from #149796.Merging
upstream/mainconflicted exactly on thedefaultRefexpression inprepareModelPolicy(). The conflict was resolved in favour of the upstream implementation, and the redundant source patch from this branch was dropped: after the merge the net diff againstupstream/mainis one new test file, and no production code.The upstream fix is not confined to that one expression. Reinstating the pre-#150509
parseModelRefWithCompatAlias({ ...params, raw: params.defaultModel })construction on top of today's tree still keeps the configured primary (run in Evidence §3), so the behaviour cannot — and does not need to — be pinned back to a single line here.What upstream still lacks is coverage for the reported shape. #150509 rewrote
src/agents/model-selection-shared.tsand the surrounding selection code without a case for a slash-containing primary that is omitted from an exact allowlist:So this PR is submitted as a test-only PR whose value is that missing regression coverage:
The change
src/auto-reply/reply/model-selection.exact-allowlist.test.ts(new) — drives the real reply-pipeline entrycreateModelSelectionState()with the reporter's config shape (exact allowlist + slash-containingmodel.primary) and asserts the fresh session keeps the configured primary, forzai-org/GLM-5.2-TEEandgoogle/gemma-4-31B-turbo-TEE.It is a sibling suite rather than an addition to
model-selection.test.tsbecause that file is grandfathered bycheck:line-cap-ratchet(2527 counted lines against a 1000 cap) and CI rejects growth of a grandfathered file. The extracted suite supplies its own prepared catalog through thepreparedModelCatalogparameter instead of mocking the catalog runtime, and no coverage was trimmed.Evidence
1. The bug is real — recorded reproduction on the pre-#150509 selection code
Recorded while this branch still carried its own fix, by pinning
src/agents/model-selection-shared.tsto base080edbedaa6(a revision that predates #150509) and running the real reply-pipeline entry. The harness passes only the model catalog throughcreateModelSelectionState()'s ownpreparedModelCatalogparameter; everything else is the reporter's config.And the same pinned revision against the suite added by this PR — the two cases fail, which is exactly the behaviour the coverage is meant to lock down:
Transcripts:
logs/real_behavior/issue-149796-evidence/harness/before-fix.txt,regression-before.txt; harness:.../harness/model-selection-before-after.mts.2. Same suite on this PR's merge head (
90ca1650df7)3. Upstream's fix is broader than the conflicted expression
Today's tree, with the pre-#150509
defaultRefconstruction reinstated insideprepareModelPolicy():Both still pass, which is why this PR keeps the upstream implementation and drops its own source change.
4. Checks on this merge head
Linked context
Fixes #149796. The behaviour is already fixed on
mainby #150509; this PR keeps the regression coverage that #150509 did not add.Tests and validation
src/auto-reply/reply/model-selection.exact-allowlist.test.ts— 2 passed on the merge head, 2 failed against the pre-refactor(models): preserve selected identities and centralize thinking policy #150509 sourcepnpm tsgo:core— cleanpnpm check:line-cap-ratchet --base upstream/main—Line-cap ratchet OK: 1 changed source files; no new violations or over-cap growth.pnpm check:max-lines-ratchet --base upstream/main—max-lines ratchet OK: 822 grandfathered suppressions.pnpm install --frozen-lockfile— cleansrc/flows/channel-setup.status.test.tsandsrc/proxy-capture/proxy-server.test.tsreproduce identically on cleanmainin this environment and are outside thesrc/agents/src/auto-replyselection path.Risk checklist
upstream/main: no production code, no config, no migration, no new optionsmodel-selection.test.tsto stay clear of the line-cap ratchet🤖 AI-assisted: This PR was developed with AI assistance.
Current-main Gateway verification
Built Gateway per-agent session.started proof, discriminating historical-hunk reversal, and gpt-5-mini live gate on
d6d2fe792786d3df8a47533e7d538fc9639a0f15. No overlap with Pash/Sarah changes.