Skip to content

ui-server: makeBridge is one 626-line function with 14 positional parameters #2516

Closed

Description

@schlessera

Context

makeBridge (packages/ui-server/src/ws/bridge.ts:33-658) is one 626-line function, measured with the TypeScript compiler API at dcf5341aa. It builds the BackendBridge that every interactive turn hands to its backend, and it is called once per turn from runRetainedSession (packages/ui-server/src/ws/run-session.ts:569).

  • bridge.ts is the third most-changed file in ui-server: 56 commits since 2026-04-01.
  • The function takes 14 positional parameters (bridge.ts:34-55), ten of them optional. They run from host, turn, promptText and backendId through recorder, onSessionNamed, onTerminalFailure, promptLabel, applicationPolicy, protectedPaths, workerProfile, onUsage and pricingContext, to mainModel. The call site passes undefined placeholders to reach the later ones.
  • One closure holds every capability:
    • frame emission (emit, bridge.ts:136-280, 145 lines);
    • permission requests (requestPermission, :281-384);
    • activity (:386);
    • the four ask-user kinds (:424-510);
    • location (:511) and mask (:536);
    • policy proposals (:562-575);
    • scratch pruning;
    • a final loop that wraps 14 named methods with the live-authority check (:640-656).
  • Its only direct test file is packages/ui-server/tests/ws-claude-effects.test.ts. Everything else reaches it through a whole turn.

#1342 lists five turn-path functions and does not list this one, although it sits on the same path and has the same problem. ConversationHost (ws/conversation.ts:130-955, 826 lines) was checked as well. It is a class whose largest methods are 112, 99 and 127 lines (start, commit, onEvent), so it already meets the epic's per-function bound and is not included here.

Scope

  • Replace the positional parameters with one options object (MakeBridgeOptions).
  • Split the body into one factory per capability, each returning its slice of BackendBridge with explicit inputs: emission, permissions, asks, location/mask, activity/inbox, policy proposal, scratch. makeBridge composes the slices and applies the authority wrapper last, unchanged.
  • Give each factory at least one direct test that does not start a backend turn.

Out of scope

Acceptance criteria

  • makeBridge is under ~150 lines, and no function in ws/bridge.ts exceeds ~200 lines.
  • makeBridge takes at most three parameters.
  • Each capability factory has a direct unit test. At least one, the ask-user factory, is proven by a recorded mutation: break its collision check, watch the named test fail, restore.
  • tests/ws-claude-effects.test.ts and the ws runtime suites pass unchanged.

Verification

bun run test packages/ui-server
bun run typecheck
bun run lint

Contract impact

None. makeBridge is internal to ui-server, and BackendBridge (ui-sdk) is unchanged.

Blocked by #2515

Found by a repository review on 2026-10-22.

2026-10-22 triage: verified the complete brief and its still-open prerequisite (#2515). Add agent-ready alongside blocked; the issue remains unpickable until its prerequisite is delivered. Preserve its explicit deferred priority and existing parent.
Blocked by #3461

Activity

  1. added
    type: refactor
    area: ui-server
    priority: p3
    blocked
    on Oct 21, 2026
  2. schlessera commented on Oct 21, 2026

    @schlessera
    OwnerAuthor

    2026-10-22 triage at main ca8842828ed8634a84c4e8aa4a88e487238721b4: verified the complete brief and its still-open prerequisite (#2515). Add agent-ready alongside blocked; the issue remains unpickable until its prerequisite is delivered. Preserve its explicit deferred priority and existing parent.

  3. added
    agent-ready
    on Oct 21, 2026
  4. self-assigned this
    on Nov 3, 2026
  5. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claim claim-2516-c7e1: working this on branch refactor/2516-split-make-bridge from epic/1342-turn-path-split (2b9a69c60), under the epic-integration-branch ruling. Blocker #2515 is delivered to that epic branch, so Blocked by #2515 and blocked stay until the batch lands on main.

    Path collisions reported by scripts/collisions.ts: #3415 (same epic, run-session.ts — the makeBridge call site only), #3342, #3404, #3407 (bridge.ts, run-session.ts), #3386 (run-session.ts). Whichever lands second rebases.

  6. added this to the 0.45.0 milestone on Nov 3, 2026
  7. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Claim claim-2516-c7e1: PR #3449 (ready) targets epic/1342-turn-path-split at 2efaf6c23, head 3624e9622. It was rebased after #3415 landed; the makeBridge call site moved to session-run/backend-entry.ts. makeBridge is now 42 lines with 3 parameters, built from per-capability factories with direct tests and a recorded ask-collision mutation. Local preflight passed; hosted proof (including the provider-history guards, which this host can't run) is pending. This issue closes when the epic batch lands on main; Blocked by #2515 and blocked stay until then. Milestone 0.45.0 set on the issue and the PR.

  8. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    #3461 closed: #3467 merged as 1ea260971. #2515 still blocks this issue.

  9. removed
    blocked
    on Nov 3, 2026
  10. schlessera commented on Nov 3, 2026

    @schlessera
    OwnerAuthor

    Unblocked: every Blocked by issue here is closed. #1362 and #2515 closed when epic #1342 batch 1 landed on main in #3520 (merge 9805f52fd).

  11. added 2 commits that reference this issue on Nov 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

agent-readyarea: ui-serverpriority: p3type: refactor

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions