Skip to content

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

Open

Description

@schlessera

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 a backend phase 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 $HOME overlay, 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

Acceptance criteria

  • A Pi turn's lifecycle record carries the backend steps 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: repro and 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 $HOME and 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 lint

Contract impact

  • This touches the integration contract, so it needs the contract label, a CONTRACT: commit prefix, and the doc updated in the same commit. Additive: subPhases steps 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

  1. added
    type: fix
    area: backends
    on Nov 20, 2026
  2. added
    priority: p2
    area: ui-server
    area: ui-sdk
    contract
    agent-ready
    on Nov 20, 2026
  3. self-assigned this
    on Nov 20, 2026
  4. schlessera commented on Nov 20, 2026

    @schlessera
    OwnerAuthor

    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.

  5. added this to the 0.45.0 milestone on Nov 21, 2026
  6. removed their assignment
    on Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-readyarea: backendsarea: ui-sdkarea: ui-servercontractpriority: p2type: fix

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions