Skip to content

[AI-3874] Fix flaky daytona refusal-size test - #2465

Merged
kanat merged 3 commits into
mainfrom
kanat/ai-3874-daytona-refusal-flake
Nov 25, 2026
Merged

kanat merged 3 commits into
mainfrom
kanat/ai-3874-daytona-refusal-flake

Conversation

@kanat

@kanat kanat commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

Why

TestDaytonaSuite/TestAnUploadsRefusalFarTooLargeIsNotReadWhole failed on CI with "44634104" is not less than "41943040" (run 45633422983, #2434). The ticket guessed process memory or GC. It is not: the test never measures the heap. It bounds the bytes the fake Daytona server wrote (counted, daytona_test.go:218-220), and that number is the bytes the router read plus whatever the kernel's socket buffers took before the router closed the connection. The buffer part is the host's setting (tcp_rmem / tcp_wmem maxima), not the router's behaviour.

server writes 200 MiB ──► send buffer ──► receive buffer ──► router reads 21 MiB, stops, closes
        old assertion: sent < 40 MiB      \_ host-dependent _/   (capped, bounded.go:65)
        new assertion: router read in (20 MiB, 40 MiB)       ◄── counted under the router's bound

The same flaw sits in the two sibling tests (TestAFileFarTooLargeIsRefusedWithoutBeingReadWhole, TestADownloadsErrorFarTooLargeIsNotReadWhole), so all three are fixed here. No production change: the router reads at most MaxFileBytes + downloadSlack + 1 bytes (bounded.go:54, :65) in every run.

Changes

  • tallied / tally: a transport under the router's bounded wrapper that counts the bytes read from the bodies of one path. The three tests build their box through tallyingBox and assert on that count (requireReadUpToTheLimit): more than MaxFileBytes (a counter that sees nothing fails) and less than 2*MaxFileBytes (the old bound, same meaning).
  • The wait for the server's handler to end is removed from the three tests (it only made the server-side count final). TestARefusedDownloadHasEndedBeforeTheNextFileIsAskedFor still checks that the router closes the refused connection.

Validation

Base reproduction: macOS, 1.3k runs (-count=50, -race, 16 parallel processes), no failure; Linux arm64 in Docker with the default buffers (tcp_rmem max 6 MiB, tcp_wmem max 4 MiB), 600 runs, no failure, server-side count up to 32.5M. With both maxima set to 32 MiB (docker run --sysctl), 3 processes x 50 runs x 3 tests:

failures
base 25 of 450 (all three tests, e.g. "44641350" is not less than "41943040")
this PR 0 of 450

On the PR: -count=50 plain and -race green; 16 processes x 25 -race runs green; whole daytona package green.

Mutants (script and log in the author notes), each run against the three tests:

mutant result
upload answer not capped (bounded.go case) TestAnUploadsRefusal... fails, read 209715200
download answer not capped TestADownloadsError... fails
downloadSlack raised to 1 GiB both fail
capped.Read unclipped and never fails both fail
download LimitReader and cap both removed the file and error-part tests fail
counter sees no request / counts nothing all three fail ("0" is not greater than "20971520")

Survivors, by design: unclipped capped.Read alone (the error still comes after at most one buffer, under the 2x bound); capped.Close returning nil (the request context's cancel closes the connection anyway, daytona.go:420-421); deleting either assertion line (the mutants above fail on exactly those lines).

🤖 Generated with Claude Code

The three oversize-answer tests bounded the bytes the fake server wrote, which includes what
the host's socket buffers took before the router closed the connection. Count what the router
read from the answer instead.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: GO

Reviewed 3bc019a merged onto main b36d78e. CI: draft, go and integration skipping; they run at gh pr ready.

Nit R1.1: the body says "The wait for the server's handler to end stays, with a deadline". The diff removes that Eventually from all three tests. Correct the sentence. The router closing the connection is still checked by TestARefusedDownloadHasEndedBeforeTheNextFileIsAskedFor, and no mutant tells the dropped wait from nothing (capped.Close returning nil survives on base too, because Run's deferred cancel closes the connection).

Nit R1.2: daytona_test.go:218-220 (unchanged lines): the upload refusal's counted wrapper and p.served["upload"] are now read by nobody, since the only sent("upload") reader was removed; the comment at line 54 still describes it. Dead after this PR; delete it or leave it.

Checked and sound:

  • Root cause reproduced: Linux arm64 container, 3 processes x 50 runs x 3 tests, tcp_rmem/tcp_wmem max 32 MiB. Base 105 failures ("45821248" is not less than "41943040"), head 0. Base with default buffers 0 (control).
  • Mutants: all the author's reproduce. Own mutants: cap lowered to 1 MiB fails on head ("1048577" is not greater than "20971520") and passes on the base tests, so the new lower bound adds coverage. Close draining the rest, slack past 2x and a half-counted cap fail on head and base alike; slack inside 2x and Close returning nil survive on both. No mutant the base killed survives on head.
  • The upper bound keeps its meaning (the router read past the limit) and loses only the host-dependent part. No sleeps or new time dependence; the counter is atomic; whole package, -race -count=20 on the three tests, vet and gofmt are clean on the merged tree.

@kanat

kanat commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator Author

Round 1 nits, both fixed (head 07755ff):

  • R1.1, PR body: the sentence now says the wait for the server's handler was removed from the three tests and that TestARefusedDownloadHasEndedBeforeTheNextFileIsAskedFor still checks that the router closes the refused connection.
  • R1.2, Fixed in 760d4e4: the unread counted wrapper and served["upload"] write in the upload refusal are deleted, with the comment clause that described them. No test: a deletion with no behaviour change. go test -race -count=10 on the three FarTooLarge tests passes.

@kanat kanat left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

VERDICT: GO

[reviewer delta R1] PR #2465, head 07755ff (previous reviewed head 3bc019a; merged onto origin/main 4a6dd11)

Prior findings

  • R1.1 (Nit, PR body sentence about the removed wait): fixed. The body now says the wait is removed from the three tests. At 07755ff those tests contain no Eventually (the old head already removed the three waits; main still has them at daytona_test.go:844, 863, 881).
  • R1.2 (Nit, dead upload counter): fixed in 760d4e4. grep -rn 'served\[\|"upload"' acceleration/internal/sandbox/daytona/ shows no reader of served["upload"]; the upload refusal now writes through io.Copy(w, ...) (daytona_test.go:218). counted is still used by the download path (daytona_test.go:305-309, :365).

Delta

  • The PR's own diff of daytona_test.go against main changed since 3bc019a only by the deletion: the upload-refusal counter lines (main's code, not this PR's) and the comment that described them. The merge of main has no conflict resolution (git show --remerge-diff 07755ff23 is empty) and main has not touched the file since 15ce5c.

Checks (07755ff merged with origin/main 4a6dd11)

  • gofmt -l on the package: clean. go vet ./internal/sandbox/...: exit 0.
  • go test -count=3 ./internal/sandbox/daytona/: ok.
  • go test -race -count=10 -run 'TestDaytonaSuite/FarTooLarge': 30 of 30 PASS, no data race.
  • Mutants on the merged tree, the three FarTooLarge tests each time:
    • T1, the counter sees no request: all three fail ("0" is not greater than "20971520").
    • T2, the counter counts nothing: all three fail.
    • M1, upload answer not capped in bounded.go: TestAnUploadsRefusalFarTooLargeIsNotReadWhole fails ("209715200" is not less than "41943040").
    • 3 checked, 0 survived. Each file was restored after its run.

New findings

None.

Not run

  • CI: the PR is a draft, so go and integration are skipped (#2130). Analyze is pending and was not waited on.
  • Packages other than sandbox/daytona were not run; the delta does not touch them.

@kanat
kanat marked this pull request as ready for review November 25, 2026 15:14
@kanat
kanat merged commit c2a4067 into main Nov 25, 2026
15 checks passed
@kanat
kanat deleted the kanat/ai-3874-daytona-refusal-flake branch November 25, 2026 20:20
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.

1 participant