Repository navigation
Description
Part of #1342.
Context
Delivered prerequisite outputs: #1037. Their output references remain relevant, but they are no longer active blockers.
startTurn is about 670 lines (packages/ui-backend-claude/src/turn-runner.ts:119-788). #1037 has landed, so the function now runs the Claude runtime in the isolated worker. Its closure declares about 30 let bindings (sawResult, refused, withheld, terminal, terminalSent, the hostRelay* group, workerFailure, finishWorker, …) shared by nested closures such as emitTerminal, releaseTerminal, unsaved and limitFailure. The subscription-gate generator is already a module-level function (gatedPrompt, same file:821), called from startTurn at :471.
Scope
Split along the boundaries that exist today:
- a
TurnTerminalobject that owns the terminal flags and their emit/release rules; - a host inference relay starter that owns the
hostRelay*state; - the stream loop and result reporting, each taking explicit inputs.
Out of scope
- Behaviour changes.
createPermissionWiringandassembleClaudeSdkTurn(backends: split the Claude backend's createPermissionWiring and assembleClaudeSdkTurn #2519).gatedPrompt, which is already separate.
Acceptance criteria
- No function in
turn-runner.tsexceeds ~150 lines. -
runBackendContractpasses for the Claude backend unchanged.
Verification
bun run test packages/ui-backend-claudeContract impact
None.
2026-10-24: replaced the pre-worker phase decomposition with the current terminal-state, relay and stream boundaries from the 2026-10-22 source check, refreshed the startTurn range, and left permission/SDK assembly to #2519.
Activity
schlessera commentedon Oct 10, 2026
Unblocked: #1037 is closed, so
scripts/sync-project.tsis removing theblockedlabel.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:startTurnis now 633 lines,packages/ui-backend-claude/src/turn-runner.ts:102-734. The body says about 460 lines at:90-550; Epic: the turn path's largest functions are split into units that can be reviewed and tested alone #1342's table has the current range.letbindings, includingsawResult,refused,withheld,terminal,terminalSent, thehostRelay*group,workerFailureandfinishWorker. Nested closures share them:emitTerminal,releaseTerminal,unsaved,limitFailureand the gated-prompt check. Phases that already exist could be extracted:TurnTerminalobject that owns the terminal flags and their emit rules;gatedPrompt, about 120 lines).turn-runner.ts30 commits, against 48 forsdk-options.tsand 43 forpermission-hooks.ts.The review also found two more oversized functions in the same backend that this issue does not cover:
createPermissionWiring(permission-hooks.ts:42-590, 549 lines) andassembleClaudeSdkTurn(sdk-options.ts:143-482, 340 lines). They are filed as #2519 under #1342, so this one can stay scoped toturn-runner.ts.schlessera commentedon Nov 3, 2026
Claiming for implementation (claim token
claim-1360-696954). Branchrefactor/1360-split-claude-start-turnfromepic/1342-turn-path-split@2b9a69c60; the PR will target that epic integration branch.Collision report for
packages/ui-backend-claude/src/turn-runner.ts: path collision with draft #3371 (epic #3234 batch, editsturn-runner.ts); the rest are closure-only overlaps.schlessera commentedon Nov 3, 2026
Implementation is in #3447 (ready), against the epic integration branch
epic/1342-turn-path-splitat2efaf6c23, headdd3396e6f. This issue closes when the epic batch lands on main. The largest function inturn-runner.tsis now 85 lines (was 712). On this host the full Claude package suite fails the same way on base and branch: the same 49 real-worker/sandbox failures. The provider-history guard and the host-relay route tests can't run here, so hosted CI is their proof. Milestone 0.45.0.refactor(backend-claude): split the Claude backend's startTurn into t…
schlessera commentedon Nov 3, 2026
Delivered to
epic/1342-turn-path-splitasb93ced200via #3447, after ready-candidate proof passed on the exact epic base. This issue closes when the epic batch lands on main.