Skip to content

ui-server: the end of a turn is one unattributed bracket, and its end stamp precedes the idle status #4281

Open

Description

@schlessera

Context

Part of #4278.

The lifecycle record attributes the start of a turn step by step (subPhases, phases governed and journal, docs/integration-contract/wire.md:584-610, added by #3355). The end of a turn has no steps. In the measurement behind #4278 the time from the last runtime record to lifecycle end is 1.30 s median and 2.71 s p90, and over a wider closing cohort the p90 is 4.6 s. It contains, in order:

  • the awaited index settle (await held.settleIndex?.(), packages/ui-server/src/ws/session-run/turn.ts:103 and :126);
  • egress settlement;
  • the journal's finish with its final observation, its reference clean-up and object collection (await host.journal?.finish(turn.turnId), packages/ui-server/src/ws/session-run/teardown.ts:51; finish, packages/ui-server/src/brain/turn-journal.ts:710-733);
  • the worktree generation close (teardown.ts:56), scope finish (:59) and failure recording (:82);
  • lifecycle finish (:83).

The lifecycle's end stamp is written before recorder settlement and the idle status that tells the client the turn is over (teardown.ts:83 against :104-106). So the recorded end of a turn is earlier than the moment a person can send the next message, by an amount nothing measures.

Without these clocks it is not possible to say how much of a slow close is the index update, the final observation or the clean-up. #4303 waits on that answer.

Scope

  • Add a closing phase to subPhases with steps in start order: backend exit, index settle (with whether an update was pending), egress settle, journal finish (reusing its existing step timers: final observation, clean-up, collection), worktree generation close, scope finish, failure recording.
  • Add milestones for recorder settlement and for the idle status emission, after the existing end stamp, so the gap between "recorded end" and "client told" is visible.
  • Extend --observation-timing to print the closing steps.

Out of scope

Acceptance criteria

  • A completed governed turn's lifecycle record carries closing steps that lie inside the interval from backend exit to the idle emission, each with start and end times.
  • With a fixture that delays the index update by a known time, the delay appears in the index-settle step and in no other step. With no pending update, that step is near zero.
  • With a fixture that delays the final observation, the delay appears in the journal-finish step.
  • A failed or cancelled turn records the closing steps it reached, by the same null and failure rules as the existing steps.
  • The steps add no write to the turn's path: they are carried by an existing milestone or terminal write, as the ui-server: a governed turn waits about 2 s in admission, and 10 s in journal begin when cold, before the backend starts #3355 steps are.
  • docs/integration-contract/wire.md ("Host turn lifecycle") lists the closing phase, its step names and the two new milestones.
  • A test covering this fails on the tree before the change and passes after.

Verification

bun run test packages/ui-server/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 and two optional milestones.
  • This changes a published package's behaviour, so it needs a changeset.

Activity

  1. added
    type: feat
    area: ui-server
    agent-ready
    on Nov 20, 2026
  2. added
    priority: p2
    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-2422ddf2. Branch: feat/4279-turn-clocks.

    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: ui-serverpriority: p2type: feat

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions