Repository navigation
CONTRACT: feat(ui-sdk,core): relay Jev reranking for governed workers - #4024
Merged
Merged
Conversation
A governed or strict turn worker never holds TYPESAFE_API_KEY, and the CLI provider relay had no family for Jev, so every hosted search ran in lifecycle order with a provider_unavailable notice. The relay gains the `typesafe` family: one route, POST /v1/systemone, with the host's key placed as a bearer token for https://api.typesafe.ai (or an operator-listed exact origin). Each attempt is metered as operation `reranking`; no rate is held for it, so its cost is unknown, never $0. The in-worker jev reranker and its selection use the relay when the key is withheld and a relay socket is present; hosts without the relay keep the notice. Credentialed maintenance runs keep the key, since their sync judge and propagation review call TypeSafe directly. Refs #3792 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 15, 2026
ui-server: a reference clone under workspaces/ counts toward files_changed and pauses the turn
#3793
Closed
Merged
8 of 9 tasks
9 tasks done
This was referenced Nov 15, 2026
Merged
3 of 5 tasks
…eranking # Conflicts: # docs/decisions/governed-writable-workers.md
This was referenced Nov 15, 2026
schlessera
marked this pull request as ready for review
November 15, 2026 20:53
This was referenced Nov 15, 2026
This was referenced Nov 15, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #3792
What changed
A governed or strict turn worker's
brain searchandbrain_searchare reranked byjevagain. Before, the worker never heldTYPESAFE_API_KEYand the CLI provider relay had no family for Jev, so every hosted search printedprovider_unavailableand fell back to lifecycle order. The relay now has atypesafefamily (x-brain-provider: typesafe) whose only route isPOST /v1/systemone. The host puts its key on that request asAuthorization: Bearer, forhttps://api.typesafe.aior an exact origin the operator lists inBRAIN_UI_CLI_PROVIDER_ORIGINS. Each attempt is metered as operationreranking. No rate is held for it, so it counts as unknown spend and toward the unpriced-token stops, never as$0. The in-worker reranker (jevReranker) and its selection (selectReranker,brain doctor) use the relay when the key is withheld and a relay socket is present. A host without the relay keeps the notice. Credentialed maintenance runs keepTYPESAFE_API_KEYas before.Why this shape
It follows the existing families (#1673, #2738): a fixed first-party route, exact origin and key binding, worker credentials stripped, the host key placed on the host, and budget admission before and just before dispatch. Nothing about validation, cancellation, redirects or redaction changes. I named the family after the vendor (
typesafe), asgemini,anthropicandopenaiare, rather than after the model.Maintenance runs deliberately keep the key. Once Jev is a built-in family,
relayedProviderKeyswould otherwise stripTYPESAFE_API_KEYfrom every credentialed maintenance run. That would break their sync judge and propagation review, which call TypeSafe directly through core'screateJevClient, outside the relay. The issue puts those uses out of scope, somaintenanceRelayedKeys(packages/ui-server/src/brain/host-boundary.ts) leaves the key in place unless the operator lists it, which is the same behaviour as today. The agent-facing relay note and the worker-host status line now say JeV is relayed. The note also stopped saying video is not relayed, which has been wrong since #2738.Contract (additive): a new relay family and route in
docs/integration-contract/cli.md("Provider relay"), plus an index entry indocs/integration-contract.md. The@schlessera/brain-commonProviderRelayFamilyand ui-sdkProviderOperationunions gain a member each. Both are/internal, and the regeneratedapi-report/is unchanged. A minor changeset is included.Proof
Failing first, on the tree before the change:
packages/core/tests/provider-relay-jev.test.ts:RELAYED_JEV_SELECTED, expected"jev", received"heuristic".packages/ui-sdk/tests/provider-relay.test.ts(jev reranking (#3792), 12 cases): the reranking request got403instead of200. Each refusal case failed onJEV_RELAY_REFUSES_OTHER_REQUESTS, gettingfamily: null, reason: "unknown_family"instead of the route-specific reason.Mutations, each restored after:
jevReranker, replaceproviderRelayFetch("typesafe", apiKeyEnv)withundefined, so the client goes direct. Both bubblewrap end-to-end cases inpackages/ui-sdk/tests/worker-provider-relay.test.ts(a governed/strict turn worker's jev reranking (#3792)) fail onRELAYED_JEV_NO_NOTICE.typesafekey placement inprovider-relay.ts.JEV_RELAY_PLACES_HOST_KEY(unit) andRELAYED_JEV_HOST_KEY_PLACED(both bubblewrap cases) fail.rerankingat$0inpriceProviderAttempt.JEV_RERANKING_UNPRICEDinpackages/ui-server/tests/provider-relay-budgets.test.tsfails.End to end, under real bubblewrap, governed and strict, keyless:
brain search --rerank jevreaches the relay. A loopback stand-in on the Jev route getsBearer <host key>and no worker headers, and the stand-in's choice ranks first.typesafe/rerankingwith the reported usage. The worker's environment holds noTYPESAFE_API_KEYand names it inBRAIN_WITHHELD_KEYS.Local runs: 171 tests pass across the affected core, common, ui-sdk and ui-server relay, reranker and budget files.
bun run typecheck,bun run lint,bun scripts/env-docs.ts --checkandbun run api-report(no diff) are clean.Draft heavy feedback at
bb51fc83(run 43736254493): unit 1-4, runtime, runtime_host, browser 1-3, layout 1-2, captures, endurance and pack all passed, including the maintenance relay and provider-history tests below.Not run locally, needs hosted proof. This host cannot create the namespaces some tests need (
unshare: write failed /proc/self/uid_map;bwrap: No permissions to create a new namespace), even with sandbox escalation. Those tests are:packages/ui-server/tests/maintenance-provider-relay.test.ts. It already asserts maintenance keepsTYPESAFE_API_KEYand names onlyANTHROPIC_API_KEY,GEMINI_API_KEY,OPENAI_API_KEYwithheld, which is exactly whatmaintenanceRelayedKeyspreserves.packages/ui-backend-{claude,pi}/tests/provider-history.test.ts).worker-sandbox.test.tscases, which fail the same way on this host without the change.Citations my edits moved (13) are repaired; no drift remains in the touched files.
Collisions at head
bb51fc83009ecf32db07212fbbdefbe4285fafea(unchanged by the later merge oforigin/mainat4035f977e, and latereb3c53ac2, which overlapped onlydocs/decisions/governed-writable-workers.mdanddocs/integration-contract/package-api.mdand merged cleanly;check:prrerun at the merge head. Later refreshes ontoed4eb5a0cand2702e2bddtouched none of this PR's files and were merges only. Merging #4008 (e1ce188d7on main) overlapped docs,host-boundary.tsandenv.ts; its only conflicts were two citation line numbers ingoverned-writable-workers.md, resolved to the merged anchors, andcheck:prwas rerun at86d8a9cd4) (bun scripts/collisions.ts --json --paths <diff>): path overlaps with #3622, #3806, #4002, #4008 and #4018, all in docs orhost-boundary.ts/env.ts, plus closure-only overlaps with #3054, #3056, #3059, #3069, #3116, #3437, #3581, #4021, #4022 and #4023.{"version":1,"kind":"brain-check-pr-receipt","head":"86d8a9cd40a80dc737c7456b1ca8a6127ef865a4","base":"origin/main","mode":"focused","startedAt":"2026-11-15T20:26:29.549Z","finishedAt":"2026-11-15T20:28:37.449Z","checks":[{"name":"all lint and leakage gates","categories":["changeset"],"outcome":"passed","elapsedMs":19090.412346000005},{"name":"environment documentation","categories":["changeset"],"outcome":"passed","elapsedMs":236.80904400000145},{"name":"pending changeset package names","categories":["changeset"],"outcome":"passed","elapsedMs":209.0428400000019},{"name":"contribution changeset","categories":["changeset"],"outcome":"passed","elapsedMs":25.69923800000106},{"name":"affected fast invariants","categories":["verify","unit"],"outcome":"passed","elapsedMs":108318.90104}]}Guard checklist (the relay route allowlist gained one route):
typesafefamily other than an exactPOST /v1/systemonewith no query is refused (route_not_allowed/method_not_allowed). So is the key toward any origin other thanhttps://api.typesafe.aior a listed one (recipient_not_authorized). It does not cover what a request body contains, as for the other families.refusedcallback and the turn's egress record, as for the other families.Checklist
docs/reflect the change.Anything left open
Nothing for this issue. The sync judge's and propagation review's direct Jev use in maintenance workers stays out of scope, as the issue says (#2504 owns the model-alias mismatch).
🤖 Generated with Claude Code