Skip to content

test(platform-cloudflare): stop test work outliving its test - #60

Merged
systemfsoftware-bot merged 1 commit into
mainfrom
fix-cloudflare-test-quiescence
Nov 26, 2026
Merged

systemfsoftware-bot merged 1 commit into
mainfrom
fix-cloudflare-test-quiescence

Conversation

@systemfsoftware-bot

@systemfsoftware-bot systemfsoftware-bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Three Cloudflare suites failed intermittently in one lane under CPU contention. The fix removes the causes; no timeout was raised and no test was skipped or weakened.

1. The eviction wait latched on a point-in-time gauge. progress-wait.test.ts "reconnects after eviction..." hit its 20 s cap at 20005 ms, with the eviction landing 0.4 s in and ~19.6 s of silence after it. The harness waited for the Object's live waiter count to equal one; a replayed awaitProgress request that registers and leaves between two observer calls is missed by such a gauge. The test worker now counts subscriptions monotonically per incarnation (incarnation + total, predicate latches), and the test waits for the count rather than the gauge. It also waits for the new incarnation to have served a subscription, which is what "the wait was reconstructed" means.

A probe measured the platform behaviour this relies on: after state.abort(), workerd re-runs the in-flight awaitProgress on the fresh incarnation (incarnation 1→2, that incarnation reports the waiter) and the client promise resolves when progress arrives. The client's retry classification never runs for an eviction, so the client needs no retry.

2. Tests left work running past their end. background-workers.test.ts passed all nine tests and then reported EnvironmentTeardownError: [vitest-worker]: Closing rpc while "resolve" was pending 38 ms later. A pool worker reuses one workerd instance across test files, so work a test leaves behind runs into the next file's environment. Every test in the affected files now ends with a quiescence barrier: disarm the eviction failpoints it armed, interrupt and await the client fibers it forked (tracked by the harness), and delete the persisted alarm of every Object it touched, so no alarm pass starts while the environment closes. Each barrier step is bounded so a wedged Object cannot stall the shared environment. progress-wait and background-workers keep their per-test caps, which the fixed tests meet with ample headroom.

3. A per-test cap sat below the work's legitimate cost. join-restart.test.ts hit its 10 s cap twice; each of its five scenarios runs about 135 sequential SQLite operations plus a cold reconstruction, and the cap applied per test. That cap and four inner Effect.timeout('2 seconds') guards on Deferred waits are removed; the suite's configured timeout is the budget.

Rejected alternatives

  • Raise the caps: the 20 s failure was a stall, not slow work, and join-restart's clean run is ~3.3 s per scenario, so a cap only decides how much contention converts into failure.
  • Retry or skip: the tests still assert the same durable behaviour.
  • Poll the Object with a fixed sleep: it measures the clock and buys nothing the Object can signal.

Verification

  • pnpm --filter @systemfsoftware/agent-platform-cloudflare run test: 35 files, 187 passed, 6 skipped.
  • pnpm typecheck, pnpm lint (0 warnings, 0 errors) and pnpm format:check pass.
  • test/progress-wait.test.ts, test/join-restart.test.ts and test/background-workers.test.ts together: 17 passed.

Test-only change; the changeset is none. A learning record accompanies it in docs/solutions/test-failures/.

Three Cloudflare suites failed intermittently in one CI lane under CPU
contention:

- the eviction progress-wait test hit its 20 s cap after a 19.6 s stall
  that began when it aborted the Object mid-wait;
- background-workers passed every test and then reported a pending
  vitest module-resolution RPC while the environment was closing;
- join-restart hit its 10 s cap twice, its five scenarios each running
  about 135 sequential SQLite operations.

The waiter-count latch was a point-in-time gauge: a replayed awaitProgress
request that registered and left between two observer calls was missed.
It becomes a monotonic per-incarnation subscription counter, and the test
latches on the count instead of the gauge. A probe confirmed the platform
re-runs an in-flight awaitProgress on the fresh incarnation after
state.abort() and resolves the client promise when progress arrives, so
the client needs no retry.

Client fibers are now tracked by the harness, and each test ends with a
quiescence barrier: disarm the eviction failpoints it armed, interrupt and
await its fibers, and delete the persisted alarm of every Object it
touched. Every barrier step is bounded so a wedged Object cannot stall the
shared environment.

The join test's 10 s per-test cap and its four inner two-second
Effect.timeout guards are removed; that work legitimately sits within a
small factor of the cap under contention, and the suite's configured
timeout is the budget. The other suites keep their caps, which the fixed
tests meet with ample headroom.
@systemfsoftware-bot systemfsoftware-bot changed the title probe test(platform-cloudflare): stop test work outliving its test Nov 26, 2026
@systemfsoftware-bot

Copy link
Copy Markdown
Contributor Author

Lead review on 4563fc4: test-only change. Waits follow real signals, and a bounded per-test quiescence barrier disarms eviction failpoints, ends client fibers and clears alarms before workerd teardown. The progress-wait and background-workers caps are restored; join-restart drops its inner wall-clock waits. Every check on the head passed on the first attempt, including both cloudflare shards and both postgres shards. Four review rounds ended with no open P0/P1.

@systemfsoftware-bot
systemfsoftware-bot merged commit 9117a27 into main Nov 26, 2026
14 of 15 checks passed
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