Repository navigation
Description
Outcome
A governed hosted turn spends its time on the model and on the tools it runs. Every host phase before, between and after the model's requests has its own clock in the turn's record, costs what its guarantee needs and no more, and the client shows which phase a turn is in.
In particular:
- Code that a turn does not use is neither walked nor journaled.
- A journal observation delays the next model request only where a recorded ruling says it must.
- Each model request's record separates host time from the provider's time to first byte.
- A person sees a phase-specific signal within the first second of a turn.
Why now
The owner of a hosted install reported that turn-by-turn conversations feel sluggish. On 2026-11-20 four independent investigations (two model families, three rounds, each main claim assigned to the other family to refute) read three weeks of that install's turn records and the code at bd751d434, and reproduced the main mechanisms on local fixtures.
The reference cohort is 82 governed Claude turns on Opus in which every main model request has a unique relay record and every tool result is paired. Median / p90. Phase medians do not add up to the median turn.
| Phase | Median | p90 | Notes |
|---|---|---|---|
| Dispatch (host probe, billing, history) | 0.16 s | 0.22 s | |
| Governed admission | 2.20 s | 4.56 s | |
| Budget, journal begin, bridge and relay setup | 0.94 s | 2.39 s | |
| Host setup, excluding queue | 3.33 s | 6.37 s | |
| Backend invocation to runtime enqueue | 1.03 s | 1.75 s | worker launch and runtime start |
| Enqueue to prompt recorded | 0.46 s | 0.78 s | includes the wait for the brain's MCP server; its share is not timed |
| Model requests, union of relay spans (3 main requests median, 7 at p90) | 25.2 s | 71.8 s | an upper bound on provider time |
| Tool intervals outside relay spans | 0.37 s | 21.2 s | 69 of 82 turns |
| Runtime outside relay spans and tools | 2.25 s | 6.95 s | post-tool holds, hooks, request assembly |
| Last runtime record to lifecycle end | 1.30 s | 2.71 s | |
| Accepted to lifecycle end | 39.0 s | 126.5 s | |
| Accepted to first completed assistant block | 10.2 s | 23.0 s | no client clock exists |
Named steps inside governed admission and journal begin (74 turns that carry the subPhases added by #3355):
| Step | Median | p90 |
|---|---|---|
sandbox_resolve |
1.21 s | 2.65 s |
boundary_prepare |
0.31 s | 1.48 s |
startup_checkpoint |
0.27 s | 0.41 s |
startup_view_cleanup |
0.26 s | 1.23 s |
journal observe at admission |
0.32 s | 1.30 s |
journal policy (ignore-policy freeze) |
0.23 s | 0.31 s |
What the measurement established:
- After a tool result the next model request leaves late. By the relay's clock, 308 of 309 after-tool requests reached the relay more than 100 ms after the tool result: 0.76 s median, 2.0 s p90 per request, and 2.76 s median, 10.1 s p90 summed per turn. The same runtime sent its next request 7 to 9 ms after a result before governed turns existed. The mechanism is the per-result journal observation with the worker stopped (CONTRACT: feat(ui): governed journal, per-chat profiles and command policy #1747, CONTRACT: enforce turn limits and recover concurrent changes #1753, CONTRACT: replace hosted full-brain copies with native deltas #1793, scheduled by ui-server: a full native journal observation runs after every tool result and delays the next request (230–860 ms per call) #2834).
- Admission walks grow with the tree, not with the turn. That brain's tree holds about 100,000 entries, of which about 80,000 are checkouts under
workspaces/, about 19,000 the rootnode_modulesand under 2,000 content. With no deploy in between, the walk-bearing part of admission rose from 0.73 s to 1.65 s as checkouts were cloned. No file in the tree had more than one link. - The first turn after an hour idle pays about double:
sandbox_resolve2.0 to 2.8 s andboundary_prepare0.9 to 1.3 s. - Relay spans are 63.5% of a median turn. That is a ceiling for the provider's share: a relay span also contains the host's admission of the request. Since about 2026-11-01, thinking-first responses reach their first delta 0.65 to 0.78 s later than in mid-October. No clock can place that between the relay path and the provider.
- Short turns are half host. On the 13 turns without tools, 52% of the time is outside relay spans.
- From accept to first content the client shows one status (read from the code path; nothing records what the browser painted).
- The Pi backend (26 turns, separate clocks): 8.4 s median from backend invocation to the first model request.
A joined projection applied every change below per turn to the same 82 turns, each credit capped by that turn's own measured span: 39.0 s to 35.4 s median, 126.5 s to about 121 s p90, first completed block 10.2 s to 9.0 to 9.3 s. It is a scenario under stated assumptions, not a production result and not a target. The deferred freeze is the only step in it that moves the whole-turn median; time to first content moves only through admission work.
Shared context
A governed turn's host path, in order. Dispatch and worker-host probe (packages/ui-server/src/ws/session-run/admission.ts:25); governed admission (begin, packages/ui-server/src/brain/governed-turn.ts, steps named at :158-336); budget; journal begin (packages/ui-server/src/brain/turn-journal.ts:535-574); bridge and relay setup (prepareRelayedEgress, packages/ui-server/src/ws/session-run/backend-entry.ts:149); backend start; per tool result a journal observation under a hold that stops every active turn's workers (toolEnded, turn-journal.ts:614-620; held, :293; the stop, packages/ui-server/src/brain/turn-scope.ts:166); a periodic observation every 15 s (turn-journal.ts:559-560); teardown (packages/ui-server/src/ws/session-run/teardown.ts:51-106).
Evidence grades used in the sub-issues. Measured: read from that install's records for the cohort named. Local: measured on a fixture shaped like that install, on another host. Scenario: computed from measured rows under stated assumptions. No change in this epic has run in production, so every saving is local or a scenario.
Rulings (maintainer, 2026-11-20). Each is repeated on the sub-issue it unblocks.
- Code lives in its own locations and is processed on demand, not for general context.
- The journal's snapshots exist to revert unintended changes to the source of truth (Markdown). Anything managed through git belongs in a separate location.
- A checkout has two modes. Inspect: read-only, nothing snapshotted. Change and push: the record of the work is a git diff.
- That diff protects tracked files and untracked files git does not ignore. Ignored files in a checkout (dependencies, build output) get no protection, because they can be regenerated. This applies inside a checkout; the brain's own
node_modulesstays protected, because later turns execute it. - Walking every file before each turn is rejected as the mechanism for proving a boundary.
- The index is a generated, disposable optimization. It needs no history.
Still open for the maintainer, with no issue of its own: whether "managed through git" includes the brain's own .git. No per-turn cost was found for it beyond a few ref rows, and nothing below depends on the answer. The recommendation is to leave it where it is.
Checked and found fine. On a healthy local fixture the inference relay adds 0.3 to 0.5 ms per 64 KiB request, the freeze signal under 1 ms and a sandbox launch about 40 ms.
Refuted during the investigation, so nobody proposes them again.
- Caching a passed sandbox or alias verdict on a shared filesystem. A cached pass cannot stand in for the proof.
- Using a bare Btrfs subvolume generation as a "nothing changed" test. It missed 16 of 16 writes without a sync, and after a sync it also advanced on 16 of 16 plain reads.
- Holding only the next tool launch instead of the worker during an observation. A background writer would run free for the whole observation, measured above 4 s.
- Keep-warm requests for the prompt cache. Modelled at about twice the cost of the cold writes they avoid.
Constraints and non-goals
- Provider history stays append-only (
docs/decisions/provider-history.md). Timing marks, phases and receipts stay in host storage. A change to the tool roster or the system prompt applies to new sessions, or the issue says how an existing session's history stays byte-identical. - Fail closed, proportionately (
docs/decisions/proportionate-containment.md). A faster path falls back to the existing check when its evidence is missing; an unknown never becomes clean. - Not weakened by anything here: credential isolation, the sandbox, full-durability commits for notes, byte before-images for notes, scope caps, the egress policy.
- Git never runs on the host over repository input (the boundary rule at the top of
packages/ui-server/src/brain/host-boundary.ts). - Nothing in this epic describes a deployment. What a self-hoster needs goes to
brain-hosting-template. - Out: model choice, effort and prompt content beyond the items listed; queueing behind a running turn of the same session.
Breakdown
Order within a group is the order the work can land. Groups are independent unless a sub-issue says Blocked by.
Independent cleanup and maintenance. #4287 and #4289 are actionable under existing rules. #4288 and #4290 have their own storage or operating-surface decisions.
- ui-server, core: a maintenance run whose git packing runs out of space still publishes its partial pack files #4287
- core: maintenance git packing cannot succeed when the pack exceeds the output stage: decide where packing runs #4288
- ui-server: the turn-end reference clean-up rescans every change row for each object reference #4289
- ui-server: journal store files that have no database row are never collected #4290
Clocks that are missing. These decide the ranking of everything after them and cannot recover the past.
- ui-sdk: the inference relay records one duration per request, so host time cannot be told from the provider's time to first byte #4279
- ui-server: nothing records how long an observation kept workers stopped, or what the stop overlapped #4280
- ui-server: the end of a turn is one unattributed bracket, and its end stamp precedes the idle status #4281
- ui-react: no client clock exists for send, first painted content and idle #4282
- ui-server: a turn's lifecycle record does not say which build ran it #4283
- native-proof: --observation-timing has no large-tree scenario, so the admission walks measure as free #4284
- backends: attribute and cut the 1.5 s between backend invocation and the first model request on the Claude backend #4285
- backends: a Pi turn still waits about 8 s before its first model request on a hosted install, and its phase timings are not recorded #4286
The stall after a tool result.
- ui-server: after each tool result the worker is stopped before it can send its next model request (0.8 s median per request) #4292
- ui-server: inference admission waits for every pending egress record commit, twice per model request #4293
- ui-server: an observation of twenty changed notes keeps every worker stopped for about four seconds #4294
Code and state out of the default turn.
- ui-sdk, ui-server: every governed turn scans and journals workspaces/; bind it read-only by default #4295
- ui-react: a control to switch a session between inspecting code and changing it #4296
- ui-server: record a writable checkout's changes as a git change receipt, not as per-file journal rows #4297
- ui-server: decide where a dependency install may write while a checkout is only inspected #4298
- ui-server: an owner-reviewed action that moves an in-brain checkout to reference source or a managed worktree #4299
- ui-sdk: the root node_modules is walked on every admission; serve it from a host-owned module store #4300
- ui-server: the state-alias proof walks the journal object store on every admission #4301
The index.
- core: an index run globs the whole tree twice and filters afterwards, so excluded directories are still walked #4291
- ui-server: the index family still adds journal rows and counts toward a turn's byte scope #4302
- ui-server: a turn stays busy until its queued index update has settled #4303
Admission.
- ui-server: governed admission waits for its startup checkpoint to be deleted #4304
- ui-server: decide which admission steps can overlap, share a commit or be reused #4305
The model side.
- backends: tool search is off behind the inference relay, so every tool definition is sent in every request #4306
- backends: built-in tools a hosted turn cannot use are in every request #4307
- backends: the Claude backend never receives the "Batch your reads" paragraph #4308
- backends: avoidable tool errors cost a model round trip each #4309
- backends: decide whether to offer the provider's fast output mode as a per-session choice #4310
What the person sees.
Hosting template.
- deploy: keep the server database and journal store on a filesystem of their own brain-hosting-template#43
- docs: a second volume for code (the reference pool) brain-hosting-template#44
Definition of done
- Every sub-issue is closed, or closed as a documented no.
- The reference budget is re-measured from lifecycle records of a hosted install that runs the changes, on a cohort defined the same way, and posted here beside the table above.
- In that re-measurement: host setup before the backend starts, the time between a tool result and the next request's dispatch, and the closing bracket each have a named clock; and no step of warm governed admission takes longer than 100 ms without a sentence in a decision record saying why it is on the turn's path.
- The decision records named in the sub-issues carry the rulings above.
2026-11-20 triage — Verified the newly attached native tasks and classified the tracking epic at p2. Release commitments remain on their individual tasks. The brain’s own Git store question is independent of the filed breakdown.
Activity
80 remaining items
CONTRACT: feat: measure a hosted turn's host overhead span by span an…