Skip to content

fix(code-review): use configured model for title/aux calls (BYOK) - #4725

Open
baanish wants to merge 4 commits into
Kilo-Org:mainfrom
baanish:main
Open

fix(code-review): use configured model for title/aux calls (BYOK)#4725
baanish wants to merge 4 commits into
Kilo-Org:mainfrom
baanish:main

Conversation

@baanish

@baanish baanish commented Jul 23, 2026

Copy link
Copy Markdown

Summary

  • Code Review sessions only set KILO_CONFIG.model, so kilo's title/aux calls fell through to the CLI default (kilo-auto/smallgoogle/gemma-4-26b-a4b-it) and billed Kilo credits even when the primary review model was BYOK.
  • For createdOnPlatform === 'code-review', pin small_model and the title agent to the same configured review model.
  • Non-code-review sessions are unchanged.

Fixes #4268

Note on root cause

Issue #4268 attributed Gemma usage under Code Reviews to gastown's Workers AI areThreadsBlocking() call. That path does use hardcoded Gemma, but it does not go through the AI gateway and would not appear as gateway Code Reviews usage (especially not with Vercel-style versioned model ids / multi-million-token volume). The Usage dashboard symptom matches kilo's title/aux model defaulting to kilo-auto/small during Code Reviewer sessions.

Test plan

  • Unit test: code-review sessions get small_model + agent.title.model equal to the configured review model
  • Unit test: cloud-agent-web sessions still omit small_model
  • Manual: configure a BYOK Code Reviewer model, run a review, confirm Usage no longer shows Gemma alongside the configured model for new reviews
Open in Web Open in Cursor 

Summary by CodeRabbit

  • Bug Fixes
    • Improved model configuration consistency for code-review sessions by applying the selected model across primary, lightweight, and title-agent settings.
    • Existing title-agent descriptions are preserved while their model configuration is correctly updated.
    • Cloud-agent web sessions continue to use the selected model without adding unnecessary lightweight or title-agent settings.

cursoragent and others added 3 commits July 23, 2026 17:33
Code Review sessions only set KILO_CONFIG.model, so kilo's title/aux
calls fell through to kilo-auto/small → Gemma and billed Kilo credits
even when the primary review model was BYOK. Pin small_model and the
title agent to the configured review model for code-review sessions.

Fixes Kilo-Org#4268
Always set the title agent model to the configured review model for
code-review sessions, even when a runtime agent named title was already
merged. Preserve other title-agent options.
…l-9bef

fix(code-review): use configured model for title/aux calls (BYOK)
@kilo-code-bot

kilo-code-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Reviewed the code-review-session model-pinning fix in session-service.ts and its accompanying unit tests; the BYOK model normalization and title-agent override logic are correct and scoped to createdOnPlatform === 'code-review' with no regressions found in changed lines.

Files Reviewed (2 files)
  • services/cloud-agent-next/src/session-service.ts
  • services/cloud-agent-next/src/session-service.test.ts

Reviewed by claude-sonnet-5 · Input: 16 · Output: 3.3K · Cached: 310.5K

Review guidance: REVIEW.md from base branch main

@St0rmz1

St0rmz1 commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Thanks for digging into this — the revised diagnosis in your PR body is correct, and it's worth recording the confirmation here since it contradicts the original theory in #4268.

The chain checks out end to end:

  • kiloSmallModelPriority() in the kilo CLI (packages/opencode/src/kilocode/provider/provider.ts:242-245) returns ["kilo-auto/small"] for any provider whose ID starts with kilo, replacing upstream's per-vendor priority list (claude-haiku-4-5 → gemini-3-flash → gpt-5-nano).
  • Provider.getSmallModel() returns from cfg.small_model before it ever reaches that list (packages/opencode/src/provider/provider.ts:1908), so the list only applies when small_model is unset — which is every cloud-agent-next session today.
  • The gateway resolves kilo-auto/small to google/gemma-4-26b-a4b-it, and to the :free variant at zero balance (apps/web/src/lib/ai-gateway/auto-model/resolution.ts:254).

So Gemma under Code Reviews is the small-model fallback, not gastown's Workers AI call. The mechanism you used is also correct: small_model is a real config key, kilo/<vendor>/<model> parses the same way the primary model field already does, and agent.title.model is honored via the config merge in agent/agent.ts. It matches the existing precedent in services/gastown/container/src/agent-runner.ts.

The one change we'd like before merging

The gate is createdOnPlatform === 'code-review', but the value pinned is the primary review model. Since the default review model is anthropic/claude-sonnet-4.6, this moves aux calls from Gemma ($0.05/M in) to Sonnet 4.6 ($3/M in) for every user who hasn't customized their model — roughly a 60x unit-price change on that traffic, to fix a BYOK-only complaint. It also multiplies: titles are generated once per session including per subtask session, so a sharded or council review produces one per sub-agent.

The intent behind small_model is a cheap model for mundane work, and upstream's priority list was already doing that per vendor before the kilo override short-circuited it. So rather than reusing the primary, we'd like the small model derived as "a cheap model from the same vendor as the effective review model", falling back to leaving small_model unset when there isn't one. That keeps BYOK users on their own provider and costs the default-model majority nothing.

Our preference for where that lives, which keeps most of your diff intact:

  1. Compute it in apps/web at dispatch time, next to resolveEffectiveModel in apps/web/src/lib/code-reviews/core/model-selection.ts. That's the only place with both the effective review model and the gateway catalog (which carries prompt_price per model), so selection can be a lookup rather than a hardcoded vendor map.
  2. Add smallModel?: string to CloudAgentPrepareSessionInput in packages/worker-utils/src/cloud-agent-next-client.ts. There's precedent — runtimeAgents already carries per-specialist models computed in apps/web and materialized downstream.
  3. Your session-service.ts block stays as written, reading that field instead of reusing normalizedModel.

If you'd rather keep this contained to session-service.ts with a small static vendor map, that's acceptable too — the requirement is only that we stop pinning the primary model. Say which way you want to go and we'll confirm before you build it.

Smaller items

  • Please change Fixes #4268 to Refs #4268. The issue also asks that the hardcoded @cf/google/gemma-4-26b-a4b-it in gastown's areThreadsBlocking() be made configurable or at least disclosed, which this PR doesn't touch — we don't want it auto-closed.
  • The surrounding config block guards runtime agents, MCP, and commands behind !bitbucketInputPath. The new block has no such guard, so Bitbucket reviews pick up an agent.title entry they didn't have before. Probably harmless, but please either add the guard or add a case covering it.
  • agent.title.model is redundant once small_model is set (the title path falls through to getSmallModel()), and it's slightly less forgiving: the small_model path catches ProviderModelNotFoundError and degrades to the primary model, whereas getModel() on the title agent does not. Same model ID as the primary so the practical risk is nil — worth keeping for the runtime-agent override case you added in the second commit, just flagging the asymmetry.
  • Two more test cases would be good: code-review with no model configured (small_model stays unset), and the Bitbucket review path.
  • CI hasn't run on this yet since it's from a fork; we'll approve the workflow once the above is in.

Happy to take this over if you'd rather not carry it further — let us know.

@St0rmz1
St0rmz1 self-requested a review July 27, 2026 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nitpick: BYOK Code Reviewer still uses hardcoded Gemma 4 (Kilo credits) alongside the configured BYOK model — please use the BYOK model for everything

3 participants