Skip to content

config: default models come from a connected provider when OpenRouter cannot answer - #2887

Open
ZeroPoint95 wants to merge 8 commits into
devfrom
zeropoint95/reachable-model-defaults
Open

ZeroPoint95 wants to merge 8 commits into
devfrom
zeropoint95/reachable-model-defaults

Conversation

@ZeroPoint95

@ZeroPoint95 ZeroPoint95 commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

What

Every built-in default model is an OpenRouter id, and an id with no connected prefix is sent to the always-present OpenRouter row, key or none. So a profile that connected only ChatGPT or only Ollama used models nobody could reach:

  • ChatGPT only (WorkAF 0.1.9 stable and the 0.1.0-dev build): the conversation, title, router, reflex and fallback all used DeepSeek/Gemini via OpenRouter, and every message failed with no API key: this session has not been given one yet. Afi never replied.
  • Ollama only: the conversation model was right, but the fallback and the title/router tier still went to OpenRouter.

Behaviour after this change

config.ReachableDefaultAt(profileDir, slot, builtIn) decides every built-in default:

  • OpenRouter key: every built-in stays exactly as it was. It returns before any source is resolved.
  • Nothing connected, or no connected provider knows its models: the built-in stays.
  • Otherwise:
    • A built-in is kept only when the conversation's provider lists it.
    • Every slot follows the conversation model's provider: the saved model, else a hosted provider before a local server.
    • Talk: the provider's starting model by the picker's own rule (Source.PreferredModel) when it names one; otherwise its strongest model.
    • Fallback: a different strong model, skipping variants such as [1m]; else another provider's talk model; else the conversation model itself, so a failed reply stays on it.
    • Light (reflex, small work, knowledge): the lightest model, passing over the conversation model when another equally light model exists.
  • Strength ranking: published intelligence index, then price, each counted only when every model carries it; then family words, parameter count and thinking levels; ties keep the provider's order.
  • Providers with no published list (Moonshot, MiniMax, Qwen) offer their preferred model plus their connection-check model (e.g. qwen3.8-flash).

It is applied at the bottom rungs:

  • ChatDefaultAt
  • ModelFallbacksAt
  • freeTierModelAt: reflex, low, title, router, reply suggestions, free helpers
  • KnowledgeModelAt
  • DefaultFallbackAt: the legacy nearest in the catalog migration in session/agent.go

Also:

  • ChatGPT crew routes: without an OpenRouter key they serve the account's remembered models instead of the vendored gpt-5.5. A ChatGPT account answered gpt-5.5 with HTTP 400 "not supported when using Codex with a ChatGPT account". With OpenRouter connected they serve the preferred id alone, as before.
  • Terminal fallback chain: sessions take ModelFallbacksNow, so a client built after /connect reads a fallback the new provider can serve. One-model runs clear it, as they clear ModelFallbacks.
  • App model list: models.list offers the engine's default as an extra row only when a connected service can send it.
  • Settings rows: the terminal settings mark knowledge, fallback, reflex and small work as changed only when the profile holds a value. The settings hints say "codeaf's default".
  • Thinking levels: remembered ChatGPT rows keep their thinking levels for ranking only (Reasoning.Known stays false).
  • Cost: provider lists are re-decoded only when their cache file changes, and each list is ranked once. A written list bumps the settings generation, so the crew snapshot rebuilds when a listing lands.
  • Docs: manual (models-and-cost.md, settings.md, what-i-remember.md, app-provider-connections.md), PERF.md "Default model lookups", and the change entry.

Self-review: three impartial review-and-repair rounds

Each round was a fresh sub-agent that reviewed the diff against the repo standards and posted nothing.

  • Round 1 found a blocker: with OpenRouter plus DeepSeek direct, a deepseek/ built-in DeepSeek didn't list fell through to OpenRouter's whole catalog, so the fallback went to its most expensive model. Fixed by the OpenRouter early return. Also fixed:
    • a talk default that could be empty
    • stale settings rows and manual lines
    • key-checked desktop providers ignoring the engine default
    • per-call file reads with no measurement
    • test gaps
  • Round 2:
    • "Hosted before local" never worked on a real profile: every row carries a plan-pause policy, which I had read as "paused". Fixed, with a test that builds the profile through ResolveSources.
    • Unknown prices ranked as cheapest. Fixed.
    • The terminal fallback chain was fixed at launch. Fixed with ModelFallbacksNow.
    • A built-in from another provider could be kept while the conversation ran elsewhere. Fixed.
    • Docs. Fixed.
  • Round 3:
    • Catalog decodes on the settings draw path and under the client lock. Now cached; gate added.
    • A stale crew snapshot after a listing landed. Fixed by bumping the settings generation.
    • Two OpenRouter-visible changes (crew routes, legacy migration). Now gated.
    • Wrong settings changed-marks. Fixed.
    • An unreachable default row in models.list. Fixed.
    • Equal-model ties. Fixed.
    • Start-model rule consistency. Fixed.

