Repository navigation
Description
Part of #734. Split from #2515, which keeps today's collision behaviour while it encapsulates the coordinator state.
Context
The four ask-user kinds share one id space for cancellation (// Cancellation shares one id space across all four ask kinds., packages/ui-server/src/ws/bridge.ts:505), but each kind checks a new request id against pending ones differently:
ask_userandask_user_listcallcollidesAcrossTurnson their own map (askUser,packages/ui-server/src/ws/bridge.ts:440-447;askUserList, same file:471-480). That refuses, and logs an ERROR, only when the existing entry belongs to another turn (collidesAcrossTurns,packages/ui-server/src/ws/turns.ts:771-785). A same-turn duplicate of the same kind is accepted andsetoverwrites the earlier entry, whose promise is then never settled. Against the other three maps they use plain.has(), which refuses any turn's entry without logging.ask_user_rankandask_user_formuse plain.has()across all four maps (askUserRank,packages/ui-server/src/ws/bridge.ts:504-508;askUserForm, same file:516-520). They refuse same-turn and cross-turn duplicates of every kind and log nothing.
Resulting matrix today:
| same kind | other kind | |
|---|---|---|
| same turn | ask_user/ask_user_list: accepted, earlier entry overwritten. rank/form: refused, no log. |
refused, no log |
| other turn | ask_user/ask_user_list: refused, ERROR logged. rank/form: refused, no log. |
refused, no log |
#724 delivered admission before emission for these paths; #734's definition of done requires that no duplicate frame settles another request. Which ids are accepted is observable to backends, so the rule is a ruling, not a refactor.
Maintainer decision (2026-10-24)
Option A: refuse every request ID already pending across all four ask-user kinds, whether the same or a different kind, in the same or a different turn. Log one consistent ERROR record for each refused duplicate. Preserve the original pending request, its promise and its answer/cancellation identity; do not overwrite or emit the refused duplicate. The stricter behavior for same-turn retries is explicitly approved as a compatibility restriction.
Scope
Apply option A to all four kinds in one shared admission check with one ERROR log shape, preserving admission before emission and the original request.
Out of scope
- Encapsulating the coordinator state and merging the four maps (ui-server: TurnCoordinator state is mutated directly from six files, and the copies of its invariants have drifted #2515).
- Approval, location and mask id collisions, which keep
collidesAcrossTurns. - Wire protocol changes.
Acceptance criteria
- Every duplicate cell of the historical matrix above is refused under option A for all four kinds, proven by a table-driven test over the 4 kinds × same/other turn × same/other kind that fails on the current tree for at least one cell.
- Each refused duplicate logs one ERROR with the same record shape for every kind.
- A refused duplicate leaves the original pending entry untouched; its original promise can still settle from its own answer or cancellation. The duplicate is refused without overwriting or emitting it, proven by a test.
- Mutation receipt: revert one kind to its old check and the table test fails on that cell.
Verification
bun run test packages/ui-server, tsc --noEmit, bun run lint, then bun run check:pr --base origin/main.
Contract impact
Option A narrows previously accepted same-turn/same-kind IDs for ask_user and ask_user_list. The maintainer explicitly approves this breaking supported-behavior restriction. Add contract and breaking, document the shared duplicate-ID rule in the chat-UI tools contract in the same CONTRACT: commit, and ship a minor changeset naming the break while pre-1.0. No wire frame/schema change; approval, location and mask collision policies are unchanged.
2026-10-24: filed from #2515's review finding; waits on the ruling in the first comment.
2026-10-24 maintainer ruling: selected A and incorporated uniform pending-ID refusal, consistent ERROR logging, original-request preservation and approved compatibility restriction. The earlier matrix documents the pre-change behavior.
Activity
schlessera commentedon Oct 24, 2026
Decision needed: which duplicate-id rule do the four ask-user kinds share?
Today the rule depends on the kind (matrix in the body):
ask_userandask_user_listaccept a same-turn duplicate of their own kind and overwrite the earlier entry, leaving its promise unsettled, and log an ERROR only for a cross-turn duplicate of their own kind.ask_user_rankandask_user_formrefuse every duplicate, of any kind and any turn, and log nothing. Cross-kind duplicates are refused silently for all four.Options:
ask_userwith the same id inside one turn now gets a refusal instead of a silent replacement.ask_userrule for all four kinds. The replaced request must then be settled explicitly (for example rejected as superseded), which today it is not.Recommendation, not a ruling: A, because the overwrite path is the one that can leave a promise unsettled. A documented "no change" (C) is also an acceptable outcome that closes this issue with a docs update.
schlessera commentedon Oct 24, 2026
Decision (maintainer, 2026-10-24): Option A. Refuse every ID already pending across all four ask-user kinds, for the same or another kind and the same or another turn. Log one consistent ERROR record per refused duplicate. Preserve the original request and promise; no overwrite or duplicate frame emission. Explicitly approve the stricter same-turn retry behavior as a breaking supported-behavior restriction, with contract documentation and a pre-1.0 minor changeset naming it. The body and acceptance criteria now select this rule; the decision is resolved.
refactor(ui-server): own turn state in TurnCoordinator behind intent …
refactor(ui-server): own turn state in TurnCoordinator behind intent …