Repository navigation
Description
Part of #1342.
Blocked by #2515
Context
handleClientMessage is 590 lines (packages/ui-server/src/ws/dispatch.ts:88-677) with 42 case labels, one per client message kind, over shared closure state. The largest is tool_approval (about 100 lines).
Sequencing: #2515 lands first. It makes the TurnCoordinator collections private behind intent methods (settleAsk, settleApproval, settleLocation, …), so the handlers extracted here call those methods instead of each carrying raw map mutations. dispatch.ts holds 6 of the 30 direct mutation sites today.
Scope
- A
Record<ClientMessage["type"], Handler>table; each handler in its own module underpackages/ui-server/src/ws/handlers/with an explicit context argument. - Exhaustiveness checked by the type (a missing kind fails
tsc).
Out of scope
- Protocol changes; ordering or concurrency changes.
- The wrong logged reason for a refused "always allow" policy grant (the rememberability rule is inlined in
dispatch.tsandws/bridge.ts). It is a behaviour fix, not part of this refactor.
Acceptance criteria
-
handleClientMessageis under ~60 lines. - Removing one handler entry fails typecheck (recorded in the PR).
- Each handler has a direct test; existing ws runtime tests pass unchanged.
Verification
bun run test packages/ui-server
bun run typecheckContract impact
None.
2026-10-24: declared #2515 as the blocker (the coordinator encapsulation lands first, per the 2026-10-22 source check), folded that check's current range and case count into Context, and kept the policy-grant log reason out of scope.
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:handleClientMessageis now 590 lines,packages/ui-server/src/ws/dispatch.ts:88-677. The body says 560 lines at:88-647; Epic: the turn path's largest functions are split into units that can be reviewed and tested alone #1342's table already has the current range.caselabels, not 41. The largest istool_approval(dispatch.ts:386-483, about 100 lines).dispatch.ts:342-382repeats the same get → match turn → delete → resolve/reject sequence four times, forlocation_response,location_error,mask_responseandmask_error.New evidence relevant to sequencing:
dispatch.tsis one of six files that mutateTurnCoordinatorcollections directly (6 of 30 sites). #2515 (under #1342) makes those collections private behind intent methods (settleAsk,settleApproval,settleLocation, …). If that lands first, the per-message handlers extracted here call intent methods instead of each carrying copies of the map invariants. Otherwise the handler split moves the raw mutations into a dozen new modules.The "always allow" rememberability rule is also inlined both here (
dispatch.ts:438-467) and inws/bridge.ts:304-305. The write-side reason ternary does not handlekind: "policy", so a refused policy grant is logged with the wrong reason. That is a behaviour fix and should stay out of this refactor, per the epic's constraint.schlessera commentedon Nov 2, 2026
Claimed (token
wi-1358-7d00ca1e) under the maintainer's epic-branch ruling: #2515 was delivered toepic/1342-turn-path-splitby #3289.Blocked by #2515andblockedstay until the epic lands on main. Branchrefactor/1358-dispatch-handler-tablefrom the epic tip0c3b83762. PR #3305 targets the epic branch and closes this issue when the epic batch lands on main. Collisions: closure-only, no path overlap.refactor(ui-server): replace the handleClientMessage switch with a pe…
schlessera commentedon Nov 2, 2026
Delivered to the epic integration branch
epic/1342-turn-path-splitas45fe0ecd2via #3305, after ready-candidate proof passed against the exact epic base. This issue closes when the epic batch lands on main.