Checks run

  • internal/config/reachable_defaults_test.go:
    • one case per shipped provider (DeepSeek, Z.ai coding plan, Moonshot, MiniMax, Qwen, ai&, OpenCode Go, Claude Code, custom endpoint), plus ChatGPT and Ollama cases
    • OpenRouter + DeepSeek direct unchanged
    • the real-profile ordering
    • ranking with missing signals
    • the listed-built-in rule
    • crew routes with and without OpenRouter
    • settings rows
    • the cached-list gate
  • go test ./internal/config/ (full package), plus focused runs of internal/session, internal/tui3, internal/provider, internal/catalog and cmd/codeaf (models, fallback, knowledge, setup, crew, seats, roles, credits, Codex, one-model, task models, insight, list models): pass.
  • make test-laws, make test-packed-manual manual-gates and make changelog-check: pass.
  • TestFactoryWriteUsesJobBaseAcrossAttempts, TestFactoryStepRetryWaitsForPreviousLeaseCleanup and TestFactoryMeasuredOnlyPublication fail on this machine identically on a clean origin/dev. They are pre-existing and out of scope.
  • Measured over a 400-model list plus Ollama: about 1,750 allocations / 2 ms per lookup before the round 3 cache, about 100 / 35 µs after. An OpenRouter profile is about 10 allocations / 6 µs.
  • Live (WorkAF built from this branch plus codeaf-desk#888), ChatGPT-only first run:
    • saved codex/gpt-6.2-sol
    • Afi and agent chats replied
    • title, router, caption and reflex ran on gpt-5.6-luna, all HTTP 200

Known limits, not verified live

  • No live test: DeepSeek, Z.ai, Moonshot, MiniMax, Qwen, ai&, OpenCode Go and custom endpoints (no accounts on the test machine).
  • Claude Code: the copy bundled with the Claude desktop app is not on PATH for codeaf, and its claude auth status reports loggedIn: false. That is a separate connection issue.
  • ChatGPT listing failure: if the account listing fails at connect, the remembered fallback rows start with gpt-5.5, so the conversation starts there, as the terminal's connect does.
  • ai&: its preferred model is a flash model, so its conversation default is light.
  • Out of scope: paused or switched-off providers are not skipped. LAN endpoints count as hosted.
  • Out of scope, noted for later: Ollama's 4096-token default context truncating prompts, timeouts for local models, error wording, and a thinking level for the mastermind seat.

Desktop half: Agent-Field/codeaf-desk#888.

🤖 Generated with Claude Code

ZeroPoint95 and others added 8 commits November 23, 2026 16:24
… cannot answer

Every built-in default (conversation, fallback, reflex and small-work helper
tiers, free helper and chat defaults, knowledge) was an OpenRouter id used
whatever was connected. With only ChatGPT connected every message failed with
"no API key"; with only Ollama the fallback, titles and routing still went to
OpenRouter.

ReachableDefaultAt keeps a built-in default while a connected service can send
it. Otherwise every slot follows the conversation model's provider (a hosted
provider before a local one when nothing is chosen): the provider's preferred
or strongest model for the conversation, a different strong model for the
fallback (none when it offers one), and its lightest model for helpers and
knowledge. Strength reads the published intelligence index, then price, then
family words, parameter size and thinking levels. With nothing connected the
built-in ids stay named, so setup is unchanged.

ChatGPT's crew routes now serve the account's remembered models instead of the
vendored preferred id alone: an account that no longer lists gpt-5.5 answered
the second router look with "not supported when using Codex with a ChatGPT
account". Remembered ChatGPT rows keep their thinking levels for ranking only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ts for unlisted providers

A built-in id that routes to a connected provider by its prefix
(deepseek/deepseek-v4.1-flash with a direct DeepSeek account) was kept on
routing alone, though that account's own list need not carry it. A provider
whose models are known must now list the model; the OpenRouter row and a
provider that can say nothing are still trusted on routing.

A provider that publishes no model list (Moonshot, MiniMax, Qwen) offered only
its preferred model, so every seat used the flagship. It now also offers the
model its connection check is sent to, which is small on purpose (Qwen's
qwen3.8-flash), and the helper seats take it.

Among equally light models the light seat takes the one the provider lists
first, its current model, not an older version or a bulkier variant (haiku
before claude-haiku-4-5, glm-5.3-flash before glm-5.3-flash[1m]).

Adds one table case per shipped provider: DeepSeek, Z.ai coding plan, Moonshot,
MiniMax, Qwen, ai&, OpenCode Go, Claude Code and a custom endpoint.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pty default, cheaper reads

