Repository navigation
Browser service: a Deadline whose timer fired reads as spent, so a paste answered timeout never runs - #400
Merged
Conversation
…ste answered timeout never runs Node can fire a timer while Date.now() still reads up to about 1 ms under the end it was armed for (4 of 500 20 ms Deadline races under load, task 92's probe). Deadline.race then rejected with timeout while check() and expired() still compared the clock with the end and let work through: paste.mjs's exclusively answered its caller timeout, and the queued paste, reached in that gap, passed its own check and ran. A retry of that command pastes twice. Per ruling 781 the deadline is now spent once a timer armed on it fires, whatever the clock reads: whenSpent(onSpent) arms that timer and marks the deadline spent before calling back, race arms its bound through it, and expired(), remaining(), check(), timeoutMs() and child() all answer from the mark first. Two other timers armed on a deadline's span answered timeout while work on the same budget went on, and now arm through whenSpent too: - Backend.request's abandon timer: a request abandoned on it left the deadline unspent, so the next request on it was still sent, and the callers' "is the deadline spent?" decisions read the clock. - Downloads.waitForDownload's wait timer: the wait answered timeout while the download's release retried on the same deadline and let it through. The tests force the early timer deterministically (support/early-timer.mjs: mocked setTimeout, Date.now() held 1 ms behind it): a paste, the Deadline itself, a backend request and a download wait. Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
SSFSKIM
added a commit
that referenced
this pull request
Nov 17, 2026
SSFSKIM
added a commit
that referenced
this pull request
Nov 17, 2026
…367) Sminos-Session: cursor235#b93055dd (cua on macbook)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
In
src/browser-service,Deadline.racearmedsetTimeout(reject, at - Date.now()), whilecheck(),expired(),remaining()andtimeoutMs()comparedDate.now()withat. Node can fire that timer whileDate.now()still reads up to about 1 ms underat. A probe under load saw it in 4 of 500new Deadline(20)races (#171 M5 task 92).So
paste.mjs'sexclusivelycould tell its caller "timeout", and the queued paste, reached in that gap, would still pass its owndeadline.check()and run. A retry of the timed-out command then pastes twice.The fix (ruling 781)
A deadline is now spent once a timer armed on it fires, whatever the clock reads.
Deadline.whenSpent(onSpent)arms the timer at the deadline's end and marks the deadline spent (a private flag) before calling back. It returns a disarm function.racearms its bound through it.expired()andremaining()answer from the mark first, socheck(),timeoutMs()andchild()agree with them. Nothing re-reads the clock to decide otherwise.Two other users armed a timer of their own on a deadline's span and had the same contradiction. Both now arm through
whenSpent:Backend.request's abandon timer (backend.mjs). A request abandoned early left its deadline unspent, so the next request on that deadline was still sent. The callers' "was the deadline spent?" decisions also read the clock:cdp.mjsfailedOnStarterBudget, and the timeout wording in chooser, actions, downloads and waits.Downloads.waitForDownload's wait timer (downloads.mjs). It was a separatesetTimeout(timeoutMs)beside aDeadline(timeoutMs). On an early fire the wait answered timeout, while the release's retry loop (releasePaused,!budget.expired()) still passed and let the download through.Every Deadline user in src/browser-service, checked
Fixed
Deadline.race, which paste'sexclusivelyrelies onBackend.request's abandon timerDownloads.waitForDownload's wait timerCovered by the fix. Each of these wakes through
raceor the request timer on the same deadline, then readsexpired()orcheck(), so each now agrees with the timer:paste.mjs: the queued operation'scheck(), andtypeText'srace(allowsRichText).cdp.mjs:withinDeadline(attachment,prepareDispatch, frame-session init), withcheckDeadlineandcallTimeoutbefore each dispatch;ensureAttachedTab's joined retry;failedOnStarterBudget;tryInitializeAttachedFrameSession.clipboard-bridge.mjsensure: its race, the joined retry, and the install's later steps.downloads.mjs:bounded, and thereleasePausedandreconfigureOrRecoverloops.deadline.expired() && isDeadlineError(error)) inchooser.mjs,actions.mjs(download media),downloads.mjs,waits.mjsandevaluate.mjs. After an early fire these used to answer the raw sentence; now they name the command's own timeout.cursor.mjsmoveMouse, whose race's error is swallowed.webmcp.mjstabNotification.Checked, and they don't share the bug. None of them answers timeout and then has later work on the same budget contradict it:
waits.mjswaitForNetworkIdle's wake timer. On an early wake it re-readsexpired(), re-arms for the 0 to 1 ms left, and gives the same answer a moment later.deadline.remaining()as a number:cdp.waitForEvent(inwaits.mjsandnavigation.mjs) andwaitForPageLoadEvent. Their timeout reaches the caller only after the command's own call returns. That call's dispatch check reads the same clock either way, so the outcome is the one an exact timer would give. The page-load wait resolves rather than rejects.min(POLL, remaining())and then re-read the clock:selectors.mjspoll,evaluate.mjsevaluateOnSelector, and the downloads retries on the service's own budgets. An early wake gives one more attempt, whose result is the answer.wheel-scroll.mjssleeps a plainPOLL_MS.dialogs.mjsanswerDialog. The deadline only bounds the call, and the close wait has a timer of its own.snapshot,injected,input,reads,actions'withinandbudgetOf,selectors'attemptBudget, andvisible-dom's child-frame budgets derived fromdeadline.at.No
Deadlineuser exists outsidesrc/browser-service.Tests
test/browser-service/support/early-timer.mjs(new) forces the early timer deterministically.setTimeoutuses node:test's mocked timers andDate.now()is the test's own.elapse(ms)runs the timers due withinmswhile the clock moves onlyms - 1, so each timer fires 1 ms short of its end. The existingcontrolled-clock.mjsmovesDateand the timers together, so its timers are never early.paste.test.mjs: a paste answered timeout by its deadline's timer never runs.errors-budgets.test.mjs: after an early fire the Deadline reads spent throughexpired,remaining,check,timeoutMs,raceandchild.whenSpentmarks it the same way, and a disarmed timer never fires.backend.test.mjs: a request abandoned on its deadline's timer leaves the deadline spent, and the next request on it is never sent.downloads.test.mjs: a download wait answered timeout by its timer lets no release of the download through after it.RED on the unfixed source: 0 of 4 pass.
the queued paste never ran. The result was{calls: 2, evaluated: 1}where{calls: 0, evaluated: 0}was expected: the timeout was answered and the queued paste then ran.expired()readfalse, expectedtrue.the timeout answered is the deadline's,false !== true.no release of the download after the wait timed out,2 !== 1.With only the
racechange (the backend and downloads changes set back), paste and budgets pass and backend and downloads still fail. So each of those two needs its own change.GREEN: 4 of 4. The whole browser-service suite (
node --test "test/browser-service/*.test.mjs") has 432 tests: 430 pass, 0 fail and 2 skipped. The skips are the two drift checks that neednpm ci.The existing real-clock paste deadline test is left as it is. With the fix, its queued paste is refused on the real clock as well.
Plugin 0.28.7.
ci-gate on e0f0669: the full run 44122424068 was RED 1/3: plugin and parity-browser passed, and
testfailed once. That failure is outside browser-service:test/linux-engine-diff/run-tmp.test.mjs:113read''for the after-the-run engine's TMPDIR. It is the stand-in write race #171 M5 task 92 found and fixed onm5-testdebt(the stand-ins now write by rename), which is not yet on main. Atest-gate rerun, 44124905434, was GREEN.Sminos-Session: linux171#3c5ca588 (cua on dc-linux171-1e68)