Skip to content

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

Merged
thymikee merged 1 commit into
mainfrom
fix/upload-lease-beat-flake
Oct 29, 2026
Merged

thymikee merged 1 commit into
mainfrom
fix/upload-lease-beat-flake

Conversation

@thymikee

@thymikee thymikee commented Oct 29, 2026 •

Copy link
Copy Markdown
Member

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

View guided diff Turn on auto-fix

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.
@vercel

vercel Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
agent-device-website Ready Ready Preview Oct 29, 2026 12:05pm UTC

Request Review

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 1 file

View guided diff | Turn on auto-fix | Re-trigger cubic

@github-actions

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 5.58 MB 5.58 MB -8.9 kB
Package (unpacked) 5.58 MB 5.57 MB -8.9 kB
Package (download) 1.70 MB 1.69 MB -2.6 kB

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 31.5 ms 32.6 ms +1.1 ms
CLI --help 57.9 ms 61.3 ms +3.4 ms

@thymikee

Copy link
Copy Markdown
Member Author

The code looks good at 30da7f5. I did not run the test, the forced-buffer repro or the stress runs, and I did not read daemon-client-lease-beat.ts to confirm the client destroys the request on lease loss, so this rests on the PR body and reading the code. The unchanged assertion should catch a regression there. Smoke Tests is still running; the diff is one provider-integration test file and Smoke Tests does not import it, so the run should not affect this change. Not blocking, and fine to take or leave: the new comments on the end handler and answerBeat, plus the expanded releaseUpload doc in test/integration/provider-scenarios/remote-upload-lease-beat.test.ts (https://github.com/callstack/agent-device/blob/30da7f5/test/integration/provider-scenarios/remote-upload-lease-beat.test.ts#L176), are long and partly repeat the answerUpload comment, so two or three sentences each naming the invariant would do: after the loss beat only the client's destroy settles the outcome, and only a renewed lease releases the artifact.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Oct 29, 2026
@thymikee
thymikee merged commit 1f7ec35 into main Oct 29, 2026
18 checks passed
@thymikee
thymikee deleted the fix/upload-lease-beat-flake branch October 29, 2026 12:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant