Skip to content

fix: clear the 15-item code sweep backlog - #4

Merged
KyleJamesWalker merged 4 commits into
mainfrom
fix/issue-3-code-sweep
Sep 3, 2026
Merged

KyleJamesWalker merged 4 commits into
mainfrom
fix/issue-3-code-sweep

Conversation

@KyleJamesWalker

Copy link
Copy Markdown
Owner

Summary

Clears all 15 items in #3. Six were small and self-contained. Four were
correctness problems under load or at the edges. Two were features. The
last three were larger: the wake lock, the missing ARIA, the test gaps.

Confirmed the eleven unverified items against the code before starting.
All 15 were real.

Why

One pattern runs through most of the list, as the issue says. The
intended behavior was already written down, or already implemented one
file over. Nobody applied it everywhere.

The auth check guarded reads and not writes. The architecture doc
described the no-op broadcast this PR now implements. Presets already
capped their text while messages and cues did not. Those fixes are small
and hard to argue with, so they came first.

The rest are real gaps rather than inconsistencies. The autopilot read
state and then acted on it. Nothing stopped the server cleanly. The
socket retried a refused handshake forever. One layer of test coverage
was missing under all of it.

Small and self-contained

  • Unauthenticated requests created rooms. Every write handler now
    validates the name, checks the token, and creates the room only after
    that. room_of() is gone, and named() carries the comment for both
    cases. tests/routes.rs asserts room_count() on all three write
    routes, and tests/api.rs asserts the picker's room list stays empty
    after three 401s.
  • A no-op command broadcast to every client. Room::apply_all
    publishes and marks the snapshot only when the state moved, which is
    what docs/architecture.md:24 always claimed. Client counts, room
    close and the keepalive still publish unconditionally.
  • The token stayed in the console address bar. The console strips it
    with history.replaceState, the way web/unlock.js already did after
    a failure.
  • No route back to the picker. One anchor in the console header. The
    duplicate id="viewerLink" in web/unlock.html is now pickerLink,
    and a test asserts no page repeats an id.
  • Space on a focused button hit the transport. A new
    targetOwnsKey() gives a focused button or link Space and Enter. The
    letter shortcuts still reach the transport. Anchors are in scope
    because the header now has one.
  • Cue delete was one unconfirmed click. It asks first, and says when
    the cue is on air and the stage title will blank.

Correctness under load and at the edges

  • The autopilot read state, then acted on it. It reads four fields
    through the new Room::peek. It then hands the same condition to the
    new Room::apply_if, which re-checks it under the write lock. An
    operator who disarms or reloads inside that window wins.
  • The agenda rebuilt its table twice a second. agendaSignature
    rounds start and end to the minute the table prints. Measured in a
    browser on a pre-show room: 5 rebuilds per 2.5 s before, 0 after.
  • No graceful shutdown. Ctrl-C and TERM now close every room and let
    the sockets send a 1001 close frame. The server waits up to five
    seconds for connections, then flushes the debounce window. Measured:
    exit in 102 ms with a live edit socket. A command sent 200 ms before
    the signal reached disk.
  • The console retried a refused socket forever. A new
    GET /api/auth separates a bad token from a dead network. The socket
    reports unauthorized and stops retrying, and the console reopens the
    token form. A viewer socket never probes, so it still retries.
  • Hot-path waste. Room::peek replaces the five-per-second clone of
    every cue. Snapshot writes moved to spawn_blocking, so a network
    mounted --state-dir cannot stall the runtime serving every socket.
  • No ceiling on cue count or text length. A room holds 500 cues. A
    message takes 280 characters, a title or a cue line 120, a cue note
    500. Text past a limit is cut, matching what presets already did. An
    import over 500 cues gets an error instead.

Larger

  • The wake lock could not work in the documented deployment. The
    viewer re-requests on visibilitychange, because the spec drops the
    lock whenever the document hides. It also stops hiding a missing API
    behind optional chaining. I took the documentation branch of the
    issue's either-or. docs/operations.md now states that the API needs
    a secure context, and that it is absent on http://<lan-ip>:8080. It
    says to turn off system sleep instead. A muted-video fallback is a
    bigger change than this backlog wants.
  • No ARIA anywhere. aria-pressed now rides on all ten screen
    toggles, plus auto-advance, aux and the tones. One pressed() helper
    sets it, so the class and the attribute cannot drift. The icon-only
    buttons carry labels, including the cue rows the console builds at
    runtime. The toast and both status badges are live regions.
  • Tests asserted one layer short. Covered above, plus two files.
    web/agenda_signature.test.mjs now feeds two consecutive
    projectAgenda outputs through the signature rather than building rows
    by hand. web/socket.test.mjs covers reconnect, backoff doubling to
    the cap, the reset on a fresh open, the refused handshake and the
    viewer's exemption. RoomSocket takes its socket, auth probe and timer
    as options so a test can drive it.

Testing

make lint and make test are clean: 337 Rust tests, 102 JavaScript
assertions. New files: tests/limits.rs, tests/markup.rs,
web/keys.test.mjs, web/socket.test.mjs.

Drove a real browser against a debug build for the parts no assertion
covers. The token leaves the URL. The picker link works. aria-pressed
tracks blackout. Space on a focused Load button loads that cue and
leaves the timer stopped.

The delete confirm blocks, then deletes on accept. The agenda holds
still with no cue active. The viewer asks for the wake lock again after
a release, and asks once while it holds one. No console errors on any
page.

Notes

Hub still has no room ceiling. The item's defect was the ordering, and
an open server creating rooms on demand is the product. A ceiling is a
separate decision.

Closes #3

Six items from #3. Each one is a rule this codebase states somewhere
and did not apply everywhere.

