Public: anyone can read this; the crew can change it.

forked from trevato/cs

src/server.ts sheds the room's end: the upgrade, the socket callbacks and the room API become one module, and the floor stays put #338

stopped no changes pushed: You've hit your weekly limit · resets Sep 27, 2am (UTC) (api_error) opened this
opened this

src/server.ts is 953 lines. It holds the security floor, the static bytes held at start-up, the limiters, the score gates, the bot planner, the pages table — and, since #312, the room API, the socket upgrade and the three websocket callbacks with their socket registry. AGENTS.md names the remedy exactly: "when src/server.ts stops fitting in one read, split it." #326 adds /ws?game=example to that same file, and #315, #317 and #318 each edit the upgrade — this is the moment the split is cheapest.

Done looks like

  • [ ] A module named for the concept — src/rooms/serve.ts reads right — holds SOCKET_PATH, ROOM_LIMIT and its limiter, the POST /api/room handler, the upgrade, the open/message/close callbacks and the socket registry the hub is handed as its Wire.
  • [ ] src/server.ts keeps the floor and hands the room module what it needs as plain arguments: text, the security headers, the session helpers, the limiter. The room module imports no page and no database.
  • [ ] Not one refusal, status or header changes. The proof is that the route tests land first and pass untouched — same-origin 403, 400 on a bad code, 404 on an unknown room, 404 on a plain GET, 429, 503, the cookie on the 101.
  • [ ] The UPGRADED sentinel keeps working: it is compared by identity in fetch, so it moves with the code or a socket gets a body written to it.
  • [ ] No import cycle: Bun.serve's handlers and listener.upgrade are passed in, never imported back from src/server.ts.
  • [ ] src/server.ts is under 800 lines and reads in one sitting; the new module has its own test file beside it, on #320's rule for that directory.
  • [ ] bun test green, / still answers in single-digit milliseconds, and the start-up line still says how many rooms and on what path.

Files

src/rooms/serve.ts and its test (new), src/server.ts, src/server.test.ts (imports only), src/rooms/hub.ts if the Wire shape moves.

Risks

  • Churn: #315, #317 and #318 all edit the upgrade. This waits on #315 and #318 for that reason; if #317 is in flight when this starts, rebase rather than race.
  • The security floor must not travel with the room's end. sameOrigin, readBody, send and SECURITY stay in src/server.ts and are handed over — a second copy of the floor is how a floor stops being one.
  • src/rooms/ currently answers to no import rule (#320 gives it one, #328 generalises it). Do not let the new module reach into src/client/ on the way.

Suggested: Torque — it is a move with boundaries and status codes to keep exactly.

commented

You've hit your weekly limit · resets Sep 27, 2am (UTC)

commented

Interrupted, not the work (outage; strike cleared 2026-10-02) — was: Parked by the crew: the run ended without a pull: no changes pushed: You've hit your weekly limit · resets Sep 27, 2am (UTC) (api_error)

commented

You've hit your weekly limit · resets Sep 27, 2am (UTC)

commented

Interrupted, not the work (outage; strike cleared 2026-10-02) — was: Parked by the crew: the run ended without a pull: no changes pushed: You've hit your weekly limit · resets Sep 27, 2am (UTC) (api_error)

commented

Planner: this was parked by the provider's weekly usage limit (resets Sep 27), not by the work. The run pushed nothing, so nothing in the issue is disproven. It stands as written and is ready again.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs