Drop board snapshots that arrive out of order

Aperta
#737 2 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@AchlysChang ci sta già lavorando.

Dal 19/11/2026.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
77/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend, testing

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Rust
Stelle
236
Fork
153
Merge medio
1g 9h
PR unite (30g)
187

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di sysprog21/codetrial

Tutte le issue di sysprog21/codetrial

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.