Skip to content

backends: attribute and cut the 1.5 s between backend invocation and the first model request on the Claude backend #4285

Closed

Description

@schlessera

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 at packages/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.

Out of scope

Acceptance criteria

  • subPhases carries a backend phase 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 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: a new subPhases phase.
  • 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

  1. added
    type: fixSomething is broken and must behave the way it is documented.
    area: mcpThe stdio MCP server and its brain_* tools.
    area: backendsAgentBackend implementations and the seam they share.
    on Nov 20, 2026
  2. added
    priority: p2Wanted, not scheduled. Pulled in when a milestone has room.
    area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.
    area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.
    contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.
    agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.
    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-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.

  5. added this to the 0.45.0 milestone on Nov 21, 2026
  6. schlessera commented on Nov 23, 2026

    @schlessera
    OwnerAuthor

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyContext and acceptance criteria are complete enough for an agent to take this unattended.area: backendsAgentBackend implementations and the seam they share.area: mcpThe stdio MCP server and its brain_* tools.area: ui-sdkWire protocol, runtime schemas, the server and client SDK surfaces.area: ui-serverHono app factory: turn coordinator, auth, session catalog, routes, cron.contractTouches the integration contract: CONTRACT: commit, contract doc updated in the same commit.priority: p2Wanted, not scheduled. Pulled in when a milestone has room.type: fixSomething is broken and must behave the way it is documented.

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions