Skip to content

Make the scheduler delivery-bound assertion deterministic - #103

Open
RenKoya1 wants to merge 1 commit into
cloudflare:mainfrom
RenKoya1:fix/scheduler-concurrency-test-flake
Open

Make the scheduler delivery-bound assertion deterministic#103
RenKoya1 wants to merge 1 commit into
cloudflare:mainfrom
RenKoya1:fix/scheduler-concurrency-test-flake

Conversation

@RenKoya1

@RenKoya1 RenKoya1 commented Aug 9, 2026

Copy link
Copy Markdown

ScheduleDriver > bounds callback concurrency and immediately continues a due backlog asserts maxActiveCallbacks === DELIVERY_CONCURRENCY, but the observed peak is a function of timing rather than of the bound: each of the four runBounded lanes runs startHook -> authorizeObservation -> onSchedule over RPC, and the callback only holds for 10ms. When the lanes drift apart the peak lands below 4 even though the runner never exceeds it.

Reproducible on macOS/arm64 (M-series):

AssertionError: expected 3 to be 4 // Object.is equality
 ❯ __tests__/schedule-driver.test.ts:735:41

Rather than weaken the assertion to an upper bound — which would stop proving the bound is reached — this holds each callback until a full set of lanes has arrived, so the peak is the runner's bound and not RPC scheduling.

The batch of 20 delivers as exactly five full rounds of four, so the barrier waits on a count that is guaranteed to arrive and needs no timeout of its own; the tail round of one is excluded by the limit argument. The barrier is off by default, leaving every other test untouched.

Verification

Four consecutive runs of schedule-driver.test.ts, alternated on the same machine with nothing else running:

run 1 run 2 run 3 run 4
main fail fail pass fail
this branch pass pass pass pass

pnpm test for the package is 102 passed / 3 skipped, and pnpm types:check is clean.

Unrelated, and untouched here: permanently fences mutations and cleans revoked storage in bounded alarm passes occasionally exceeds the 5s vitest timeout under CPU contention (it showed up on main run 4 above, and on this branch too when the whole monorepo suite runs in parallel). That is a separate load sensitivity, not the assertion this PR is about.

@github-actions

github-actions Bot commented Aug 9, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@RenKoya1
RenKoya1 force-pushed the fix/scheduler-concurrency-test-flake branch from 107af8d to 5cd8ac3 Compare August 9, 2026 17:09
`maxActiveCallbacks` was asserted to equal DELIVERY_CONCURRENCY, but the
observed peak depends on how the four delivery lanes interleave: each
lane does startHook -> authorize -> callback over RPC, and the callback
only holds for 10ms. On a fast machine the lanes drift apart and the peak
lands at 2 or 3, failing the test (reproducible on macOS/arm64).

Hold the first five rounds of callbacks until a full set of lanes has
arrived, so the peak is the runner's bound rather than RPC timing. The
barrier waits on a count that is guaranteed to arrive, so it adds no
wall-clock assumption of its own, and the tail round of one is excluded.
@RenKoya1

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

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