Repository navigation
Description
Context
Part of #4278.
On the Claude backend, after the host has finished admission, a turn still waits about a second and a half before its first model request leaves. In the measurement behind #4278: 1.03 s median and 1.75 s p90 from backend invocation to the runtime's first enqueue, then 0.46 s and 0.78 s until the runtime records the prompt.
The lifecycle record covers this with one number, backendStartupMs (backend invoked to first frame, packages/ui-server/src/activity/turn-lifecycle.ts:78). What is inside it is known only from reading the code and from local fixtures:
- a second worker-host probe before the worker starts (
requireWorkerHostAsync,packages/ui-backend-claude/src/turn-runner.ts:174; the first is atpackages/ui-server/src/ws/session-run/admission.ts:25); - the sandboxed worker launch (about 40 ms locally);
- the runtime's own start: reading settings, the skills listing and root instructions;
- the wait for the brain's stdio MCP server (
brain mcp,packages/core/src/mcp-server.ts) before the first request. Local estimates put its share between 0.13 and 0.35 s, depending on the fixture. It is not timed on a hosted server.
Scope
Start with the existing backend startup clock (backendStartupMs, packages/ui-server/src/activity/turn-lifecycle.ts:78), the repeated host probe (requireWorkerHostAsync, packages/ui-backend-claude/src/turn-runner.ts:174) and the current relay entry. Keep backend sub-phase reporting compatible with the Pi task #4286. Publish only marks the runtime has actually observed. Attribute an unavailable SDK sub-phase as missing evidence rather than inferring it from request time.
- Attribute the interval with sub-phase timings in the lifecycle record, as ui-server: a governed turn waits about 2 s in admission, and 10 s in journal begin when cold, before the backend starts #3355 did for admission: host probe, worker launch, runtime process start to SDK initialisation, MCP server connections (one step per server), first enqueue, prompt recorded, first relay request received.
- Add the same steps to
--observation-timing. - Then cut what the attribution shows to be avoidable within the existing per-turn worker and authority boundary. A change in where repository inputs or tools are executed requires its own recorded scope. Candidates to measure, not assumptions: the brain MCP server's start (lazy imports, or serving its read tools from the host under the worker's masks), and the repeated host probe (see ui-server: decide which admission steps can overlap, share a commit or be reused #4305).
Out of scope
- Retaining a worker or a runtime process between turns. The per-turn worker is a decided boundary.
- The Pi backend: 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 tool roster and tool search: backends: tool search is off behind the inference relay, so every tool definition is sent in every request #4306.
Acceptance criteria
-
subPhasescarries abackendphase whose steps lie between backend invocation and the first relay request, with a unit test for containment and for the null and failure rules. - The harness reports those steps for five warm turns and a first turn after server start, for the Claude backend.
- The PR states which step dominates on the native fixture and what it changed, with before and after receipts. If nothing avoidable is found, it says so with the numbers, and that closes the criterion.
- If the brain MCP server's start is cut, a test shows its tools are available to the first request exactly as before, and the tool list sent to the provider is byte-identical to the list before the change.
-
docs/integration-contract/wire.md("Host turn lifecycle") lists the new phase and step names. - A test covering this fails on the tree before the change and passes after.
Verification
bun run test packages/ui-server/tests packages/ui-backend-claude packages/core/tests
bun scripts/prove-native-host.ts --backend=claude --observation-timing
bun run typecheck
bun run lintContract impact
- This touches the integration contract, so it needs the
contractlabel, aCONTRACT:commit prefix, and the doc updated in the same commit. Additive: a newsubPhasesphase. - This changes a published package's behaviour, so it needs a changeset.
2026-11-20 triage — Verified the invocation, worker probe and lifecycle anchors at main 63bb400b3. The measurement phase is independently actionable, and the existing criterion allows a measured no-change result.
Activity
schlessera commentedon Nov 20, 2026
Claimed for implementation. Claim token:
claim-1833b477. Branch:feat/4285-backend-startup-phase.Worked as part of the #4278 epic integration branch epic/4278-host-overhead (one main landing for the epic). Collisions: none recorded at claim.
schlessera commentedon Nov 23, 2026
Closed by #4444, squash-merged to main as
a3395c4b2. The combined review found every non-native criterion met. Native-measurement criteria for this issue moved to #4420 by maintainer decision, because native proof cannot run on the integration host.