A rejected caller no longer leaves a room behind. Every write handler
validates the name and checks the token first. It creates the room
only after that. Reads were already guarded.

A command that changes nothing sends no frame. Room::apply_all
publishes and marks the snapshot only when the state moved.
docs/architecture.md already said so.

The autopilot re-checks its decision under the write lock. It reads
four fields through Room::peek rather than cloning the whole room
five times a second per room. It then hands the same condition to
Room::apply_if. An operator who disarms inside that window wins.

Ctrl-C and TERM now stop the server in order. It closes every room
and lets the sockets send a 1001 close frame. It waits up to five
seconds for connections. It then writes what was still inside the
debounce window.

Snapshot writes run on a blocking thread. A slow state directory no
longer stalls the runtime that serves every socket.

Every part of a room has a ceiling. A room holds 500 cues. A message
takes 280 characters, a title or a cue line 120, a cue note 500. The
parser refuses an import over the cue ceiling rather than cutting it
in silence.

Adds GET /api/auth, which answers 401 without a valid token. The
console uses it to tell an expired token from a dropped network.

Refs #3
Seven items from #3, all of them in the pages rather than the server.

The console strips the operator token from the address bar and from
browser history. `web/unlock.js` already did this after a failure.

The console header links back to the room picker. Switching rooms
takes one click rather than an edit to the URL.

A focused button or link keeps Space and Enter. Tabbing to a rundown
control and pressing Space started or paused the show, and the control
never fired. The letter shortcuts still reach the transport.

Deleting a cue asks first, and says when the cue is on air. Clearing
a room and deleting one both asked already.

The agenda signature rounds to the minute the table prints. Before a
show every projected time tracks the wall clock. The table therefore
rebuilt itself twice a second forever.

A refused edit socket reports the token rather than reconnecting. The
console says so and reopens the token form. It no longer sits on
offline with no way back in.

The viewer asks for the screen wake lock again whenever the tab
returns. The browser drops the lock every time the document hides.

A screen reader now gets the state that was CSS only. Every toggle and
tone carries aria-pressed. The icon buttons carry labels. The toast
and both status badges are live regions.

Refs #3
The wake lock entry promised something the documented deployment
cannot do. The API needs a secure context. It is absent on the plain
http://<lan-ip>:8080 this server is usually reached at. The entry now
says so, and says what to do instead.

Also documents the state ceilings and the new /api/auth endpoint. Adds
what a stop writes, and the JavaScript suites that cover the socket.

Refs #3
Six findings, in the order they would bite an operator.

Space goes back to the transport after a mouse click. A click leaves the
button focused, so the last commit handed Space to that button. An
operator who pressed Blackout and then Space toggled the screen rather
than pausing the show. A click on a button now returns focus to the
page. Only a control the operator tabbed to keeps Space and Enter.
`detail` tells the two apart, so keyboard activation still works.

Two snapshot writers no longer share one temporary file. The final flush
at a stop can run beside the debounced writer. Both used
`<room>.json.tmp`, so one could rename the other's file away and lose
the snapshot. Each write now names its own file. A mutex orders a write
against a delete.

A write in flight can no longer resurrect a deleted room. The writer
keeps the room it read and skips one the hub has retired.

The stop sequence writes before it closes the rooms. Otherwise the
writer takes a closing room for a deleted one and skips it. A serving
error no longer returns early past that write. A server task that ends
on its own no longer leaves the process waiting for a signal. Nothing
would send one.

The agenda drops the seconds in 12-hour mode. `slice(0, undefined)` kept
the whole string, and the minute-rounded signature froze those seconds.
The clock format now also belongs to what the table repaints on.

Three smaller ones. `AuxSet` caps its label like every other line. The
console fields carry `maxlength`, so the operator sees a limit rather
than losing text to the server. The autopilot checks that the cue it
read still follows the active one. The viewer asks for one wake lock at
a time.

Refs #3
@KyleJamesWalker

Copy link
Copy Markdown
Owner Author

Reviewed the first three commits and fixed six findings in 6af2488.
One was a regression this PR introduced.

Space after a mouse click. A click leaves the button focused, so the
keyboard fix handed Space to that button. Pressing Blackout and then
Space toggled the screen rather than pausing the show, which is worse
than the bug it replaced. A click on a button now returns focus to the
page, and only a control the operator tabbed to keeps Space and Enter.
:focus-visible alone was not enough: a programmatic click still
matches it. I checked both paths in a browser.

Two writers, one temporary file. The final flush at a stop can run
beside the debounced writer, and both used <room>.json.tmp. One could
rename the other's file away. Each write now names its own file. The
test for it fails without the fix.

A write in flight could resurrect a deleted room. The writer now
skips a room the hub retired. The stop sequence writes before it closes
the rooms, so a closing room is not mistaken for a deleted one.

The agenda kept the seconds in 12-hour mode. slice(0, undefined)
returns the whole string. The minute-rounded signature then froze those
seconds for up to a minute. The clock format is now part of what
the table repaints on, so switching it repaints at once.

Three smaller ones. AuxSet caps its label, and the console fields
carry maxlength. The autopilot checks that the cue it read still
follows the active one. The viewer asks for one wake lock at a time.

One finding I did not fix. syncField clears a field's draft flag
when a frame arrives carrying the same value. A no-op command now sends
no frame, so a field the operator typed back to the server's value stays
flagged until the next keepalive. For up to 15 seconds it ignores a
second operator's change to that field. It is self-healing and needs two
operators on one field, so I left it rather than adding state to track
it. Say the word if you want it closed.

@KyleJamesWalker
KyleJamesWalker merged commit 3509f90 into main Sep 3, 2026
9 checks passed
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.

Backlog: 15 findings from a code sweep (bugs, features, test gaps)

1 participant