Skip to content

Commit ec66d0a

Browse files
anandgupta42claude
andcommitted
fix: offer Altimate Base to every user on an implicit free Zen default
Closes #1301. The 0.11.0 migration to Altimate Base only fired when `opencode/big-pickle` was in persisted `recent`, which only a picker writes. 1,027 of 1,031 Big Pickle machines were implicit-default users with no `recent`, so on 0.11.x they were silently rerouted to the next public free Zen model (`nemotron-3.5-lightning-free`) and never offered Base. TUI (`packages/tui`) - `usesImplicitFreeDefault()`: eligibility is now "launch default resolves to a free public OpenCode Zen model (Big Pickle included), no explicit selection, no project provider allowlist", judged on `fallbackModel()` so a restored session model is never mistaken for the default. - One startup decision in `app.tsx` replaces the two racing effects: prior decline → skip; registered Base → migrate silently; returning user (prompt history at startup, project sessions, or a recent model) → migration disclosure; a brand-new user keeps the first-run welcome picker. A `dialog.replace()` that loses a race falls through instead of latching. - Escape / Ctrl-C on the migration disclosure now routes through the close guard to the same path as explicit No: the decline is persisted AND the provider picker opens, instead of stranding the user on the retired model. - Migration copy names the actual free model being moved. - Telemetry: `altimate_base_confirm_shown` / `altimate_base_choice` / `altimate_base_register_result` now fire for the migration origin (they were gated on the first-run funnel, so the migration was invisible), with an `origin` field. - `PromptHistory` exposes `loaded()` and a one-time `hadHistoryAtStartup()`. Server (`packages/opencode`) - `Provider.defaultModel()` and the ACP default scan: a registered Altimate Base now outranks the keyless public Zen tier (`options.apiKey === "public"`) and nothing else; a keyed Zen account or any BYOK provider still wins. Headless hosts (`serve` behind the VS Code extension) therefore land on Base once the install is registered. Tests: `test/context/local.test.ts` (free-Zen detection, eligibility, recents rewrite), `test/cli/tui/dialog-altimate-base.test.tsx` (migration telemetry without first-run, Escape → decline + picker, generalized copy), `test/provider/provider.test.ts` and `test/acp/default-model.test.ts` (public tier vs keyed Zen vs registered Base, recents precedence unchanged, Big Pickle never migrated headlessly). Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_012uzYijGHdhxvpUzhgWxayo
1 parent 342370e commit ec66d0a

16 files changed

Lines changed: 1273 additions & 184 deletions

File tree

‎docs/docs/configure/providers.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ registration request; **No** is selected by default. After registration, the mod
6868
explicit model is selected. Big Pickle is retired as a new selection — it no longer appears in the
6969
picker or the full model catalog for users choosing a model for the first time. Users already on
7070
Big Pickle are still detected on launch and offered Altimate Base through the same consent gate.
71+
If you decline the default switch, `declinedManagedBaseDefault: true` in the state directory's `model.json` keeps public Zen ahead of registered Base for headless and ACP defaults, with Base used only as a last resort; accepting migration or explicitly selecting Base clears the flag.
7172

7273
Official release binaries embed the current gateway endpoint at build time. Operators and local
7374
development can override it without changing code:

