Skip to content

ui-react: pull reconnect, auth and outbound-queue lifecycle out of createWebSocketClient #1362

Closed

Description

@schlessera

Part of #1342.

Context

createWebSocketClient is about 1,010 lines (packages/ui-react/src/connection.ts:29-1036) and is only exercised through runtime tests. Inbound frames are routed in three layers, not one per-kind table:

  1. handleServerMessage (connection.ts:328) prefilters and keeps turn bookkeeping.
  2. handleFrame (connection.ts:386) is a msg.type if/else chain that fully handles retry_receipt, ask_answer_receipt and session_queue, then runs the demux.
  3. The typed handler map runs last, and registers no-op entries for the frames handled earlier: retry_receipt: () => {} and ask_answer_receipt: () => {} (packages/ui-react/src/hooks/websocket-handlers/chat.ts:403-404), session_queue: () => {} (packages/ui-react/src/hooks/websocket-handlers/connection.ts:45).

The map's exhaustiveness assertions therefore do not prove where a frame is handled.

Scope

  • Extract reconnect/backoff, auth refresh, the outbound queue and dispatch into modules with direct unit tests.
  • As part of the dispatch extraction, move the handling of retry_receipt, ask_answer_receipt and session_queue into the typed handler map, so the map is the single routing table and its no-op entries go away. Handling order and effects stay the same.

Out of scope

  • Protocol or timing changes.

Acceptance criteria

  • createWebSocketClient is under ~200 lines.
  • Reconnect backoff and outbound queue have unit tests that fail when their ordering is broken (mutation recorded).
  • Offline/reconnect browser specs pass unchanged.
  • No handler-map entry for a server frame is a no-op; a test asserts that each of the three moved frames is handled by its map entry.

Verification

bun run test packages/ui-react

Contract impact

None.

2026-10-24: removed the closed #1380 blocker, refreshed the range, and replaced the inaccurate "per-kind split" description with the three-layer routing from the 2026-10-22 source check; the dispatch extraction now makes the handler map the single routing table.

Activity

  1. added
    type: refactor
    area: ui-react
    priority: p2
    agent-ready
    on Oct 9, 2026
  2. added
    blocked
    on Oct 9, 2026
  3. schlessera commented on Oct 9, 2026

    @schlessera
    OwnerAuthor

    Unblocked: #1380 is closed, so scripts/sync-project.ts is removing the blocked label.

  4. removed
    blocked
    on Oct 9, 2026
  5. schlessera commented on Oct 21, 2026

    @schlessera
    OwnerAuthor

    Source check at dcf5341aa during the 2026-10-22 repository review:

    • The citation is out of date. createWebSocketClient is now 1,008 lines, packages/ui-react/src/connection.ts:29-1036. The body says about 870 lines at :20-892.

    • The blocker has already closed. The body still says Blocked by #1380, but ui-react: stores and lib import from components #1380 is closed. The stale blocker line should be removed (the issue does not carry the blocked label).

    • New evidence about the "per-kind split" this body points to. Inbound frame routing actually runs in three layers:

      1. handleServerMessage (connection.ts:328) does prefiltering and turn bookkeeping.
      2. handleFrame (connection.ts:386) is a long msg.type if/else chain. It fully handles retry_receipt, ask_answer_receipt and session_queue, then runs the demux.
      3. The typed handler map runs last.

      The map registers no-op entries for frames handled earlier: retry_receipt: () => {} and ask_answer_receipt: () => {} (packages/ui-react/src/hooks/websocket-handlers/chat.ts:403-404), and session_queue: () => {} (hooks/websocket-handlers/connection.ts:45). The exhaustiveness assertions over the map therefore no longer prove where a frame is handled. Moving that handling into the map would make it the single routing table, and it fits this issue's "dispatch" extraction.

  6. self-assigned this
    on Nov 2, 2026
  7. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    Claimed (token wi-1362-3900e7ec). Branch refactor/1362-ws-lifecycle-extraction from epic/1342-turn-path-split @ 45fe0ecd2; the PR targets that epic branch. Collision report: path overlap with #3371 on packages/ui-react/src/hooks/websocket-handlers/connection.ts; closure-only overlaps with other open PRs, including #3360 on the same epic branch. My diff stays out of the #3360 chat-slices files.

  8. added this to the 0.45.0 milestone on Nov 2, 2026
  9. schlessera commented on Nov 2, 2026

    @schlessera
    OwnerAuthor

    PR #3390 is open and ready against epic/1342-turn-path-split (head 8fa3836f7, base 45fe0ecd2). createWebSocketClient is now 164 lines, composed from directly tested parts under packages/ui-react/src/ws-client/. The three frames are routed through their map entries. Mutation receipts are on the PR. Hosted selected proof is pending. This issue closes when the epic batch lands on main. Follow-ups: #3388 (CI file-input selection for the moved audit consumer), #3389 (remaining voice- and SDK-consumed no-op map entries, needs scoping).

  10. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Delivered to its epic integration branch as 2b9a69c60 via #3390, after ready-candidate proof passed on the exact epic base. This issue closes when the epic batch lands on main.

  11. removed their assignment
    on Nov 3, 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-reactpriority: p2type: refactor

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions