Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/automatic-index-admission-requeue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-sdk": patch
"@schlessera/brain-ui-server": patch
---
An automatic index refused at maintenance admission because the temporary-storage budget is busy, for example by a turn's scratch check, now stays pending and runs once the budget frees instead of failing. A turn's scratch check and an index you request keep their current outcomes. The busy message names what holds the budget by kind (index, scratch query, git, sync, probe or command), without paths or identities.
3 changes: 3 additions & 0 deletions api-report/ui-sdk.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1057,6 +1057,8 @@ export "./internal" (./src/internal.ts)
type MaintenanceEnvelope
type MaintenanceHost
type MaintenanceResult
MaintenanceTempBusyError
type MaintenanceTempKind
type MaintenanceWorker
NATIVE_MANAGER_MAX_DELTA_BYTES
NATIVE_MANAGER_OPERATION_TIMEOUT_MS
Expand Down Expand Up @@ -1265,6 +1267,7 @@ export "./internal" (./src/internal.ts)
requestPolicyPermission
requireWorkerHost
requireWorkerHostAsync
reserveMaintenanceTemp
resolveMaintenanceTempLimits
resolveOutputStagingLimits
resolveTurnTempLimits
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/claude-code-runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ next to it.
- **Updated.** Nothing in the tree installs, updates, pins or reads the version
of this binary. The only version probe in the server is for the `brain` CLI
(`Probe the selected content CLI`,
`packages/ui-server/src/brain/client.ts:152-220`, called at
`packages/ui-server/src/brain/client.ts:163-231`, called at
`probeBrainCliVersion(config.brainPath`, `packages/ui-server/src/app.ts:450`).
`brain doctor` runs `claude mcp list` from `PATH` (`which("claude")`,
`packages/core/src/cli/commands/doctor.ts:503-507`) — the user's own Claude
Expand Down Expand Up @@ -243,7 +243,7 @@ than refuses on a mismatch.**
pair is one nobody measured.
- **At boot, from the binary a turn would spawn.** The same shape as the
`brain` CLI probe (`Probe the selected content CLI`,
`packages/ui-server/src/brain/client.ts:152`). The SDK's
`packages/ui-server/src/brain/client.ts:163`). The SDK's
resolver is not exported, so the probe must not re-implement it. The SDK
resolves the binary when a query is built, and fails there if none is found
(`node_modules/@anthropic-ai/claude-agent-sdk/sdk.mjs:228`); it then hands
Expand Down
8 changes: 4 additions & 4 deletions docs/decisions/governed-writable-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ 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:420-427`).
relay (`providerRelayFor`, `packages/ui-server/src/brain/host-boundary.ts:422-429`).
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.
Expand Down Expand Up @@ -2267,15 +2267,15 @@ as agent workers. It retains one execution view and binds the owned stage drain
before setup can spawn a worker, so setup failure also preserves unresolved
cleanup authority. Credentialed and no-helper maintenance keep their existing
paths (`launchMaintenanceWorker`,
`packages/ui-sdk/src/server/maintenance-worker.ts:248-330`).
`packages/ui-sdk/src/server/maintenance-worker.ts:250-332`).

The frozen Git adapter is concrete first-party input. Its bounded installer
places only its fixed files in an initially absent private control directory
inside the existing attested stage. Each consumer sees the fixed Git target
read-only; its writable stage alias is concealed and the control directory is
excluded even from default-scope publication. This changes no source modes,
manager reader authority or helper protocol (`prepareMaintenanceGitInput`,
`packages/ui-sdk/src/server/maintenance-worker.ts:97-115`). Required lower Git
`packages/ui-sdk/src/server/maintenance-worker.ts:99-117`). Required lower Git
metadata must still support the actual consumer operations; safe.directory is
an exact host-selected-root check, not permission to write an unmapped inode.
For the three fixed Git mask targets, originally absent directories are created
Expand Down Expand Up @@ -3918,7 +3918,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:594-628`).
Host commands bind that cwd to the selected brain (`function hostSpawn`,
`packages/ui-server/src/brain/host-boundary.ts:511-522`).
`packages/ui-server/src/brain/host-boundary.ts:514-525`).
- 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
8 changes: 4 additions & 4 deletions docs/decisions/http-api-boundary.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ explicit supported rows, not silently excluded by this distinction.

The source audit on 2026-09-30 used
`e0875269b21b707482545be9e94901acb897893b`. The public health mount precedes auth
(`createHealthRoutes`, `packages/ui-server/src/app.ts:918`), the API guard follows
public ceremonies (`authGuard`, `packages/ui-server/src/app.ts:939`), and the
WebSocket admission is separate (`"/ws"`, `packages/ui-server/src/app.ts:1145`).
(`createHealthRoutes`, `packages/ui-server/src/app.ts:920`), the API guard follows
public ceremonies (`authGuard`, `packages/ui-server/src/app.ts:941`), and the
WebSocket admission is separate (`"/ws"`, `packages/ui-server/src/app.ts:1147`).
Static serving is conditional (`if (options.staticRoot)`,
`packages/ui-server/src/app.ts:1165-1186`). That order establishes access;
`packages/ui-server/src/app.ts:1167-1188`). That order establishes access;
it does not select compatibility status.

A hermetic real-app launch, with temporary brain root, in-memory database,
Expand Down
2 changes: 1 addition & 1 deletion docs/decisions/native-brain-storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ A failed or interrupted preparation poisons the stage for further payloads and
publication until it is discarded. The private control marker is bound to the
existing stage/checkpoint, command generation, descriptor and owned drain;
no generic copying or reader authority is added (`prepareMaintenanceWorker`,
`packages/ui-sdk/src/server/maintenance-worker.ts:117-148`).
`packages/ui-sdk/src/server/maintenance-worker.ts:119-150`).

