fix(test): keep a lost-lease upload from draining out of socket buffers

Merged
TH
1mo ago
+18-2

Summary

Fixes the load-dependent flake in test/integration/provider-scenarios/remote-upload-lease-beat.test.ts ("a lease lost mid-upload aborts the upload and no install request goes out"), which failed in CI (run 40856845842, job 123389835057) with Expected: "canceled" Received: "drained" on a PR that touched no upload or lease code.

Root cause is the test's fake daemon, not the client. req.pause() stops JavaScript from reading, not the kernel from accepting: on a runner whose TCP buffers cover the 4MB artifact, the whole body sits in socket buffers. Two orderings then let the fake report drained after the lease-loss beat:

  1. releaseUpload()'s resume() replays the buffered body, and the queued end is dispatched before the client's already-in-flight socket destroy.
  2. In lost mode, beat 1 (a renewed beat) called releaseWithheldUpload(), reopening the valve before the loss was ever declared.

The client is correct: a lease-loss beat synchronously aborts the upload signal (daemon-client-lease-beat.ts reportTerminalBeatFailure) and node:http destroys the request; bytes already in kernel buffers cannot be unsent. The fix makes the fake deterministic without sleeps or timeouts: an end delivered after the loss was declared is refused as a completion (only the destroy is an observation), and only a renewed lease releases the withheld artifact. The assertion is unchanged. Touched file: 1 (test-only).

Validation

  • Base 9bcc02158b, head 30da7f50a8.
  • Repro (forced interleaving: artifact sized to sit wholly in kernel buffers, the CI condition): base fails 10/10 with the exact CI assertion (Received: "drained"), head passes 10/10.
  • Head, unmodified artifact: all 3 tests in the file pass 10/10 repeats at idle and 4 concurrent runs x 5 repeats under 12 CPU stressors (20/20, 0 failures).
  • pnpm check:affected --run --head 30da7f50a8d62a5e7b52bda213a8f31fa77af42b: passed, exactCommit=true (receipt .tmp/validation/run-S4XVLS/receipt.json). Selected 12 checks; runnable checks (format, lint, typecheck, fallow, vitest-related) all exit 0; broad lanes are GitHub-authoritative skips.
  • CI obligations: the provider-integration and coverage jobs at the PR head.

šŸ¤– Generated with Claude Code