| 1 | # Signed cloud facts |
| 2 | |
| 3 | Cloud facts are an optional signed overlay for model metadata and unset provider |
| 4 | model defaults. They are **off by default**: a client fetches nothing unless the |
| 5 | setting is turned on. |
| 6 | |
| 7 | One production key, `cwf-2026-09`, is pinned in the Rust and website trust |
| 8 | tables with the `founder` role. This document and the source it describes do |
| 9 | not establish a deployed endpoint, a published database row, signing-key |
| 10 | custody, or a real provider request; check the live channel for those. The JSON |
| 11 | under `docs/cloud-facts/stable.json` is unsigned authoring material; its release |
| 12 | entry matches the checked-in `web/data/latest-published-release.json` receipt. |
| 13 | It is not a publication receipt. Public test fixtures establish local behavior |
| 14 | only. |
| 15 | |
| 16 | Related: [models and providers](MODELS_AND_PROVIDERS.md), [catalog refresh](CATALOG_REFRESH.md), and [provider routes](PROVIDERS.md). |
| 17 | |
| 18 | ## Authority and configuration |
| 19 | |
| 20 | ```toml |
| 21 | [cloud_facts] |
| 22 | enabled = false |
| 23 | channel = "stable" |
| 24 | ttl_hours = 6 |
| 25 | ``` |
| 26 | |
| 27 | `CODEWHALE_CLOUD_FACTS=1|0` overrides the setting; |
| 28 | `CODEWHALE_DISABLE_CLOUD_FACTS=1` is the hard disable. Channel, URL and local |
| 29 | signed-envelope overrides are `CODEWHALE_CLOUD_FACTS_CHANNEL`, |
| 30 | `CODEWHALE_CLOUD_FACTS_URL` (optional `{channel}` placeholder) and |
| 31 | `CODEWHALE_CLOUD_FACTS_PATH`. A local file is still subject to all trust checks. |
| 32 | Production network refresh is suppressed in CI; tests opt into an explicit |
| 33 | loopback fixture transport policy. |
| 34 | |
| 35 | Loading a config object is structural. Accepted startup/reload settings admit |
| 36 | one process-wide source generation. A refresh captures that generation before |
| 37 | work and must still own it to publish either memory or disk state. Disabling or |
| 38 | changing the source invalidates earlier work, clears the prior overlay and |
| 39 | invalidates catalog readers. Hard disable also blocks local-file/cache reads, |
| 40 | new network work, cache writes and a late refresh's publication. |
| 41 | |
| 42 | Startup can read a bounded regular cache file and launch a background refresh; |
| 43 | network success is never a startup dependency. Missing, rejected, inapplicable |
| 44 | or expired facts leave the remaining catalog authorities usable. Status reports |
| 45 | whether facts are off, inert, verified, rejected or unavailable through the |
| 46 | existing compact catalog/status surface. |
| 47 | |
| 48 | ## Key roles |
| 49 | |
| 50 | Every pinned key has a role, recorded in both trust tables and compared by |
| 51 | `check:facts`. One public key may appear under one key ID only. |
| 52 | |
| 53 | - `founder`: held by a person, may sign any payload the client understands, on |
| 54 | any channel. |
| 55 | - `automation`: for a scheduled publisher. A payload authenticated only by an |
| 56 | automation key is accepted when all of the following hold, and is otherwise |
| 57 | rejected whole as outside the key's scope: |
| 58 | - the channel the client asked for ends in `-models`. An automation key can |
| 59 | never authenticate `stable`, `beta` or any other founder channel, so it |
| 60 | cannot replace a founder release or move that channel's rollback floor; |
| 61 | - `facts_version` equals `published_at` in Unix seconds, so a version cannot |
| 62 | run ahead of the clock and exhaust the channel's version space; |
| 63 | - `not_after` is present, later than `published_at`, and at most seven days |
| 64 | after it. Both timestamps are whole-second UTC; |
| 65 | - it carries at most 256 model entries and no provider defaults, release |
| 66 | facts, announcements or field outside the known payload fields; |
| 67 | - every model entry is an upsert or a deprecation using only `provider`, |
| 68 | `id`, `op`, `context_window`, `max_output`, `reasoning`, `display_name`, |
| 69 | `deprecated_at`, `replacement`, `note`, `applies_to` and |
| 70 | `pricing_withheld`. Prices, `allow_unlisted`, `reasoning_options` and any |
| 71 | other field are refused; |
| 72 | - text fields are plain (no control characters) and bounded, a context window |
| 73 | is between 1,024 and 20,000,000 tokens, and a maximum output is between 1 |
| 74 | and 2,000,000 and not above the context window. |
| 75 | |
| 76 | The same rule is written three times: `automation_scope_violation` in |
| 77 | `crates/config/src/cloud_facts/verify.rs`, `automationScopeViolation` in |
| 78 | `web/lib/cloud-facts.ts`, and the function of that name in |
| 79 | `web/scripts/facts-publish.mjs`. All three are tested against |
| 80 | `docs/cloud-facts/fixtures/automation-scope-cases.json`. |
| 81 | |
| 82 | If an envelope carries both a founder and an automation signature that verify, |
| 83 | the founder signature decides and the scope does not apply. |
| 84 | |
| 85 | What this does not do: |
| 86 | |
| 87 | - **No automation key is pinned**, and a test in each language fails if one |
| 88 | appears without that test being changed. |
| 89 | - **No client fetches a `-models` channel.** On the `registry` channel (below), |
| 90 | a future pinned automation key may sign bounded model-and-offering registry |
| 91 | updates, never new provider admissions. |
| 92 | - **No scheduled publisher exists**, and `emit-sql --public-key` still performs |
| 93 | no pin, role or scope check. |
| 94 | - The seven-day limit bounds one payload. A client keeps applying a cached |
| 95 | payload through the existing 48-hour grace after `not_after`, and whoever |
| 96 | holds the key can sign a new payload at any time. |
| 97 | |
| 98 | ## Verification and expiration |
| 99 | |
| 100 | The `facts/v1` envelope contains exact base64 payload bytes, their SHA-256, |
| 101 | Ed25519 signatures and repeated metadata. The signed message is: |
| 102 | |
| 103 | ``` |
| 104 | "codewhale-facts/v1\0" || key_id || "\0" || payload_bytes |
| 105 | ``` |
| 106 | |
| 107 | Clients verify bounded envelope/payload sizes, supported envelope and algorithm, |
| 108 | an active pinned key, signature and digest, signed/outer metadata agreement, |
| 109 | channel, schema, semantic-version applicability and the accepted version floor. |
| 110 | The key ID participates in the signature. Rotation can carry extra signatures; |
| 111 | at least one active approved key must verify. A database key registry is not a |
| 112 | trust root. |
| 113 | |
| 114 | Publication, expiration and announcement dates must be valid UTC timestamps. |
| 115 | Future publications are rejected outside the bounded clock tolerance. Signed |
| 116 | expiry is never extended by a successful refresh or `304`. The client's stated |
| 117 | 48-hour expiry grace is included in the scoped validity bound; after that bound |
| 118 | facts are stale and cannot supply catalog prices or defaults. The public relay |
| 119 | rejects expired delivery. Per-item applicability and announcement windows are |
| 120 | re-evaluated when cached data is reused. |
| 121 | |
| 122 | A `304` authenticates nothing by itself: cached bytes must re-verify against the |
| 123 | current keys, channel, binary version, rollback floor and clock. Cache and ETag |
| 124 | identity are partitioned by source/channel, and channel rollback protection |
| 125 | survives a source change. HTTP bodies, outer disk cache records and labels are |
| 126 | bounded; cache/local readers reject symlinks, non-regular files, multiply linked |
| 127 | files and oversized input. A failed or untrusted response cannot become a new |
| 128 | catalog authority. |
| 129 | |
| 130 | ## Catalog and cost behavior |
| 131 | |
| 132 | The existing compiler inserts cloud facts at layer 15: |
| 133 | |
| 134 | ``` |
| 135 | 0 bundled Models.dev < 10 live Models.dev < 12 Codewhale corrections |
| 136 | < 15 verified cloud facts < 20 provider-owned live < 25 Codewhale account |
| 137 | < 30 config < 40 user overrides < policy DENY |
| 138 | ``` |
| 139 | |
| 140 | An upsert patches specified metadata fields. `pricing_withheld` (a reason) |
| 141 | clears a row's price so it reads as unknown rather than as a misleading flat |
| 142 | rate; the bundled corrections in `crates/config/assets/catalog_corrections.json` |
| 143 | use the same field and patch code. Creating a row requires either its |
| 144 | context window or an `allow_unlisted` assertion (below); an attested ID-only row |
| 145 | is created with every limit, price and capability **unknown** rather than |
| 146 | inferred from a sibling model or a lower stale layer. Deprecation annotates; |
| 147 | hide only removes lower bundled/Models.dev rows. Cloud data cannot delete |
| 148 | provider-live, account, config or user rows. |
| 149 | |
| 150 | **Which rows a patch reaches.** An upsert replaces fields on a row held at |
| 151 | layer 0 or 10 — the bundled Models.dev seed or a live Models.dev refresh, |
| 152 | including rows a bundled Codewhale correction patched — and is skipped with a receipt on anything at |
| 153 | layer 20 and above. That reach is the point of the layer split: most models a |
| 154 | user sees are described by Models.dev rather than by the provider, so a stale |
| 155 | context window or a changed rate on such a model is exactly what a signed |
| 156 | correction exists to fix, without a reinstall. |
| 157 | |
| 158 | The distinction is what was *asked*, not what was fetched most recently. A |
| 159 | provider `/v1/models` answer is a fact about an endpoint the user |
| 160 | authenticated to, so it outranks a signed correction and is only ever |
| 161 | completed, never displaced. A Models.dev refresh is a public third-party |
| 162 | catalog that is merely fresher than the copy compiled into the binary, so it |
| 163 | is corrigible on the same terms as that copy. A refreshed row therefore carries |
| 164 | `CatalogSource::ModelsDevLive` and no endpoint fingerprint; only a provider |
| 165 | roster carries `CatalogSource::Live`. |
| 166 | |
| 167 | A provider `/v1/models` roster is authoritative for the IDs it lists **and for |
| 168 | its own omissions**. This client keeps no history of past rosters, so it cannot |
| 169 | tell a never-listed preview from a model the provider retired, and it does not |
| 170 | guess: no local layer — bundled, Models.dev, or anything else — is evidence |
| 171 | about what a provider once served. Without an explicit assertion the roster |
| 172 | stands, and a signed patch can never put an omitted ID back. |
| 173 | |
| 174 | `allow_unlisted` is that explicit assertion: a signed boolean on one model |
| 175 | patch, default false, meaning "this exact ID is available on this provider's |
| 176 | official endpoint even though the roster omits it". It is honored only on an |
| 177 | `upsert` and only in a payload that carries `not_after`, so the claim always |
| 178 | expires and has to be renewed by publishing rather than lived with. An older |
| 179 | client that predates the field deserializes it as false and simply keeps roster |
| 180 | dominance. The assertion grants nothing else: it does not bypass identity, |
| 181 | region, endpoint, account/OAuth entitlement, or user configuration precedence, |
| 182 | and it names one exact ID — no prefix, family or fallback. |
| 183 | |
| 184 | `hide` and `deprecate` act on a row the local catalog holds. An attested row is |
| 185 | retracted by dropping its upsert from the next payload or letting `not_after` |
| 186 | lapse. A failed or rejected request is never treated as evidence a model is |
| 187 | absent, and no fallback model is substituted for one. |
| 188 | |
| 189 | A roster that answers with IDs alone has said nothing about limits or |
| 190 | capabilities — it has not said they are unknown. Signed values therefore |
| 191 | **complete** a provider-live row where it is silent, and never displace what the |
| 192 | provider stated: layer 20 still wins every field it sets. Completion covers |
| 193 | context, max output and reasoning support. One helper does this for the picker, |
| 194 | the metadata lookup and the route resolver alike, so those three cannot drift; |
| 195 | on the route-scoped surfaces it is gated by the identity/endpoint rule below, |
| 196 | while the cross-provider merged view stays partition-scoped as it already is for |
| 197 | ordinary patches. It deliberately excludes price: a |
| 198 | filled price would sit on a provider-live row with a signed price source, which |
| 199 | the dispatch-quote check does not admit, so it would render without being |
| 200 | billable. Cloud prices continue to apply only where no fresh roster owns the |
| 201 | row, keeping the price classes atomic and the source recorded. |
| 202 | |
| 203 | Signed rows are scoped to one canonical provider identity on that provider's |
| 204 | official HTTPS endpoint contract, so a custom or proxied base URL never inherits |
| 205 | them. Catalog partitions collapse regional and dual-wire aliases onto a vendor |
| 206 | primary (`deepseek-cn` and `deepseek-anthropic` read `deepseek`; |
| 207 | `siliconflow-CN` reads `siliconflow`), and that collapse is not a channel for |
| 208 | facts: only a route whose own canonical identity is the identity the payload |
| 209 | names consumes them, matching how provider defaults have always been keyed. |
| 210 | Signing for an identity the catalog collapses is therefore inert rather than |
| 211 | cross-applied. The cross-provider merged view remains partition-scoped by |
| 212 | design; the endpoint contract is enforced at the route-scoped surfaces that |
| 213 | execution, pricing, and the model list read. |
| 214 | |
| 215 | Capability and price provenance are independent. A capability-only patch keeps |
| 216 | the original price source. A cloud price block replaces all token classes |
| 217 | atomically; omitted cache/input/output classes remain unknown. The source |
| 218 | records signed facts version, verifying key, fetch time and validity bound. |
| 219 | Mutable cloud prices are frozen with the exact dispatch route and persisted |
| 220 | with the existing cost receipt. Later refresh/disable cannot reprice that turn, |
| 221 | and an old receipt with no frozen cloud quote cannot borrow a later cloud price. |
| 222 | Provider-owned billing tiers, subscription/local surfaces and routing-dependent |
| 223 | prices retain their existing checks. |
| 224 | |
| 225 | Cloud model defaults are consulted only when no explicit selection or stronger |
| 226 | provider/account roster applies, through the normal route resolver. Codex model |
| 227 | availability and Ollama endpoint tags retain their own authority. Cloud data |
| 228 | cannot introduce a provider implementation, billing owner or wire protocol. |
| 229 | A cloud `base_url` field is accepted only by the shared static public HTTPS |
| 230 | endpoint contract; it is not consumed to migrate an execution endpoint. |
| 231 | |
| 232 | ## Model and provider registry (`registry.json`) |
| 233 | |
| 234 | The signed models-and-providers registry (`codewhale.registry.v1`) travels in |
| 235 | the same `facts/v1` Ed25519 envelope on the `registry` channel (up to 8 MiB |
| 236 | payload), verified by `crates/config/src/cloud_facts/registry.rs` and fetched |
| 237 | and cached by `crates/cloud-facts/src/registry.rs` at |
| 238 | `$CODEWHALE_HOME/facts/registry-cache.json`. Full schema, resolver overlay |
| 239 | precedence, and pulled-provider admission rules live in |
| 240 | [Models and providers](MODELS_AND_PROVIDERS.md#4-signed-registryjson-codewhaleregistryv1-updates). |
| 241 | |
| 242 | Envelope and transport rules shared with cloud facts: |
| 243 | |
| 244 | - Follows `[cloud_facts]` opt-in (`enabled = false` by default) and |
| 245 | `CODEWHALE_DISABLE_CLOUD_FACTS=1` hard disable; CI suppresses network pulls. |
| 246 | When enabled, the source defaults to |
| 247 | `https://codewhale.net/api/facts/v1/registry` (or `CODEWHALE_CLOUD_FACTS_URL` |
| 248 | when templated with `{channel}`), overridable via `CODEWHALE_REGISTRY_URL` or |
| 249 | `CODEWHALE_REGISTRY_PATH`. |
| 250 | - `envelope.facts_version` must equal `registry.revision` (`>= 1`), |
| 251 | `envelope.published_at` must equal `registry.generated_at` (not in the future |
| 252 | beyond clock tolerance), `sha256` must match, and `revision` must not fall |
| 253 | below the highest accepted revision. Floor checks and overlay installation |
| 254 | share the same lock and source-generation ticket as facts publication, and |
| 255 | disabling cloud facts clears the active registry overlay immediately. |
| 256 | - Key-role boundary on `registry`: a `founder` key may sign model/offering |
| 257 | updates, naming-rule and default changes, and new public-HTTPS |
| 258 | OpenAI-compatible descriptor providers. An `automation` key is accepted only |
| 259 | with a valid bounded `not_after` window, and may change only models, |
| 260 | offerings and built-in providers' `models.aliases` / `models.wire_slugs`; |
| 261 | `accept`, `strip_prefixes`, `ids`, default models, offering default flags, |
| 262 | catalog headers, corrections and `pricing_withheld` need a founder signature |
| 263 | (exact rules in |
| 264 | [Models and providers](MODELS_AND_PROVIDERS.md#key-roles-automation-vs-founder)). |
| 265 | Built-in provider endpoints, auth modes and wire policies are never altered by |
| 266 | pulled data. |
| 267 | - The admission `base_url` check is static. Model requests to a custom provider |
| 268 | whose host an active verified registry admitted resolve that host on every |
| 269 | connection and refuse private, loopback, link-local and cloud-metadata |
| 270 | answers; see |
| 271 | [Models and providers](MODELS_AND_PROVIDERS.md#pulled-provider-admission-ssrf-and-credential-isolation) |
| 272 | for what that guard does and does not cover. |
| 273 | - The website relay (`web/app/api/facts/v1/[channel]/route.ts`) and publisher |
| 274 | (`web/scripts/facts-publish.mjs`) verify and serve `codewhale.registry.v1` |
| 275 | envelopes (`CW-8253`); activating the public `registry` channel row in |
| 276 | Supabase and signing remain operator actions, and the Platform database |
| 277 | export cutover (`CW-8249`, `CW-8255`) remains planned; see |
| 278 | [Models and providers](MODELS_AND_PROVIDERS.md#6-planned-not-shipped-yet). |
| 279 | - As for facts, an equal revision replaces the held copy, and a torn cache |
| 280 | file loses the floor at the next start. |
| 281 | |
| 282 | ## Website transport |
| 283 | |
| 284 | `web/app/api/facts/v1/[channel]/route.ts` implements GET/HEAD for the public |
| 285 | channel. It reads `facts_current` over PostgREST using only the publishable |
| 286 | Supabase key, validates the complete signed envelope and caches only verified |
| 287 | responses. Existing `CURATED_KV` can retain a last-good copy, which is bounded |
| 288 | and revalidated under the same current trust/time rules before stale fallback. |
| 289 | |
| 290 | With no active pinned key, delivery fails closed. Missing connection settings, |
| 291 | invalid upstream data or unavailable backing storage produce explicit errors. |
| 292 | HEAD responses, including errors, have no body. A strong ETag binds the complete |
| 293 | verified envelope, including signatures, so trust-material changes cannot reuse |
| 294 | an old representation validator. Conditional requests do not bypass validation. |
| 295 | |
| 296 | Required deployment configuration, if separately authorized, is `SUPABASE_URL` |
| 297 | and `SUPABASE_PUBLISHABLE_KEY`. A service-role credential never belongs in the |
| 298 | website. `facts_current` must be a read-only view with explicit SELECT grants, |
| 299 | RLS and policies limited to published public channels. This repository slice |
| 300 | performs no remote schema, grant, key, or data mutation; those controls require |
| 301 | separate deployment evidence. |
| 302 | |
| 303 | Two storage properties are part of the delivery contract rather than an |
| 304 | implementation detail, because a published fact is retracted through them: |
| 305 | |
| 306 | - **A channel serves its head version only.** Revoking, expiring or |
| 307 | future-dating the head must make the channel serve *nothing*, never the |
| 308 | previous release. Silently re-serving an older version is a rollback |
| 309 | delivered to every client whose version floor is not yet set; the repair for |
| 310 | a bad release is publishing a higher `facts_version`, and the client's own |
| 311 | rollback floor is the second line of defence, not the first. |
| 312 | - **`facts_version` is monotonic per channel.** Accepting a version at or below |
| 313 | a channel's published high-water mark would let a withdrawn payload return. |
| 314 | |
| 315 | Retraction therefore has two independent halves, and the operator should know |
| 316 | which one they are using. Publishing a later payload that drops the entry (or |
| 317 | letting `not_after` lapse) retracts the *fact*, and a client applies that at its |
| 318 | next successful refresh. `facts-publish.mjs revoke` stops the *release* at the |
| 319 | transport instead: it hands nothing to a client that asks, so a client already |
| 320 | holding the revoked envelope keeps applying it until its cached copy goes stale |
| 321 | — `ttl_secs`, 6 h by default, after which the payload stops being applied |
| 322 | whether or not a refresh succeeds. Neither half is instantaneous, and this layer |
| 323 | has no recall channel; a fact that must stop applying at an exact moment belongs |
| 324 | in `not_after`, not in a later revocation. |
| 325 | |
| 326 | ## Authoring and public fixtures |
| 327 | |
| 328 | `web/scripts/check-cloud-facts.mjs` checks the unsigned source, release receipt, |
| 329 | Rust/web key-table equality and the public signed fixtures. It distinguishes a |
| 330 | valid empty trust table from a parser failure and rejects fixture trust anchors. |
| 331 | |
| 332 | `web/scripts/facts-publish.mjs` supports validation, key generation, signing, |
| 333 | verification, SQL generation and publication. Signing/publishing are operator |
| 334 | actions requiring the relevant authority. Production verification/signing |
| 335 | requires an active pinned key; explicit fixture verification is separate. Key |
| 336 | generation creates a new private file exclusively, and CI signing is rejected |
| 337 | before any private-key read. Numeric version fields must be safe positive |
| 338 | integers before SQL or publication. Do not use real private keys in a repository, |
| 339 | logs or test fixtures. |
| 340 | |
| 341 | `docs/cloud-facts/fixtures/test-only-signing-key.pem` is deliberately public and |
| 342 | has one exact GitGuardian path exception. Its public key is never pinned in a |
| 343 | production table. Tests may sign synthetic payloads using that fixture or an |
| 344 | ephemeral in-memory test key. No fixture signature establishes production trust. |
| 345 | |
| 346 | To activate a future channel: approve key custody and its public anchor, update |
| 347 | both trust tables, verify and ship that anchor, then separately approve signing |
| 348 | and publication. Before signing, choose a facts version above the channel’s |
| 349 | verified published floor; the unsigned source version is not a live-channel receipt. Rotation pins the next key before dual-signing and retiring the |
| 350 | old key; there is no in-band command that can install or expand trust anchors. |
| 351 | |
| 352 | Release notices and announcements are represented and scoped but do not replace |
| 353 | the existing release checker or introduce announcement rendering in this slice. |
| 354 | Organization-specific trust, automated publication and endpoint migration are |
| 355 | not implemented. |
| 356 |