Repository navigation
Description
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:103and: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
closingphase tosubPhaseswith 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
idlestatus emission, after the existing end stamp, so the gap between "recorded end" and "client told" is visible. - Extend
--observation-timingto print the closing steps.
Out of scope
- Changing the order of the closing work or what it waits for.
- Making the turn report idle earlier: ui-server: a turn stays busy until its queued index update has settled #4303.
- The quadratic clean-up statement: ui-server: the turn-end reference clean-up rescans every change row for each object reference #4289.
Acceptance criteria
- A completed governed turn's lifecycle record carries
closingsteps that lie inside the interval from backend exit to theidleemission, 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 theclosingphase, 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 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 and two optional milestones. - This changes a published package's behaviour, so it needs a changeset.
Activity
schlessera commentedon Nov 20, 2026
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.