Skip to content

bridge: split bridge.tsx by concern — state, stream, requests, rows (Arkho #77, 7.157.3) - #200

Merged
SSFSKIM merged 3 commits into
mainfrom
arkho-77-bridge-split
Oct 16, 2026
Merged

SSFSKIM merged 3 commits into
mainfrom
arkho-77-bridge-split

Conversation

@SSFSKIM

@SSFSKIM SSFSKIM commented Oct 16, 2026

Copy link
Copy Markdown
Owner

Arkho board ticket #77: split hooks/mods/bridge.tsx by concern. The behavior is unchanged. Version 7.157.3, over main's 7.157.2 (main merged at b2a59fa0).

Problem

bridge.tsx was 2,036 lines and carried five concerns, each with its own state and its own asynchronous boundaries: the stream, control, requests and settlement, row order and export, and the child and the session. A change to one concern meant reading the whole file. DC2 (PR #195) left the split as residue, and #78 (plugin-own notices) is blocked on it.

The layout

bridge.tsx (988 lines) keeps the hooks, registerBridge, bridgeStart, and every function that takes $: control (steer, interrupt, chooseModel, compact/runCompaction, deliver, mainTurnEnded, and the unknown-turn guard), the child and the session (onLine, startChild, switchSession, awaitNextSession, beat), and awaitDecision. The rest now sits beside it in modules that take no $. Each module imports only the ones listed before it, so there is no import cycle:

Module Lines What it holds
bridge-state.tsx 274 the one BridgeState object (export let state), its types, fresh/resetBridge, and the shared helpers (message, isRecord, parsed, capped, loopKey, isEffort)
bridge-stream.tsx 357 the mod's copy of the live state (track, trackChunk, resyncEvent, forgetLive, adoptSeed, adoptKept), the poster (emit, pump, poster, lose, retire, stopChild), and a held step end (endStep, releaseStepEnd)
bridge-requests.tsx 329 raise, settle, claimCheck, decisionRecorded, settleDecided, callEnded, settleFromTranscript, answeredThrough, onAskNote, answerFromOutside, withdrawAll, firstQuestion, askCallFor
bridge-rows.tsx 160 noticeRow, announceRow, nameBlock, observeRow, exportRow, keepAsk

Two placements differ from the ticket's grouping. Both keep the import graph acyclic:

  • endStep and releaseStepEnd live in the stream module, not with the rows. track() releases a held end when a subagent stops, and emit → track → releaseStepEnd → emit is one recursion through the poster's entry point. With these two in the stream module, the rows module calls into the stream and the stream never calls back.
  • stopChild lives beside retire, which the poster calls. If it stayed in bridge.tsx, the stream module would have to import the file that imports it.

A pure move

Every function body and constant moved verbatim. The only code edits are export on declarations that another module now imports, and the import lines. The section comment // Requests from outside the terminal. was dropped; the requests module's header replaces it. The module-header paragraphs moved to the modules they describe. bridge.tsx re-exports everything it exported before (TEXT_CAP, capped, resetBridge, STEP_END_WAIT_MS, RECORD_WAIT_MS, TRANSCRIPT_RETRY_MS, onAskNote), so register.tsx and tests/mods/bridge.test.ts keep their imports unchanged.

The files were generated by a script that slices main's bridge.tsx by line range and asserts that every non-blank body line lands in exactly one module. A separate check compares the multiset of lines before and after, with export stripped on both sides: the one line lost is that section comment, and every line added is a header, an import, or a re-export.

Validation Evidence

Claim Command Output
Same mods test count tests/mods/run-mods-tests.sh, gated on 1-minute load < 60, inside with-slot.sh main: 298 pass, 0 fail (start load 58.28); the split: 298 pass, 0 fail (start load 56.56); ask search: all checks passed
The bridge's sminos suites pass tests/sminos/test-bridge{,-control,-requests,-export,-order}.sh, one at a time, gated 99, 79, 75, 15 and 31 assertions passed (start loads 57.66, 55.70, 56.60, 58.38, 58.26). test-bridge-order.sh runs bridge_order.py. After merging main (#199 changed the control suite), test-bridge-control.sh again: 80 assertions passed (start load 57.07)
The live walk passes on the split tests/mods/live-walk-check.py (merged tree, claude 2.1.301; it spends model calls) passed: 45 of 45 checks passed (start load 56.93), including a module reload mid-response, steer, interrupt, decide, answer, compact, model, the [ answer ] press, and the row-notice audit
No new validator warning, and the same $ calls claude plugin validate --json . before and after The reports are identical: errors, warnings, every note, and the gating hooks. That note is truncated in the report, so the bridge was also validated alone (a staged plugin whose register calls only registerBridge). Its full calls: line is identical before and after, down to every via path: $.clock.after (via bridgeStart, interrupt, startChild), … $.turn.abort (via interrupt), $.ui.log
Types tsc over hooks/mods and tests/mods against the 2.1.301 engine types the same two errors as main, both in ask.tsx (L1454, L1496; the re-entry comparison); none in any bridge file
Independent review doperpowers:reviewer-high, lens: hook registration order, $ scoping, shared state "No material findings." Verdict: correct

Residue

  • On claude 2.1.301 the validator follows $ across an import (a probe with logIt($) imported from a sibling file reported $.fs.read (via logIt) and no refusal). That contradicts the "$ may only be passed to functions in the same file" rule quoted in CLAUDE.md and in the ask-async design, which cite an earlier build's refusal. The runtime loader was not tested with $ crossing a file, so the split keeps to the rule. Whether the rule still binds is open.
  • For board-api suite hygiene: rc exit-status helper + BOARD_RUN_TOKEN hermeticity #78: the bg job's notice report in this walk shows exactly the six unnamed rows of the bridge's own compaction (system/compact_boundary, the summary user row, agent_listing_delta, mcp_instructions_delta, environment, model, all within 2 ms). runCompaction stays in bridge.tsx because it takes $; noticeRow and the cut are in bridge-rows.tsx.

bridge.tsx had grown to 2,036 lines carrying five concerns. It now keeps
the hooks and every function that takes `$` (the session start, the child
and the session it serves, control, the wait for a decision), and the
rest moves beside it into modules that take no `$`:

- bridge-state.tsx: the one state object, its types, resetBridge, and
  the shared helpers;
- bridge-stream.tsx: the mod's copy of the live state, the poster, the
  child's stop, and a step end held for its rows;
- bridge-requests.tsx: requests from outside and their settlement;
- bridge-rows.tsx: each kept row's notice, and the export to the host.

Each module imports only the ones listed before it, so there is no import
cycle. That is why the held step end (endStep, releaseStepEnd) sits with
the stream that track() releases it from, and stopChild sits with the
poster's retire. The split only moves code: every function body and
constant is unchanged, with `export` added where another module imports
it. bridge.tsx re-exports what it exported before, so register.tsx and
the tests import the same names. For a bridge-only module, the validator
reports the same `$` calls, with the same call paths, as before.

Arkho board #77.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant