Repository navigation
Description
Context
Part of #4278.
On a hosted install, a Pi turn waits 8.4 s at the median and 9.8 s at p90 between backend invocation and its first model request (26 governed turns with complete clocks; first host frame at 8.2 s and 9.8 s). That is more than all the host setup the two backends share (3.4 s), and it holds on resumed turns.
#2023 reported the same 6 to 8.5 s and was closed by #2071, which made a resumed turn open its transcript directly and added a phase breakdown: internal debug observations in the private parent/worker protocol, and an offline command (packages/ui-backend-pi/scripts/measure-startup.ts). On that harness a new turn reaches its first provider request in about 0.65 to 0.7 s, dominated by worker bootstrap and static imports. #2071 said plainly that its fixture did not reproduce the hosted delay.
So the hosted 8 s is still unexplained, and the breakdown that exists is not written anywhere a hosted turn's record can show it. The path: createPiBackend (packages/ui-backend-pi/src/backend.ts), the per-turn worker session (packages/ui-backend-pi/src/session-pool.ts, session-runtime.ts, worker-entry.ts), resources and extensions (session-resources.ts).
Scope
Start independently with the worker timing messages (startup_timing, packages/ui-backend-pi/src/worker-entry.ts:43; const timing, same file:102) and persist the observed phases using the existing lifecycle timer (timer, packages/ui-server/src/activity/turn-lifecycle.ts:45-51). Coordinate the additive backend phase with #4285. Preserve unknown stages and separate host and worker time bases.
- Write the phases fix(backends): measure Pi startup and avoid archive scans on resume #2071 already observes (preparation, worker spawn, bootstrap and imports, resource and extension load, session open, first backend frame, first provider request) into the lifecycle record's
subPhases, as abackendphase with the same rules as the existing steps. - Reproduce the hosted delay offline. The differences between the fix(backends): measure Pi startup and avoid archive scans on resume #2071 fixture and a hosted worker to test, one at a time: the sandbox profile and its mounts on a tree of about 100,000 entries, the installed extensions and their cache, the size of the worker's module graph on a cold page cache, the
$HOMEoverlay, and the private network namespace with the egress bootstrap. - Cut what the attribution shows to be avoidable without changing per-turn isolation.
Out of scope
- Retaining Pi workers or sessions between turns (backends: run pi sessions and extensions in an isolated worker behind a pipe-only RPC #1038 decided the per-turn worker).
- The costs both backends share before the backend starts: ui-sdk, ui-server: every governed turn scans and journals workspaces/; bind it read-only by default #4295 and ui-server: the state-alias proof walks the journal object store on every admission #4301.
Acceptance criteria
- A Pi turn's lifecycle record carries the
backendsteps listed above, with a unit test for containment and the null and failure rules. - A checked-in offline measurement reproduces a first-request time of several seconds, and names the condition that produces it. If no offline condition reproduces it, the PR lists each condition tried with its numbers, and the issue stays open with
needs: reproand the hosted sub-phases as the next evidence. - The dominant phase is cut, with before and after numbers in the PR, or the PR records why it must stay.
- Two consecutive turns of one session still run in distinct workers with distinct per-turn
$HOMEand temp, by the existing test. -
docs/integration-contract/wire.md("Host turn lifecycle") lists the new step names. - A test covering this fails on the tree before the change and passes after.
Verification
In an isolated frozen install at main 63bb400b3 with Bun 1.4.4, the --runs=3 command exited 1 before timing because the worker-boundary probe could not create the nested bubblewrap namespace. Use a qualified Linux or WSL runner for the measurement. If the independent timing delivery still leaves the hosted delay unattributed, advance the issue with Refs and record needs: repro with the new required phase evidence as specified above.
bun packages/ui-backend-pi/scripts/measure-startup.ts --runs=3
bun run test packages/ui-backend-pi packages/ui-server/tests
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:subPhasessteps for the backend phase. - This changes a published package's behaviour, so it needs a changeset.
2026-11-20 triage — Verified the shipped timing messages and recorded the bounded runner limitation. The instrumentation has an independent keyless test path.
Activity
schlessera commentedon Nov 20, 2026
Claimed for implementation. Claim token:
claim-df4c8e9e. 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.