Skip to content
Merged
8 changes: 8 additions & 0 deletions .changeset/3792-relay-jev-reranking.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@schlessera/brain-common": minor
"@schlessera/brain": minor
"@schlessera/brain-ui-sdk": minor
"@schlessera/brain-ui-server": minor
---

Hosted search is reranked again. A governed or strict turn worker whose `TYPESAFE_API_KEY` the host withholds now sends the `jev` reranker's request through the host's provider relay, under the new `typesafe` family (`x-brain-provider: typesafe`, `POST /v1/systemone` only). The host adds its key for `https://api.typesafe.ai` and meters each request as operation `reranking`, with an unknown cost rather than zero. `brain search` and `brain_search` in such a worker no longer report `provider_unavailable` and fall back to lifecycle order. A host without the relay keeps that notice, and a credentialed maintenance worker keeps its JeV key as before.
2 changes: 1 addition & 1 deletion docs/decisions/claude-code-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ next to it.
`packages/ui-server/src/brain/client.ts:180-248`, called at
`probeBrainCliVersion(config.brainPath`, `packages/ui-server/src/app.ts:478`).
`brain doctor` runs `claude mcp list` from `PATH` (`which("claude")`,
`packages/core/src/cli/commands/doctor.ts:505-509`) — the user's own Claude
`packages/core/src/cli/commands/doctor.ts:507-511`) — the user's own Claude
Code on their own machine, to check the MCP registration, not the server's
binary.
- **Two moving parts.** The SDK is a runtime dependency of
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/cost-tracking.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,10 +228,10 @@ feed the inference budgets, not Activity rollups: they never change a run's
recorded or effective cost. Units are what the provider reported in the raw
response, before an SDK converts it. Completion tokens are priced through the
same `RollupPricing` as the agent's own inference, on the direct route
(`priceProviderAttempt`, `packages/ui-server/src/pricing/provider-pricing.ts:36-75`).
(`priceProviderAttempt`, `packages/ui-server/src/pricing/provider-pricing.ts:38-77`).
Embeddings are in neither remote catalog, so the built-in model has one dated
row per input modality, from Google's published list price, and it counts as
an estimate (`GEMINI_EMBEDDING_PRICES`, `packages/ui-server/src/pricing/provider-pricing.ts:23-25`).
an estimate (`GEMINI_EMBEDDING_PRICES`, `packages/ui-server/src/pricing/provider-pricing.ts:25-27`).
A modality without a row, inline media without a modality split, and every
image request stay unpriced. The CLI's own per-image estimate is not a provider
receipt and is never booked. Unknown is never zero here either: an attempt
Expand Down
13 changes: 8 additions & 5 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,10 +543,13 @@ maintenance worker no longer receives the keys the provider relay carries
(`GEMINI_API_KEY`, `ANTHROPIC_API_KEY`, `OPENAI_API_KEY` and keys the operator
lists for it), and the brain's `.env*` files are masked as they are for a
credential-free worker. Its `brain` CLI reaches those providers through its own
relay (`providerRelayFor`, `packages/ui-server/src/brain/host-boundary.ts:432-439`).
relay (`providerRelayFor`, `packages/ui-server/src/brain/host-boundary.ts:441-448`).
What remains is narrower and stated in the status: keys the relay does not
carry (the `jev` reranker's, a `brain sync` agent runner's login) and every
key on a host without managed native storage, where there is no relay.
key on a host without managed native storage, where there is no relay. Since
#3792 a turn worker's `jev` reranker is relayed; a maintenance worker keeps
that key, because its sync judge and propagation review call TypeSafe
directly.

### Module jobs: durable state and other repositories — 2026-11-02 (#3380)

