Skip to content

[CTX-1382] fix(runtime): freeze the fs.list rate-window clock in tests - #2306

Merged
Xuepoo merged 2 commits into
mainfrom
ctx-window/deflake
Oct 20, 2026
Merged

Xuepoo merged 2 commits into
mainfrom
ctx-window/deflake

Conversation

@Xuepoo

@Xuepoo Xuepoo commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes the Windows CI flake on PR #2292:
plugin_runtime::services::tests::fs_list_window_reopens_after_the_accepted_window
panicked with exhausted window must deny: Table([]) — the listing succeeded
where the test expects E_FS_OVER_BOUND. #2281 fixed the same class of defect
in the fs.list cap tests; this covers the rate-window tests.

Root cause

The accepted fs.list window is one second (FS_LIST_WINDOW = RC8_WINDOW),
and admission read the real clock on every call (admit_fs_list ->
refresh_fs_window -> Instant::now). Three tests exhaust that window with
~1024 real listings, each doing grant matching, canonicalization, read_dir,
and scope filtering:

  • fs_list_tight_loop_hits_the_per_plugin_window
  • fs_list_empty_pages_still_charge_the_op_window
  • fs_list_window_reopens_after_the_accepted_window

On a loaded runner the loop outlives the window, the window advances mid-loop,
the usage clears, no denial ever arrives, and the test fails. The existing
refresh_fs_window_at helper only covered the last two assertions of the
reopen test, never the exhaustion loop itself.

Determinism method

  • Thread an explicit window instant through admission (admit_fs_list_at) and
    the listing path (fs_list_at). HostServices::fs_list_with_expiry passes
    Instant::now() at the same point as before: window length, caps, the scan
    expiry, and the denial ordering are unchanged.
  • All three window tests drive one frozen instant (fs_window_start + 1 ms),
    so "exhausted denies", "usage survives until the window elapses", and "one
    full window later reopens" are exact. The reopen test no longer pokes
    refresh_fs_window_at directly.
  • Window tests also pass the named FIXTURE_SCAN_BUDGET (60 s) as the scan
    expiry instead of the production 50 ms budget, and the remaining fs.list
    tests in the module use the same budget. Under load the scan deadline could
    otherwise abort a 1024-call loop with E_TIMEOUT before the rate window
    denied; that is the failure seen on the first head of this PR.

Test-module audit (plugin_runtime)

Converted:

  • debug_trace_expired_call_never_opens_a_trace used Instant::now() plus
    thread::sleep(2ms); now an instant 1 ms in the past.
  • overlay::tests::timeout_revokes_at_the_deadline asserted the live side with
    Instant::now(); it now asserts on both sides of an explicit deadline.

Deliberately left real-time:

  • plugin_runtime::spawn live process lifecycle tests (sleep-poll on real
    child processes; bounding them needs a process-runner seam, not a clock).
  • plugin_runtime::fs_list::large_directory_aborts_near_the_scan_deadline
    (the dedicated scan-deadline test; wall-clock by definition).
  • fs/resolution fixture mtimes dated relative to SystemTime::now()
    (fresh/stale by construction, no boundary to cross).
  • services::tests::window_advance_restores_budget (history window) sets the
    window start into the past; no assertion depends on elapsed time.

Mutation evidence

Each mutation was applied, the fs_list filter run, then reverted:

Mutation Caught by
refresh_fs_window_at never advances fs_list_window_reopens_after_the_accepted_window (elapsed window must restore capacity got E_FS_OVER_BOUND)
admit_fs_list_at returns Ok(()) without charging fs_list_empty_pages_still_charge_the_op_window, fs_list_window_reopens_after_the_accepted_window
FS_LIST_WINDOW shortened to 500 µs fs_list_window_reopens_after_the_accepted_window (usage must survive until the window elapses got Ok)

Verification

  • 40 concurrent runs of cargo nextest run -p bitty-runtime fs_list (4 workers
    x 10, CARGO_BUILD_JOBS=8): every run 23 tests run: 23 passed, zero
    failures.
  • cargo nextest run -p bitty-runtime: 2658 passed, 2 skipped.
  • cargo fmt --all -- --check: clean.
  • RUSTFLAGS="-D warnings" cargo clippy --workspace --all-targets --locked: clean.
  • RUSTFLAGS="-D warnings" cargo check --target x86_64-pc-windows-gnu --workspace --all-targets --locked: clean.

Priority: P1 | Area: runtime | Labels: bug,P1,area:runtime | Milestone: 0.0.24 | RFC: RFC-0005 | Task: CTX-1382

Closes #2305

Summary by CodeRabbit

  • Bug Fixes
    • Improved timeout boundary handling so expiration occurs precisely at the configured deadline.
    • Made filesystem rate-limit and debug-trace expiry behavior more consistent and deterministic.
  • Tests
    • Updated timing-related tests to use fixed timestamps, reducing reliance on delays and wall-clock progression.

The accepted `fs.list` window is one second and admission read the real
clock on every call, so the three rate-window tests — which exhaust the
window with ~1024 real listings — drifted across the boundary on a loaded
runner, cleared the usage mid-loop, and then failed with `Table([])` where
they expect `E_FS_OVER_BOUND`. That is the Windows failure on PR #2292.

