The lease-lost scenario's fake daemon reported the upload 'drained'
instead of 'canceled' when the runner's socket buffers held the whole
artifact: req.pause() stops JavaScript from reading, not the kernel
from accepting, so resuming after the lease-loss beat replays the
buffered body and its queued 'end' is dispatched before the client's
already-in-flight destroy. A beat in 'lost' mode also released the
valve, which on such a runner could land the entire body before the
loss was ever declared.
Refuse an 'end' delivered after the loss was declared — only the
destroy settles that artifact — and let only a renewed lease release
the withheld upload. The client is unchanged: it already aborts the
upload signal synchronously when a beat reports the lease gone.
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) withExpected: "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 reportdrainedafter the lease-loss beat:releaseUpload()'sresume()replays the buffered body, and the queuedendis dispatched before the client's already-in-flight socket destroy.lostmode, beat 1 (a renewed beat) calledreleaseWithheldUpload(), 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.tsreportTerminalBeatFailure) andnode:httpdestroys the request; bytes already in kernel buffers cannot be unsent. The fix makes the fake deterministic without sleeps or timeouts: anenddelivered 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
9bcc02158b, head30da7f50a8.Received: "drained"), head passes 10/10.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.🤖 Generated with Claude Code