Repository navigation
fix(#1227): resolvedModel picks the phase's main model, not the first modelUsage key - #1229
Merged
Merged
Conversation
… modelUsage key Map order is not dispatch order: a Haiku helper call is listed first on every phase since 2026-09-20, and an advisor model is its own key. selectResolvedModel prefers keys matching the dispatched model, then the largest token volume. Fixes the #975 phasePolicies.resolvedModel and the #1198 run-log/top-level model that derive from it. Entire-Checkpoint: 5fb75d344561
…e first-key comments QA follow-up: without a phase policy there is no hint, and a short phase's uncached advisor read or a helper's web-search read can out-volume the main model. Only the main loop re-reads a cached conversation (helper: 0 cache reads in 140/140 recorded rows; advisor reads are never cached), so filter to cached keys before comparing volume. Entire-Checkpoint: a71cb33f89cf
4 tasks
7 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Delivers #1227.
What
resolvedModelwasObject.keys(modelUsage)[0]. Since 2026-09-20, the first key has been a Haiku helper call on every phase, so #975'sphasePolicies.<phase>.resolvedModel, #1198's run-logmodel, and the top-level metricsmodelall record Haiku.The new
selectResolvedModel(modelUsage, requested)inphase-executor.tsworks in two steps:agentConfig.model, an alias likeopusor a full ID). If none match, it keeps all keys.Between those two steps it keeps only keys with cache reads, when any exist. Only the main loop re-reads a cached conversation. The advisor's read is never cached, and the Haiku helper had 0 cache reads in 140 of 140 recorded
phaseUsagerows, while every main-model row had some. This covers phases with no configured model (no hint), where a short phase's advisor or helper read can be the bigger number. The probe shape in the tests is an Opus main model plus a Fable advisor.phaseUsagerows are unchanged.Acceptance criteria
resolvedModelis the main model when a Haiku helper is listed first. Covered byphase-executor.test.ts > #1227 selectResolvedModel(the recorded fix(metrics): tokensUsed is 0 on every recorded run — capture-tokens.sh reads .usage (transcripts carry .message.usage) and run reads the wrong dir; wire SDK modelUsage tokens+costUSD per phase × model into metrics and stats #986 fixture, which is Haiku-first) and end to end byphase-executor.model-roles.test.ts(executePhaseWithRetrywith a Haiku-first real-shape map).resolvedModelnever selects the advisor key when the dispatched model's key is present. Covered by the unit test and by the model-roles test withphasePolicies.exec.model = "opus".modeland the top-levelmodelconsumePhaseResult.resolvedModelunchanged (batch-executor.tsandrun-orchestrator.ts:2056). The existing test "derives model from the first phase … with a resolvedModel" inrun-orchestrator.test.tscovers that plumbing. The corrected value entering it is proven by the model-roles test above.normalizeModelUsagedocblock,types.tsresolvedModel,agent-driver.tsmodelUsage).claude-sonnet-5unit fixture inphase-executor.test.ts, the file the AC names.The old #975 fixture used snake_case field names with the main model listed first. That shape passed with the bug in place, so I replaced it with the SDK's real camelCase fields and a Haiku-first order.
Verification
npm run build && npm test: 351 files, 8636 passed, 1 expected fail, 3 skipped.return keys[0]instead of the volume reduce;1227 picks the main model, not the Haiku helper listed first (recorded map)failed; restored.candidates = pool);1227 without a hint, prefers the cached main model over a larger uncached advisor or helper readfailed; restored.candidates = keys);1227 never selects the advisor key when the dispatched model's key is presentfailed; restored.Side finding (not fixed here)
phase-executor.model-roles.test.tsdrives the real exec path againstprocess.cwd(). Running it on a dirty tree auto-commits your work aschore(#975): wip checkpoint …, which happened while I wrote this fix. CI is unaffected because the tree is clean there.Relates to #975, #1198, #1138.
🤖 Generated with Claude Code