Drop board snapshots that arrive out of order

Offen
#737 2 Kommentare 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@AchlysChang arbeitet bereits daran.

Seit 19.11.2026.

Bewertung

Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Anfängerfreundlichkeit
77/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
rust
Bereich
backend, testing

Rechercherichtung

Start at livekit::board::record and trace how the browser sends board streams and how HintAttempt.board_revisions uses recorded revisions. Then read tests/unit/livekit/board.rs and add the reverse-order delivery case described in the issue. Done means the older snapshot is dropped and the test observes one revision.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Board snapshots reach livekit::board::record (src/livekit/board.rs:469) in the order their readers finish, not the order the browser sent them. Each byte stream is drained on its own spawned task (handle_board_event, src/livekit/board.rs:333) and the finished boards enter the room loop's queue in whatever order those tasks call tx.send. The browser sends one board at a time (board.publishing in web/interview.js, uploading in web/example-board.js), so the agent sees two streams back to back rather than overlapping, but with two drain tasks on a multi-threaded runtime the later stream can still finish first. record compares a board only with the previous one, so the older board is then taken as a new change: HintAttempt.board_revisions (#707) counts it, a Candidate-led hint held for lack of an attempt can be released by a board the candidate drew before the clue, and the interviewer and read_board are left on the older drawing.

Proposal

Number every board on the wire and have the agent drop a board that is not newer than the last one it recorded from the same page.

Where the sequence goes on the wire

boardStreamOptions (web/lib.js) already takes the sequence the page keeps (board.sequence in web/interview.js, st.boardSequence in web/task.js) and puts it only in the stream name, board-<n>.jpg, which the agent does not read. The proposal adds it to the stream attributes as sequence, a decimal string, beside strokes and checkpoint, because the attributes are the only part of the header the agent reads (strokes_from_attributes and checkpoint_from_attributes, src/livekit/board.rs:302 and :313). A new sequence_from_attributes reads it the same way, at the same place in handle_board_event, and BoardSnapshot carries it to record. The name keeps the number for logs.

A page reload

board.sequence starts at 0 on every page load, so after a reload the new page's boards are numbered below the old page's and would all be dropped. The ordering therefore has to restart with the page. Resetting the agent's last sequence when the candidate's participant reconnects is not enough on its own: a board the old page finished sending can still be waiting in the queue when the reconnect is handled, and recorded after the reset it would set the last sequence high again and drop the new page's boards until it caught up; the reset would also need a hook in each of the three room loops that read boards (src/livekit.rs, src/livekit/recovery.rs, src/livekit/tasks.rs). Instead the page generates a random id once per load and sends it as a second attribute, page, and the agent compares sequences only within one page id. A board from a different page id than the last one recorded starts a new page and is recorded; a board from the page id that was just replaced is dropped, which covers an old page's board that finishes after the new page's first one. The id is an opaque random string, not a timestamp, so no clock on either side is involved, and a client that lies about it can only cause its own boards to be dropped or kept.

What record does with a dropped board, and with one that carries no sequence

A dropped board changes nothing: not board_snapshots, hint_attempt.board_revisions, board_strokes, board_drawn, last_board_at_ms, latest, unsent or the phase checkpoints, and record returns false as it does for an unchanged board. The same check runs in keep (src/livekit/board.rs:501), the variant for a room with no interview state, and in keep_board in src/livekit/tasks.rs, which currently copies the stroke count before calling keep and has to make that copy only for a board that was kept. A dropped board is logged once to stderr with both sequences.

A board whose sequence or page is missing or does not parse is recorded exactly as today and does not move the last sequence. That follows the rule strokes_from_attributes already states: the picture is the message, and a board is still worth showing when an attribute beside it did not survive. Only a client that is not the browser sends such a board, and it can only lose ordering for its own boards.

Wire fixture and tests

tests/fixtures/board-stream.json is generated from boardStreamOptions by scripts/gen-wire-fixtures.mjs and read by reads_the_attributes_the_browser_sent (tests/unit/livekit/board.rs:136). Regenerating it puts sequence and page on its three cases, and that test also asserts the sequence and page each case parses to, so a browser that renames or stops sending either attribute fails there. The page id in the fixture is a fixed string passed in by the generator, so the fixture stays deterministic. tests/browser/lib.test.js asserts the new attributes in its boardStreamOptions case. Unit tests in tests/unit/livekit/board.rs: two boards recorded newest first count one revision and leave the newer image as latest; a board from a new page id after a high sequence is recorded; a board from the replaced page id after that is dropped; a board without a sequence is recorded and does not move the last sequence; and keep drops a stale board the same way.

The comment in web/interview.js

The comment on board.sequence says the agent reads the name for nothing, deliberately, and keeps the newest board it finished reading rather than the highest number. That is the behavior this issue changes, so the comment is rewritten to say the number is now on the wire as sequence and the agent drops a board numbered at or below the last one from the same page, while board.publishing remains what keeps the page itself from opening two streams at once.

Contract

This changes no prompt, score anchor or report shape, so per docs/interview-contract-versions.md ("Changing it") it opens no bundle and adds no row. The board_image wire description in docs/task-mode.md names the stroke count as the stream's attribute, so it gains sequence and page and the drop rule.

Out of scope

Run results and other packets travel on the reliable data channel in order and are not affected. Who sends a board and how large it may be stay as they are.

Vorherrschende Sprache
Rust
Sterne
236
Forks
153
Ø Merge
1 T. 9 Std.
Gemergte PRs (30 T.)
187

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus sysprog21/codetrial

Alle Issues in sysprog21/codetrial

Ähnliche Issues

Weitere Issues zu Rust

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.