From an impartial review of #2887:

- An OpenRouter key now keeps every built-in exactly as it was. With DeepSeek
  connected directly beside it, a deepseek/ built-in that DeepSeek does not list
  fell through to choosing among OpenRouter's whole catalog: the fallback went
  to its most expensive model and helpers to its cheapest.
- The talk, fallback and light seats are never empty when the built-in is not:
  with no models known anywhere the built-in is kept, and with one model the
  fallback names that model, so a failed reply stays on it instead of letting
  the catalog suggest a model on a provider nobody connected.
- A fallback skips a variant of the conversation model (glm-5.3[1m]) while a
  different model is offered; a paused plan is chosen only when nothing else is
  connected; thinking levels use roles.SplitEffort.
- The knowledge and fallback settings rows say codeaf's default instead of the
  OpenRouter model; the legacy nearest-in-the-catalog fallback migrates to the
  profile's default fallback.
- Cost: each service's models are read once per call, the OpenRouter key is
  checked before any source is resolved, config.Load resolves the default only
  when CODEAF_MODEL is unset, and the credit check resolves it only once its
  cheap conditions hold. Measured per call: an OpenRouter profile 91 → 10
  allocs (about 41µs → 6µs); ChatGPT + Ollama fallback 298 → 205, reflex
  305 → 212.
- Manual: the remaining "DeepSeek V4.1 Flash by default" fallback lines, the
  knowledge row's OpenRouter wording, Claude Code plan limits, paused plans.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…g, live terminal fallback

From review round 2 of #2887:

- Every persisted row carries a plan-pause policy ("wait" or "use
  pay-as-you-go"), which hostedFirst read as a paused plan, so on a real
  profile every service ranked alike and a local server listed first won the
  conversation. The paused rank is gone; a test now builds the profile through
  ResolveSources (Ollama listed before DeepSeek) and checks every seat.
- A published intelligence index or price now counts only when every model in
  the list carries it; a model whose price is unknown no longer ranks as the
  cheapest, so a mixed catalog cannot put a flagship in the light seats.
- A built-in another connected account lists is no longer taken while the
  saved conversation model runs on a different provider; the fallback and light
  seats walk the providers hosted-first after the conversation's own.
- The terminal chat's fallback chain was read once at launch. Sessions now take
  ModelFallbacksNow, which a model client built later (a live switch onto a
  provider connected with /connect) asks again; one-model runs clear it too.
- Doc comments and the settings hint say the conversation model is named when
  the providers offer only that one; the legacy migration comment names the
  person's own row; all-caps lead-ins in the new comments are sentences.
- Manual: ChatGPT's connect lands on gpt-5.5 only when the account lists it, a
  crew seat on the plan may use any listed model, one local model shared with
  the helpers is slower; the paused-plan sentence is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r crew unchanged

From review round 3 of #2887:

- Provider lists are decoded again only when their cache file changes
  (recallCached) and each list is filtered and ranked once (rankView). The
  settings sheet asks for the defaults on every paint and the model-client
  lock is held while the fallback chain is read. Over a 400-model DeepSeek
  list plus Ollama: about 1,750 allocations and 2 ms per lookup before, about
  100 and 35 µs after. TestUnchangedProviderListsAreReadAndRankedOnce counts
  decodes and rankings (listReads, listRanks); PERF.md "Default model lookups".
- A written model list bumps the settings generation (NoteModelListChanged,
  ConnectCodex, ConnectClaudeCode, the model shelf and the terminal's connect),
  so the crew snapshot is rebuilt once a listing lands instead of keeping a
  helper tier read from a cold list.
- With OpenRouter connected, ChatGPT crew routes serve the preferred id alone,
  as before, and the legacy nearest-in-the-catalog fallback migrates to
  codeaf's default (DefaultFallbackAt), not to the person's first row entry.
- The terminal's settings mark knowledge, fallback models, reflex and small
  work as changed only when the profile holds a value (FollowsProviders,
  WrittenAt); comparing against an untouched profile marked them on every
  profile without OpenRouter.
- models.list offers the engine's default as an extra row only when a
  connected service can send it, so first-run setup cannot save the built-in
  OpenRouter model while a provider's list is still arriving.
- With no saved conversation model, the helpers follow the provider chosen for
  the conversation; equally light models pass over the conversation model;
  a provider that names a starting model starts where the picker and the
  terminal's connect do (Source.PreferredModel), others on their strongest.
- Docs: the knowledge hint and manual say the conversation provider's
  lightest model; ranking signals count only when every model carries them;
  test comments are sentences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ZeroPoint95
ZeroPoint95 marked this pull request as ready for review November 23, 2026 23:53
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