Repository navigation
Description
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.tsis 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 fromhost,turn,promptTextandbackendIdthroughrecorder,onSessionNamed,onTerminalFailure,promptLabel,applicationPolicy,protectedPaths,workerProfile,onUsageandpricingContext, tomainModel. The call site passesundefinedplaceholders 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).
- frame emission (
- 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
BackendBridgewith explicit inputs: emission, permissions, asks, location/mask, activity/inbox, policy proposal, scratch.makeBridgecomposes 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
- Changing how coordinator state is stored or mutated. The TurnCoordinator encapsulation issue in this review owns that, and this split should land after it so the factories call intent methods.
handleClientMessage(ui-server: replace the 41-case handleClientMessage switch with a per-message handler table #1358) andrunRetainedSession(ui-server: split runRetainedSession into lifecycle stages #1359).- Changing which backends get the live-authority wrapper (
bridge.ts:640), the voice capability narrowing, or any bridge behaviour. ConversationHost.
Acceptance criteria
-
makeBridgeis under ~150 lines, and no function inws/bridge.tsexceeds ~200 lines. -
makeBridgetakes 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.tsand the ws runtime suites pass unchanged.
Verification
bun run test packages/ui-server
bun run typecheck
bun run lintContract 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
schlessera commentedon Oct 21, 2026
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.schlessera commentedon Nov 3, 2026
Claim
claim-2516-c7e1: working this on branchrefactor/2516-split-make-bridgefromepic/1342-turn-path-split(2b9a69c60), under the epic-integration-branch ruling. Blocker #2515 is delivered to that epic branch, soBlocked by #2515andblockedstay until the batch lands on main.Path collisions reported by
scripts/collisions.ts: #3415 (same epic,run-session.ts— themakeBridgecall site only), #3342, #3404, #3407 (bridge.ts,run-session.ts), #3386 (run-session.ts). Whichever lands second rebases.schlessera commentedon Nov 3, 2026
Claim
claim-2516-c7e1: PR #3449 (ready) targetsepic/1342-turn-path-splitat2efaf6c23, head3624e9622. It was rebased after #3415 landed; themakeBridgecall site moved tosession-run/backend-entry.ts.makeBridgeis 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 #2515andblockedstay until then. Milestone 0.45.0 set on the issue and the PR.schlessera commentedon Nov 3, 2026
#3461 closed: #3467 merged as
1ea260971. #2515 still blocks this issue.schlessera commentedon Nov 3, 2026
Unblocked: every
Blocked byissue here is closed. #1362 and #2515 closed when epic #1342 batch 1 landed on main in #3520 (merge9805f52fd).refactor(ui-server): split makeBridge into capability factories behin…
Merge pull request #3569 from schlessera/epic/1342-turn-path-split