Repository navigation
test: run two trace budget tests on the virtual clock so a slow runner cannot flake them - #59
Merged
Merged
Conversation
…r cannot flake them Both tests asserted budgets that real time could spend. On the Windows CI runner the real-time budget was consumed by file I/O and oversleeping, not by the property under test. slow_pre_capture_preserves_dispatch_budget gave the whole action 500 ms of wall clock and slept 50 ms for real inside the pre capture. It now freezes the virtual clock, makes the capture consume its entire capped deadline (400 ms) and asserts the dispatch receives exactly the 100 ms reserve, which is stricter than before. artifact_capture_budget_supports_deadline_bound_screenshot_backends lost a capture when opening the artifact lock file took longer than the fixed 50 ms lock wait, which is real time on a slow runner. It now runs on the virtual clock, so the lock wait cannot expire and the 250 ms backend minimum is checked against exact remaining budgets.
gshost1
marked this pull request as ready for review
November 8, 2026 19:51
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.
What and why
Two core unit tests failed intermittently on "Test (Windows)" (x86_64-pc-windows-msvc) on PRs that do not touch
crates/core/src/trace/(PR #6 head 6f4306d; PR #54 head 4e5e0a5, run 42498487874, job 128785895630). Both pass on Windows ARM64, macOS and Linux. Test-only change; no product code touched.Both tests are now deterministic on the existing
VirtualClock(crates/core/src/wait/deadline.rs), the same clockcontended_artifact_lock_preserves_dispatch_budgetalready uses.Timing analysis
slow_pre_capture_preserves_dispatch_budget(TIMEOUT "Target did not become actionable within the wait budget").artifact_capture_budget_supports_deadline_bound_screenshot_backends(left: 1, right: 2).Deadline::standard), pre and post captures capped at 1 s, the backend needs at least 250 ms remaining, and the artifact lock wait is a fixed 50 ms (ARTIFACT_LOCK_WAIT_MS).FileLock::acquireopens the lock file first and then checksdeadline.is_expired(), so the 50 ms real-time window also covers opening the lock file. On a slow Windows filesystem that open can exceed 50 ms, the capture is skipped withlock_failed, and one of the two screenshots is lost. The 50 ms wait is deliberate in the product (see the comment intrace_artifact_budget.rs) and is left alone.Changes
trace_artifacts_dispatch_budget_tests.rs: freeze the virtual clock; the first screenshot callscrate::wait::deadline::sleep(deadline.remaining()), so it consumes its whole capped deadline (400 ms, virtual). New assertions, which are stricter than before: the dispatch receives exactly the 100 ms reserve, and exactly 400 ms of virtual time elapsed. The oldwas_cappedbranch with a real 50 ms sleep is gone.trace_artifacts_more_tests.rs: freeze the virtual clock in the one test, so the lock wait cannot expire and remaining budgets are exact.How tested
All through
serial_cargo.sh, one command at a time, macOS arm64.cargo test -p agent-desktop-core --lib -- --exact <path>,RUST_TEST_THREADS=2: 200/200 and 200/200.yesCPU burners at normal priority on 8 cores, load average about 50: 200/200 and 200/200.cargo build --tests -p agent-desktop-core, thencargo test -p agent-desktop-core --lib: 1827 passed, 0 failed.cargo clippy -p agent-desktop-core --all-targets -- -D warnings: clean.cargo fmt --all -- --check: clean.cargo check -p agent-desktop-core --all-targets --target x86_64-pc-windows-msvc: clean.bash .githooks/pre-commitover staged changes: passed. Committed with the hook bypassed afterwards (--no-verify) because it had just run.Invert-verify (product code temporarily broken, test watched fail, restored):
ref_action/action_artifacts.rs:pre_capture_deadlinereturnsSome(parent)instead ofparent.capped(capture_budget).slow_pre_capture_preserves_dispatch_budgetfails withTimeout "Operation exceeded its deadline".TRACE_CAPTURE_BUDGET_MSchanged from 1000 to 200.artifact_capture_budget_supports_deadline_bound_screenshot_backendsfails withleft: 0, right: 2.Risks