## 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](https://claude.com/claude-code)
---------
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>