Skip to content

test(daemon): make the upload deadline tests deterministic under load - #4813

Merged
thymikee merged 3 commits into
mainfrom
fix/upload-deadline-test-determinism
Nov 20, 2026
Merged

thymikee merged 3 commits into
mainfrom
fix/upload-deadline-test-determinism

Conversation

@thymikee

@thymikee thymikee commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Summary

Some upload deadline tests failed in the Coverage job on unrelated PRs (#4722 job 136185562286, #4724 job 136241335534). The cause was in the tests. They waited for the server by counting event-loop turns, or they moved the fake clock before the server had reached the state the case depends on. Under Coverage the server's filesystem completions run late. The product code did not change. No failure showed the server resetting an earlier answer.

Root cause per test (upload-http-deadline.test.ts):

  • "an expired queued request with an unread body never resets the earlier answer", and also "a queued 308 behind a long finalize …": the test advanced the clock 150 s after flushIO() and assumed B's 308 was already committed. When B's offset stat ran late, B's inactivity ceiling fired first, so B answered a typed 500. That is correct product behavior. The test now waits for the server to end B's response before it moves the clock.
  • "guard: a single-shot upload expiring behind a long finalize …": after the hash was released, a bounded loop (50 × flushIO) waited for two responses. It did not throw when it gave up, so a late rename produced []. The test now waits for B's admission and for B's committed answer, then for two complete responses parsed from the socket.
  • "a chunk refused by its byte cap …": the same bounded loop waited for the 400, and the server-close check used flushIO with getConnections. The test now waits for the parsed response, for the server FIN, and for the server-side connection close.
  • Same pattern, found under CPU load (2 of 60 runs): "a single-shot upload that expires mid-body …" moved the clock 61 s per step without checking that the server had accepted the bytes. The clock then fired the inactivity ceiling and later the 5 s grace. The test now waits for the accepted bytes before each step. The reason assertion is back to the strict transfer_ingress_deadline_exceeded.
  • The oversized-JSON tests and the held-hook waits in upload-http-socket-ownership.test.ts had the same turn counting. They now wait on the parsed response, the FIN, the connection close, the hook's own call, and the signal's abort event.

The new upload-loopback.fixtures.ts holds the shared event helpers: watchServer (the server's own request/response hooks and connection close), readResponses (complete HTTP responses, FIN and errors from a raw socket), and watchAcceptedArtifactBytes. No assertion is weaker, and there are no retries or new sleeps.

Validation

Head 32677009f7. pnpm check:affected --run passed with exactCommit=true (format, lint, typecheck, layering, fallow, vitest-related).

Reproduction: a probe that is not committed (NODE_OPTIONS=--import slow-io.mjs) adds a real-time delay after fs.promises completions. It reproduces each CI failure with the same assertion:

Probe (10 runs each) before (main) after
stat/rename/truncate/rm +25 ms: both queued-308 tests 10/10 fail 0/10
rename +1500 ms: guard test 10/10 fail 0/10
stat/rename/truncate/rm +600 ms: byte-cap test 10/10 fail 0/10
CPU load, coverage, 12 parallel runs + 24 busy loops 2/60 fail (single-shot mid-body) 0/200 (10 parallel + 16 busy loops)
200 sequential runs under the coverage config (final head) — 0/200

The CPU-load runs had a low base rate: a second 100-run batch on main passed 100/100. That is why the probe is the reliable reproduction.


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

View guided diff Turn on auto-fix

The pipelined and lingering-close cases waited for the server by counting event-loop
turns (flushIO, bounded polling loops) or moved the fake clock before the server had
committed the state the case depends on. Under Coverage instrumentation the server's
filesystem completions run late, so a queued 308 was not yet committed when the clock
expired its request, and the polling loops gave up before the answers arrived.

The cases now wait on explicit events: the server's own request and response hooks
(watchServer), complete HTTP responses parsed from the raw socket and the server FIN
(readResponses), the server connection close, the auth hook's own call, and the bytes
the single-shot upload accepted before each clock step. No production change.
@thymikee

Copy link
Copy Markdown
Member Author

Merged main at 22d36bc to resolve the conflict. The new head is ef17a4244f.

#4800 on main fixed two of the same tests in upload-http-deadline.test.ts with a receivedText helper. In both conflicting tests I kept this PR's version, which waits on the parsed responses from the shared fixture, and removed the receivedText helper because nothing else uses it. The three upload test files pass (25 tests, 3 runs in a row), and typecheck and lint are clean. I did not rerun check:affected or the 200-run loop after the merge; hosted CI validates this head.

@github-actions

github-actions Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.45 MB 6.45 MB 0 B
Package (unpacked) 6.45 MB 6.45 MB 0 B
Package (download) 1.97 MB 1.97 MB -11 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 20.2 ms 20.3 ms +0.1 ms
CLI --help 46.8 ms 44.3 ms -2.5 ms

@thymikee

Copy link
Copy Markdown
Member Author

Coverage failed at ef17a4244f on test/integration/provider-scenarios/ios-wait-selector.test.ts (expected wait_target_absent, received wait_deadline_exceeded). That is not from this PR. #4794 made a late wait capture a timeout, and the poll then reported wait_deadline_exceeded under load. #4814 fixes that verdict. I reran the failed job.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Apex Sentinel: 1 new finding on ef17a42. The verdict and the full list are in the summary comment.

@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of c1cd641

Since the review of ef17a42: 0 new · 0 still open · 1 no longer raised (1 marked fixed)

No open findings.

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (c98eee1ed162).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

This PR is ready at c1cd641. The review found no problems in the code, all checks pass, and there are no conflicts.

Not blocking, take or leave each:

  • seen in watchServer is never read, so it and the list parameter of notify() can go.
  • The await flushIO() after releaseWrite at upload-http-deadline.test.ts:162 still stands in for "the rollback finished" before the real-timer retry. If upload admission does not serialize the retry behind the held handler, waiting on the rollback's own completion would be safer under Coverage.
  • The mid-body test calls watchServer(server) inside its 5-attempt loop at line 758, which stacks listeners on each attempt. Creating the watcher once before the loop, like the other tests, would be cleaner.

The earlier inline thread about reporting a reset or early close instead of waiting 3 s is fixed at this head and can be resolved: #4813 (comment)

Not verified here: the tests and the slow-IO probe were not run, so the before/after flake rates are the author's. That the tests still catch regressions was judged by reading the upload ingress dispose, fail and end paths, not by a mutation run. Whether admission serializes the retry at line 162 was not traced.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 20, 2026
@thymikee
thymikee merged commit e4c5491 into main Nov 20, 2026
18 checks passed
@thymikee
thymikee deleted the fix/upload-deadline-test-determinism branch November 20, 2026 15:13
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