Skip to content

feat: user-overridable model facts (context window etc.) — models.json-style override layer #2330

Description

@Astro-Han

Problem

Model facts (context window, max tokens, capabilities, price) are read-only metadata today, with no user override channel:

  • A custom model (e.g. a relay/transit-station model id) that is neither in the catalog nor returned by the provider's /v1/models fetch gets contextWindow = undefined, and the runtime falls back to hardcoded defaults (defaultCompactReserveTokens → 16_384, context-budget-policy.ts:394). The user has no way to tell the app "this model actually has a 200K window".
  • The only custom-model entry point is a plain model-id string in the connection form (settings-provider-copy.ts:104 — "填写你的中转站模型 ID…或自定义模型名").
  • Pricing has the same shape: a 17-entry hand-maintained snapshot (see feat(scripts): sync the full models.dev fact set (pricing, description, knowledge, input limits) #2329) plus the override editor coming in the Pricing settings work — but no unified "model facts" override surface.

This is one class of problem: the app's model facts come from catalog sync + provider fetch, and users have no override channel.

Ecosystem findings (surveyed local sources of Pi, opencode, Hermes, Codex CLI, Gemini CLI, LobeChat, Kimi Code)

Project Config surface context window override price override Merge semantics
Pi ~/.pi/agent/models.json ✅ per-model ✅ cost field providers.<id>.models[] upsert (add/replace) + providers.<id>.modelOverrides.<modelId> field-level patch, one ordered pipeline (provider-composer.ts:425-434), overrides = "topmost user-config layer"
opencode opencode.json providers ✅ limit.context field-merged ({...base, ...config}) ✅ cost (whole-replace) models.dev fills first (builtin snapshot → disk cache → network), user config overrides last (config/plugin/provider.ts:76-113)
Hermes config.yaml ✅ 9-level priority ladder; user override only at the top, uncovered fields probe down ❌ (live /v1/models pricing, display-only) Facts (id list, context, capabilities, price) and user overrides strictly separated; override keys are provider × model
Codex CLI ~/.codex/config.toml ✅ model_context_window, clamped by min(max_context_window) ❌ Built-in providers are reserved ids — cannot be overridden, only new names (config_toml.rs:899-918); user catalog replaces bundled catalog
LobeChat DB tables (ai_models with source: builtin/custom/remote) ✅ per-model contextWindowTokens ✅ full pricing (only project that supports it) Builtin rows protected from remote writes; user values override field-by-field; source immutable once set
Kimi Code ~/.kimi-code/config.toml ✅ maxContextSize (default 131072) ❌ Remote refresh owns a whitelist of fields only; user overrides never touched (model-alias-merge.ts:25-60)
Gemini CLI ~/.gemini/settings.json ❌ (uses compression ratio instead) ❌ Alias inheritance chain + level-scoped overrides

Consensus patterns across all surveyed harnesses:

  1. Built-in facts are read-only generated artifacts (models.dev / compile-time snapshot); users never rewrite the built-in table.
  2. User override is field-level; context window is the universally supported field (price only in LobeChat — Maka's pricing override work would make us the second).
  3. Priority: user > remote/dynamic > built-in, with the built-in snapshot as offline fallback.
  4. Override keys are provider × model, not bare model id (Hermes: same id differs by serving provider).

Proposed shape

A user override layer in the spirit of Pi's models.json / opencode's providers section, paired with the generated pricing table from #2329:

models.json (user-editable; or a Settings UI equivalent)
├── models[]            → add or whole-replace a model (id, api, baseUrl, contextWindow, maxTokens, capabilities, cost…)
└── modelOverrides      → { "<provider>:<model>": { contextWindow?, maxTokens?, … } } field-level patches

Design points (borrowed from the survey):

  • Field-level merge ({ ...base, ...override }), the opencode limit pattern — never whole-entry replacement, so catalog updates keep flowing to untouched fields.
  • Single ordered merge pipeline with a documented "user is topmost" layer (Pi's provider-composer.ts:425-434 is the reference).
  • provider × model keys.
  • Schema validation with graceful fallback (Pi: bad models.json → error surfaced, built-ins still work).
  • Built-in facts stay read-only: generated from models.dev (metadata today, pricing after feat(scripts): sync the full models.dev fact set (pricing, description, knowledge, input limits) #2329); user file never writes them.
  • Pricing override keeps going through the existing override editor (feat(desktop): add isolated Pricing settings editor #2218 direction) — the models.json layer is for facts that have no UI yet (context window first).

Relationship to open work

Validation

  • Context budget decisions (context-budget-policy.ts:410-424) resolve the overridden window instead of the 16K fallback for a custom model.
  • Contract test: override merges field-by-field; catalog refresh does not clobber overridden fields; unknown ids in modelOverrides are ignored (Pi semantics) or flagged.
  • Offline: built-in snapshot still works with no models.json present.

Activity

  1. Nyvo-io commented on Aug 11, 2026

    @Nyvo-io
    Contributor

    I would like to take this issue. I audited current main after #2399 and propose keeping model-fact overrides on the existing Runtime Host ownership path: a versioned, schema-validated, root-scoped authority keyed by provider:model, with field-level user override > provider inventory > generated metadata precedence. Effective facts will feed the canonical model catalog and pre-dispatch Run composition so context/input budgets use the override, while generated facts remain read-only and the existing pricing authority/UI is not duplicated. Unknown entries will remain non-sendable until referenced by an existing connection or saved model choice.

    I will cover contract/store/projection behavior, malformed-document fallback with bounded diagnostics, provider refresh preserving untouched and overridden fields, restart persistence, and end-to-end context-budget resolution with focused Core, Storage, Runtime Host, and execution tests. I will keep unrelated provider creation and model-picker redesign out of this slice. Please assign me if this boundary matches the intended scope.

  2. Astro-Han commented on Aug 13, 2026

    @Astro-Han
    ContributorAuthor

    Assigned! @Nyvo-io

  3. added
    enhancement
    on Aug 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancement

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions