fix(code-review): pin a same-vendor small model for BYOK reviews - #6033
Open
maphew wants to merge 1 commit into
Open
fix(code-review): pin a same-vendor small model for BYOK reviews#6033maphew wants to merge 1 commit into
maphew wants to merge 1 commit into
Conversation
Code Review sessions let the Kilo CLI choose title and auxiliary models. The CLI fell through to `kilo-auto/small`, which resolves to Gemma on Kilo credits. This happened even when the user set a BYOK review model. See issue Kilo-Org#4268. Resolve a cheap model from the same vendor as the effective review model. Use the OpenRouter catalog prices for managed vendors. Use the BYOK primary model for direct-BYOK vendors when the catalog has no cheaper sibling. Leave `small_model` unset when no cheaper managed sibling exists. Thread the value from apps/web dispatch to the sandbox session config. Persist it in the v2 session metadata. Include it in the create-intent fingerprint. Add `small_model` and `agent.title.model` to the sandbox KILO_CONFIG for code-review sessions only. Do not inject `agent.title` for Bitbucket sessions. Tests cover the resolver, payload plumbing, session materialization, the metadata round trip, and the Durable Object registration boundary.
maphew
marked this pull request as ready for review
September 10, 2026 01:43
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (19 files)
Reviewed by grok-4.6 · Input: 123K · Output: 14K · Cached: 573.2K Review guidance: REVIEW.md from base branch |
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.
Refs #4268.
Problem
A user set a BYOK model for Code Reviewer. The review itself used that model.
But Kilo credits still went down. The Kilo CLI used a separate small model for
title and auxiliary calls. The CLI fell through to
kilo-auto/small. Thatresolves to
google/gemma-4-26b-a4b-it. The Gemma call goes through Kilo, notthe user provider.
Change
The web dispatcher now picks a cheaper model from the same vendor as the
effective review model. It uses the OpenRouter catalog and prompt prices.
the catalog has no cheaper BYOK sibling. This keeps the call on the user key.
small_modelunset. The CLIkeeps its current default in that case.
The value travels as
smallModelfromapps/webto the sandbox sessionconfig. It is stored in the v2 session metadata. It is part of the create
intent fingerprint. The sandbox
KILO_CONFIG_CONTENTgetssmall_modelandagent.title.model. This applies to code-review sessions only. Bitbucketsessions do not get
agent.title.Relation to other work
inactivity. This PR takes over that design.
areThreadsBlocking()to use a BYOK model. Thatpath uses Cloudflare Workers AI, not the Kilo gateway. It does not draw Kilo
credits. This PR does not change gastown. The hardcoded Gemma id in gastown
stays as a separate, smaller follow-up.
Adversarial review
An independent review agent examined the diff against main. It found one
critical defect in the first revision. The Durable Object rebuilt
metadata.agentfrom a fixed field list. It droppedsmallModel, so the fixwas inert. The fix now writes
smallModelinregisterSessionand in theadmitted-plan agent. A new Durable Object integration test asserts the
persisted value. A second review pass confirmed that all findings are closed.
Verification
Passed:
pnpm run typecheckinapps/web,services/cloud-agent-next,services/code-review-infra, andpackages/worker-utils.oxlintandoxfmt --list-differenton all changed files.vitest runinservices/cloud-agent-nextforsession-service.test.ts,session/session-prepare.test.ts,persistence/session-metadata.test.ts,and
router/handlers/session-worktree.test.ts: 453 tests pass.vitest run --config vitest.workers.config.tsfortest/integration/session/code-review-small-model.test.tsandtest/integration/session/start-execution-v2.test.ts: 41 tests pass.Not run locally:
apps/webjest tests (model-selection.test.ts,prepare-review-payload.test.ts). The jest global setup needs a livePostgreSQL test database. The sandbox has no Docker and no database. CI
covers these tests.