‎docs/docs/reference/telemetry.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ We collect the following categories of events:
5757
| `onboarding_started` | The first-run setup gate opened (fresh launch with no usable model). |
5858
| `model_picker_shown` | The provider picker was displayed. `trigger` distinguishes the first run from `/connect`, from declining Altimate Base, and from the prompt gate. |
5959
| `provider_selected` | A provider row was chosen — `altimate_gateway`, `altimate_base`, `anthropic`, `openai`, `google`, `search_all`, or `other` for anything outside the curated five. `provider_id` carries the raw id only for publicly-known providers, so a provider you named yourself in config is reported as `other` with no name attached. `via_search` marks a pick made inside the full catalogue after choosing "Search all providers…". **Choosing search emits this event twice for one user** — once as `search_all`, then again with the provider actually chosen — so count distinct users or filter on `via_search`, not raw event count. Recorded at the moment of choice, so a sign-in that is then cancelled still counts. |
60-
| `altimate_base_confirm_shown` / `altimate_base_choice` | The Altimate Base disclosure was shown (`welcome` or `model` origin), and what the user decided (`accept`/`cancel`). |
61-
| `altimate_base_register_result` | The consented registration outcome: `success`, `rate_limited`, `unavailable`, `network`, or `error`. No credential or gateway response body is included. |
60+
| `altimate_base_confirm_shown` / `altimate_base_choice` | The Altimate Base disclosure was shown, and what the user decided (`accept`/`cancel`). `origin` is `welcome`, `model`, or `migration` (returning free-default users offered Altimate Base on launch); required for the disclosure event and optional for the choice event. |
61+
| `altimate_base_register_result` | The consented registration outcome: `success`, `rate_limited`, `unavailable`, `network`, or `error`. Optional `origin` is `welcome`, `model`, or `migration` (returning free-default users offered Altimate Base on launch). No credential or gateway response body is included. |
6262
| `gateway_device_code_issued` | The Altimate Gateway authorize URL was built and the browser open attempted. **Name note:** the flow is a browser loopback OAuth — there is no device code. The name follows the original event spec. |
6363
| `gateway_auth_completed` / `gateway_auth_failed` | Gateway sign-in outcome. `reason` is `timeout`, `denied`, or `error` — never the underlying message, which can contain the instance name. An unrecognised callback state does not reject the pending attempt, so a CSRF mismatch surfaces as `timeout`. |
6464
| `instance_connected` | Credentials received and saved. `time_to_connect_ms` runs from the start of the authorize call, so it includes the browser launch. No instance or tenant name is sent. |

