Repository navigation
fix: reject unavailable explicit models #1804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
anandgupta42
wants to merge
76
commits into
main
Choose a base branch
from
fix/explicit-model-no-silent-cloud-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,276
−357
Open
Changes from all commits
Commits
Show all changes
76 commits
Select commit
Hold shift + click to select a range
8368238
fix: reject unavailable explicit models
anandgupta42 249d768
fix: mark model resolution guidance for upstream merges
anandgupta42 9193979
fix: preserve valid restored TUI selections
anandgupta42 036f575
test: cover CLI model precedence over agent config
anandgupta42 0fcfdb4
fix: reject empty explicit agent model values
anandgupta42 aaf5d79
fix: preserve valid session models and align config readers
anandgupta42 6247df2
fix: preserve shell and command-specific model execution
anandgupta42 55b5249
fix: preserve TUI config migration precedence
anandgupta42 cf7a851
fix: keep shell execution independent of model availability
anandgupta42 f2c1da5
fix: retain legacy TUI migration and verify shared config discovery
anandgupta42 67bfa15
fix: honor migrated default agent in attached runs
anandgupta42 889e09a
fix: validate the model used by each submission
anandgupta42 7a5fae9
fix: preserve TUI drafts and session model selection
anandgupta42 1abf265
chore: mark session model history customization
anandgupta42 84f3969
fix: keep picker recovery scoped to the active conversation
anandgupta42 d7194ce
fix: preserve the attached build agent alias
anandgupta42 54408c8
fix: validate pasted commands and preserve picker recovery
anandgupta42 1088905
fix: match command agent aliases and scope picker overrides
anandgupta42 7c5e531
fix: carry effective models through command execution and follow-ups
anandgupta42 8cc4a37
fix: keep a session picker after command history restores
anandgupta42 414ecc5
fix: retain draft edits made during session creation
anandgupta42 f7261de
fix: preserve model picks and draft mode across conversations
anandgupta42 1b3dcda
test: assert both command inference requests use the effective model
anandgupta42 57ad99b
test: exercise the production draft revision during session setup
anandgupta42 69548eb
fix: preserve command and prompt intent during async setup
anandgupta42 106ec35
fix: keep explicit effort when session history matches its model
anandgupta42 d5a0b6a
fix: scope model effort to its conversation
anandgupta42 2b6e7e2
fix: keep local submissions independent of model and catalog failures
anandgupta42 b950792
fix: report an unavailable async prompt model once and skip display-o…
anandgupta42 33898af
fix: suppress only already-reported async model errors and record aut…
anandgupta42 e144871
fix: track the agent list per workspace and reload catalogs on worksp…
anandgupta42 ab664dc
fix: report explicit subtask models, retry only gateway failures, kee…
anandgupta42 70992db
fix: share report-once model validation, keep 5xx retries, and test p…
anandgupta42 5497a16
test: wait for the subtask model error text, not the echoed model id
anandgupta42 fbfb838
fix: skip display-only rows in ACP restore and migrate branded TUI ke…
anandgupta42 32e3144
test: use the Effect instance fixtures for the plan exit and async er…
anandgupta42 1db0cbf
fix: load TUI config from .altimate-code directories and match loader…
anandgupta42 71452f8
test: run the new ACP restore tests through the Effect test fixture
anandgupta42 50f33a8
fix: restore ACP replies only when their parent prompt is in view, an…
anandgupta42 1f97aee
fix: keep restoring long agent turns whose prompt is beyond the ACP page
anandgupta42 a21ec26
fix: name project copies with a slug when the configured model is una…
anandgupta42 f11ff27
test: allow the instance-scoped async error and plan exit tests 30s o…
anandgupta42 0a3f7a8
fix: log why project copy naming fell back to a slug
anandgupta42 1a4babb
fix: keep prompt enhancement on the configured provider when its mode…
anandgupta42 470da1e
fix: name the agent config when a subagent model is unavailable, and …
anandgupta42 a4daa65
fix: check a subagent model before creating its child session and kee…
anandgupta42 3303316
refactor: share the unavailable-model message between session and tas…
anandgupta42 5d7c979
fix: keep the guided model error instead of a second send-failure toa…
anandgupta42 406b1ea
fix: mark the TUI send-failure guard as altimate code
anandgupta42 ee0a035
fix: recognise the SDK-wrapped model rejection so the TUI shows one e…
anandgupta42 1975131
fix: return 400 only for an unavailable model and keep the empty 200 …
anandgupta42 2640160
fix: keep the failed-subtask child session and relabel its model erro…
anandgupta42 87e06a4
fix: keep 404 and busy-session statuses on the prompt route
anandgupta42 4983c4b
fix: explain an empty model value and open the picker for a new user …
anandgupta42 cb20b9f
refactor: route the submit-time model check through a tested helper
anandgupta42 8080d94
feat: open the model picker when a submitted configured model is unav…
anandgupta42 eda34f9
fix: report a subagent or compaction model against its agent config
anandgupta42 d72498d
fix: scope the unavailable-model picker and advice to sources a pick …
anandgupta42 d3e00d4
fix: share model-error reporting and one submission-model precedence
anandgupta42 d2b69a8
fix: tailor unavailable-model advice to whether a pick or config edit…
anandgupta42 109de66
fix: keep config advice to config sources and report each model error…
anandgupta42 7975784
fix: check cancellation before subagent model validation and keep pro…
anandgupta42 5ab7583
docs: describe `markReported` as covering any error already published
anandgupta42 4dfa517
fix: align command model labels and document per-conversation model p…
anandgupta42 4f330a9
fix: share the config-source rule across server, CLI and TUI and log …
anandgupta42 27134fe
fix: keep the subagent model check under its own marker and scope the…
anandgupta42 84e6023
fix: drop an unread reported mark and scope the picker docs to the ch…
anandgupta42 8d26b13
fix: open the model picker when a subtask parent chat model is unavai…
anandgupta42 d62f59a
test: cover request, subtask and session-history sources in CLI error…
anandgupta42 a8ffdf6
refactor: use one name for the config-source rule and pass picker ori…
anandgupta42 bf30f08
test: move the configured-default-model regression onto the Effect te…
anandgupta42 9c70cd4
test: assert the configured default model error names its source
anandgupta42 70bddb7
fix: bind the subagent trace only after its model check passes
anandgupta42 15f231d
fix: recheck cancellation after the subagent model lookup
anandgupta42 6e922e0
test: pin the trace binding for an available subagent model
anandgupta42 9deb719
test: assert the subagent trace is bound before its prompt runs
anandgupta42 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // altimate_change start — the single definition of a config-backed model source label. | ||
| // | ||
| // Model selection errors name where the model came from ("config (model)", 'agent "x" config (model)', | ||
| // "CLI --model", ...). Server, CLI and TUI all decide from that label whether to point at the config | ||
| // files, so the rule lives here once. | ||
| export const CONFIG_MODEL_SOURCE_SUFFIX = "config (model)" | ||
|
|
||
| /** Whether a source label names a config setting the user can correct. */ | ||
| export function isConfigModelSource(source: string | undefined) { | ||
| return source?.endsWith(CONFIG_MODEL_SOURCE_SUFFIX) === true | ||
| } | ||
| // altimate_change end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,47 @@ | ||
| // altimate_change - new file | ||
| import { isConfigModelSource } from "@opencode-ai/core/altimate-model-source" | ||
| // | ||
| // Extra guidance for a "Model not found" error. The Anthropic provider lost its Claude Pro/Max sign-in | ||
| // in 0.12.11, so a saved `anthropic/...` model with only that login now fails to resolve; the bare | ||
| // error gave no reason. Only a missing provider gets the hint: an Anthropic provider that is there | ||
| // with an unknown model name needs a different model, not a key. | ||
| export const modelConfigHint = | ||
| "Check the provider and model in your project config (altimate-code.json or opencode.json, including .jsonc files, at the project root or in .altimate-code/ or .opencode/) or global config (~/.config/altimate-code/)." | ||
|
|
||
| export function modelNotFoundHint(providerID: string | undefined, providerMissing: boolean | undefined) { | ||
| if (providerID !== "anthropic" || providerMissing !== true) return undefined | ||
| return "The Anthropic provider needs an API key. For a Claude Pro or Max plan, run /connect and pick Claude subscription." | ||
| } | ||
|
|
||
| /** Whether to point at the config files: a config setting chose the model, or the source is unknown. */ | ||
| export function showsConfigHint(source: string | undefined) { | ||
| return source === undefined || isConfigModelSource(source) | ||
| } | ||
|
|
||
| export function modelNotFoundMessage(providerID: string | undefined, modelID: string | undefined, source?: string) { | ||
| const sourceHint = source ? ` (from ${source})` : "" | ||
| if (!modelID) { | ||
| const empty = providerID ? `Empty model name in "${providerID}/"${sourceHint}` : `Empty model value${sourceHint}` | ||
| // An environment variable that is not set substitutes to "", the usual cause of an empty config value. | ||
| if (isConfigModelSource(source)) | ||
| return `${empty}: the model key is incomplete. If it references an environment variable such as "\${ALTIMATE_MODEL}", check that the variable is set; otherwise set a provider/model-name value or remove the key.` | ||
| return `${empty}. Use a provider/model-name value.` | ||
| } | ||
| return `Model not found: ${providerID}/${modelID}${sourceHint}` | ||
| } | ||
|
|
||
| // Full user-facing text for an unavailable model: the source-named line, suggestions, provider | ||
| // guidance and where to correct the config. | ||
| export function modelSelectionErrorText(data: { | ||
| providerID?: string | ||
| modelID?: string | ||
| source?: string | ||
| suggestions?: readonly string[] | ||
| providerMissing?: boolean | ||
| }) { | ||
| const message = modelNotFoundMessage(data.providerID, data.modelID, data.source) | ||
| const hint = data.suggestions?.length ? ` Did you mean: ${data.suggestions.join(", ")}?` : "" | ||
| const guidance = modelNotFoundHint(data.providerID, data.providerMissing) | ||
| const where = showsConfigHint(data.source) ? ` ${modelConfigHint}` : "" | ||
| return `${message.endsWith(".") ? message : message + "."}${hint}${guidance ? ` ${guidance}` : ""}${where}` | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import type { MessageV2 } from "../../session/message-v2" | ||
|
|
||
| const SHELL_MARKER = "The following tool was executed by the user" | ||
|
|
||
| // Shell and direct MCP commands record a model on their user row for display only; model | ||
| // resolution must skip those rows instead of treating them as a model choice. | ||
| export function isModelMetadataOnly(parts: readonly MessageV2.Part[]) { | ||
| return parts.some( | ||
| (part) => | ||
| part.type === "text" && | ||
| (part.metadata?.modelMetadataOnly === true || (part.synthetic === true && part.text === SHELL_MARKER)), | ||
| ) | ||
| } | ||
|
|
||
| const reported = new WeakSet<object>() | ||
|
|
||
| // Record that the session already received an error event for this error (an unavailable model or an | ||
| // unknown agent), so a route that catches it does not publish it again. | ||
| export function markReported(error: unknown) { | ||
| if (typeof error === "object" && error !== null) reported.add(error) | ||
| } | ||
|
|
||
| export function wasReported(error: unknown) { | ||
| return typeof error === "object" && error !== null && reported.has(error) | ||
| } | ||
|
|
||
| export * as ModelMetadata from "./model-metadata" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import { NamedError } from "@opencode-ai/core/util/error" | ||
| import { Bus } from "../../bus" | ||
| import { Session } from "../../session" | ||
| import { Provider, validateModelSelection } from "../../provider/provider" | ||
| import type { ModelID, ProviderID } from "../../provider/schema" | ||
| import type { SessionID } from "../../session/schema" | ||
| import { modelSelectionErrorText } from "../provider/model-hint" | ||
| import { ModelMetadata } from "./model-metadata" | ||
| import { Log } from "../../util/log" | ||
|
|
||
| const log = Log.create({ service: "model-report" }) | ||
|
|
||
| // Publish an error event the client relies on (the route may not publish it again); a failed publish | ||
| // must still leave a trace. | ||
| export function publishReported(sessionID: SessionID, error: InstanceType<typeof NamedError.Unknown>) { | ||
| void Bus.publish(Session.Event.Error, { sessionID, error: error.toObject() }).catch((cause) => | ||
| log.warn("session error event not published", { sessionID, cause }), | ||
| ) | ||
| } | ||
|
|
||
| // Publish guided text for an unavailable model once, marking the error so routes don't repeat it. | ||
| export function reportModelSelectionError(sessionID: SessionID, error: unknown) { | ||
| if (!Provider.ModelNotFoundError.isInstance(error)) return | ||
| ModelMetadata.markReported(error) | ||
| publishReported(sessionID, new NamedError.Unknown({ message: modelSelectionErrorText(error.data) })) | ||
| } | ||
|
|
||
| // Validate a selected model, publishing guided text once and rethrowing the same error instance. | ||
| export async function validateOrReport( | ||
| sessionID: SessionID, | ||
| model: { providerID: ProviderID; modelID: ModelID }, | ||
| source: string, | ||
| ) { | ||
| return validateModelSelection(model, source).catch((error) => { | ||
| reportModelSelectionError(sessionID, error) | ||
| throw error | ||
| }) | ||
| } | ||
|
|
||
| export * as ModelReport from "./model-report" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.