Claude Code. Any Model. The most powerful AI coding agent now speaks every language.
test: the routing gate, and the backend's reply on the v3 contract
Jack Rudenko182116ebd236
diff --git a/ai-docs/reports/REPLY_FEEDBACK_catalog_contract_v3-20260909.md b/ai-docs/reports/REPLY_FEEDBACK_catalog_contract_v3-20260909.mdnew file mode 100644index 00000000..72d60835--- /dev/null+++ b/ai-docs/reports/REPLY_FEEDBACK_catalog_contract_v3-20260909.md@@ -0,0 +1,210 @@+# Reply to Claudish Feedback — Catalog Contract v3++**Feedback reviewed:** `/Users/jack/mag/claudish/.claude/worktrees/nok3/ai-docs/reports/FEEDBACK_catalog_contract_v3-20260909.md`+**Replacement plan:** `/Users/jack/mag/models-index/.claude/worktrees/new-subscriptin-model/ai-docs/final-catalog-v3-plan.md`+**Disposition:** all substantive findings are accepted; two requested outcomes are qualified at their actual evidence/ownership boundaries. No product code or deployment is part of this response.++## Decision vocabulary++- **Accepted:** incorporated as stated.+- **Accepted with qualification:** the underlying issue is accepted, but the evidence or repository boundary does not support the full requested guarantee.+- **Rejected:** not incorporated because source evidence contradicts it or it violates the clean-v3 decision.++No feedback section is rejected wholesale.++## A. Confirmed decisions++These remain fixed and are not reopened.++| Feedback item | Decision | Result in replacement plan |+|---|---|---|+| Only canonical and mapped inclusions create membership | Accepted | `ModelInclusionV3` is the sole membership input. Family/display/prose/qualifier rows cannot carry canonical membership. Raw collector and manual-override membership writes are forbidden. |+| `(routeId, routeProfileId)` separates provider identity from endpoint/credential silo | Accepted | `RouteBindingV3` remains required for supported routes. Direct and subscription profiles have distinct endpoint and credential IDs. |+| Immutable generations, sealed SHA-256 manifest, CAS activation, pinned pagination | Accepted | Preserved with create-only writes, readback, deterministic hashing, immutable activation, pinning, rollback, and retention. |+| Read-time roster coverage/expiry | Accepted | Preserved. Expiry immediately removes negative authority even if active generation does not change. |+| Redirects are separate evidence-bearing records | Accepted | `ProviderModelRedirectV3` remains separate from memberships and aliases. GLM redirects remain explicit. |+| Same-target duplicate dedupe; conflicts block activation | Accepted | Preserved as a reconciliation and activation invariant. |+| Canonical provider IDs are `anthropic` and `moonshotai` | Accepted | Strict route enum keeps these names and rejects `native-anthropic` and consumer route ID `kimi`. |++Evidence agreement: current `subscription-plan-membership.ts` performs a string/alias join; current v2 plan and aggregator shapes in `schema.ts` permit the ambiguous states the discriminated v3 contracts remove. The replacement plan continues to delete the defect classes instead of adding v2 guards.++## B. Open item 1 — Codex roster authority++### Decision: Accepted++The plan now changes `openai-codex` from `catalog` to `hybrid`.++Source evidence:++- `functions/src/collectors/scraper/openai-codex-models.ts` selects public rows with:++ ```ts+ model.supported_in_api === true && model.visibility !== "hide"+ ```++- The source is the public checked-in Codex model registry. That predicate establishes public API visibility/eligibility. It does not establish exhaustive entitlement for a user's ChatGPT/Codex subscription.+- Freshly fetching a source changes observation freshness; it does not broaden the source's authority.++Applied corrections:++1. The public registry is supplemental positive evidence only.+2. A public exact row may add an inclusion.+3. Public absence may not prove non-entitlement, remove membership, produce `not-served`, or satisfy an authoritative roster requirement.+4. Account-authenticated client discovery is the entitlement authority.+5. `OPENAI_CODEX_FALLBACK_MODEL_SLUGS` is removed from the v3 collector path. A hardcoded fallback list establishes neither membership, completeness, nor freshness.+6. The supported route remains `openai/codex-subscription`; route support and roster authority are independent.++This also generalizes the plan's authority rule: authentication determines evidence scope; freshness alone never upgrades public product metadata into account-entitlement evidence.++## C. Open item 2 — seven Mistral moving-pointer rows++### Decision: Accepted with evidence qualification++The safety finding is accepted: a dated canonical model must not publish a mutable pointer as if it were that dated model's exact callable external ID.++Applied contract correction:++- `AggregatorRouteV3` now places `externalModelId` only on the `mapped` branch.+- The `unknown` branch may retain `observedExternalModelId` as non-callable evidence and adds `mutable_pointer_only` and `identity_conflict` reasons.+- A mapped dated Mistral route requires official evidence that the external ID is both callable and identifies that exact dated model.+- A model-card/page slug, date similarity, mutable alias, successor relationship, or inferred naming convention is insufficient.++Seven mandatory audit fixtures are now in the plan:++| Canonical model | Observed pointer | Default safe result |+|---|---|---|+| `codestral-2508` | `mistral-code-fim-latest` | unknown `mutable_pointer_only` |+| `ministral-3-14b-instruct-2512` | `ministral-14b-latest` | unknown `mutable_pointer_only` |+| `ministral-3-3b-instruct-2512` | `ministral-3b-latest` | unknown `mutable_pointer_only` |+| `ministral-3-8b-instruct-2512` | `ministral-8b-latest` | unknown `mutable_pointer_only` |+| `mistral-large-2512` | `mistral-large-latest` | unknown `mutable_pointer_only` |+| `mistral-medium-2604` | `magistral-medium-latest` | drop mapping; unknown `identity_conflict` if retained as evidence |+| `mistral-small-2603` | `magistral-small-latest` | drop mapping; unknown `identity_conflict` if retained as evidence |++The qualification is about exact replacement IDs: this architecture review does not claim a dated wire ID is callable unless a refreshed official API/documented fixture proves it. Where that proof exists at implementation time, the exact ID may be mapped. Otherwise the route remains unknown.++The two family concerns are accepted, not left ambiguous. Repository source separates Mistral and Magistral model-page mappings, and `functions/src/merger-aliases.test.ts` already asserts that `magistral-small-latest` must not alias Mistral Small or `mistral-small-2603`. The replacement plan extends that invariant to both Medium and Small and to serving rows. It does not infer which dated Magistral model a moving pointer currently targets.++## D. Open risk — client propagation and cutover++### D1. The coordination risk++**Decision: Accepted.** “Clients must update” was an assumption and is now a hard external dependency with an owner, test evidence, and cutover gate.++### D2. Cutover date with lead time++**Decision: Accepted with scheduling qualification.** The replacement plan names **2026-10-07 as the no-earlier-than cutover date**, providing 28 days from the feedback date. It is an earliest eligibility date, not deployment authorization. It may move later. The plan forbids moving earlier without a newly reviewed safety decision.++The date remains gated on:++- a Claudish safety release shipping first;+- a v3-capable Claudish build passing emulator acceptance;+- backend tests/build/emulator checks passing;+- deliberate route/recommendation diff review;+- owner acknowledgment of residual never-updated-client risk;+- separate production authorization.++### D3. `contractVersion` on all response shapes++**Decision: Accepted.** Every v3 success and error body, including HTTP 410, 426, and 503, requires `contractVersion: 3`.++The plan adds explicit protocol negotiation:++```http+Accept: application/vnd.models-index.catalog+json;version=3+```++Missing or wrong negotiation receives versioned HTTP 426 `catalog_client_upgrade_required` and never a v3 success payload. A pinned generation no longer retained receives versioned 410 `generation_gone`. Missing/corrupt active state receives versioned 503 `catalog_unavailable`. This is rejection, not dual serving or compatibility.++### D4. Guarantee that any un-updated client fails visibly++**Decision: Accepted as a client requirement; rejected as a backend-only guarantee.**++The current shipped Claudish source prevents the backend from honestly making that guarantee:++- `packages/cli/src/providers/catalog-client.ts:400` returns `{ kind: "fetch_failed", reason: "http_error" }` for any non-2xx response without parsing its body.+- The function documentation at lines 384–386 says failures leave memory and disk caches untouched.+- `warmCatalog` is documented at line 455 as falling through to the disk-read fallback.+- `ensureCatalogReady` at lines 463–465 proceeds with whatever the disk cache holds.++Therefore backend 426 prevents schema-blind parsing of a v3 200 response, but an already installed client can ignore the body and continue with stale v2 cache. The backend cannot update an npm installation, erase its filesystem, or force its resolver to surface an error.++The replacement plan consequently requires a Claudish safety release to detect 426/v3, invalidate or refuse unsafe v2 cache routing, and fail loudly before production cutover. Claudish must prove that behavior. Any claim that all pre-safety-release installations fail visibly would exceed the observed evidence.++This qualification is not a request for compatibility. There is still no v2 success service, parser, converter, old-root read, or dual write in v3.++### D5. Pre-cutover integration target++**Decision: Accepted.** The canonical target is local Firebase Emulator Suite using project ID `demo-models-index`. A real Claudish build can point to emulator Functions using the already present `CLAUDISH_CATALOG_URL` and `CLAUDISH_PLANS_URL` overrides in `packages/cli/src/providers/catalog-client.ts`.++The backend rehearsal builds and activates emulator generations G0 and G1, enabling generation pinning, 410, expiry, rollback, and active/previous tests. A remote staging Firebase project is optional, not assumed, and requires separate authorization and credentials. Production is not a validation environment.++## E. Claudish commitments++### Decision: Recorded as dependencies; not credited as completed++| Claudish commitment | Backend dependency/disposition |+|---|---|+| v3/426 detector with loud failure | Hard pre-cutover gate; client-owned evidence required |+| canonical route IDs; old names user-facing only | Required for v3 acceptance; shortcuts remain outside backend contract |+| `(routeId, routeProfileId)` model | Required to preserve endpoint/credential billing isolation |+| read `plan.route` and `sourceProviderId` | Required before consuming v3 |+| generation pinning and 410/503 handling | Required in shared emulator test |+| consume `rosterCoverage` and remove over-broad roster inference | Required for correct negative verdicts; may ship after initial v3 only if the initial client treats non-complete coverage conservatively |+| independently rank aggregator rows, scope membership to plan, log unresolved routes | Acknowledged as client work outside this backend implementation |++No statement in the replacement plan claims these client changes have been implemented or tested.++Qualification on sequencing: a v3 client cannot safely defer conservative handling of `rosterCoverage`. It may defer removal of old internal code after v3 goes live, but until then it must treat expired/unknown coverage as incapable of proving absence. Otherwise the contract's freshness guarantee would be lost at consumption.++## F. Validation ownership++### F1. Backend-owned tests — Accepted and expanded++The replacement plan adds or preserves:++- strict schema and recursive forbidden-name scans;+- exact 19-plan decision matrix;+- Codex supplemental/hybrid tests and prohibition on fallback-derived membership;+- all seven Mistral pointer/family fixtures;+- Alibaba ten-row evidence and absolute Qwen credential/endpoint isolation;+- GLM redirect separation;+- roster completeness, scope, carry-forward, and read-time expiry;+- immutable generation, hash, readback, CAS, pinning, rollback, and retention tests;+- exact response-body coverage for success, 410, 426, and 503;+- all query/projection modes against `demo-models-index`;+- recommendation/default/search/changelog generation consistency;+- recursive rejection of all forbidden v2 fields/names.++### F2. Client-only validation — Accepted with one wording correction++The four feedback scenarios remain client-owned, with this precise first scenario:++1. A **Claudish safety release**, not an arbitrary never-updated binary, meeting 426 or v3 fails visibly, refuses unsafe v2-cache routing, and does not silently choose metered service.+2. `qwen3.5-plus` remains unknown rather than not-served for unsupported Alibaba Coding Plan routing; Alibaba credentials never reach Qwen Token Plan.+3. GLM 4.5/4.6/4.7 membership and actual execution identity match the approved redirect contract.+4. Recommended-set diff is unchanged or every change is deliberate.++The original wording “an un-updated Claudish ... fails visibly” cannot be proven by backend integration because observed old-client source ignores non-2xx bodies and retains cache. The safety release is the first version that can satisfy that acceptance criterion.++## Summary of plan changes++1. `openai-codex`: `catalog` → `hybrid`; public registry supplemental; fallback membership removed.+2. `AggregatorRouteV3`: callable external ID only on mapped branch; evidence-specific unknown reasons added.+3. Seven Mistral rows receive exact pointer/family audit rules and regression tests.+4. `magistral-*` is explicitly prohibited from routing Mistral Medium/Small.+5. Explicit v3 `Accept` negotiation and versioned 426/410/503 contracts added.+6. `contractVersion: 3` required on every v3 body.+7. `2026-10-07` named as no-earlier-than cutover eligibility date with hard prerequisites.+8. Local `demo-models-index` emulator plus Claudish URL overrides defined as the shared target.+9. Old-client cache behavior documented as a client-owned residual risk rather than a backend guarantee.+10. Backend and client test ownership separated so no unimplemented Claudish work is credited.++## Rejected items++No substantive feedback request is rejected. Two overbroad implications are rejected on observed evidence:++- freshness of a public Codex registry cannot establish exhaustive subscription entitlement;+- a backend 426 cannot by itself guarantee visible failure in every already-installed Claudish version that ignores non-2xx bodies and retains disk cache.++Both rejections strengthen, rather than weaken, the requested data-safety goal.diff --git a/scripts/route-table-snapshot.ts b/scripts/route-table-snapshot.tsnew file mode 100644index 00000000..493c4127--- /dev/null+++ b/scripts/route-table-snapshot.ts@@ -0,0 +1,220 @@+#!/usr/bin/env bun+/**+ * The routing gate: pin the route of every catalog model, then prove a change moved+ * only what it meant to move.+ *+ * The routing redesign replaces a hand-written table with candidates gathered from+ * the cloud models catalog. That changes EVERY bare-name route at once, so the only+ * honest gate is the whole table, read twice. A passing test suite cannot show this:+ * the suite asserts the routes someone thought to write down, and the ones nobody+ * wrote down are exactly where a silent removal hides.+ *+ * Capture BEFORE the change, capture again after, then diff:+ *+ * bun run scripts/route-table-snapshot.ts capture before.json+ * # ... make the change ...+ * bun run scripts/route-table-snapshot.ts capture after.json+ * bun run scripts/route-table-snapshot.ts diff before.json after.json+ *+ * The diff classifies every difference. `lost` is the one that must be empty unless+ * the design names that removal: a provider that used to serve a model and no longer+ * appears is a user whose key stopped working, with no error to read.+ *+ * Environment-dependent by design. It calls the real `route()`, so it sees this+ * machine's credentials and `defaultProvider`. Both snapshots must come from the+ * same machine with the same configuration, which is why each file records them.+ */++import { readFileSync } from "node:fs";+import { homedir } from "node:os";+import { join } from "node:path";+import { loadConfig } from "../packages/cli/src/profile-config.js";+import { readAllModelsCache } from "../packages/cli/src/providers/all-models-cache.js";+import { route } from "../packages/cli/src/providers/routing-rules.js";++/** One model's resolved chain, flattened to the strings a request would carry. */+interface RouteRow {+ modelId: string;+ kind: "ok" | "no-route";+ /** `provider@model` per hop, primary first. Empty for `no-route`. */+ chain: string[];+ /** Why there is no route, verbatim. Only for `no-route`. */+ reason?: string;+}++interface Snapshot {+ capturedAt: string;+ catalogGenerationId: string;+ /** Recorded because the chain is credential-filtered: a different machine gives a different table. */+ defaultProvider: string | undefined;+ entryCount: number;+ rows: RouteRow[];+}++/** How many routes to resolve at once. `route()` can touch discovery, so it is not free. */+const CONCURRENCY = 8;++async function capture(outPath: string, limit?: number): Promise<void> {+ const cache = readAllModelsCache();+ if (!cache || cache.entries.length === 0) {+ console.error(+ `No cloud models catalog cache at ${join(homedir(), ".claudish", "cloud-models-catalog-v3.json")}.\n` ++ "Refresh it first — an empty catalog captures an empty table, which would make any diff look clean.",+ );+ process.exit(1);+ }++ const modelIds = cache.entries.map((entry) => entry.modelId);+ const ids = limit ? modelIds.slice(0, limit) : modelIds;+ const rows: RouteRow[] = [];+ let done = 0;++ for (let start = 0; start < ids.length; start += CONCURRENCY) {+ const batch = ids.slice(start, start + CONCURRENCY);+ const settled = await Promise.all(+ batch.map(async (modelId): Promise<RouteRow> => {+ try {+ const plan = await route(modelId);+ if (plan.kind === "ok") {+ return {+ modelId,+ kind: "ok",+ chain: [plan.primary, ...plan.fallbacks].map((hop) => hop.modelSpec),+ };+ }+ return { modelId, kind: "no-route", chain: [], reason: plan.reason };+ } catch (error) {+ // A throw is itself a finding: record it rather than losing the row.+ return {+ modelId,+ kind: "no-route",+ chain: [],+ reason: `threw: ${error instanceof Error ? error.message : String(error)}`,+ };+ }+ }),+ );+ rows.push(...settled);+ done += batch.length;+ if (done % 200 === 0 || done === ids.length) {+ process.stderr.write(` resolved ${done}/${ids.length}\n`);+ }+ }++ const snapshot: Snapshot = {+ capturedAt: new Date().toISOString(),+ catalogGenerationId: cache.catalogGenerationId,+ defaultProvider: loadConfig().defaultProvider,+ entryCount: cache.entries.length,+ rows,+ };+ await Bun.write(outPath, `${JSON.stringify(snapshot, null, 2)}\n`);++ const routed = rows.filter((row) => row.kind === "ok").length;+ console.log(+ `Wrote ${outPath}: ${rows.length} models, ${routed} routed, ${rows.length - routed} with no route, generation ${snapshot.catalogGenerationId}.`,+ );+}++function loadSnapshot(path: string): Snapshot {+ return JSON.parse(readFileSync(path, "utf-8")) as Snapshot;+}++function diff(beforePath: string, afterPath: string): void {+ const before = loadSnapshot(beforePath);+ const after = loadSnapshot(afterPath);++ if (before.catalogGenerationId !== after.catalogGenerationId) {+ console.warn(+ `WARNING: different catalog generations (${before.catalogGenerationId} vs ${after.catalogGenerationId}).\n` ++ "Differences below mix the code change with a catalog change and cannot be attributed to either.\n",+ );+ }+ if (before.defaultProvider !== after.defaultProvider) {+ console.warn(+ `WARNING: defaultProvider differs (${before.defaultProvider ?? "(none)"} vs ${after.defaultProvider ?? "(none)"}). The fallback hop will differ for every model.\n`,+ );+ }++ const beforeRows = new Map(before.rows.map((row) => [row.modelId, row]));+ const afterRows = new Map(after.rows.map((row) => [row.modelId, row]));++ const lost: string[] = []; // a provider that used to serve this model no longer appears+ const gained: string[] = []; // a new provider appears+ const reordered: string[] = []; // same providers, different order+ const becameNoRoute: string[] = [];+ const becameRouted: string[] = [];+ const disappeared: string[] = []; // model absent from the after snapshot+ const appeared: string[] = [];++ for (const [modelId, beforeRow] of beforeRows) {+ const afterRow = afterRows.get(modelId);+ if (!afterRow) {+ disappeared.push(modelId);+ continue;+ }+ if (beforeRow.kind === "ok" && afterRow.kind === "no-route") {+ becameNoRoute.push(`${modelId}: had ${beforeRow.chain.join(" -> ")}; now ${afterRow.reason ?? "no reason"}`);+ continue;+ }+ if (beforeRow.kind === "no-route" && afterRow.kind === "ok") {+ becameRouted.push(`${modelId}: now ${afterRow.chain.join(" -> ")}`);+ continue;+ }+ const beforeSet = new Set(beforeRow.chain);+ const afterSet = new Set(afterRow.chain);+ const missing = beforeRow.chain.filter((hop) => !afterSet.has(hop));+ const extra = afterRow.chain.filter((hop) => !beforeSet.has(hop));+ if (missing.length > 0) {+ lost.push(`${modelId}: lost ${missing.join(", ")} (was ${beforeRow.chain.join(" -> ")})`);+ }+ if (extra.length > 0) {+ gained.push(`${modelId}: gained ${extra.join(", ")}`);+ }+ if (missing.length === 0 && extra.length === 0 && beforeRow.chain.join("|") !== afterRow.chain.join("|")) {+ reordered.push(`${modelId}: ${beforeRow.chain.join(" -> ")} => ${afterRow.chain.join(" -> ")}`);+ }+ }+ for (const modelId of afterRows.keys()) {+ if (!beforeRows.has(modelId)) appeared.push(modelId);+ }++ const section = (title: string, lines: string[], verdict: "must-be-empty" | "review"): void => {+ const mark = lines.length === 0 ? "none" : `${lines.length}`;+ console.log(`\n## ${title} — ${mark}${verdict === "must-be-empty" && lines.length > 0 ? " <-- MUST be named by the design" : ""}`);+ for (const line of lines.slice(0, 40)) console.log(` ${line}`);+ if (lines.length > 40) console.log(` … ${lines.length - 40} more`);+ };++ console.log(+ `Route table: ${before.rows.length} models before, ${after.rows.length} after, generation ${after.catalogGenerationId}.`,+ );+ section("Routes LOST", lost, "must-be-empty");+ section("Became no-route", becameNoRoute, "must-be-empty");+ section("Models disappeared from the table", disappeared, "must-be-empty");+ section("Routes GAINED", gained, "review");+ section("Became routed", becameRouted, "review");+ section("Order changed, same providers", reordered, "review");+ section("Models appeared in the table", appeared, "review");++ const blocking = lost.length + becameNoRoute.length + disappeared.length;+ console.log(+ `\nVerdict: ${blocking === 0 ? "no route was removed" : `${blocking} removals to justify or fix`}.`,+ );+ process.exit(blocking === 0 ? 0 : 1);+}++const [command, a, b] = process.argv.slice(2);+if (command === "capture" && a) {+ const limitArg = process.argv.find((arg) => arg.startsWith("--limit="));+ await capture(a, limitArg ? Number(limitArg.split("=")[1]) : undefined);+} else if (command === "diff" && a && b) {+ diff(a, b);+} else {+ console.error(+ "usage:\n" ++ " bun run scripts/route-table-snapshot.ts capture <out.json> [--limit=N]\n" ++ " bun run scripts/route-table-snapshot.ts diff <before.json> <after.json>",+ );+ process.exit(2);+}