- Thread an explicit window instant through `admit_fs_list_at` and
  `fs_list_at`; `HostServices::fs_list_with_expiry` passes `Instant::now()`
  at the same point as before, so accepted window semantics, caps, and the
  scan expiry are unchanged.
- All three window tests drive one frozen instant derived from the
  services' window start, so "exhausted denies", "usage survives inside the
  window", and "one full window later reopens" are exact; the reopen test
  no longer pokes `refresh_fs_window_at` directly.
- Audit of the `plugin_runtime` test modules also converted the sleep-based
  `debug_trace_expired_call_never_opens_a_trace` (instant 1 ms in the past)
  and the overlay `timeout_revokes_at_the_deadline` boundary (assert on
  both sides of an explicit deadline).

Left real-time on purpose: live process lifecycle tests in
`plugin_runtime::spawn`, the dedicated scan-deadline test in
`plugin_runtime::fs_list`, and future/past-dated `SystemTime` fixture
mtimes in `fs`/`resolution` (exact by construction, no boundary to cross).

Closes #2305
@Xuepoo Xuepoo added this to the 0.0.24 milestone Oct 20, 2026
@Xuepoo Xuepoo added bug Something isn't working P1 Priority: high area:runtime Area: runtime orchestration labels Oct 20, 2026
@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI (base), Organization UI (inherited)
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7dba7427-b4d1-4930-aa7b-eb3621e71587
📥 Commits

Reviewing files that changed from the base of the PR and between ab73f3a and b155706.

📒 Files selected for processing: 2
  • crates/bitty-runtime/src/plugin_runtime/overlay.rs
  • crates/bitty-runtime/src/plugin_runtime/services.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The filesystem listing path now accepts an explicit rate-window instant, while production calls continue to use the current time. Timing-sensitive filesystem and plugin runtime tests use fixed instants or explicit deadlines.

Changes: Plugin runtime timing

Layer / File(s) Summary
Explicit clock for filesystem listing
crates/bitty-runtime/src/plugin_runtime/services.rs
Filesystem listing admission and execution now use an explicit window instant. The production entry point supplies the current instant.
Deterministic filesystem rate-window tests
crates/bitty-runtime/src/plugin_runtime/services.rs
Filesystem listing tests use frozen timestamps and a generous scan deadline. The window tests check exhaustion and reopening without relying on wall-clock progression.
Explicit-time test assertions
crates/bitty-runtime/src/plugin_runtime/services.rs, crates/bitty-runtime/src/plugin_runtime/overlay.rs
The debug-trace expiry test uses a past instant. The overlay timeout test checks both sides of an explicit deadline.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to b1557

This change makes timing-sensitive filesystem listing tests deterministic and leaves production behavior unchanged. No actionable merge-blocking risk is identified.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 18 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: freezing the fs.list rate-window clock in runtime tests.
Linked Issues check Passed Issue #2305 requires deterministic fs.list rate-window tests, explicit clock flow, unchanged production behavior, and the related timing-test audit. services.rs adds admit_fs_list_at and `fs_lis…
Out of Scope Changes check Passed The reviewed changes are limited to Issue #2305. The fs.list clock seam, deterministic rate-window tests, fixture scan budget, debug-trace timing test, and overlay deadline test directly support the…
Full details: Linked Issues check

Explanation

Issue #2305 requires deterministic fs.list rate-window tests, explicit clock flow, unchanged production behavior, and the related timing-test audit. services.rs adds admit_fs_list_at and fs_list_at; production calls fs_list_at(..., Instant::now()). The three rate-window tests use one frozen instant, and the reopen test verifies in-window denial and post-window recovery without direct refresh calls. The debug-trace and overlay deadline tests now use explicit instants. The fixture scan budget supports the rate-window assertions without changing production limits.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to Issue #2305. The fs.list clock seam, deterministic rate-window tests, fixture scan budget, debug-trace timing test, and overlay deadline test directly support the issue or its specified audit. The diff does not demonstrate unrelated production behavior or unrelated test scope.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

`list_at` still passed the RC-1 50 ms scan budget as the expiry, so the
1024-call exhaustion loops could abort with `E_TIMEOUT` before the rate
window denied — the new CI failure in
`fs_list_tight_loop_hits_the_per_plugin_window` on PR #2306.

- Add the named `FIXTURE_SCAN_BUDGET` (60 s) and pass it as the scan expiry
  from `list_at`; window accounting stays frozen and exact.
- Convert the remaining fs.list tests in this module
  (`fs_list_serves_granted_entries_with_untrusted_shape`,
  `fs_list_without_backend_or_grant_fails_closed`) to the same fixture
  budget through `list_with_generous_budget`, so no fs.list test in the
  module races a wall clock any more.
- The tight-loop test keeps asserting `E_FS_OVER_BOUND` and that the byte
  charge denies before the op cap; removing the byte charge still fails it
  at call 1025.

Production budgets and window semantics are unchanged.
@Xuepoo
Xuepoo merged commit 37266fb into main Oct 20, 2026
18 checks passed
@Xuepoo
Xuepoo deleted the ctx-window/deflake branch October 20, 2026 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Area: runtime orchestration bug Something isn't working P1 Priority: high

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[0.0.24] fs.list rate-window test depends on wall clock

1 participant