Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(model-hub): spell route hops like the inventory, publish contract v6

cyh44bd53b48cef
diff --git a/config/v2_config.py b/config/v2_config.py
index 33900d99b..8546a87a7 100644
--- a/config/v2_config.py
+++ b/config/v2_config.py
@@ -2914,7 +2914,13 @@ class ModelHubRouteHopConfig:
or _contains_model_hub_credential_material(model_id)
):
raise ValueError("Config 'model_hub.agents.routes.hops.model_id' is invalid")
- return cls(source_id=source_id, model_id=model_id)
+ # A hop names a model in some source's inventory, and membership is decided
+ # by an exact comparison against that inventory. So the reference has to be
+ # spelled by whatever spells the thing it refers to: normalizing one side
+ # only would turn a working chain into `model_unsupported` on upgrade.
+ from core.handlers.model_hub.identifiers import normalized_model_id
+
+ return cls(source_id=source_id, model_id=normalized_model_id(model_id))
def to_payload(self) -> dict:
return {"source_id": self.source_id, "model_id": self.model_id}
@@ -2932,10 +2938,23 @@ class ModelHubRouteConfig:
if not isinstance(hops, list):
raise ValueError("Config 'model_hub.agents.routes.hops' must be an array")
parsed = tuple(ModelHubRouteHopConfig.from_payload(hop) for hop in hops)
- pairs = [(hop.source_id, hop.model_id) for hop in parsed]
- if len(set(pairs)) != len(pairs):
+ # Duplicates as written stay a malformed payload. Duplicates that appear
+ # only once spelling is settled are a legacy file naming one upstream model
+ # in two spellings — the second hop could never have been reached past the
+ # first, so dropping it preserves the chain, where raising would fail the
+ # config load the persisted-shape rule requires to succeed.
+ as_written = [(hop["source_id"], hop["model_id"]) for hop in hops]
+ if len(set(as_written)) != len(as_written):
raise ValueError("Config 'model_hub.agents.routes.hops' must contain unique pairs")
- return cls(hops=parsed)
+ deduplicated: list[ModelHubRouteHopConfig] = []
+ seen: set[tuple[str, str]] = set()
+ for hop in parsed:
+ pair = (hop.source_id, hop.model_id)
+ if pair in seen:
+ continue
+ seen.add(pair)
+ deduplicated.append(hop)
+ return cls(hops=tuple(deduplicated))
def to_payload(self) -> dict:
return {"hops": [hop.to_payload() for hop in self.hops]}
diff --git a/core/handlers/model_hub/provenance.py b/core/handlers/model_hub/provenance.py
index be6eb5773..b846f8155 100644
--- a/core/handlers/model_hub/provenance.py
+++ b/core/handlers/model_hub/provenance.py
@@ -1369,7 +1369,7 @@ class TurnCorrelationRegistry:
self.store.put(
{
- "contract_version": 5,
+ "contract_version": 6,
"turn_id": normalized_turn_id,
"ts": ts or _utc_now_iso(),
"agent": trace.agent,
diff --git a/core/handlers/model_hub/service.py b/core/handlers/model_hub/service.py
index f63d35b3a..7f9b9f545 100644
--- a/core/handlers/model_hub/service.py
+++ b/core/handlers/model_hub/service.py
@@ -112,9 +112,9 @@ from .resolver import (
from .revocations import CredentialRevocationJournal
from .usage import USAGE_DEFAULT_WINDOW_DAYS, BoundedUsageLedger
-CONTRACT_VERSION = 5
-AGENT_CHAIN_CONTRACT_VERSION = 5
-PROBE_RESULT_CONTRACT_VERSION = 5
+CONTRACT_VERSION = 6
+AGENT_CHAIN_CONTRACT_VERSION = 6
+PROBE_RESULT_CONTRACT_VERSION = 6
# Settlement generations are minted per attempt start and live only in this
# runtime's ledger, which restarts with the process. Every generation this
# runtime mints is therefore strictly greater than this pre-attempt value, and
@@ -540,7 +540,7 @@ def _runtime_payload(status: EngineStatus) -> dict:
manager = EngineRuntimeManager()
return {
- "contract_version": 5,
+ "contract_version": 6,
"host_platform": status.host_platform or manager.host_platform(),
"manifest": manager.contract_manifest(),
"status": {
diff --git a/docs/plans/model-hub-contracts/README.md b/docs/plans/model-hub-contracts/README.md
index 6670b0737..ddf50be8f 100644
--- a/docs/plans/model-hub-contracts/README.md
+++ b/docs/plans/model-hub-contracts/README.md
@@ -1,12 +1,19 @@
# Model Hub contracts
-Status: **FINAL v5 shape, implementation-gated (2026-08-11 contract completion)**.
+Status: **FINAL shape, implementation-gated. `contract_version` is 6 (2026-08-19 usage
+metering); 5 published the 2026-08-11 contract completion.**
-These files describe the terminal contract for Model Hub before first release. There is
-no v4-to-v5 data migration, compatibility reader, conversion transaction, or version
-discriminator: Model Hub has not shipped. `contract_version` is 5 wherever a versioned
-object exists. The owner-approved pre-release network correction removes the earlier
-persistent network/timeout cooldown spelling without adding a compatibility path.
+These files describe the terminal contract for Model Hub before first release. No bump
+carries a data migration, compatibility reader, conversion transaction, or version
+discriminator: Model Hub has not shipped, so republishing the shape converts nothing.
+`contract_version` is 6 wherever a versioned object exists. The owner-approved
+pre-release network correction removes the earlier persistent network/timeout cooldown
+spelling without adding a compatibility path.
+
+`v5` is still written throughout these files and stays: it names the contract-completion
+generation they were authored in, and sentences such as "Minimum v5 set" or
+`adapter-interface.py`'s dated header describe what that generation said. Only
+`contract_version` — the value a consumer reads and the closure below guards — moves.
The contracts and their consumers must coexist on one tested PR head before Model Hub
can be enabled. CI evaluates that head, not individual commits. A green intermediate
@@ -83,7 +90,7 @@ comparison. A gate may not report success by comparing stale input with itself.
## Version closure
-The terminal value 5 must coexist in all registered version locations on the same tested head:
+The terminal value 6 must coexist in all registered version locations on the same tested head:
- `mirror-registry.json`
- `agent-chain.schema.json`
@@ -92,11 +99,30 @@ The terminal value 5 must coexist in all registered version locations on the sam
- `runtime-dependency.schema.json`
- `guard-refusal.schema.json`
- `turn-provenance.schema.json`
+- `api-response.schema.json`
+- `api.md`
- `core/handlers/model_hub/service.py`
- `core/handlers/model_hub/provenance.py`
+- `ui/src/components/settings/models/types.ts`
- `tests/test_model_hub_config.py`
- `tests/test_model_hub_api.py`
- `tests/test_model_hub_l3.py`
+- `tests/test_model_hub_resolution.py`
+- `tests/test_model_hub_runtime.py`
+- `ui/src/components/settings/models/*.test.*`
+
+`tests/test_model_hub_config.py::test_every_versioned_object_ends_at_the_terminal_version_the_code_writes`
+enforces the closure over whatever schemas this directory holds rather than over this
+list, so a versioned object added later is covered without an edit here. This list stays
+as the reader's map of where the value is published.
+
+One object diverges, and only in what it accepts. Every versioned object except
+`TurnProvenance` is an envelope built and consumed inside one request, so it is pinned
+to the terminal value alone. `TurnProvenance` is written to disk, where records a
+released build persisted outlive the bump that republished the shape — the same
+persisted-shape rule that governs config files. It therefore accepts the released values
+as a set ending at the terminal one, and nothing branches on which member a record
+carries.
The three-value protocol closure includes `source.schema.json`, `adapter-interface.py`,
and the byte-identical `core/handlers/model_hub/adapter.py` on the same tested head.
@@ -115,13 +141,15 @@ revision; the discovering lane does not reinterpret or edit the contract in plac
| `agent-chain.schema.json` | Read projection of exact stored hops plus current execution position, runnability, blockers, live connection backoff, retry metadata, and model supply state. |
| `probe-result.schema.json` | Saved recovery probes and route probes over exact configured hops, including the live connection-backoff reason without persistent network health. |
| `observation-result.schema.json` | Non-persisting Add-time connectivity, authentication, response-backed protocol, and inventory observation. |
-| `turn-provenance.schema.json` | Exactly attributed turn attempts and terminal outcome; no policy or mapping discriminator. |
+| `turn-provenance.schema.json` | Exactly attributed turn attempts and terminal outcome; no policy or mapping discriminator. The one versioned object persisted to disk, so it accepts every released version. |
+| `usage-summary.schema.json` | Metered token usage over a trailing local-day window, aggregated from proxied turns. A report only: no consumer may feed it back into resolution, admission, or cooldown. |
| `resolution-event.schema.json` | Pull-feed Source/resolution records and their closed reason/detail vocabulary. |
| `oauth-flow.schema.json` | Subscription creation and re-auth presentation without secret material. |
| `migration-scan.schema.json` | Copy-only import of existing native CLI/provider configuration; not an internal contract migration. |
| `runtime-dependency.schema.json` | Managed local Gateway asset, lifecycle, and health. |
| `guard-refusal.schema.json` | Shared guarded-mutation refusal whose two arrays are the exact plan echoed by a confirmed retry. |
-| `api.md` | Routes, envelopes, exact Source order and Route-chain writes, guards, OAuth/import results, provenance, and runtime status. |
+| `api.md` | Routes, envelopes, exact Source order and Route-chain writes, guards, OAuth/import results, provenance, usage, and runtime status. |
+| `api-response.schema.json` | Machine-readable response contract and real-response exercise for every route in `api.md`, at exact route-table parity. |
| `opencode-overlay.md` | Stable OpenCode provider/model identifiers and exact configured-hop overlay behavior. |
| `adapter-interface.py` | Adapter protocol, observation, credential, discovery, invocation, cleanup, and classification boundary. |
| `mirror-registry.json` | Executable authority/mirror registry and terminal contract version. |
diff --git a/docs/plans/model-hub-contracts/agent-chain.schema.json b/docs/plans/model-hub-contracts/agent-chain.schema.json
index 4574a813b..8b54df1b0 100644
--- a/docs/plans/model-hub-contracts/agent-chain.schema.json
+++ b/docs/plans/model-hub-contracts/agent-chain.schema.json
@@ -7,7 +7,7 @@
"required": ["contract_version", "backend", "model_id", "chain", "current", "supply_state"],
"additionalProperties": false,
"properties": {
- "contract_version": { "const": 5 },
+ "contract_version": { "const": 6 },
"backend": { "enum": ["claude", "codex", "opencode"] },
"model_id": { "type": "string" },
"current": {
@@ -161,7 +161,7 @@
],
"examples": [
{
- "contract_version": 5,
+ "contract_version": 6,
"backend": "claude",
"model_id": "claude-opus-4-6",
"chain": [{ "source_id": "src_claudepro1", "model_id": "claude-opus-4-6", "channel": "native_cli", "health": "cooldown", "runnable": false, "reason": null, "retry_at": "2026-07-29T04:00:00Z" }],
@@ -169,7 +169,7 @@
"supply_state": "waiting"
},
{
- "contract_version": 5,
+ "contract_version": 6,
"backend": "opencode",
"model_id": "custom/glm-5.2",
"chain": [{ "source_id": "src_relay9c1x", "model_id": "glm-5.2", "channel": "hub", "health": "backoff", "runnable": false, "reason": "models.source.backoff.connection_failed", "retry_at": "2026-08-11T11:55:08Z" }],
@@ -177,7 +177,7 @@
"supply_state": "waiting"
},
{
- "contract_version": 5,
+ "contract_version": 6,
"backend": "codex",
"model_id": "gpt-5.6",
"chain": [{ "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "channel": "native_cli", "health": "healthy", "runnable": false, "reason": "native_cli_unavailable", "retry_at": null }],
@@ -185,7 +185,7 @@
"supply_state": "interrupted"
},
{
- "contract_version": 5,
+ "contract_version": 6,
"backend": "codex",
"model_id": "gpt-5.6",
"chain": [{ "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "channel": "native_cli", "health": "backoff", "runnable": false, "reason": "native_cli_unavailable", "retry_at": "2026-08-11T11:55:08Z" }],
@@ -193,7 +193,7 @@
"supply_state": "interrupted"
},
{
- "contract_version": 5,
+ "contract_version": 6,
"backend": "claude",
"model_id": "claude-haiku-4-5",
"chain": [],
diff --git a/docs/plans/model-hub-contracts/api-response.schema.json b/docs/plans/model-hub-contracts/api-response.schema.json
index c76a0daae..a0f1889eb 100644
--- a/docs/plans/model-hub-contracts/api-response.schema.json
+++ b/docs/plans/model-hub-contracts/api-response.schema.json
@@ -134,7 +134,7 @@
"SuccessCore": {
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5}
+ "contract_version": {"const": 6}
}
},
"SourceListResponse": {
@@ -143,7 +143,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"sources": {"type": "array", "items": {"$ref": "#/definitions/SourceApi"}}
}
},
@@ -153,7 +153,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"observation": {"$ref": "model-hub/observation-result.schema.json"}
}
},
@@ -163,7 +163,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"source": {"$ref": "#/definitions/SourceApi"},
"added_to": {"type": "array", "items": {"$ref": "#/definitions/AddedTo"}},
"adopted_by": {"type": "array", "items": {"$ref": "#/definitions/AdoptedBy"}, "uniqueItems": true}
@@ -175,7 +175,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"source": {"$ref": "#/definitions/SourceApi"}
}
},
@@ -185,7 +185,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"source": {"$ref": "#/definitions/SourceApi"},
"removed_hops": {"type": "array", "items": {"$ref": "#/definitions/RouteHopRef"}},
"interrupted": {"type": "array", "items": {"$ref": "#/definitions/SupplyGap"}}
@@ -197,7 +197,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"removed_hops": {"type": "array", "items": {"$ref": "#/definitions/RouteHopRef"}},
"interrupted": {"type": "array", "items": {"$ref": "#/definitions/SupplyGap"}}
}
@@ -208,7 +208,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"agents": {"type": "array", "items": {"$ref": "#/definitions/AgentSupplyApi"}}
}
},
@@ -218,7 +218,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"agent": {"$ref": "#/definitions/AgentSupplyApi"}
}
},
@@ -228,7 +228,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"chain": {"$ref": "model-hub/agent-chain.schema.json"}
}
},
@@ -238,7 +238,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"chain": {"$ref": "model-hub/agent-chain.schema.json"},
"removed_hops": {"type": "array", "items": {"$ref": "#/definitions/RouteHopRef"}},
"interrupted": {"type": "array", "items": {"$ref": "#/definitions/SupplyGap"}}
@@ -250,7 +250,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"probe": {"$ref": "model-hub/probe-result.schema.json"}
}
},
@@ -260,7 +260,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"events": {"type": "array", "items": {"$ref": "model-hub/resolution-event.schema.json"}}
}
},
@@ -270,7 +270,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"usage": {"$ref": "model-hub/usage-summary.schema.json"}
}
},
@@ -280,7 +280,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"flow": {
"allOf": [
{"$ref": "model-hub/oauth-flow.schema.json"},
@@ -302,7 +302,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"flow": {
"allOf": [
{"$ref": "model-hub/oauth-flow.schema.json"},
@@ -325,7 +325,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"flow": {
"allOf": [
{"$ref": "model-hub/oauth-flow.schema.json"},
@@ -350,7 +350,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5}
+ "contract_version": {"const": 6}
}
},
"RuntimeApi": {
@@ -372,7 +372,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"scan": {"$ref": "model-hub/migration-scan.schema.json"}
}
},
@@ -382,7 +382,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"applied": {"type": "integer", "minimum": 0},
"sources": {"type": "array", "items": {"$ref": "#/definitions/SourceApi"}},
"added_to": {"type": "array", "items": {"$ref": "#/definitions/AddedTo"}}
@@ -394,7 +394,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"provenance": {"$ref": "model-hub/turn-provenance.schema.json"}
}
},
@@ -404,7 +404,7 @@
"additionalProperties": false,
"properties": {
"ok": {"const": true},
- "contract_version": {"const": 5},
+ "contract_version": {"const": 6},
"runtime": {"$ref": "#/definitions/RuntimeApi"}
}
}
diff --git a/docs/plans/model-hub-contracts/api.md b/docs/plans/model-hub-contracts/api.md
index c2beb3b20..50df584aa 100644
--- a/docs/plans/model-hub-contracts/api.md
+++ b/docs/plans/model-hub-contracts/api.md
@@ -2,9 +2,9 @@
Status: **Normative v5** — Model Hub implementations must conform, and the response conformance guard enumerates this route table and validates one real server response for every route.
-Success envelope: `{ok: true, contract_version: 5, ...}`.
+Success envelope: `{ok: true, contract_version: 6, ...}`.
Failure envelope:
-`{ok: false, contract_version: 5, error: <machine_code>, detail?: <i18n_key>}`.
+`{ok: false, contract_version: 6, error: <machine_code>, detail?: <i18n_key>}`.
`detail` is always a string. Structured error data lives in a named sibling.
Guarded mutation refusals specialize that envelope through
`guard-refusal.schema.json`; both report arrays are required and together form the plan
@@ -441,7 +441,7 @@ The terminal result of both ordinary API-key creation and OAuth creation is:
```json
{
"ok": true,
- "contract_version": 5,
+ "contract_version": 6,
"source": {
"id": "src_anthkey01",
"kind": "api_key",
@@ -519,7 +519,7 @@ Every guarded Source/inventory mutation uses the §4.5 envelope matrix and the c
```json
{
"ok": false,
- "contract_version": 5,
+ "contract_version": 6,
"error": "source_last_supplier",
"would_remove_hops": [],
"would_interrupt": [
@@ -651,7 +651,7 @@ API-key success:
```json
{
"ok": true,
- "contract_version": 5,
+ "contract_version": 6,
"source": {
"id": "src_relay9c1x",
"kind": "api_key",
@@ -742,7 +742,7 @@ Status and submit return the same terminal shape:
```json
{
"ok": true,
- "contract_version": 5,
+ "contract_version": 6,
"flow": {
"flow_id": "oaf_claude01",
"client_nonce": "ofn_01j5w8z7p4n6q2rt",
@@ -802,9 +802,9 @@ a valid `interrupted` chain.
```json
{
"ok": true,
- "contract_version": 5,
+ "contract_version": 6,
"chain": {
- "contract_version": 5,
+ "contract_version": 6,
"backend": "codex",
"model_id": "gpt-5.6",
"chain": [
@@ -829,7 +829,7 @@ In Direct mode both chain and probe refuse with:
```json
{
"ok": false,
- "contract_version": 5,
+ "contract_version": 6,
"error": "direct_mode",
"detail": "models.hub.direct_mode"
}
@@ -843,9 +843,9 @@ A successful probe nests its result:
```json
{
"ok": true,
- "contract_version": 5,
+ "contract_version": 6,
"probe": {
- "contract_version": 5,
+ "contract_version": 6,
"backend": "claude",
"channel": "hub",
"reachable": false,
@@ -868,7 +868,7 @@ not-ready carries the closed i18n key `models.probe.native_cli_unavailable`.
```json
{
- "contract_version": 5,
+ "contract_version": 6,
"backend": "codex",
"channel": "native_cli",
"reachable": true,
@@ -881,7 +881,7 @@ not-ready carries the closed i18n key `models.probe.native_cli_unavailable`.
```json
{
- "contract_version": 5,
+ "contract_version": 6,
"backend": "codex",
"channel": "native_cli",
"reachable": false,
@@ -897,7 +897,7 @@ No candidate is an API error with a typed model-scoped state:
```json
{
"ok": false,
- "contract_version": 5,
+ "contract_version": 6,
"error": "probe_no_candidate",
"detail": "models.probe.no_candidate.waiting",
"supply": {
@@ -956,7 +956,7 @@ ambiguous absence are explicit and distinguishable from an unknown turn:
```json
{
"ok": false,
- "contract_version": 5,
+ "contract_version": 6,
"error": "provenance_unavailable",
"detail": "models.provenance.direct_mode"
}
@@ -965,7 +965,7 @@ ambiguous absence are explicit and distinguishable from an unknown turn:
```json
{
"ok": false,
- "contract_version": 5,
+ "contract_version": 6,
"error": "provenance_unavailable",
"detail": "models.provenance.attribution_ambiguous"
}
diff --git a/docs/plans/model-hub-contracts/guard-refusal.schema.json b/docs/plans/model-hub-contracts/guard-refusal.schema.json
index 2c178988e..b9478d1a5 100644
--- a/docs/plans/model-hub-contracts/guard-refusal.schema.json
+++ b/docs/plans/model-hub-contracts/guard-refusal.schema.json
@@ -60,7 +60,7 @@
],
"properties": {
"ok": { "const": false },
- "contract_version": { "const": 5 },
+ "contract_version": { "const": 6 },
"error": {
"enum": [
"source_last_supplier",
@@ -113,7 +113,7 @@
"examples": [
{
"ok": false,
- "contract_version": 5,
+ "contract_version": 6,
"error": "source_model_in_route_chain",
"would_remove_hops": [
{
diff --git a/docs/plans/model-hub-contracts/mirror-registry.json b/docs/plans/model-hub-contracts/mirror-registry.json
index b8cd2708b..e73ea2895 100644
--- a/docs/plans/model-hub-contracts/mirror-registry.json
+++ b/docs/plans/model-hub-contracts/mirror-registry.json
@@ -1,5 +1,5 @@
{
- "contract_version": 5,
+ "contract_version": 6,
"input_generation": {
"mode": "same_run_live_files",
"external_snapshot": "content_fingerprint_required"
diff --git a/docs/plans/model-hub-contracts/observation-result.schema.json b/docs/plans/model-hub-contracts/observation-result.schema.json
index e5e7a5ead..2e7130935 100644
--- a/docs/plans/model-hub-contracts/observation-result.schema.json
+++ b/docs/plans/model-hub-contracts/observation-result.schema.json
@@ -15,7 +15,7 @@
],
"additionalProperties": false,
"properties": {
- "contract_version": { "const": 5 },
+ "contract_version": { "const": 6 },
"outcome": {
"enum": [
"observed",
@@ -122,7 +122,7 @@
],
"examples": [
{
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "observed",
"reachable": true,
"authenticated": "authenticated",
@@ -131,7 +131,7 @@
"models": ["gpt-5.6"]
},
{
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "authentication_failed",
"reachable": true,
"authenticated": "rejected",
@@ -140,7 +140,7 @@
"models": []
},
{
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "ambiguous",
"reachable": true,
"authenticated": "unknown",
@@ -149,7 +149,7 @@
"models": []
},
{
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "unreachable",
"reachable": false,
"authenticated": "unknown",
@@ -158,7 +158,7 @@
"models": []
},
{
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "adapter_error",
"reachable": null,
"authenticated": "unknown",
@@ -167,7 +167,7 @@
"models": []
},
{
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "timeout",
"reachable": null,
"authenticated": "unknown",
diff --git a/docs/plans/model-hub-contracts/probe-result.schema.json b/docs/plans/model-hub-contracts/probe-result.schema.json
index 59bb1b54b..706a06219 100644
--- a/docs/plans/model-hub-contracts/probe-result.schema.json
+++ b/docs/plans/model-hub-contracts/probe-result.schema.json
@@ -7,7 +7,7 @@
"required": ["contract_version", "backend", "channel", "reachable", "source_id", "model_id", "latency_ms", "error"],
"additionalProperties": false,
"properties": {
- "contract_version": { "const": 5 },
+ "contract_version": { "const": 6 },
"backend": { "enum": ["claude", "codex", "opencode"] },
"channel": { "enum": ["hub", "native_cli"] },
"reachable": { "type": "boolean" },
@@ -62,10 +62,10 @@
}
],
"examples": [
- { "contract_version": 5, "backend": "codex", "channel": "hub", "reachable": true, "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "latency_ms": 412, "error": null },
- { "contract_version": 5, "backend": "claude", "channel": "hub", "reachable": false, "source_id": "src_relay9c1x", "model_id": "glm-5.2", "latency_ms": 287, "error": "models.source.needs_action.balance_exhausted" },
- { "contract_version": 5, "backend": "codex", "channel": "hub", "reachable": false, "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "latency_ms": null, "error": "models.source.backoff.connection_failed" },
- { "contract_version": 5, "backend": "codex", "channel": "native_cli", "reachable": true, "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "latency_ms": null, "error": null },
- { "contract_version": 5, "backend": "codex", "channel": "native_cli", "reachable": false, "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "latency_ms": null, "error": "models.probe.native_cli_unavailable" }
+ { "contract_version": 6, "backend": "codex", "channel": "hub", "reachable": true, "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "latency_ms": 412, "error": null },
+ { "contract_version": 6, "backend": "claude", "channel": "hub", "reachable": false, "source_id": "src_relay9c1x", "model_id": "glm-5.2", "latency_ms": 287, "error": "models.source.needs_action.balance_exhausted" },
+ { "contract_version": 6, "backend": "codex", "channel": "hub", "reachable": false, "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "latency_ms": null, "error": "models.source.backoff.connection_failed" },
+ { "contract_version": 6, "backend": "codex", "channel": "native_cli", "reachable": true, "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "latency_ms": null, "error": null },
+ { "contract_version": 6, "backend": "codex", "channel": "native_cli", "reachable": false, "source_id": "src_chatgptplus", "model_id": "gpt-5.6", "latency_ms": null, "error": "models.probe.native_cli_unavailable" }
]
}
diff --git a/docs/plans/model-hub-contracts/runtime-dependency.schema.json b/docs/plans/model-hub-contracts/runtime-dependency.schema.json
index 6d3ad44af..cde81a633 100644
--- a/docs/plans/model-hub-contracts/runtime-dependency.schema.json
+++ b/docs/plans/model-hub-contracts/runtime-dependency.schema.json
@@ -7,7 +7,7 @@
"required": ["contract_version", "manifest", "status"],
"additionalProperties": false,
"properties": {
- "contract_version": { "const": 5 },
+ "contract_version": { "const": 6 },
"host_platform": {
"type": "string",
"pattern": "^[a-z0-9]+(?:-[a-z0-9_]+)+$",
@@ -127,7 +127,7 @@
},
"examples": [
{
- "contract_version": 5,
+ "contract_version": 6,
"host_platform": "darwin-arm64",
"manifest": {
"name": "cliproxyapi",
diff --git a/docs/plans/model-hub-contracts/turn-provenance.schema.json b/docs/plans/model-hub-contracts/turn-provenance.schema.json
index 338b277df..a352d4e46 100644
--- a/docs/plans/model-hub-contracts/turn-provenance.schema.json
+++ b/docs/plans/model-hub-contracts/turn-provenance.schema.json
@@ -2,7 +2,7 @@
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "model-hub/turn-provenance.schema.json",
"title": "TurnProvenance",
- "description": "v5 debug record for one exactly attributed Gateway turn. It records exact configured Source/model attempts in stored order and one terminal outcome. No route-policy or runtime-mapping discriminator exists; ambiguous attempts produce no record.",
+ "description": "Persisted debug record for one exactly attributed Gateway turn. It records exact configured Source/model attempts in stored order and one terminal outcome. No route-policy or runtime-mapping discriminator exists; ambiguous attempts produce no record.",
"type": "object",
"required": [
"contract_version",
@@ -20,7 +20,11 @@
],
"additionalProperties": false,
"properties": {
- "contract_version": { "const": 5 },
+ "contract_version": {
+ "enum": [5, 6],
+ "$comment": "The only versioned object that is written to disk instead of exchanged inside one request, so its released values are a set rather than a constant. A record a v5 build persisted keeps validating -- tests/fixtures/model_hub/released_v5_permission_denied.json is the evidence -- while new records carry the terminal value, which is the last member. Every other versioned object is an in-process envelope and stays pinned to that value alone.",
+ "description": "Generation that wrote this record. Nothing branches on it: readers accept every released value and the shape is identical across them."
+ },
"turn_id": {
"type": "string",
"description": "Opaque id in the existing turn/session id space."
@@ -316,7 +320,7 @@
],
"examples": [
{
- "contract_version": 5,
+ "contract_version": 6,
"turn_id": "turn_01k9x2m4",
"ts": "2026-07-29T06:32:11Z",
"agent": "claude",
@@ -341,7 +345,7 @@
"blockers": []
},
{
- "contract_version": 5,
+ "contract_version": 6,
"turn_id": "turn_01k9x33p",
"ts": "2026-07-29T06:41:02Z",
"agent": "opencode",
@@ -362,7 +366,7 @@
"blockers": []
},
{
- "contract_version": 5,
+ "contract_version": 6,
"turn_id": "turn_01k9x3zq",
"ts": "2026-07-29T06:48:20Z",
"agent": "codex",
@@ -382,7 +386,7 @@
]
},
{
- "contract_version": 5,
+ "contract_version": 6,
"turn_id": "turn_01k9x4b7",
"ts": "2026-07-29T07:02:44Z",
"agent": "claude",
@@ -402,7 +406,7 @@
"blockers": []
},
{
- "contract_version": 5,
+ "contract_version": 6,
"turn_id": "turn_01k9x5ca",
"ts": "2026-07-29T07:08:00Z",
"agent": "codex",
diff --git a/docs/plans/model-hub-usage-metering.md b/docs/plans/model-hub-usage-metering.md
index d1261d5a2..56347d529 100644
--- a/docs/plans/model-hub-usage-metering.md
+++ b/docs/plans/model-hub-usage-metering.md
@@ -307,6 +307,47 @@ OpenCode identity helpers by relative import without tripping it. Pre-existing a
alone here — closing it requires ruling on `service.py`'s existing relative import of
`STANDARD_OPENCODE_VENDOR_IDS`, which is a separate question from this stage.
+### Round 5 (head `8e2af4a4b`)
+
+The two remaining P2 threads. Both fixes are one line of behavior; what took the round
+was that each one, once written, exposed something the change it belonged to had left
+half-done.
+
+- **Route hops are spelled by whatever spells what they name** (`config/v2_config.py`).
+ Round 4 moved model-ID canonicalization into `ModelHubModelConfig.from_payload` so a
+ persisted inventory normalizes on load. A route hop names a model in that inventory,
+ and `inspect_exact_hop` decides membership by an exact comparison — so normalizing one
+ side only converts a working chain into `model_unsupported` on upgrade. `from_payload`
+ now applies `normalized_model_id` to the hop too. The dedup check that follows had to
+ split in two: duplicates *as written* stay a malformed payload and raise, while
+ duplicates that appear only once spelling is settled are a legacy file naming one
+ upstream model twice — the second hop was already unreachable past the first, so it
+ collapses and the chain loads, where raising would fail a config load the
+ persisted-shape rule requires to succeed.
+- **`contract_version` 5 → 6, and the persisted object that cannot follow it**
+ (9 contract files, `service.py`, `provenance.py`). The usage route is a new versioned
+ surface, so the contract's single-number closure has to move as a whole. Bumping it
+ broke `test_released_v5_permission_denied_records_degrade_at_read_boundary`, which is
+ the point: `TurnProvenance` is the only versioned object written to disk, so records a
+ released v5 build persisted outlive the bump that republished the shape. It now accepts
+ `{5, 6}` — a set ending at the terminal value — while every other versioned object,
+ being an envelope built and consumed inside one request, stays pinned to 6 alone.
+
+Two invariant tests hold the properties rather than the cases.
+`test_every_versioned_object_ends_at_the_terminal_version_the_code_writes` reads the
+accepted values out of whatever schemas the contracts directory holds and compares them
+with each other *and* with `CONTRACT_VERSION`; nothing did that before, which is how
+round 4 could have shipped a half-applied bump.
+`test_config_reload_spells_route_hops_like_the_inventory_they_name` seeds a model and the
+hop naming it in every spelling a persisted config can carry, rather than listing the
+spellings that are exempt.
+
+Writing them surfaced a third gap of the same shape: the contracts `README.md` index had
+been missing `api-response.schema.json` since before this PR and `usage-summary.schema.json`
+since this one — a file that ships but is invisible to anyone reading the index.
+`test_contracts_readme_indexes_every_file_beside_it` now compares the table with the
+directory, so the next file added is caught here instead of by whoever needed it.
+
## Todo
- [x] Usage taxonomy and extraction in `stream_wire.py`
diff --git a/tests/test_model_hub_api.py b/tests/test_model_hub_api.py
index 22c3ceaa5..ad8589c31 100644
--- a/tests/test_model_hub_api.py
+++ b/tests/test_model_hub_api.py
@@ -805,7 +805,7 @@ def test_runtime_start_is_explicit_and_returns_v4_status(tmp_path):
runtime = asyncio.run(service.runtime_start())
assert adapter.start_calls == 1
- assert runtime["contract_version"] == 5
+ assert runtime["contract_version"] == 6
assert runtime["status"]["health"] == "ok"
_assert_valid("runtime-dependency.schema.json", runtime)
@@ -975,7 +975,7 @@ def test_runtime_start_crosses_the_controller_rpc_boundary(monkeypatch):
async def rpc(operation, payload=None):
calls.append((operation, payload))
- return {"contract_version": 5, "status": {"health": "ok"}}
+ return {"contract_version": 6, "status": {"health": "ok"}}
monkeypatch.setattr(model_hub_client, "_rpc", rpc)
@@ -992,7 +992,7 @@ def test_runtime_install_crosses_the_controller_rpc_boundary(monkeypatch):
async def rpc(operation, payload=None):
calls.append((operation, payload))
- return {"contract_version": 5, "status": {"health": "installing"}}
+ return {"contract_version": 6, "status": {"health": "installing"}}
monkeypatch.setattr(model_hub_client, "_rpc", rpc)
@@ -5235,7 +5235,7 @@ def test_runtime_start_route_requires_csrf_before_starting_engine(monkeypatch, t
assert accepted.status_code == 200
runtime = accepted.get_json()["runtime"]
assert adapter.start_calls == 1
- assert runtime["contract_version"] == 5
+ assert runtime["contract_version"] == 6
_assert_valid("runtime-dependency.schema.json", runtime)
diff --git a/tests/test_model_hub_config.py b/tests/test_model_hub_config.py
index 0c88e472e..2d129a543 100644
--- a/tests/test_model_hub_config.py
+++ b/tests/test_model_hub_config.py
@@ -27,6 +27,7 @@ from config.v2_config import (
V2Config,
is_model_hub_enabled,
)
+from core.handlers.model_hub.service import CONTRACT_VERSION
from core.services.settings import default_config
from core.handlers.model_hub.adapter import (
OBSERVATION_TERMINAL_RULES,
@@ -100,7 +101,7 @@ def test_protocol_vocabulary_matches_authority_and_rejects_removed_alias():
def test_unsaved_observation_schema_closes_all_terminal_shapes():
schema = _schema("observation-result.schema.json")
- assert schema["properties"]["contract_version"]["const"] == 5
+ assert schema["properties"]["contract_version"]["const"] == 6
assert tuple(schema["properties"]["outcome"]["enum"]) == tuple(
member.value for member in ObservationOutcome
)
@@ -124,7 +125,7 @@ def test_observation_terminal_authority_and_schema_accept_the_same_products():
def payload(observation: SourceObservation) -> dict:
return {
- "contract_version": 5,
+ "contract_version": 6,
"outcome": observation.outcome.value,
"reachable": observation.reachable,
"authenticated": (
@@ -623,7 +624,7 @@ def test_guard_refusal_error_requires_its_corresponding_nonempty_plan_array():
route_refusal = {
"ok": False,
- "contract_version": 5,
+ "contract_version": 6,
"error": "source_in_route_chain",
"would_remove_hops": [hop],
"would_interrupt": [],
@@ -686,7 +687,7 @@ def test_v5_mirror_registry_is_executable_and_complete():
registry = json.loads((CONTRACTS / "mirror-registry.json").read_text(encoding="utf-8"))
schemas = _mirror_schemas(registry)
- assert registry["contract_version"] == 5
+ assert registry["contract_version"] == 6
ids = [entry["id"] for entry in registry["entries"]]
assert ids
assert len(ids) == len(set(ids))
@@ -694,6 +695,78 @@ def test_v5_mirror_registry_is_executable_and_complete():
_validate_mirror_entry(entry, schemas)
+def _versioned_nodes(node):
+ """Yield every `contract_version` subschema, however deeply a branch nests it."""
+
+ if isinstance(node, dict):
+ declared = node.get("properties")
+ if isinstance(declared, dict) and isinstance(declared.get("contract_version"), dict):
+ yield declared["contract_version"]
+ for value in node.values():
+ yield from _versioned_nodes(value)
+ elif isinstance(node, list):
+ for item in node:
+ yield from _versioned_nodes(item)
+
+
+def test_every_versioned_object_ends_at_the_terminal_version_the_code_writes():
+ # One number spans all versioned objects, so a bump has to move every one of
+ # them at once — round 4 shipped it half-applied because nothing compared the
+ # schemas with each other or with the writer. Reading the accepted values out
+ # of whatever schemas the directory holds, rather than listing the ones that
+ # carry a version, covers an object added later without editing this test.
+ #
+ # TurnProvenance is the one exception, and it earns it by being written to
+ # disk: the same bump that republishes an envelope would strand every record
+ # a released build persisted, so it accepts the released values and ends at
+ # the terminal one. The `== [terminal]` branch is what keeps that from
+ # spreading to objects that never outlive their request.
+ terminal = json.loads((CONTRACTS / "mirror-registry.json").read_text(encoding="utf-8"))[
+ "contract_version"
+ ]
+ assert CONTRACT_VERSION == terminal
+ persisted = {"turn-provenance.schema.json"}
+ checked = set()
+ for path in sorted(CONTRACTS.glob("*.schema.json")):
+ for node in _versioned_nodes(json.loads(path.read_text(encoding="utf-8"))):
+ checked.add(path.name)
+ accepted = [node["const"]] if "const" in node else list(node["enum"])
+ assert accepted == sorted(set(accepted)), path.name
+ assert accepted[-1] == terminal, path.name
+ if path.name in persisted:
+ assert accepted[0] < terminal, path.name
+ else:
+ assert accepted == [terminal], path.name
+ assert persisted <= checked
+ assert "api-response.schema.json" in checked
+
+ # The UI declares the same number as a literal type, and `tsc` is the only
+ # thing that would have caught it drifting — one language boundary away from
+ # every check above, which is where this bump went half-applied a second time.
+ # A regex over the declaration is cheap; noticing in review is not.
+ declared = re.search(
+ r"^export const CONTRACT_VERSION = (\d+) as const;$",
+ Path("ui/src/components/settings/models/types.ts").read_text(encoding="utf-8"),
+ flags=re.MULTILINE,
+ )
+ assert declared is not None
+ assert int(declared.group(1)) == terminal
+
+
+def test_contracts_readme_indexes_every_file_beside_it():
+ # The index is what a reader consults to learn a contract exists at all, so a
+ # file missing from it is invisible even though it ships. Both this PR's
+ # `usage-summary.schema.json` and the older `api-response.schema.json` had gone
+ # unlisted, which is what a hand-maintained list does on a long enough timeline.
+ # Comparing against the directory rather than against a second list means the
+ # next file added is caught by this test instead of by whoever needed it.
+ readme = (CONTRACTS / "README.md").read_text(encoding="utf-8")
+ indexed = set(re.findall(r"^\| `([^`]+)` \|", readme, flags=re.MULTILINE))
+ present = {path.name for path in CONTRACTS.iterdir() if path.is_file()}
+ assert present - indexed == set()
+ assert indexed - present == set()
+
+
def test_v5_mirror_registry_mutation_probes_detect_every_comparable_drift():
registry = json.loads((CONTRACTS / "mirror-registry.json").read_text(encoding="utf-8"))
schemas = _mirror_schemas(registry)
@@ -1104,7 +1177,7 @@ def test_v5_shape_amendments_reject_the_false_states_they_replace():
with pytest.raises(ValidationError):
chain_validator.validate(interrupted)
exact_hop = {
- "contract_version": 5,
+ "contract_version": 6,
"backend": "claude",
"model_id": "claude-opus-4-6",
"chain": [{
@@ -1602,6 +1675,52 @@ def test_config_reload_migrates_legacy_mapping_to_exact_route_hop(monkeypatch, t
assert loaded.model_hub.sources[0].models[0].reasoning_efforts == []
+def test_config_reload_spells_route_hops_like_the_inventory_they_name(monkeypatch, tmp_path):
+ # A hop names a model in a source's inventory, and `inspect_exact_hop` decides
+ # membership by comparing the two identifiers exactly, so the chain only
+ # survives an upgrade while one rule spells both sides — the set equality below
+ # is that same comparison, taken over the whole route. The file seeds a model
+ # *and* the hop naming it in every spelling a persisted config can carry rather
+ # than listing the spellings that are exempt: a spelling admitted later is
+ # covered here without editing this test, which is what an enumeration misses.
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ spellings = (
+ lambda base: base,
+ lambda base: f" {base}",
+ lambda base: f"{base} ",
+ lambda base: f" {base} ",
+ lambda base: f"\t{base}\n",
+ lambda base: " ",
+ )
+ source = copy.deepcopy(_schema("source.schema.json")["examples"][0])
+ source["supply_channel"] = "native_cli"
+ source["models"] = [
+ {
+ "id": spelling(f"claude-opus-4-{index}"),
+ "display_name": None,
+ "origin": "discovered",
+ "reasoning_efforts": [],
+ "discovered_at": "2026-07-23T03:00:00Z",
+ }
+ for index, spelling in enumerate(spellings)
+ ]
+ current = api.config_to_payload(default_config(), include_secrets=True, include_internal=True)
+ current["model_hub"]["sources"] = [source]
+ menu_model, route = next(iter(current["model_hub"]["agents"]["claude"]["routes"].items()))
+ route["hops"] = [
+ {"source_id": source["id"], "model_id": model["id"]} for model in source["models"]
+ ]
+ config_path = tmp_path / "config.json"
+ config_path.write_text(json.dumps(current, ensure_ascii=False), encoding="utf-8")
+
+ loaded = V2Config.load(config_path=config_path)
+
+ assert loaded.load_warnings == ()
+ hub = loaded.model_hub
+ hops = hub.agents["claude"].routes[menu_model].hops
+ assert {hop.model_id for hop in hops} == {model.id for model in hub.sources[0].models}
+
+
def test_config_reload_recovers_dangling_legacy_custom_source_order(monkeypatch, tmp_path):
monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
current = api.config_to_payload(default_config(), include_secrets=True, include_internal=True)
@@ -2419,6 +2538,22 @@ def test_route_hops_allow_one_source_to_supply_distinct_models():
]
}
)
+ # Two hops that only become one pair once spelling is settled are a legacy
+ # file naming one upstream model twice, not a malformed payload: the second
+ # was already unreachable past the first, so it collapses and the chain loads.
+ # Raising here would instead fail a load the persisted-shape rule requires
+ # to succeed.
+ collapsed = ModelHubRouteConfig.from_payload(
+ {
+ "hops": [
+ {"source_id": "src_same0001", "model_id": "model-a"},
+ {"source_id": "src_same0001", "model_id": " model-a "},
+ ]
+ }
+ )
+ assert [(hop.source_id, hop.model_id) for hop in collapsed.hops] == [
+ ("src_same0001", "model-a"),
+ ]
def _ordering_source(
diff --git a/tests/test_model_hub_l3.py b/tests/test_model_hub_l3.py
index eea5d4852..95d8cb6ba 100644
--- a/tests/test_model_hub_l3.py
+++ b/tests/test_model_hub_l3.py
@@ -4408,7 +4408,7 @@ def test_source_observation_reduces_the_order_at_the_first_authenticated_proof(
_assert_valid(
"observation-result.schema.json",
{
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "adapter_error",
"reachable": True,
"authenticated": "unknown",
@@ -5493,7 +5493,7 @@ def test_native_chain_visibility_and_probe_readiness(tmp_path: Path) -> None:
probe = asyncio.run(service.probe_agent("codex", "shared-model"))
assert probe == {
- "contract_version": 5,
+ "contract_version": 6,
"backend": "codex",
"channel": "native_cli",
"reachable": True,
diff --git a/tests/test_model_hub_resolution.py b/tests/test_model_hub_resolution.py
index b42a701c5..a9d629378 100644
--- a/tests/test_model_hub_resolution.py
+++ b/tests/test_model_hub_resolution.py
@@ -1674,7 +1674,7 @@ def test_service_accepts_authoritative_reachable_adapter_error(tmp_path):
)
assert result["observation"] == {
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "adapter_error",
"reachable": True,
"authenticated": "unknown",
@@ -1704,7 +1704,7 @@ def test_unknown_adapter_error_does_not_claim_connection(tmp_path):
assert exc.value.code == "discovery_failed"
assert exc.value.detail == "modelHub.errors.adapter_error"
assert exc.value.data["observation"] == {
- "contract_version": 5,
+ "contract_version": 6,
"outcome": "adapter_error",
"reachable": None,
"authenticated": "unknown",
diff --git a/tests/test_model_hub_runtime.py b/tests/test_model_hub_runtime.py
index 818fe9321..21fdb2ce4 100644
--- a/tests/test_model_hub_runtime.py
+++ b/tests/test_model_hub_runtime.py
@@ -742,7 +742,7 @@ def test_manifest_resolution_drives_admission_persistence_and_schema(
installer=manager,
state_store=EngineStateStore(tmp_path / "state"),
)
- projected = {"contract_version": 5, **supervisor.status()}
+ projected = {"contract_version": 6, **supervisor.status()}
schema = json.loads(
Path("docs/plans/model-hub-contracts/runtime-dependency.schema.json").read_text(
encoding="utf-8"
diff --git a/ui/src/components/settings/models/AgentCard.test.tsx b/ui/src/components/settings/models/AgentCard.test.tsx
index de74e2922..98db3d3fd 100644
--- a/ui/src/components/settings/models/AgentCard.test.tsx
+++ b/ui/src/components/settings/models/AgentCard.test.tsx
@@ -17,7 +17,7 @@ import { freshRuntimeProjection } from './runtimeLifecycle';
import type { AgentSupply, RuntimeDependency, Source } from './types';
const runtime: RuntimeDependency = {
- contract_version: 5,
+ contract_version: 6,
manifest: { name: 'cliproxyapi', resolution: 'resolved', version: '1.0.0', source_sha: 'fixture', assets: [] },
status: { installed_version: '1.0.0', verified: true, listening: null, health: 'ok', last_check: null },
};
@@ -61,14 +61,14 @@ describe('AgentCard', () => {
it('derives takeover from the exact current hop', () => {
const key = modelChainKey('claude', 'claude-opus-4-6');
- render(<I18nextProvider i18n={i18n}><AgentCard agents={[hubAgent]} sources={[source('src_a', 'Primary'), source('src_b', 'Backup')]} chains={{ [key]: readyRegion({ contract_version: 5, backend: 'claude', model_id: 'claude-opus-4-6', current: { source_id: 'src_b', model_id: 'claude-opus-4-6' }, chain: [{ source_id: 'src_a', model_id: 'claude-opus-4-6', channel: 'hub', health: 'cooldown', runnable: false, reason: null, retry_at: '2099-01-01T00:00:00Z' }, { source_id: 'src_b', model_id: 'claude-opus-4-6', channel: 'hub', health: 'healthy', runnable: true, reason: null, retry_at: null }], supply_state: 'ok' }) }} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);
+ render(<I18nextProvider i18n={i18n}><AgentCard agents={[hubAgent]} sources={[source('src_a', 'Primary'), source('src_b', 'Backup')]} chains={{ [key]: readyRegion({ contract_version: 6, backend: 'claude', model_id: 'claude-opus-4-6', current: { source_id: 'src_b', model_id: 'claude-opus-4-6' }, chain: [{ source_id: 'src_a', model_id: 'claude-opus-4-6', channel: 'hub', health: 'cooldown', runnable: false, reason: null, retry_at: '2099-01-01T00:00:00Z' }, { source_id: 'src_b', model_id: 'claude-opus-4-6', channel: 'hub', health: 'healthy', runnable: true, reason: null, retry_at: null }], supply_state: 'ok' }) }} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);
expect(screen.getByText(/Backup/)).toBeTruthy();
expect(screen.getByText(/takeover/i)).toBeTruthy();
});
it('does not call a later current hop takeover unless the head is unavailable for cooldown', () => {
const key = modelChainKey('claude', 'claude-opus-4-6');
- render(<I18nextProvider i18n={i18n}><AgentCard agents={[hubAgent]} sources={[source('src_a', 'Primary'), source('src_b', 'Backup')]} chains={{ [key]: readyRegion({ contract_version: 5, backend: 'claude', model_id: 'claude-opus-4-6', current: { source_id: 'src_b', model_id: 'claude-opus-4-6' }, chain: [{ source_id: 'src_a', model_id: 'claude-opus-4-6', channel: 'native_cli', health: 'healthy', runnable: false, reason: 'native_cli_unavailable', retry_at: null }, { source_id: 'src_b', model_id: 'claude-opus-4-6', channel: 'hub', health: 'healthy', runnable: true, reason: null, retry_at: null }], supply_state: 'ok' }) }} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);
+ render(<I18nextProvider i18n={i18n}><AgentCard agents={[hubAgent]} sources={[source('src_a', 'Primary'), source('src_b', 'Backup')]} chains={{ [key]: readyRegion({ contract_version: 6, backend: 'claude', model_id: 'claude-opus-4-6', current: { source_id: 'src_b', model_id: 'claude-opus-4-6' }, chain: [{ source_id: 'src_a', model_id: 'claude-opus-4-6', channel: 'native_cli', health: 'healthy', runnable: false, reason: 'native_cli_unavailable', retry_at: null }, { source_id: 'src_b', model_id: 'claude-opus-4-6', channel: 'hub', health: 'healthy', runnable: true, reason: null, retry_at: null }], supply_state: 'ok' }) }} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);
expect(screen.getByText(/Backup/)).toBeTruthy();
expect(screen.queryByText(/takeover/i)).toBeNull();
});
@@ -76,7 +76,7 @@ describe('AgentCard', () => {
it('hides current and takeover projections while the runtime is stopped', () => {
const key = modelChainKey('claude', 'claude-opus-4-6');
const stopped = { ...runtime, status: { ...runtime.status, health: 'down' as const } };
- render(<I18nextProvider i18n={i18n}><RuntimeAgentCard runtime={freshRuntimeProjection(readyRegion(stopped))} agents={[hubAgent]} sources={[source('src_a', 'Primary'), source('src_b', 'Backup')]} chains={{ [key]: readyRegion({ contract_version: 5, backend: 'claude', model_id: 'claude-opus-4-6', current: { source_id: 'src_b', model_id: 'claude-opus-4-6' }, chain: [{ source_id: 'src_a', model_id: 'claude-opus-4-6', channel: 'hub', health: 'cooldown', runnable: false, reason: null, retry_at: '2099-01-01T00:00:00Z' }, { source_id: 'src_b', model_id: 'claude-opus-4-6', channel: 'hub', health: 'healthy', runnable: true, reason: null, retry_at: null }], supply_state: 'ok' }) }} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);
+ render(<I18nextProvider i18n={i18n}><RuntimeAgentCard runtime={freshRuntimeProjection(readyRegion(stopped))} agents={[hubAgent]} sources={[source('src_a', 'Primary'), source('src_b', 'Backup')]} chains={{ [key]: readyRegion({ contract_version: 6, backend: 'claude', model_id: 'claude-opus-4-6', current: { source_id: 'src_b', model_id: 'claude-opus-4-6' }, chain: [{ source_id: 'src_a', model_id: 'claude-opus-4-6', channel: 'hub', health: 'cooldown', runnable: false, reason: null, retry_at: '2099-01-01T00:00:00Z' }, { source_id: 'src_b', model_id: 'claude-opus-4-6', channel: 'hub', health: 'healthy', runnable: true, reason: null, retry_at: null }], supply_state: 'ok' }) }} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);
expect(screen.queryByText(/Backup/)).toBeNull();
expect(screen.queryByText(/takeover/i)).toBeNull();
@@ -85,7 +85,7 @@ describe('AgentCard', () => {
it('offers only gateway enablement and ignores stale chain data in direct mode', () => {
const key = modelChainKey('claude', 'claude-opus-4-6');
- render(<I18nextProvider i18n={i18n}><AgentCard agents={[{ ...hubAgent, mode: 'direct', sources: null, routes: null, supply_status: null, model_supply: null }]} sources={[source('src_a', 'Primary'), source('src_b', 'Backup')]} chains={{ [key]: readyRegion({ contract_version: 5, backend: 'claude', model_id: 'claude-opus-4-6', current: { source_id: 'src_b', model_id: 'claude-opus-4-6' }, chain: [{ source_id: 'src_a', model_id: 'claude-opus-4-6', channel: 'hub', health: 'cooldown', runnable: false, reason: null, retry_at: '2099-01-01T00:00:00Z' }, { source_id: 'src_b', model_id: 'claude-opus-4-6', channel: 'hub', health: 'healthy', runnable: true, reason: null, retry_at: null }], supply_state: 'ok' }) }} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);
+ render(<I18nextProvider i18n={i18n}><AgentCard agents={[{ ...hubAgent, mode: 'direct', sources: null, routes: null, supply_status: null, model_supply: null }]} sources={[source('src_a', 'Primary'), source('src_b', 'Backup')]} chains={{ [key]: readyRegion({ contract_version: 6, backend: 'claude', model_id: 'claude-opus-4-6', current: { source_id: 'src_b', model_id: 'claude-opus-4-6' }, chain: [{ source_id: 'src_a', model_id: 'claude-opus-4-6', channel: 'hub', health: 'cooldown', runnable: false, reason: null, retry_at: '2099-01-01T00:00:00Z' }, { source_id: 'src_b', model_id: 'claude-opus-4-6', channel: 'hub', health: 'healthy', runnable: true, reason: null, retry_at: null }], supply_state: 'ok' }) }} pendingBackends={new Set()} switchFailures={new Set()} connectingBackend={null} onConnectHub={vi.fn()} onSwitchDirect={vi.fn()} onOpenOrder={vi.fn()} onOpenRoute={vi.fn()} onProbeSettled={vi.fn()} /></I18nextProvider>);
expect(screen.queryByText(/Source order/i)).toBeNull();
expect(screen.queryByRole('button', { name: /route chain/i })).toBeNull();
expect(screen.queryByText(/Backup/)).toBeNull();
diff --git a/ui/src/components/settings/models/EnableGatewayDialog.test.tsx b/ui/src/components/settings/models/EnableGatewayDialog.test.tsx
index 95008fa54..166240b59 100644
--- a/ui/src/components/settings/models/EnableGatewayDialog.test.tsx
+++ b/ui/src/components/settings/models/EnableGatewayDialog.test.tsx
@@ -34,7 +34,7 @@ const runtime = (
? 'unresolved' as const
: hostPlatform === 'linux-amd64' ? 'unsupported' as const : 'resolved' as const;
return {
- contract_version: 5,
+ contract_version: 6,
...(hostPlatform === undefined ? {} : { host_platform: hostPlatform }),
manifest: resolution === 'unresolved'
? { name: 'cliproxyapi', resolution, assets: [] }
diff --git a/ui/src/components/settings/models/InstallGatewayDialog.test.tsx b/ui/src/components/settings/models/InstallGatewayDialog.test.tsx
index d9408c938..661964e2f 100644
--- a/ui/src/components/settings/models/InstallGatewayDialog.test.tsx
+++ b/ui/src/components/settings/models/InstallGatewayDialog.test.tsx
@@ -10,7 +10,7 @@ import { modelsApi } from './modelsApi';
import type { RuntimeDependency } from './types';
const runtime = (health: RuntimeDependency['status']['health']): RuntimeDependency => ({
- contract_version: 5,
+ contract_version: 6,
manifest: {
name: 'cliproxyapi',
resolution: 'resolved',
diff --git a/ui/src/components/settings/models/RouteChainDialog.test.tsx b/ui/src/components/settings/models/RouteChainDialog.test.tsx
index d1836de98..9c9af8066 100644
--- a/ui/src/components/settings/models/RouteChainDialog.test.tsx
+++ b/ui/src/components/settings/models/RouteChainDialog.test.tsx
@@ -52,7 +52,7 @@ const sources: Source[] = [
},
];
const chain: AgentChain = {
- contract_version: 5,
+ contract_version: 6,
backend: "claude",
model_id: "opus-5",
current: { source_id: "src_b", model_id: "opus-5" },
diff --git a/ui/src/components/settings/models/RuntimeNotStartedAction.test.tsx b/ui/src/components/settings/models/RuntimeNotStartedAction.test.tsx
index 2c2270871..b7a689b6d 100644
--- a/ui/src/components/settings/models/RuntimeNotStartedAction.test.tsx
+++ b/ui/src/components/settings/models/RuntimeNotStartedAction.test.tsx
@@ -31,7 +31,7 @@ const runtime = (
? 'unresolved' as const
: hostPlatform === 'linux-amd64' ? 'unsupported' as const : 'resolved' as const;
return {
- contract_version: 5,
+ contract_version: 6,
...(hostPlatform === undefined ? {} : { host_platform: hostPlatform }),
manifest: resolution === 'unresolved'
? { name: 'cliproxyapi', resolution, assets: [] }
diff --git a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
index 356530f80..e4e8fc5d4 100644
--- a/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
+++ b/ui/src/components/settings/models/SettingsModelsPage.render.test.tsx
@@ -22,7 +22,7 @@ const directAgent = (backend: AgentBackend): AgentSupply => ({
});
const runtime: RuntimeDependency = {
- contract_version: 5,
+ contract_version: 6,
manifest: { name: 'cliproxyapi', resolution: 'resolved', version: '1', source_sha: 'a'.repeat(40), assets: [] },
status: { installed_version: '1', verified: true, health: 'ok' },
};
@@ -73,7 +73,7 @@ const takeoverAgent: AgentSupply = {
};
const takeoverChain: AgentChain = {
- contract_version: 5,
+ contract_version: 6,
backend: 'codex',
model_id: 'gpt-5.6-sol',
current: { source_id: 'src_relay', model_id: 'gpt-5.6-sol' },
@@ -585,7 +585,7 @@ describe('SettingsModelsPage surface branches', () => {
builtin_models: [modelId],
};
const affectedChain: AgentChain = {
- contract_version: 5,
+ contract_version: 6,
backend: 'claude',
model_id: modelId,
current: { source_id: retainedSource.id, model_id: modelId },
diff --git a/ui/src/components/settings/models/SupplyGraph.test.ts b/ui/src/components/settings/models/SupplyGraph.test.ts
index 9fe532107..59d1e88f2 100644
--- a/ui/src/components/settings/models/SupplyGraph.test.ts
+++ b/ui/src/components/settings/models/SupplyGraph.test.ts
@@ -7,7 +7,7 @@ import { buildSupplyRelations as buildRelations } from './supplyRelations';
import type { AgentChain, AgentSupply, RuntimeDependency, Source } from './types';
const runtime: RuntimeDependency = {
- contract_version: 5,
+ contract_version: 6,
manifest: { name: 'cliproxyapi', resolution: 'resolved', version: '1.0.0', source_sha: 'fixture', assets: [] },
status: { installed_version: '1.0.0', verified: true, listening: null, health: 'ok', last_check: null },
};
@@ -47,7 +47,7 @@ const agent: AgentSupply = {
};
const chain = (current: string, headHealth: AgentChain['chain'][number]['health'] = 'healthy', headRunnable = true, reason: AgentChain['chain'][number]['reason'] = null): AgentChain => ({
- contract_version: 5,
+ contract_version: 6,
backend: 'claude',
model_id: 'model-a',
current: { source_id: current, model_id: 'model-a' },
diff --git a/ui/src/components/settings/models/apiFailure.test.ts b/ui/src/components/settings/models/apiFailure.test.ts
index 0faec4373..7f5b8b1f8 100644
--- a/ui/src/components/settings/models/apiFailure.test.ts
+++ b/ui/src/components/settings/models/apiFailure.test.ts
@@ -33,7 +33,7 @@ afterEach(() => {
describe('apiFailure — whether the route named the failure', () => {
it('posts installation to the dedicated runtime route', async () => {
const runtime = {
- contract_version: 5,
+ contract_version: 6,
manifest: { name: 'cliproxyapi', resolution: 'resolved', version: '1', source_sha: 'sha', assets: [] },
status: { installed_version: null, verified: false, listening: null, health: 'installing', last_check: null },
} as const;
diff --git a/ui/src/components/settings/models/gatewayAdoption.test.ts b/ui/src/components/settings/models/gatewayAdoption.test.ts
index 378dd19af..ddae21d76 100644
--- a/ui/src/components/settings/models/gatewayAdoption.test.ts
+++ b/ui/src/components/settings/models/gatewayAdoption.test.ts
@@ -14,7 +14,7 @@ const agent = (mode: AgentSupply['mode']): AgentSupply => ({
});
const runtime = (health: RuntimeDependency['status']['health']): RuntimeDependency => ({
- contract_version: 5,
+ contract_version: 6,
manifest: { name: 'cliproxyapi', resolution: 'resolved', version: '1', source_sha: 'a'.repeat(40), assets: [] },
status: { installed_version: health === 'not_installed' ? null : '1', verified: health !== 'not_installed', health },
});
diff --git a/ui/src/components/settings/models/runtimeLifecycle.test.ts b/ui/src/components/settings/models/runtimeLifecycle.test.ts
index 40e8a1135..a13e40e09 100644
--- a/ui/src/components/settings/models/runtimeLifecycle.test.ts
+++ b/ui/src/components/settings/models/runtimeLifecycle.test.ts
@@ -11,7 +11,7 @@ const asset = (platform: 'darwin-arm64' | 'linux-amd64') => ({
});
const runtime = (resolution: 'resolved' | 'unresolved' | 'unsupported'): RuntimeDependency => ({
- contract_version: 5,
+ contract_version: 6,
host_platform: 'darwin-arm64',
manifest: resolution === 'unresolved'
? { name: 'cliproxyapi', resolution, assets: [] }
diff --git a/ui/src/components/settings/models/types.ts b/ui/src/components/settings/models/types.ts
index 463bedcba..9128c9fc4 100644
--- a/ui/src/components/settings/models/types.ts
+++ b/ui/src/components/settings/models/types.ts
@@ -10,7 +10,7 @@
// and the PR records the server implementation and feature-flag activation
// edge. The client never synthesizes a fallback payload shape.
-export const CONTRACT_VERSION = 5 as const;
+export const CONTRACT_VERSION = 6 as const;
export const AGENT_CHAIN_CONTRACT_VERSION = CONTRACT_VERSION;
export const PROBE_RESULT_CONTRACT_VERSION = CONTRACT_VERSION;