Skip to content

[Bug] Model ID case normalization causes exact-match failure and silent fallback to wrong model #705

Open

Description

@e-kotov

Summary

When jcode populates the account model catalog from a custom OpenAI-compatible endpoint, it forcefully lowercases all model IDs. However, model validation uses a case-sensitive exact match against that lowercased set, causing any mixed-case model ID (e.g., GPT5-Mitarbeitende) to fail validation. provider_init logs this failure as a warning (invisible under --quiet), and model resolution silently falls back to the alphabetically first catalog entry.

Step-by-Step Failure Chain

  1. Catalog Lowercasing: In crates/jcode-base/src/provider/models.rs:569-577, populate_account_models_for_scope normalizes every catalog model ID through normalize_model_id -> to_ascii_lowercase() before inserting it into the catalog set.
  2. Case-Sensitive Validation Failure: In crates/jcode-provider-openai-runtime/src/openai_provider_impl.rs:693-697, set_model validates requested model IDs with an exact, case-sensitive match (known == model). A requested ID like GPT5-Mitarbeitende fails comparison against the lowercased catalog entry gpt5-mitarbeitende.
  3. Silent Warning: In src/cli/provider_init.rs:1798, provider.set_model failures are treated as non-fatal warnings (warn!("Failed to set initial model: {}", e)). This warning is entirely omitted if the user is running under --quiet.
  4. Phantom Model Substitution: In crates/jcode-provider-openai-runtime/src/lib.rs:1263, when set_model fails, model_id() falls back to get_best_available_openai_model(), which selects the alphabetically first catalog entry (e.g., gpt5-mini-mitarbeitende).

Net Impact

Requesting a valid mixed-case model like GPT5-Mitarbeitende silently sends gpt5-mini-mitarbeitende (in lowercase) on the wire. This causes silent model substitution and unexpected HTTP 404 errors from custom gateways, with no indication to the user that their requested model was rejected. There is no standard dictating that OpenAI-compatible endpoints must use lowercase models.

Proposed Fix

  1. Preserve Original Case: Stop forcefully lowercasing model IDs in populate_account_models_for_scope. The catalog should store the exact strings returned by the provider's /models endpoint.
  2. Flexible Validation & Transmission: In set_model, when validating the user's requested model against the catalog:
    • Attempt an exact case-sensitive match first.
    • If that fails, attempt a case-insensitive fallback (for user CLI convenience).
    • In either case, always adopt the exact casing from the catalog for internal state and wire transmission.
  3. Hard Error on Failure: Treat set_model failures during CLI initialization as fatal errors rather than silent warnings to prevent phantom model swaps.

Activity

  1. added
    bug
    priority: medium
    triage: reproducible
    autonomous: likely
    on Aug 2, 2026
  2. 1jehuang commented on Aug 2, 2026

    @1jehuang
    Owner

    Thanks, this is a well-traced four-step failure chain and the "silent substitution" outcome is the concerning part: running and evaluating a different model than requested, with the only warning suppressed under --quiet.

    Labeled autonomous: likely. Two sub-problems here, and they want different fixes:

    1. The case mismatch itself. Catalog IDs are lowercased on insert, then compared case-sensitively on lookup. Making the comparison case-insensitive is the mechanical fix.
    2. The silent fallback. Arguably the more important half. An explicitly requested model that cannot be honoured should be a hard error, not a warning plus a substitution. That is a behaviour change, so it needs a maintainer's call.

    Note #724 reports the same silent-substitution behaviour from a different cause (a model missing from the catalog entirely), which suggests the fallback path, not just the case handling, is the thing to fix.

    --- — Jcode agent (automated triage), on behalf of @1jehuang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    autonomous: likelybugpriority: mediumtriage: reproducible

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions