Skip to content

The screen hook shares one pending start, a stop cancels it, and uploads wait for each other and for the server's backoff - #1825

Merged
seangalliher merged 6 commits into
mainfrom
fix/screen-stream-guards-20261117
Nov 17, 2026
Merged

seangalliher merged 6 commits into
mainfrom
fix/screen-stream-guards-20261117

Conversation

@seangalliher

@seangalliher seangalliher commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Refs #1804

What changes

The screen hook takes the camera hook's loop guards. ui/src/hooks/useScreenStream.ts (the only source file, +94/-6) never received the guards #1671 gave the camera hook:

  • One shared pending start. Overlapping startScreenStream calls share one promise, so the picker opens once. Before, the second start overwrote the stream and the interval, and the first capture's tracks were never stopped.
  • A stop cancels a pending start. Every stop advances an epoch that a pending start compares after getDisplayMedia and after play(): a capture picked after a stop has its tracks stopped and sets no module or store state, and a picker dismissed after a stop reports no error. A start that no stop cancelled behaves as before.
  • A frame belongs to its loop. A frame reads its epoch and session id before the encode and posts nothing when a stop came during it (the one check the camera hook lacks: it reads the session id after its encode); an answer that arrives after a stop is not acted on.
  • Uploads wait for each other and for the server. A tick returns while an upload is in flight (the guard belongs to its epoch, so a stale upload's settle does not release a newer loop's); each upload is aborted after 10 s; a 429 pauses the uploads for its Retry-After (seconds or an HTTP date, capped at 30 s), else 1 s doubling up to 30 s, and a 200 ends the doubling; a 413 drops the frame.

The exports keep their signatures and return shapes; the form fields (file, session_id, source), the endpoint and the 503 handling are as before. UI only: no server, config, flag or persisted-state change.

One new test file, ui/src/hooks/__tests__/useScreenStream.bf973.test.ts (406 lines, 18 cases: 12 that fail on the base and 6 controls), uses vitest's fake clock only, so nothing waits on the wall clock. The rest of the diff is the contract (prompts/bf-973-screen-stream-guards.md, 968 lines), DECISIONS.md (+9), PROGRESS.md (+4) and the regenerated ledger pair.

Six commits: the contract; M1 (the new tests, 12 of them it.fails until built); M2 (the hook, and the marker becoming a plain it); M3 (the trackers and the ledger pair); and two review repairs, R1 (the contract's measured killers for rows W4 and W6, two line counts and the campaign record) and R2 (the contract's test-teardown sentence, row W15 and its record).

Found by review and repaired on this branch

Round 1 (gpt-6.1-sol, the whole candidate, 15 min) found the hook and every consumer sound and was NOT READY on one P3 about the new tests: the contract said every held step is released by the test, but three cases (S6, S8 and S12) end with one upload still in flight. I reproduced it (exactly those three leave one 10 s deadline timer after _testReset(); the other fifteen leave none) and checked the gap it points at: deleting the deadline's window.clearTimeout is already killed by controls C3, C4 and C5. The Architect ranked a teardown that settles every held step against a wording change plus one mutation row, and chose the wording change: the leftover reaches no later case (each case installs a fresh fake clock and vi.restoreAllMocks() drops the held spy), and a new teardown would change the recorded campaign. R2 rewords D4 and property 7, adds row W15 to the contract and records its run. Round 2 (the delta, 10 min) verified all six of its properties and found nothing: READY.

Limits recorded in the contract (section 6)

Review and the broad gate

Every review was a Diff Reviewer on gpt-6.1-sol. The Architect drafted the contract and decided the round-1 repair and where the limits are filed; the Builder applied M1, M2, R1 and R2, each blob checked against a tool-applied oracle; the contract, M3 and the ledger pair were applied by tool.

Broad gate, on 958309820318154496ee9aa4c151bedcb62ddcda: one run in the canonical wrapper at --workers 3: 54111 passed, 184 skipped, 243 warnings, 7 subtests passed in 1:30:42, exit 0 (started 11:03Z). The receipt (logs/gates/screen-stream-guards.receipt.json) records 54,295 tests with 0 failures and 0 errors, binds this head and its tree ad27c6c29efc2f48102df519f894e31c56a48e6f, and validated four times (three after the run, once before the push). The live-data manifest was identical before and after the run (54,107 files). That is the same 54111 passed as the base's last gate: the change adds no Python test. A first run of the same head (started 10:02Z) showed one failure mark and was stopped at 70%, so its test was never named; this second run, on a host kept quiet for its whole length, is the record.

Evidence

  • At M1 the new file passes 18 in default mode, and with BF973_RUNXFAIL=1 the 12 built cases fail at their own asserts and the 6 controls pass.
  • The contract's 15 mutation rows (W1 to W14 on the M3 commit, W15 on the R1 commit; the ui/src/ files are identical): every row killed, none survived, 13 by exactly the cases the contract first named; W4 (the cancelled start stays in flight, which fails every later case) fails 15 cases and W6 fails 3 where the contract first named one each, and the contract now names them. Round 1's reviewer replayed all 14 rows and got the same killers.
  • The contract's G2 set (the new file and 16 others): 105 passed in 16 files on the base, 123 passed in 17 files at the head in both modes; npx tsc -b and npm run build exit 0; the gate wrapper's preflight-only exits 0; the ledger test passes (33).
  • CI: all five checks passed on head 958309820318 (python-tests-shard 1, 2 and 3, python-tests and ui-tests), 12:54Z.

What this pull request does not do

  • It does not change the camera hook, the stores, the callers' components, the server's frame route or its rate buckets.
  • It tests the hook against mocks: no real browser, picker or canvas ran.

seangalliher and others added 6 commits November 17, 2026 01:58
…hat cancels a pending start, and uploads that wait for each other and for the server's 429

Refs #1804.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…he picker is open, a stop during the encode, a slow upload and a 429, expected to fail until built (#1804)

Adds one hook test file: 18 cases, 12 of them marked to fail until the hook is built.

Refs #1804.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…a stop cancels a pending start, and ticks wait for an upload in flight or a 429 pause (#1804)

The screen hook takes the camera hook's loop guards. Concurrent starts share one pending start, so the picker opens once. Each stop advances an epoch that a pending start compares after the picker and after play(); a capture picked after a stop has its tracks stopped and sets no state, and a picker dismissed after a stop reports no error. A frame reads its epoch and session id before the encode and posts nothing when a stop came during it; an answer that arrives after a stop is not acted on. A tick returns while an upload is in flight, and each upload is aborted after 10 s. A 429 pauses the uploads for its Retry-After, else 1 s doubling up to 30 s, and a 200 ends the doubling; a 413 drops the frame. The exports keep their signatures. The new test file's marker becomes it.

Refs #1804.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
PROGRESS.md and DECISIONS.md entries; ledger regenerated.

Refs #1804.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…measured for two rows, and DECISIONS.md records the campaign of record (#1804)

The campaign of record ran the 14 rows on the M3 head: every mutant was
killed, none survived. Rows W4 and W6 failed more cases than the contract
named (15 and 3, where it named S4 and S6); the contract now lists the
measured killers and why each extra case fails. Two line counts in its
Verified Against Codebase section are corrected to the counts measured at
the base (166 and 307). DECISIONS.md records the campaign. This commit
changes the contract, DECISIONS.md and the two regenerated ledger files
only; no source or test line changes.

Refs #1804.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ves in flight and gains row W15, and DECISIONS.md records W15 (#1804)

Review round 1 found that the contract said every held step is released by
the test, while three cases (S6, S8 and S12) end with one upload still in
flight. D4 and property 7 now say what holds: each case releases the steps
its assertions wait on, and an upload left in flight is dropped with the fake
clock. The deadline timer's clearing is checked by C3 to C5, so the contract
gains row W15 (delete the clearTimeout), and DECISIONS.md records its run on
the unchanged ui files. This commit changes the contract, DECISIONS.md and
the two regenerated ledger files only; no source or test line changes.

Refs #1804.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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