The root manager configuration fixes the application UID/group and the existing
output allowance and aggregate budget. Requests cannot choose host paths or
Expand Down
4 changes: 2 additions & 2 deletions docs/decisions/runtime-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ Paths may appear in local diagnostics; public fixtures use temporary paths.
| Requirement | Initial value | Evidence and limit of the claim |
| --- | --- | --- |
| 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:121`); 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`). |
| 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:48`; `function checkRuntime`, `packages/core/src/cli/commands/doctor.ts:85-92`). 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. |
Expand Down Expand Up @@ -275,7 +275,7 @@ reciprocal host-version negotiation is involved.

| Existing boundary | How this design uses it |
| --- | --- |
| `probeBrainCliVersion` / `brainCliCommand` (`export async function probeBrainCliVersion`, `packages/ui-server/src/brain/client.ts:153-220`) | Reuse executable selection, wrapper, deadline and cleanup; add host floor composition, strict comparison and invocation verification without duplicating the 0.33.0 constant. |
| `probeBrainCliVersion` / `brainCliCommand` (`export async function probeBrainCliVersion`, `packages/ui-server/src/brain/client.ts:164-231`) | Reuse executable selection, wrapper, deadline and cleanup; add host floor composition, strict comparison and invocation verification without duplicating the 0.33.0 constant. |
| `installedAgentSdkVersion` (`export function installedAgentSdkVersion`, `packages/ui-backend-claude/src/runtime-probe.ts:55-61`) | Retain importer-relative resolution; validate package name/version and the owner's manifest range. |
| `selectedSpawn` / `probeClaudeRuntime` (`export function selectedSpawn`, `packages/ui-backend-claude/src/runtime-probe.ts:69-96`; `export async function probeClaudeRuntime`, `packages/ui-backend-claude/src/runtime-probe.ts:127-147`) | Keep SDK-selected command capture, native/JS override argv, environment, timeout and group cleanup; add strict identity validation and composed runtime floors. |
| `probeBackendRuntimes` (`export async function probeBackendRuntimes`, `packages/ui-server/src/agent/backend.ts:394-444`) | Forward validated host requirements; retain active-backend selection and separate unmeasured-pair logging. |
Expand Down
6 changes: 3 additions & 3 deletions docs/decisions/session-principals.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ Both reviewers verified every row below against the source.
| Cookie verify | `auth.ts:265-296` | strict `^(\d+)\.(\d+)$`, safe integers, future/expired rejection, `cookieEpoch === sessionsEpoch(db)` |
| Global epoch | `auth.ts:302-318` | `settings` row; missing = 0; non-integer **throws** |
| Global revoke | `auth.ts:321-330` | `setSetting` (overflow-guarded) + `clients.closeAll(1008, …)` |
| Auth routes | `authRoutes`, `app.ts:924` | mounted **before** the guard at `authGuard(authMode`, `app.ts:939`; logout guards itself (`resolveCookiePrincipal(c, auth, deps.db)`, `auth.ts:798`) |
| Passkey management | `passkeyManagementRoutes`, `app.ts:949` | mounted **after** the guard ("Mount AFTER the auth guard") |
| WS guard | `"/ws"`, `app.ts:1145-1162` | origin → `isWsAuthorized` (returns a boolean, `auth.ts:221-237`) → capacity → upgrade |
| Auth routes | `authRoutes`, `app.ts:926` | mounted **before** the guard at `authGuard(authMode`, `app.ts:941`; logout guards itself (`resolveCookiePrincipal(c, auth, deps.db)`, `auth.ts:798`) |
| Passkey management | `passkeyManagementRoutes`, `app.ts:951` | mounted **after** the guard ("Mount AFTER the auth guard") |
| WS guard | `"/ws"`, `app.ts:1147-1164` | origin → `isWsAuthorized` (returns a boolean, `auth.ts:221-237`) → capacity → upgrade |
| WS upgrade | `ws/connection.ts:262-264` | `createWsUpgrade` ignores the request context |
| WS admission | `ws/connection.ts:84` | `clients.add(ws)` — the socket's identity is unknown |
| Turn record | `ws/run-session.ts:136-144` | recorder built from `{turnId, sessionId, billing}`; `RunningTurn` (`ws/turns.ts:55-77`) has no actor |
Expand Down
2 changes: 1 addition & 1 deletion docs/hosting/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ the separately authorized cache measurement procedure.

**The server refuses to boot against `@schlessera/brain` older than 0.44.0.**
The floor is enforced at
(`MIN_BRAIN_CLI_VERSION`, `packages/ui-server/src/brain/client.ts:121`) and covers
(`MIN_BRAIN_CLI_VERSION`, `packages/ui-server/src/brain/client.ts:132`) and covers
all commands and flags the server invokes, including 0.42.0’s scratch pin input.
From 0.44.0 the search index lives in `.brain-index/` instead of a root-level
`brain.db`: the server reads it there, deletes the old root-level copy at boot
Expand Down
11 changes: 11 additions & 0 deletions docs/hosting/agent-workers.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,17 @@ aggregate explicitly for parallel maintenance. Neither value derives from
agent-session concurrency or uses agent turn temp, runtime state or the
separately bounded startup/publication storage.

Admission is immediate: a command that does not fit is refused with
`worker_state_busy` before anything runs. The refusal names what holds the
budget by kind only (`index`, `scratch query`, `git`, `sync`, `probe` or
`command`), never a path or a process. At the defaults one allowance fills the
budget, so the automatic index and a turn's scratch check cannot overlap
(#3461). An automatic index that loses that race stays pending and runs as
soon as the budget frees; it is not reported as a failure, and close
discards it. A turn whose scratch check loses keeps `.brain/scratch/`
read-only for that turn, as before. An index you request still reports busy
at once.

Each command's sized private `/tmp` contains scratch and fresh XDG config,
cache, data and state directories. Credential-free HOME is also in that
filesystem. Credentialed HOME is readable but read-only; writes requiring a
Expand Down
2 changes: 1 addition & 1 deletion docs/plans/async-collaboration-requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ Stated before the requirements because five of them derive from it.
that is the shape to copy, including its `close()` lifecycle.
- R19. **The cron backstop has independent authorization before the general guard.**
Mount it on the existing listener before
(`app.use("/api/*", authGuard(`, `packages/ui-server/src/app.ts:939`).
(`app.use("/api/*", authGuard(`, `packages/ui-server/src/app.ts:941`).
Authorize a boot-minted ephemeral token, rotated each boot and stored in a
0600 runtime file, with the actual socket address as an additional check.
Proxy headers cannot authorize it. The poke succeeds in every auth mode
Expand Down
2 changes: 1 addition & 1 deletion docs/plans/async-collaboration.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ system gate. It is not a prerequisite to rebuild or a new independent package.
owns manual triggers/history; it does not tick the inbox.
- **Two connections:** (`export function createUiDb(`, `packages/ui-server/src/db/client.ts:27-44`) sets WAL,
foreign keys and a 5-second busy timeout. Claims are immediate transactions.
- **Auth mounting:** (`app.use("/api/*", authGuard(`, `packages/ui-server/src/app.ts:939`) follows public routes;
- **Auth mounting:** (`app.use("/api/*", authGuard(`, `packages/ui-server/src/app.ts:941`) follows public routes;
(`export function authGuard(`, `packages/ui-server/src/middleware/auth.ts:184-244`) binds principals in each auth mode.
An internal poke needs independent token authorization before this guard.
- **Permission parking:** (`requestPermission: (req) => {`, `packages/ui-server/src/ws/bridge.ts:362-456`). Timeout unwind is
Expand Down
2 changes: 1 addition & 1 deletion docs/plans/chat-history-deletion.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ Preserve the existing bounded-wait ownership distinction during that drain.
writers; rejection retains the original cleanup continuation, writer and reader
until genuine settlement, rather than authorizing their replacement
(`guardSqliteCleanup`, `packages/ui-server/src/db/write-worker.ts:206-234`;
`close: () => closing ??= guardSqliteCleanup`, `packages/ui-server/src/app.ts:1255-1305`).
`close: () => closing ??= guardSqliteCleanup`, `packages/ui-server/src/app.ts:1257-1307`).
The native lease manager retains its own pending operations and durable unknown
root outcomes through close (`return { client, writer, recoverDeadOwners`,
`packages/ui-server/src/brain/native-brain-leases.ts:274-287`). A caller deadline
Expand Down
2 changes: 1 addition & 1 deletion docs/plans/navigation-recovery.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ implementation. Any PR moving these lines owns their citation repairs.

- Activity resolution: (`.get("/activity/runs", (c) => {`, `packages/ui-server/src/routes/activity.ts:145-283`).

- API authorization: (`app.use("/api/*", authGuard(authMode, auth, db));`, `packages/ui-server/src/app.ts:939`).
- API authorization: (`app.use("/api/*", authGuard(authMode, auth, db));`, `packages/ui-server/src/app.ts:941`).

- Queued acceptance: (`// Queue it as the session's next turn; report queued immediately.`, `packages/ui-server/src/ws/run-session.ts:1107-1152`).

Expand Down
2 changes: 1 addition & 1 deletion docs/plans/storage-lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Use maintenance workers for repository code, the CLI and Git. Host routes may
perform narrowly validated descriptor operations, as the journal/revert do;
they must not evaluate brain configuration, hooks, filters or executables.
The existing brain client supplies boundary execution
(`async function execBrain`, `packages/ui-server/src/brain/client.ts:271-325`).
(`async function execBrain`, `packages/ui-server/src/brain/client.ts:285-340`).
Do not turn the new surface into a host command runner or an extension seam.

Reuse existing authorization. A requested reversible, fully journaled edit
Expand Down
1 change: 1 addition & 0 deletions packages/ui-sdk/src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export { workerHostProven, HOST_MASKS, MAINTENANCE_HOME, WORKER_PROVIDER_RELAY_D
export type { MaintenanceEnvelope } from "./server/worker-launcher.js";
export { brainGitSync, CREDENTIAL_FREE_ENV, prepareMaintenanceGitInput, prepareMaintenanceWorker, launchMaintenanceWorker, launchMaintenanceWorkerAsync, maintenanceLaunch, probeMaintenanceWorker, probeNativeMaintenanceWorker, runMaintenanceWorker, runMaintenanceWorkerSync } from "./server/maintenance-worker.js";
export type { MaintenanceHost, MaintenanceCommand, MaintenanceResult, MaintenanceWorker } from "./server/maintenance-worker.js";
export { MaintenanceTempBusyError, reserveMaintenanceTemp, type MaintenanceTempKind } from "./server/maintenance-temp-budget.js";
export { createWorkerStartupView, prepareNativeWorkerStartupView, retainWorkerStartupView, nativeWorkerStartupInput, isManagedWorkerStartupView, hasManagedNativeStorage } from "./server/worker-startup-view.js";
export type { WorkerStartupView } from "./server/worker-startup-view.js";
export function maintenanceGitEntry(): string { return Bun.resolveSync("./server/maintenance-git-entry", import.meta.dir); }
Expand Down
4 changes: 2 additions & 2 deletions packages/ui-sdk/src/server/bridge-tools/mask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ function* scratchIgnoredSteps(rootReal: string, maintenance?: import("../mainten
// a maintenance worker (#1648); one that cannot run refuses the mask.
const inRepo =
existsSync(join(rootReal, ".git")) ||
(yield* brainGitSteps(rootReal, ["rev-parse", "--git-dir"], maintenance)) === 0;
(yield* brainGitSteps(rootReal, ["rev-parse", "--git-dir"], { ...maintenance, tempKind: "scratch_query" })) === 0;
const query = ["check-ignore", "-q", "--no-index", "--", SCRATCH_DIR];
return scratchIgnoreResult({ exitCode: yield* brainGitSteps(rootReal, query, { ...maintenance, ...(!inRepo ? { emptyRepository: true } : {}) }), killed: false });
return scratchIgnoreResult({ exitCode: yield* brainGitSteps(rootReal, query, { ...maintenance, tempKind: "scratch_query", ...(!inRepo ? { emptyRepository: true } : {}) }), killed: false });
}

function scratchIgnoreUnavailable(): Error {
Expand Down
Loading
Loading