Skip to content

test(cli): the upload cut test stops failing on busy Windows runners - #7843

Merged
miguel-heygen merged 2 commits into
mainfrom
fix/cli-upload-cut-test-slow-first-try
Nov 15, 2026
Merged

miguel-heygen merged 2 commits into
mainfrom
fix/cli-upload-cut-test-slow-first-try

Conversation

@miguel-heygen

@miguel-heygen miguel-heygen commented Nov 15, 2026 •

Copy link
Copy Markdown
Collaborator

What

The upload.test.ts test "stops after a second identical cut" no longer fails on busy Windows runners. Its test server now drops the connection 1,600 ms after it starts reading, not 400 ms. The test also covers the case that broke it: a first try that is slow to start.

Why

It was the most frequent failure in recent red Windows runs. It failed the engine-cli-1 lane with expected 3 to be 2 (three tries where two are expected), and that knocks PRs out of the merge queue.

The upload counts two cuts as the same cut when their ages are within 20% of each other (isSameCut in uploadPut.ts). The client measures a try's age from before it connects; the test server measures the cut from when it starts reading. I logged both, 40 loops on a windows-latest runner, half of them with 4 CPU-burning jobs:

  • the first try's age ran past the server's cut by 13 to 19 ms when quiet and 41 to 53 ms under load, the second try's by about 5 ms
  • the server's own drop came anywhere from 400 to 431 ms
  • the gap between the two ages reached 65 ms, against a tolerance of 85 to 95 ms at a 400 ms cut

The real lane runs the engine and CLI suites at once, so the gap goes over and a third try follows. The upload code is right: a real link's cut comes seconds in, where tens of ms of setup are noise. The test left itself no room.

Related work

None. uploadParts.test.ts's cut tests cut at 1,200 ms and are not in the Windows failures.

How

  • CUT_MS = 1600, used by the drain fixture, gives about 380 ms of tolerance. The fixture's per-chunk wait caps the 16 MB body at 8 MB/s, so it takes at least 2 s and the cut still comes before the end.
  • Why not 1,200 ms, as uploadParts uses: I tried that first. Across 30 loops on windows-latest, 20 of them with 8 CPU-burning jobs, it passed every time, but the closest loop had only 7 ms to spare. The first try's extra delay reached 145 ms on top of the 150 ms the test adds on purpose.
  • A new "late cut" plan answer waits 150 ms before it starts reading, so the first try is slow to start the same way it was on the runner. The test's plan is ["late cut", "cut"].
  • The test gets a 15 s timeout: two 1.6 s tries plus setup can pass vitest's 5 s default on a busy runner.
  • No product code changes.

Test plan

  • Unit tests updated: packages/cli/src/cloud/upload.test.ts
  • fails without the fix: with ["late cut", "cut"] and the old 400 ms cut, the test fails 3 runs of 3 on Linux with expected 3 to be 2, the same assertion as on the Windows runner. At 1,600 ms it passes.
  • The whole upload.test.ts passes 20 of 20 tests, 3 runs in a row; uploadParts.test.ts passes 9 of 9.
  • oxfmt and oxlint are clean.
  • Windows at 1,600 ms: 40 loops on windows-latest, 30 of them with 8 CPU burners. All 40 passed with exactly 2 tries. Under load the first try's extra delay reached 168 ms, and the closest loop still had 69 ms to spare (175 ms when quiet). That is with the test's own 150 ms delay included.

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed at d5921bc03d023b58882a8deafb060a123275f5f8.

No blocker found. This changes the simulated cut timing, not the production tolerance or retry policy. At the longer cut age, the deliberate 150 ms first-attempt delay fits the existing 20% comparison window; the 16 MiB throttled body is still cut mid-transfer. The assertion still requires the repeated-cut message and exactly two requests. The larger test timeout only accommodates the longer fixture.

Validation: full build and 29 upload/uploadParts tests pass. Restoring only the 400 ms cut makes the delayed-start test fail with expected 3 to be 2. Disabling the production repeated-cut guard makes the same test fail with the four-attempt exhaustion error. Thus it still detects a real behavior regression.

Nit: this increases timing headroom rather than making the test deterministic. Extreme scheduling delay can still exceed the relative tolerance. I did not verify a Windows load loop; the Windows engine-cli job was still pending when checked.

Need: yes · Size: ok · Reuse: existing real-socket fixture and production cut comparison · Simpler: already minimal · Structure: fine (checked uploadPut and multipart timing fixtures; no split)
Risk: low — test-only change.

Verdict: APPROVE
Reasoning: The fixture better represents the intended timing relationship and retains a mutation-verified behavioral assertion.

— Rames

@jrusso1020 jrusso1020 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approve. Re-reviewed at ce16f29d9dfe0d1528918d12c6bb833ae5ea388a. The only change since the last approval (d5921bc0) is CUT_MS going from 1200 to 1600, plus its comment. No source change.

The test still fails when upload-cut handling regresses. I ran it at this head with mutations to uploadPut.ts:

  • Head: passes three runs in a row, and the whole upload.test.ts file passes (20/20).
  • repeatedCut always undefined (the second identical cut no longer stops the upload): fails.
  • isSameCut tolerance 0.2 down to 0.05: fails.
  • Tolerance 0.2 down to 0.1: passes. That's expected, since 150 ms over about 1750 ms is about 8.6%. At 1200 ms the 150 ms late start was about 11% of the cut age, so that mutation would have failed. The slow-start leg now catches a tolerance tightened below about 8.6% instead of about 11%. Non-blocking: that is still far from 20%, and the test's job is the stop itself.

It doesn't hide a real problem either. The drain sleeps ceil(len/8192) ms per chunk, so the 16 MB body needs at least 2 s, and a slower runner only makes that longer. A 1.6 s cut, or 1.75 s for the late try, always lands first, so both tries are real cuts with bytes sent.

— Rames

@miguel-heygen
miguel-heygen added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit 2ea78c0 Nov 15, 2026
163 of 164 checks passed
@miguel-heygen
miguel-heygen deleted the fix/cli-upload-cut-test-slow-first-try branch November 15, 2026 14:32
wangzheuser pushed a commit to wangzheuser/hyperframes that referenced this pull request Nov 15, 2026
* chore: release v0.9.53

* chore: release v0.9.53 notes include heygen-com#7836 and heygen-com#7839

* chore: release v0.9.53 notes include heygen-com#7840 and heygen-com#7843
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.

2 participants