ductor icon indicating copy to clipboard operation
ductor copied to clipboard

Gemini CLI model discovery fails with v0.38.x (bundled architecture)

Open downwind7clawd-ctrl opened this issue 7 months ago • 4 comments

Bug Description

Gemini CLI model discovery returns 0 models when using Gemini CLI v0.38.x+, causing the model selector to fall back to only 3 hardcoded models (gemini-2.5-flash, gemini-2.5-flash-lite, gemini-2.5-pro). Newer models like gemini-3-flash-preview, gemini-3.1-flash-lite-preview are not available in the selector.

Root Cause

Starting from v0.38.x, the Gemini CLI package moved to a bundled architecture:

/home/david/.npm-global/lib/node_modules/@google/gemini-cli/bundle/gemini.js

The model discovery in ductor_bot/cli/gemini_utils.py looks for gemini-cli-core/dist/src/config/models.js at these paths:

  1. <npm_global_root>/@google/gemini-cli/node_modules/@google/gemini-cli-core/dist/src/config/models.js
  2. <cli_path_package_root>/node_modules/@google/gemini-cli-core/dist/src/config/models.js
  3. Various NVM / npm flat layout paths

None of these paths exist in the bundled layout. The gemini-cli-core is no longer a separate package under node_modules/ — it's inlined into bundle/gemini.js.

Steps to Reproduce

  1. Install Gemini CLI v0.38.x+: npm install -g @google/gemini-cli
  2. Install ductor: pipx install ductor
  3. Configure ductor with provider: gemini
  4. Start ductor and send /model
  5. Observe that only 3 fallback models appear instead of the full model list

Expected Behavior

All available Gemini models (including preview models like gemini-3-flash-preview) should be discoverable and shown in the /model selector.

Actual Behavior

Discovery returns 0 models, falls back to hardcoded 3 models. Log output:

Gemini cache refresh forced
Discovered 0 Gemini models
Using hardcoded Gemini fallback models (not persisted)
Gemini cache loaded: 3 models

Environment

  • ductor: 0.15.0
  • Gemini CLI: 0.38.2
  • Python: 3.12.3
  • OS: Ubuntu 22.04 (Linux)
  • Install method: pipx

Additional Notes

I verified the Gemini CLI bundled path:

$ readlink -f /home/david/.npm-global/bin/gemini
/home/david/.npm-global/lib/node_modules/@google/gemini-cli/bundle/gemini.js

No gemini-cli-core directory exists:

$ ls /home/david/.npm-global/lib/node_modules/@google/gemini-cli/node_modules/@google/
(none — no separate packages)

Suggested Fix

The discover_gemini_models() function in gemini_utils.py should be updated to also support the bundled layout:

  1. Try to import/export VALID_GEMINI_MODELS from bundle/gemini.js
  2. Or parse model identifiers from the bundled JS file directly
  3. Alternatively, use gemini --output-format json or similar CLI command to query available models
  4. The _discover_models_via_node() fallback regex extraction already works as a last resort, but only if the models.js path is found

downwind7clawd-ctrl avatar Apr 17 '26 23:04 downwind7clawd-ctrl

Additional: Default model should be gemini-2.5-flash, not gemini-2.5-pro

As a side effect of the issue above, the default model in the example config and initial setup is gemini-2.5-pro, which has very limited free-tier capacity.

In my case, ductor consumed the entire Gemini Pro quota (100%) in the background before I even sent my first message — through init processes like trusted workspace setup, skill sync, and model cache refresh. The user never explicitly requested Pro.

Additionally, /new resets the provider session but preserves the model field in sessions.json, which overrides the config default. So even after changing the config default to gemini-2.5-flash, the bot kept using gemini-2.5-pro until sessions.json was manually edited.

Suggestions

  1. Change the default model to gemini-2.5-flash — More generous free-tier limits, faster responses, and sufficient for most coding tasks.
  2. Make /new respect the config default model — Currently sessions.json model persists across /new resets, which is confusing.
  3. Consider adding a --model flag or env var to the background init/setup processes so they don't burn through Pro quota silently.

downwind7clawd-ctrl avatar Apr 17 '26 23:04 downwind7clawd-ctrl

Update: Still present in ductor 0.15.0 + Gemini CLI 0.38.2

Confirmed the issue persists. Additional observations:

Performance Impact

The discovery failure causes a significant side effect: every session loads 24K+ input tokens even for simple messages. This is because:

  1. --include-directories . gets passed to the Gemini CLI (from cli_parameters.gemini config), causing the entire workspace to be included in every request
  2. Without proper model discovery, the session management cannot optimize context size

A partial workaround is manually updating ~/.ductor/config/gemini_models.json with the correct model list extracted from the bundle:

{
    "last_updated": "2026-04-21T09:30:00.000000+00:00",
    "models": [
        "gemini-2.5-flash",
        "gemini-2.5-flash-lite", 
        "gemini-2.5-pro",
        "gemini-3-flash-preview",
        "gemini-3-pro-preview",
        "gemini-3.1-flash-lite-preview",
        "gemini-3.1-pro-preview"
    ]
}

The models can be extracted from the bundle:

grep -oh gemini-[a-z0-9._-]* \
  /path/to/gemini-cli/bundle/chunk-*.js | sort -u

Suggested Bundle-Aware Discovery

The _gemini_models_js_candidates() function should add bundle paths:

# In _gemini_models_js_candidates():
bundle_dir = gemini_cli_root / "bundle"
if bundle_dir.is_dir():
    for js_file in bundle_dir.glob("chunk-*.js"):
        candidates.append(js_file)

And _discover_models_from_models_js() should handle the regex extraction for these chunk files (which already works via _extract_models_from_text()).

downwind7clawd-ctrl avatar Apr 21 '26 09:04 downwind7clawd-ctrl

Fixed via PR #105 (@attid) in v0.16.0. The new bundled-chunks discovery path handles Gemini CLI v0.38.x correctly. Regression-tested. Thanks @attid for tracing this to the exact bundled chunk path — made the fix straightforward.

PleasePrompto avatar Apr 21 '26 10:04 PleasePrompto

Fixed — landed via PR #105 (@attid) in v0.16.0.

Thanks @attid for the PR and for the detailed write-up. The new bundled-chunks discovery path handles v0.38.x correctly and is version-robust going forward. Regression-tested.

PleasePrompto avatar Apr 21 '26 10:04 PleasePrompto