Expand Down Expand Up @@ -672,7 +675,7 @@ the key and forwards it as the turn's own egress (G5). A key goes only to its
built-in first-party origin, or to an exact origin the operator lists for that
key in `BRAIN_UI_CLI_PROVIDER_ORIGINS`, under the 2026-10-23 ruling on #1673;
the backends' origin rulings grant the CLI nothing by analogy
(`startProviderRelay`, `packages/ui-sdk/src/server/provider-relay.ts:323-328`).
(`startProviderRelay`, `packages/ui-sdk/src/server/provider-relay.ts:329-334`).
The inference relay's placeholder is not a key: the launcher names a key that
holds it as withheld, so a relayed Claude API-key turn's `anthropic-haiku`
reaches the host's key instead of failing authentication. The `jev` reranker
Expand Down Expand Up @@ -4200,7 +4203,7 @@ only that line for a refused CONNECT. The provider relay passes the proxy's
reason through as the refusal body's `error.message` and an additive
`error.reason`, using the `egress_denial` reason words plus
`outward_not_approved` (`const refuse`,
`packages/ui-sdk/src/server/provider-relay.ts:386-391`). The OpenAI image
`packages/ui-sdk/src/server/provider-relay.ts:392-397`). The OpenAI image
provider no longer appends its account hint to a relay refusal
(`const relayRefusal`, `packages/module-images/src/providers/openai.ts:258-259`).
A cancelled connection keeps its bare 403. The system prompt's turn-lifecycle
Expand Down Expand Up @@ -4352,7 +4355,7 @@ files, `.claude/`, `.agents/`, `.pi/`, `.mcp.json`, and
- The core CLI loads `brain.config.ts` or `brain.config.json` at the canonical
brain cwd (`loadUserConfig`, `packages/core/src/lib/config.ts:660-694`).
Host commands bind that cwd to the selected brain (`function hostSpawn`,
`packages/ui-server/src/brain/host-boundary.ts:526-537`).
`packages/ui-server/src/brain/host-boundary.ts:535-546`).
- Bun startup uses root `bunfig.toml` and `package.json`; retained literal
preload/module inputs can identify a nested module's nearest package scope.
The inventory walks parent directories only within the originating journal
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/interpreted-briefing.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ deadline, one bounded rate-limit retry and explicit failure outcomes
(`createJevClient`, `packages/core/src/lib/jev.ts:248-333`). The search
reranker also uses Choice, but asks which search candidate answers a query;
its probabilities rank candidate IDs, not briefing action categories
(`jevReranker`, `packages/core/src/providers/rerankers/jev.ts:227-244`).
(`jevReranker`, `packages/core/src/providers/rerankers/jev.ts:231-248`).
Reuse the transport, not the search question. TypeSafe's
[API reference](https://docs.typesafe.ai/api) and
[model limitations](https://docs.typesafe.ai/model-jaggedness/jev-1.13)
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/runtime-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ Paths may appear in local diagnostics; public fixtures use temporary paths.
| --- | --- | --- |
| Claude backend's SDK range | Retain `^0.3.241` | It is the published declaration (`"@anthropic-ai/claude-agent-sdk"`, `packages/ui-backend-claude/package.json:49`). Registry metadata on 2026-09-30 confirms 0.3.241 exists. This is a declared compatibility bound, not proof every allowed release passed current measurements. |
| ui-server's content CLI floor | Retain `0.33.0` | `--` support is the reason documented immediately above `MIN_BRAIN_CLI_VERSION` (`MIN_BRAIN_CLI_VERSION`, `packages/ui-server/src/brain/client.ts:132`); the initial boot refusal test used 0.32.9. The current test exercises the corrected floor (`a 0.40.0 brain repo pin`, `packages/ui-server/tests/brain-client.test.ts:247-259`). |
| Bun engine floor | Retain existing `>=1.3.5` declarations | Existing engine metadata and the doctor's CVE-based warning (`const MIN_BUN`, `packages/core/src/cli/commands/doctor.ts:50`; `function checkRuntime`, `packages/core/src/cli/commands/doctor.ts:87-94`). This record introduces no new doctor verdict or blanket boot gate. |
| Bun engine floor | Retain existing `>=1.3.5` declarations | Existing engine metadata and the doctor's CVE-based warning (`const MIN_BUN`, `packages/core/src/cli/commands/doctor.ts:51`; `function checkRuntime`, `packages/core/src/cli/commands/doctor.ts:88-95`). This record introduces no new doctor verdict or blanket boot gate. |
| Pi SDK requirements | Retain existing exact `0.87.1` declarations | `packages/ui-backend-pi/package.json`; a host floor composes with each actual imported Pi dependency's existing exact requirement. The Claude range ruling does not authorize changing Pi's pins. |
| Additional default Claude runtime floor | None | There is no evidenced numerical incompatibility threshold in the existing record. The successful pairs are observations, not proof that the preceding release fails. A new library floor needs a feature requirement or reproducible incompatibility and its versioning review. |
| Example host SDK/runtime floors | `0.3.283` / `2.1.283` | The installed SDK manifest and `MEASURED_RUNTIME` (`export const MEASURED_RUNTIME`, `packages/ui-backend-claude/src/measured-runtime.ts:18-25`) identify this measured pair, rechecked in commit `e1ce9600`. This is a host choosing the demonstrated baseline, not a new default package floor. |
Expand Down
4 changes: 2 additions & 2 deletions docs/extending/compute-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ inside core. Core declares it as an optional peer; an instance naming `boat`
without the package installed is `provider_unavailable` and names the install
it needs. A built-in package is loaded only when an instance names it; it
exports `computeProvider` and may export `defaultKeyEnv`, the variable an
instance without `apiKeyEnv` reads (`export async function loadComputePackage`, `packages/core/src/lib/registry.ts:437-461`).
instance without `apiKeyEnv` reads (`export async function loadComputePackage`, `packages/core/src/lib/registry.ts:439-463`).
Resolution gives each instance its own options and secret
(`export async function resolveComputeInstance`, `packages/core/src/lib/registry.ts:515-561`).
(`export async function resolveComputeInstance`, `packages/core/src/lib/registry.ts:517-563`).

## The Boat built-in

Expand Down
28 changes: 16 additions & 12 deletions docs/hosting/agent-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -1341,15 +1341,15 @@ keep.
| Claude through the host inference relay | Only placeholders under the Claude CLI's own variables |
| pi through the relay | Nothing |
| Restricted (autonomous) | Unchanged: its envelope's minimum environment |
| Maintenance workers | No relayed key (`GEMINI_API_KEY`, `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, and keys listed in `BRAIN_UI_CLI_PROVIDER_ORIGINS`) and no `.env*`; the CLI reaches those providers through the [metered relay](#metered-provider-relay-1673). Keys the relay does not carry (`TYPESAFE_API_KEY`, `CLAUDE_CODE_OAUTH_TOKEN` for a `brain sync` agent runner) stay |
| Maintenance workers | No relayed key (`GEMINI_API_KEY`, `ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, and keys listed in `BRAIN_UI_CLI_PROVIDER_ORIGINS`) and no `.env*`; the CLI reaches those providers through the [metered relay](#metered-provider-relay-1673). Keys the relay does not carry for them stay: `TYPESAFE_API_KEY`, which their sync judge and propagation review send to TypeSafe directly (only turn workers relay it, #3792), and `CLAUDE_CODE_OAUTH_TOKEN` for a `brain sync` agent runner |

**Which commands need a key.** The audit of the first-party commands an agent
runs in its worker:

| Command | Key it reads (default variable) | In a worker that lacks it |
| --- | --- | --- |
| `brain search` (hybrid or vector), and `brain_search` from the brain's own `brain mcp` server | The embeddings provider's `apiKeyEnv` (`GEMINI_API_KEY`) for the query embedding | Keyword results. The warning names the provider, with `degraded_to=keyword_search` (`none` for `--mode vector`) |
| `brain search` with an enabled `jev` reranker or `--rerank jev` | The reranker's `apiKeyEnv` (`TYPESAFE_API_KEY`) | Lifecycle order, `degraded_to=lifecycle_order` |
| `brain search` with an enabled `jev` reranker or `--rerank jev` | The reranker's `apiKeyEnv` (`TYPESAFE_API_KEY`) | Lifecycle order, `degraded_to=lifecycle_order`, on a host without the relay; reranked through it otherwise (#3792) |
| `brain index --embeddings` | The embeddings key | A keyword index, `degraded_to=keyword_index` on stderr |
| `brain process` | The completions provider's `apiKeyEnv` (`GEMINI_API_KEY` for `gemini-flash`, `ANTHROPIC_API_KEY` for `anthropic-haiku`) | Refused, naming the provider |
| `brain image` | `OPENAI_API_KEY`, `GEMINI_API_KEY` | Refused, naming each withheld provider (the pinned one with `--provider` or `--model`) |
Expand Down Expand Up @@ -1378,8 +1378,9 @@ worker keeps its ordinary messages. The token's grammar is part of the
**What #1673 changes.** On a turn with a turn proxy, the commands above that
use a Gemini, Anthropic or OpenAI image provider work again, through the
[metered relay](#metered-provider-relay-1673), with no key in the worker. The
`jev` reranker still reports `provider_unavailable`; `brain video watch` is
relayed since #2738.
same holds for `brain video watch` since #2738, and for the `jev` reranker
since #3792: a relayed turn's `brain search` and `brain_search` are reranked
instead of reporting `provider_unavailable`.
A relayed Claude API-key turn holds the inference placeholder under
`ANTHROPIC_API_KEY`; the launcher names that key in `BRAIN_WITHHELD_KEYS`, and
the CLI's `anthropic-haiku` reaches the host's key through the relay instead of
Expand All @@ -1396,8 +1397,9 @@ own at `/run/brain-providers/relay.sock`. The launcher names it in
its native request there (the routes are in the
[CLI contract](../integration-contract/cli.md#provider-relay-additive-0440-1673)):
Gemini embeddings and completions, the Gemini Files lifecycle a local video
needs (#2738), Anthropic completions, and OpenAI and Gemini images. The `jev`
reranker is not relayed.
needs (#2738), Anthropic completions, OpenAI and Gemini images, and the `jev`
reranker's one request (#3792). A maintenance run keeps its JeV key and does
not relay it.

**Video files (#2738).** A relayed `brain video watch` uploads, polls, uses and
deletes its file through the relay. The relay keeps the upload URL the provider
Expand All @@ -1414,8 +1416,9 @@ deleted with the host's key when the turn's relay stops.

**Who may receive a key.** The relay sends `GEMINI_API_KEY` only to
`https://generativelanguage.googleapis.com`, `ANTHROPIC_API_KEY` only to
`https://api.anthropic.com` and `OPENAI_API_KEY` only to
`https://api.openai.com`, in the header that provider expects. A custom
`https://api.anthropic.com`, `OPENAI_API_KEY` only to
`https://api.openai.com` and `TYPESAFE_API_KEY` only to
`https://api.typesafe.ai`, in the header that provider expects. A custom
endpoint (`GOOGLE_GEMINI_BASE_URL`, `GEMINI_BASE_URL`, `OPENAI_BASE_URL`) or a
custom `apiKeyEnv` is refused, before any contact, unless the operator lists
that key and exact origin in `BRAIN_UI_CLI_PROVIDER_ORIGINS`:
Expand Down Expand Up @@ -1443,8 +1446,8 @@ read from the raw response before any SDK drops them. An attempt a crash
interrupts therefore stays disclosed. When a turn ends, its relay waits for
in-flight attempts to report before the turn's accounting closes. Gemini embeddings
are priced at Google's published list price per modality; completions use
the same Activity price table as the agent's own inference; image units stay
unpriced. Reported tokens without a price count toward the unpriced-token
the same Activity price table as the agent's own inference; image units and
JeV reranking (operation `reranking`, #3792) stay unpriced. Reported tokens without a price count toward the unpriced-token
stops; a request whose provider reported no usage is unknown spend and never
blocks by itself. A turn's requests count toward its turn, conversation and
UTC-day budgets and appear in its budget receipt, whose coverage now names
Expand Down Expand Up @@ -1700,7 +1703,8 @@ qualifies existing first-party request shapes. The
[metered provider relay](#metered-provider-relay-1673) built on it in
[#1673](https://github.com/schlessera/brain-kit/issues/1673) relays the rows
below except video and JeV; [#2738](https://github.com/schlessera/brain-kit/issues/2738)
added video.
added video and [#3792](https://github.com/schlessera/brain-kit/issues/3792)
JeV, for turn workers.

| CLI consumer / provider | Credential selection | Native destination and request family | Accounting at the consumer |
| --- | --- | --- | --- |
Expand All @@ -1715,7 +1719,7 @@ The factories and concrete recipient provenance are implemented at
(`geminiEmbeddings`, `packages/core/src/providers/embeddings/gemini.ts:59-221`),
(`geminiCompletions`, `packages/core/src/providers/completions/gemini.ts:56-134`),
(`anthropicCompletions`, `packages/core/src/providers/completions/anthropic.ts:63-147`)
and (`jevReranker`, `packages/core/src/providers/rerankers/jev.ts:227-347`).
and (`jevReranker`, `packages/core/src/providers/rerankers/jev.ts:231-272`).
Configured model labels, endpoint overrides and key-variable names select native
routing; none grants permission to release a host-held credential.

Expand Down
3 changes: 2 additions & 1 deletion docs/hosting/paid-cli-provider-qualification.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ the maintainer's 2026-10-23 rulings on that issue: first-party recipients by
default plus `BRAIN_UI_CLI_PROVIDER_ORIGINS`, a socket the CLI finds through
`BRAIN_PROVIDER_RELAY_SOCKET`, per-attempt rows with no reservation, maintenance
charged to its turn or day, and no relay for video or JeV. #2738 later relayed
the video Files lifecycle (see below). The sections below
the video Files lifecycle (see below), and #3792 the JeV reranker's request for
turn workers (`typesafe` family, operation `reranking`, unpriced). The sections below
keep the audit's evidence and requirements; where the relay settles one, it
says so.

Expand Down
13 changes: 13 additions & 0 deletions docs/integration-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ same-commit update of the index or relevant authoritative component. How they ar

The reasoning is in [decisions/contract-versioning.md](decisions/contract-versioning.md).

## JeV reranking through the provider relay (additive, 0.45.0, #3792)

The CLI provider relay gains the `typesafe` family, `x-brain-provider:
typesafe`, whose only route is `POST /v1/systemone`. A governed or strict turn
worker whose `TYPESAFE_API_KEY` the host withholds sends the `jev` reranker's
request there; the host adds its key for `https://api.typesafe.ai` and meters
the attempt as operation `reranking`, with an unknown cost rather than zero.
Such a worker's `brain search` and `brain_search` are reranked instead of
reporting `provider_unavailable` and falling back to lifecycle order; a host
without the relay keeps that notice. Credentialed maintenance workers keep the
key as before. See [the CLI component](integration-contract/cli.md#provider-relay-additive-0440-1673).
This ships in a minor; no breaking ruling is required.

## The Start card's persona choice (additive, 0.45.0, #3698)

In `@schlessera/brain-ui-react`, the conversation client's state adds
Expand Down
Loading
Loading