Skip to content

fix(platform): keep a flash-suffixed model id on Gemini CLI runs - #3998

Merged
larryro merged 1 commit into
mainfrom
fix/gemini-cli-flash-model-rewrite
Sep 30, 2026
Merged

larryro merged 1 commit into
mainfrom
fix/gemini-cli-flash-model-rewrite

Conversation

@larryro

@larryro larryro commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

What broke

Every Gemini CLI project-agent run on a model whose id ends in flash failed on its first model call — deepseek-flash, glm-5.3-flash, qwen3.6-flash, OpenRouter google/gemini-3.5-flash / deepseek/deepseek-v4-flash, and a byo Google gemini-3-flash was silently served as gemini-3.5-flash.

Reproduced on the dev stack (task "测试", org test, Gemini CLI + the org's custom DeepSeek record, model deepseek-flash): four runs in 20 s, each harness_error with the CLI's own words, [API Error: {"error":{"code":500,"message":"could not auto resolve a provider for the request, please specify a provider explicitly"}}]. The gateway log shows why:

POST /genai/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt=sse → 400
User-Agent: GeminiCLI-tui/0.49.0/ma9DZO…__deepseek__deepseek-flash/deepseek-flash

The --model the platform passed only survives in the user agent; the request path carries the CLI's own gemini-3.5-flash, which Bifrost cannot resolve.

Root cause

gemini-cli 0.49.0 (the pinned CLI), packages/core/src/config/models.ts:

if (useGemini3_5Flash && isFlashModel(resolved) && normalizedModel !== PREVIEW_GEMINI_FLASH_MODEL)
  return DEFAULT_GEMINI_FLASH_MODEL; // 'gemini-3.5-flash'

isFlashModel() includes model.endsWith('flash'), and useGemini3_5Flash comes from hasGemini35FlashGAAccess(), which is unconditionally true for AuthType.USE_GEMINI — the gemini-api-key auth type the harness pins on the managed lane. There is no setting for that gate. Upstream narrowed the predicate to an explicit allow-list in 0.61.0 (isPromotableFlashModel: "Keep explicit versioned model IDs intact so callers can pin newer or older Flash models").

The fix

resolveModel has a second path: with experimental.dynamicModelConfiguration on, it returns modelConfigService.resolveModelId(id), which returns an id it has no rule for unchanged, and the flash block is never reached. The gemini harness settings now carry that fragment on both lanes, so the CLI requests the id the platform resolved — a managed gateway ref verbatim, a byo vendor id verbatim.

Proven on the dev stack with the pinned 0.49.0 CLI against the real gateway: with the fragment, …__deepseek__deepseek-flash/deepseek-flash reaches the gateway unchanged, HTTP 200, result: success; deepseek-v4-pro behaves as before.

Why not bump the pin

0.61.0/0.62.0 fix the rewrite but 0.62.0 also refuses a system settings file unless the file and every ancestor directory are owned by root and not group/other-writable (packages/core/src/utils/security.ts). tale-gemini-run stages the per-exec settings as agent under a mkdtemp in /tmp, so the pin lands on "Invalid auth method selected" (exit 41) before the first call — verified with 0.62.0 installed into a temp prefix inside a session container. Moving the harness to a newer CLI is a separate re-integration; the wrapper's staging contract has to change first.

Gates

  • lib/harnesses/fixtures/exec/gemini.yml re-frozen (the byte-for-byte golden gate): the 20 stdin payloads gain "experimental":{"dynamicModelConfiguration":true}, nothing else moves.
  • lib/harnesses/exec-builder.test.ts: the gemini exec carries the fragment on both lanes and passes a flash-suffixed --model verbatim (managed gateway ref and byo gemini-3-flash).
  • tests/integration/container-sandbox-runtime-test.ts: the pinned CLI through tale-gemini-run against a loopback stand-in for the gateway (answers 400, so no retry loop; no key, no network) — with the harness settings the request path is /v1beta/models/probe-provider/probe-model-flash; the control run without the fragment still shows the rewrite, so a CLI bump that drops it turns this red on purpose with the message to remove the fragment. Both directions observed in the local tale-sandbox-runtime:latest image (3.4 s); the whole suite run locally against a fresh image build: 89 passed, 0 failed.
  • tests/manual/reference/automation.md gets the row.
  • Local: vitest --project server lib/harnesses 228/228, tsc --noEmit clean, oxlint/oxfmt clean, lint:manual green, lint:conflicts green.

The pinned Gemini CLI (0.49.0) rewrites any --model ending in "flash" to
its own gemini-3.5-flash on API-key auth (config/models.ts resolveModel:
isFlashModel = endsWith('flash'), gated by hasGemini35FlashGAAccess(),
which is unconditionally true for gemini-api-key). A managed
`…/deepseek-flash` therefore reached the gateway as a bare
gemini-3.5-flash and every run died with 400 "could not auto resolve a
provider"; a byo Google gemini-3-flash was silently promoted the same way.

The harness settings now turn on the CLI's dynamic model configuration,
whose resolveModelId returns an id it has no rule for unchanged, so the
CLI requests the id the platform resolved on both lanes. Upstream
narrowed the rewrite to its own aliases in 0.61.0; 0.62.0 also requires
a root-owned system settings file, so the pin bump is separate work.

Gates: the golden exec fixture is re-frozen; exec-builder pins the
fragment and the verbatim --model on both lanes; the runtime image test
drives the pinned CLI through tale-gemini-run against a loopback
gateway stand-in and asserts the request path keeps a flash-suffixed
id, with a control run that still shows the rewrite so a CLI bump that
drops it fails on purpose.
@larryro
larryro merged commit 71fada3 into main Sep 30, 2026
68 of 69 checks passed
@larryro
larryro deleted the fix/gemini-cli-flash-model-rewrite branch September 30, 2026 13:51
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.

1 participant