Repository navigation
test(browse): de-flake the lease expiry assertion in ring-buffer runtime - #2556
Closed
frederik-kaster-noygear wants to merge 1 commit into
Closed
frederik-kaster-noygear wants to merge 1 commit into
frederik-kaster-noygear wants to merge 1 commit into
Conversation
'lease registry is independent of ring buffer state' ended by asserting that two back-to-back mintLease() calls produced identical expiresAt values. That only holds if both calls land in the same millisecond; under full-suite load they sometimes straddle a tick and the test failed with a 1 ms difference. It passed standalone and in most full runs, so it read as noise rather than a real regression. Assert closeness (<= 5 ms) instead of equality. The property the test exists to check is that both leases got the same TTL policy and that neither is coupled to ring-buffer state; wall-clock coincidence was never part of that, so nothing is lost. Injecting a clock into pty-session-lease would have bought exact equality at the cost of a test seam in production code for an assertion that does not need one. Swept the rest of browse/test/ for the same shape: no other assertion compares two separately-sampled timestamps for exact equality. The timestamp equalities in cdp-inspector-history-cap use synthetic counters, and the elapsed-duration budgets in sanitize and security-audit-r2 have order-of-magnitude headroom. Verified over 7 consecutive full `bun test browse/test/` runs: the lease assertion never failed. One run showed 2 unrelated load flakes (browser-skills-e2e nested `bun test` returning only its banner, and the pair-agent tunnel eval timing out on connect); both passed in the others. Co-Authored-By: Claude Fable 5 <[email protected]>
|
Merging to
After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here |
4 of 9 tasks
Owner
|
Closing as superseded: the lease-expiry flake was fixed in v1.64.1.0 with a 50ms tolerance window (browse/test/terminal-agent-ring-buffer-runtime.test.ts:154). Thank you for the report/patch — the class is covered on main. |
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 flake
browse/test/terminal-agent-ring-buffer-runtime.test.ts— the testlease registry is independent of ring buffer stateends by asserting that two back-to-backmintLease()calls produce identicalexpiresAtvalues:mintLease()computesexpiresAtasDate.now() + LEASE_TTL_MS, so this only holds if both calls land inside the same millisecond. Under full-suite load they sometimes straddle a tick and the test fails on a 1 ms difference. It passes reliably when the file is run on its own, which is what makes it read as noise rather than a real regression.Observed failing roughly 1 run in 3 of
bun test browse/test/.The fix
Assert closeness rather than equality:
The property this test exists to check is that both leases got the same TTL policy and that neither is coupled to ring-buffer state. Wall-clock coincidence was never part of that, so nothing is lost — a real coupling regression (say, one lease inheriting a ring-buffer-derived expiry) would still blow well past a 5 ms window.
I considered injecting a fixed clock into
browse/src/pty-session-lease.tsto makemintLeasedeterministic and keep exact equality. That works, but it adds a test seam to production code for an assertion that doesn't need one, so I went with the smaller change. Happy to switch if you'd prefer the deterministic-clock version.I did not delete the assertion — the independence property is worth keeping.
Scope check
I swept the rest of
browse/test/for the same shape. No other assertion compares two separately-sampled timestamps for exact equality:cdp-inspector-history-cap.test.tstimestamp equalities use synthetic counter values (0,49,50), not sampled clockspty-session-lease.test.tsandsse-session-cookie.test.tsalready usetoBeGreaterThansanitize.test.tsandsecurity-audit-r2.test.tsare a different pattern and have order-of-magnitude headroomVerification
7 consecutive full
bun test browse/test/runs (121 files, ~140 s each). The lease assertion did not fail in any of them.One run showed 2 unrelated load flakes that passed in the others and are untouched by this change:
browser-skills-e2e.test.ts:89(its nestedbun testsubprocess returned only its banner before a summary was captured) andpair-agent-tunnel-eval.test.ts(20 s timeout,Unable to connect). Both look like separate issues worth their own fix.🤖 Generated with Claude Code