Repository navigation
Description
Part of #1342.
Blocked by #2515
Context
runRetainedSession was 791 lines (packages/ui-server/src/ws/run-session.ts:196-986 at epic-branch 2b9a69c60), mixing setup, admission, the event pump, send ordering, failure classification and teardown. It declares many mutable let flags (budgetFailure, journalFailure, scopeStopReason, cancelledAdmission, revokedAdmission, …) that together encode the turn outcome and are resolved by one nested ternary. The budget_warning/budget_block governance-event payload is built by hand at four sites with an inconsistent actor.
Sequencing: #2515 lands first. It makes coordinator state private (this file holds 6 direct mutation sites plus coordinator.startingSessions += 1) and removes the host → conversation → run-session → host value import cycle, so the stages extracted here call intent methods. Send order is already per-host state (nextSendOrder, packages/ui-server/src/ws/host.ts:280, delivered by #1364).
Scope
- Extract setup, admission (governed hold, budget, journal), event pumping, send ordering, failure classification and teardown into named functions with explicit inputs. Admission and failure classification return a discriminated outcome instead of mutable flags.
- One helper builds the budget governance-event payload.
Out of scope
- Moving
nextSendOrder(already per-host since ui-server: make login buckets, passkey challenges, sync locks and send order per-app #1364). - Behaviour changes, including which actor a budget event records; if the helper must pick one, keep each site's current value.
Acceptance criteria
- The function is under ~150 lines; each stage has a direct test.
- Session runtime tests, including reconnect and abort, pass unchanged.
Verification
bun run test packages/ui-serverContract impact
None.
2026-10-24: replaced the #1364 blocker (closed; send order is per-host) with #2515, and folded the 2026-10-22 source check (current range, outcome flags, budget-event duplication, coordinator sequencing) into Context and Scope.
2026-11-03: citation check against epic/1342-turn-path-split at 2b9a69c60 (TypeScript AST). The function spanned run-session.ts:196-986, 791 lines, not :196-898. The four hand-built budget-event sites were at :539, :616, :623 and :870. #2515 is delivered on that branch (#3289). Scope and acceptance criteria are unchanged.
Activity
schlessera commentedon Oct 21, 2026
Source check at
dcf5341aaduring the 2026-10-22 repository review (measured with the TypeScript compiler API). The citation in this body is out of date:runRetainedSessionis now 639 lines,packages/ui-server/src/ws/run-session.ts:192-830. The body says about 400 lines at:165-566; Epic: the turn path's largest functions are split into units that can be reviewed and tested alone #1342's table has the current range.letflags (budgetFailure,journalFailure,scopeStopReason,cancelledAdmission,revokedAdmission, …) that together encode the turn outcome. They are resolved by one nested ternary atrun-session.ts:738. Extracting admission (governed hold, budget, journal) and failure classification into units that return a discriminated outcome would remove most of them.budget_warning/budget_block) is built by hand at four sites:run-session.ts:518,:605,:619and:728. The actor is computed inconsistently (governedHold?.vs!.). AbudgetEvent(kind, item, attribution, stage)helper would remove that duplication.coordinator.startingSessions += 1at:205. ui-server: TurnCoordinator state is mutated directly from six files, and the copies of its invariants have drifted #2515 (under Epic: the turn path's largest functions are split into units that can be reviewed and tested alone #1342) makes coordinator state private. Doing that first keeps this split from copying the invariants into each stage.run-session.ts:34-40importsMAX_SESSION_QUEUE,QUEUE_MAX_BYTES,QUEUE_WARN_BYTESandturnLogAttributesfromhost.ts. That closes ahost → conversation → run-session → hostvalue import cycle, which ui-server: TurnCoordinator state is mutated directly from six files, and the copies of its invariants have drifted #2515 also removes.The
Blocked by #1364line still stands: #1364 is open.schlessera commentedon Nov 3, 2026
Claiming this for implementation (claim token
claim-1359-1793667878-4055).Branch:
refactor/1359-split-retained-session-stages, started fromepic/1342-turn-path-splitat2b9a69c60under the maintainer's epic-branch ruling. #2515 is delivered on that branch (#3289), soBlocked by #2515andblockedstay until the epic lands on main. The PR targets the epic branch.Collisions (
bun scripts/collisions.ts --paths packages/ui-server/src/ws/run-session.ts): open PRs against main also change this file. They are #3342, #3386, #3404 and #3407. Everything else showed up only as test-closure overlap. Whichever change lands second will need a rebase.fix(ui-server): keep the slot's state transitions in one synchronous …
test(ui-server): cover synchronous slot registration and admission co…
schlessera commentedon Nov 3, 2026
Implementation is in #3415 (ready). It targets
epic/1342-turn-path-splitat base2b9a69c60; head01cc8a891. Hosted proof run: 41571716330.runRetainedSessiondrops from 791 lines to 73. Its stages live inpackages/ui-server/src/ws/session-run/, and each has a direct test. Admission and failure classification return discriminated outcomes. OnebudgetEvent()helper serves all four budget-event sites, each keeping its current values. Local evidence: check:pr passes, mutation receipts are in the PR, and the full ui-server comparison against the base shows no persistent new failures. Worker-boundary tests and the provider-history guard can't run on the local host, so they rely on hosted CI.This issue stays open with
Blocked by #2515andblockeduntil the epic batch lands on main. The assignment stays while the PR is live.refactor(ui-server): split runRetainedSession into lifecycle stages (#…
schlessera commentedon Nov 3, 2026
Delivered to
epic/1342-turn-path-splitas2efaf6c23via #3415, after ready-candidate proof passed on the exact epic base. This issue closes when the epic batch lands on main.Merge branch 'main' into epic/3428-session-taint