‎packages/opencode/src/acp/service.ts‎

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -811,10 +811,14 @@ async function loadDirectorySnapshot(sdk: OpencodeClient, directory: string) {
811811
// `model: "altimate-free/altimate-base"` alongside any `provider` allowlist end up with a
812812
// `defaultModel` pointing at a provider this snapshot had just excluded — ACP would still
813813
// select and route the managed model even though it was hidden from `modelOptions`.
814+
// The async snapshot loader also honors the TUI's persisted recents and default-switch decline.
815+
const { recent, declinedManagedBaseDefault } = await Provider.readDefaultModelState()
814816
const defaultModel = defaultModelFromConfig(
815817
config?.model,
816818
snapshotProviders,
817819
config?.provider as Record<string, unknown> | undefined,
820+
declinedManagedBaseDefault,
821+
recent,
818822
)
819823
// altimate_change end
820824
ACPProfile.duration("acp.directory.defaultModel.resolve", defaultModelStarted, { configured: !!defaultModel })
@@ -856,6 +860,10 @@ export function defaultModelFromConfig(
856860
configuredModel: string | undefined,
857861
providers: Record<ProviderV2.ID, Provider.Info>,
858862
providerFilter?: Record<string, unknown>,
863+
// altimate_change start — persisted recents and default-switch consent, normalized by the shared state reader
864+
declinedManagedBaseDefault = false,
865+
recent: Awaited<ReturnType<typeof Provider.readDefaultModelState>>["recent"] = [],
866+
// altimate_change end
859867
): Directory.DefaultModel | undefined {
860868
// altimate_change start — fork Provider ids are branded ProviderID/ModelID; re-brand to core ProviderV2.ID/ModelV2.ID (identity at runtime)
861869
const configured = configuredModel
@@ -869,6 +877,15 @@ export function defaultModelFromConfig(
869877
const configuredProviderEntries = Object.keys(providerFilter ?? {})
870878
const hasProviderAllowlist = configuredProviderEntries.length > 0
871879

880+
for (const entry of recent) {
881+
const providerID = ProviderV2.ID.make(entry.providerID)
882+
const modelID = ModelV2.ID.make(entry.modelID)
883+
if (!providers[providerID]?.models[modelID]) continue
884+
// Match Provider.defaultModel(): only managed Base recents are restricted by an allowlist.
885+
if (entry.providerID === "altimate-free" && hasProviderAllowlist) continue
886+
return { providerID, modelID }
887+
}
888+
872889
// Prefer altimate-backend/altimate-default when the fork's backend is available and the user
873890
// hasn't pinned a model — restores dropped fork behavior (the merge fell straight through to the
874891
// opencode provider, routing ACP clients away from altimate's backend). Honors an explicit
@@ -882,11 +899,21 @@ export function defaultModelFromConfig(
882899
return { providerID: ProviderV2.ID.make("altimate-backend"), modelID: ModelV2.ID.make("altimate-default") }
883900
}
884901

885-
// First-session ACP startup must not scan historical sessions just to infer
886-
// a default. Configured model, opencode provider, then sorted best model keep
887-
// the protocol response deterministic without extra session/message reads.
902+
// First-session ACP startup must not scan historical sessions just to infer a default.
903+
// Recents above come from model.json, not session storage. After configured/recent choices
904+
// and the backend preference, use the opencode provider, then the sorted best model,
905+
// without extra session/message reads.
906+
const baseProvider = providers[ProviderV2.ID.make("altimate-free")]
907+
const registeredBaseAvailable = Boolean(baseProvider?.models[ModelV2.ID.make("altimate-base")]) && !hasProviderAllowlist
888908
const providerAllowed = (id: string) =>
889-
id !== "altimate-free" && (!hasProviderAllowlist || Object.prototype.hasOwnProperty.call(providerFilter, id))
909+
id !== "altimate-free" &&
910+
(!hasProviderAllowlist || Object.prototype.hasOwnProperty.call(providerFilter, id)) &&
911+
!(
912+
registeredBaseAvailable &&
913+
!declinedManagedBaseDefault &&
914+
id === "opencode" &&
915+
providers[ProviderV2.ID.make(id)]?.options.apiKey === "public"
916+
)
890917
const opencodeProvider = providerAllowed("opencode") ? providers[ProviderV2.ID.make("opencode")] : undefined
891918
const opencodeModel = opencodeProvider
892919
? Provider.sort(Object.values(opencodeProvider.models)).find((model) => model.id !== "big-pickle")
@@ -901,12 +928,14 @@ export function defaultModelFromConfig(
901928
).find((model) => !(model.providerID === "opencode" && model.id === "big-pickle"))
902929
if (best) return { providerID: ProviderV2.ID.make(best.providerID), modelID: ModelV2.ID.make(best.id) }
903930

904-
// Altimate Base replaces Big Pickle as the free fallback, but only as a LAST resort and only
905-
// after the user consented and registered (which is why it is present in `providers`). Anything
906-
// else connected outranks the request-logging tier. A project provider block cannot force the
907-
// managed model; an explicit configured model above remains authoritative.
908-
const baseProvider = providers[ProviderV2.ID.make("altimate-free")]
909-
if (!hasProviderAllowlist && baseProvider?.models[ModelV2.ID.make("altimate-base")]) {
931+
// Altimate Base replaces Big Pickle as the free fallback only after the user consented and
932+
// registered (which is why it is present in `providers`). Anything the user actually connected
933+
// outranks the request-logging tier, except the keyless public Zen tier, which ranks below
934+
// registered Base unless the user declined the default switch in model.json. After a decline,
935+
// public Zen stays in both scans and Base is only the last resort. A keyed Zen account still
936+
// wins. A project provider block cannot force the managed model; an explicit configured model
937+
// above remains authoritative.
938+
if (registeredBaseAvailable) {
910939
return { providerID: ProviderV2.ID.make("altimate-free"), modelID: ModelV2.ID.make("altimate-base") }
911940
}
912941
return undefined

‎packages/opencode/src/altimate/telemetry/index.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,18 +1027,20 @@ export namespace Telemetry {
10271027
type: "altimate_base_confirm_shown"
10281028
timestamp: number
10291029
session_id: string
1030-
origin: "welcome" | "model"
1030+
origin: "welcome" | "model" | "migration"
10311031
}
10321032
| {
10331033
type: "altimate_base_choice"
10341034
timestamp: number
10351035
session_id: string
1036+
origin?: "welcome" | "model" | "migration"
10361037
choice: "accept" | "cancel"
10371038
}
10381039
| {
10391040
type: "altimate_base_register_result"
10401041
timestamp: number
10411042
session_id: string
1043+
origin?: "welcome" | "model" | "migration"
10421044
result: "success" | "rate_limited" | "unavailable" | "network" | "error"
10431045
}
10441046
| {

‎packages/opencode/src/provider/provider.ts‎

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,12 +2193,26 @@ export namespace Provider {
21932193
)
21942194
}
21952195

2196-
// altimate_change start — discard malformed persisted model references before use
2196+
// altimate_change start — normalize persisted model references and default-switch consent
21972197
function isModelReference(model: unknown): model is { providerID: ProviderID; modelID: ModelID } {
21982198
if (!model || typeof model !== "object") return false
21992199
const value = model as Record<string, unknown>
22002200
return typeof value.providerID === "string" && typeof value.modelID === "string"
22012201
}
2202+
2203+
// Share the TUI's persisted default-switch consent with headless and ACP selection.
2204+
// Missing, unreadable, or malformed state preserves the existing default behavior.
2205+
export async function readDefaultModelState() {
2206+
return Filesystem.readJson<{
2207+
recent?: { providerID: ProviderID; modelID: ModelID }[]
2208+
declinedManagedBaseDefault?: boolean
2209+
}>(path.join(Global.Path.state, "model.json"))
2210+
.then((state) => ({
2211+
recent: Array.isArray(state?.recent) ? state.recent.filter(isModelReference) : [],
2212+
declinedManagedBaseDefault: state?.declinedManagedBaseDefault === true,
2213+
}))
2214+
.catch(() => ({ recent: [], declinedManagedBaseDefault: false }))
2215+
}
22022216
// altimate_change end
22032217

22042218
export async function defaultModel() {
@@ -2218,11 +2232,7 @@ export namespace Provider {
22182232
const baseModelID = ModelID.make(FreeTier.MODEL_ID)
22192233
const baseProvider = providers[baseProviderID]
22202234
const registeredBaseAvailable = Boolean(baseProvider?.models[baseModelID]) && !hasProviderAllowlist
2221-
const recent = (await Filesystem.readJson<{ recent?: { providerID: ProviderID; modelID: ModelID }[] }>(
2222-
path.join(Global.Path.state, "model.json"),
2223-
)
2224-
.then((x) => (Array.isArray(x.recent) ? x.recent.filter(isModelReference) : []))
2225-
.catch(() => [])) as { providerID: ProviderID; modelID: ModelID }[]
2235+
const { recent, declinedManagedBaseDefault } = await readDefaultModelState()
22262236
for (const entry of recent) {
22272237
// A recent entry is the user's own last pick, so it is never rewritten here — not even a
22282238
// legacy Big Pickle one. The TUI owns the migration because it owns the disclosure, and
@@ -2258,9 +2268,12 @@ export namespace Provider {
22582268
// altimate_change end
22592269

22602270
// altimate_change start — select registered Altimate Base and never select Big Pickle implicitly
2261-
// Altimate Base owns the free fallback role that used to belong to Big Pickle, but only as a
2262-
// LAST resort. Anything the user has actually connected outranks the request-logging tier, so
2263-
// adding a paid key never silently routes prompts to the free gateway. A project provider
2271+
// Altimate Base owns the free fallback role that used to belong to Big Pickle. Anything the
2272+
// user has actually connected outranks the request-logging tier; the keyless public Zen tier
2273+
// ranks below registered Base unless the user declined the default switch in model.json.
2274+
// After a decline, public Zen stays in the scan and Base is only the last resort.
2275+
// A keyed Zen account still wins, so adding a paid key never silently routes prompts to the
2276+
// free gateway. A project provider
22642277
// block cannot force the managed model; an explicit `model` setting above remains
22652278
// authoritative.
22662279
// Base is excluded from the ordinary scan so it can only be reached by the last-resort branch
@@ -2270,6 +2283,13 @@ export namespace Provider {
22702283
)
22712284
if (candidates.length === 0 && !registeredBaseAvailable) throw new Error("no providers found")
22722285
for (const provider of candidates) {
2286+
if (
2287+
registeredBaseAvailable &&
2288+
!declinedManagedBaseDefault &&
2289+
provider.id === "opencode" &&
2290+
provider.options.apiKey === "public"
2291+
)
2292+
continue
22732293
const model = sort(Object.values(provider.models)).find(
22742294
(candidate) => !(provider.id === "opencode" && candidate.id === "big-pickle"),
22752295
)

0 commit comments

Comments
 (0)