Skip to content

test(link): hold large socket writes so pending-upload cases hold on Windows - #8627

Merged
lidge-jun merged 2 commits into
devfrom
fix/dev-red-link-held-socket-writes
Nov 13, 2026
Merged

lidge-jun merged 2 commits into
devfrom
fix/dev-red-link-held-socket-writes

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Nov 13, 2026 •

Copy link
Copy Markdown
Owner

Summary

The 14-shard Windows dev batch (run 43343080374, windows 8/14 and 10/14) failed five link tests from #8584 and #8594. They created a "pending upload" by writing a 48 MiB body to a Home that never reads it, assuming the write cannot complete. Bun completes a plain TCP write once the OS accepts it, and Windows can take a whole large nonblocking send into its socket buffer. On the Windows runners the write completed immediately: toHomeBytes read 50331648 instead of 0, cut uploads counted complete, and the zstd preparation allowance was released (0 instead of 30758256) before the Home read anything.

The product counts what its contract says ("bytes whose socket write completed"); the tests' platform assumption was wrong. This PR:

  • adds tests/helpers/held-socket-writes.ts, which holds completion of large node:net writes the way an undrained send buffer does on Linux/macOS (bytes still flow; the socket ending or closing fails the write), and uses it in the five cases, so they exercise a pending write on every OS;
  • makes the zstd case wait (bounded, 2 s) for the allowance release after cancel(). The relay's SSE cancel is fire-and-forget (void reader.cancel(...) in src/client/link-relay.ts), so release on the same tick was a Linux timing coincidence, not a promise;
  • states in src/link/traffic.ts, structure/remote-link.md and the Remote Link guide that a write completes when the OS accepts it, and that Windows can accept a whole large body at once (it did on CI). Winsock may also accept less, so this is described as possible, not guaranteed.

No runtime code changes; every original assertion is kept.

Verification

  • Windows reproduced on Linux with a scratch preload that makes Socket#_write complete on acceptance, as Windows does. Before the fix: bun test --preload <eager> tests/clients/link-traffic.test.ts tests/clients/link-request-zstd.test.ts gave 31 pass, 5 fail, the same five tests with the same values as CI (50331648; 30758256 vs 0). After: 36 pass, 0 fail.
  • Same two files without the preload: 36 pass, 0 fail.
  • bun run typecheck: exit 0. bun run structure:check: passed.
  • bun run test:changed (1580 files, because a helper changed): the only failures are in files that do not import the new helper, and they fail identically on unmodified dev on this host in isolation (e.g. tests/server/local-control-socket.test.ts 17 fail, tests/cli/cli-codex-cli-update.test.ts 16 fail). tests/storage/storage-mutation-race.test.ts failed under parallel load and passes alone (7/7).
  • NOT RUN: a real Windows runner (PR CI has no Windows shards; the maintainer's next dev batch covers it), and the full suite.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed.
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

…Windows

The link traffic and request-zstd tests made a write "pending" by sending a 48 MiB body
to a Home that never reads it. Bun completes a plain TCP write once the OS accepts it, and
Windows accepts a whole nonblocking send at once, so on the 14-shard Windows batch the
write completed immediately: toHomeBytes read 50331648 instead of 0, cut uploads counted
complete, and the preparation allowance was released before the Home read the body.

A test helper now holds the completion of large socket writes (bytes still flow; the
socket ending or closing fails the write), so these cases exercise a pending write on
every platform. The zstd case waits, bounded, for the release after cancel, since the
relay cancels its upstream without awaiting the teardown. The traffic contract docs now
say a write completes when the OS accepts it, which on Windows is the whole body.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 02:42
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T02:44:08.951237Z 0780b49 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Nov 13, 2026
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 4 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 10 included reviews currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0780b49 and ea635bd.

Files selected for processing: 4

  • docs-site/src/content/docs/guides/remote-link.md
  • src/link/traffic.ts
  • structure/remote-link.md
  • tests/helpers/held-socket-writes.ts

No actionable comments were generated in the recent review.

Walkthrough

The change documents platform-specific link upload accounting and updates client tests to hold large socket writes pending while checking upload and cancellation behavior.

Changes: Link traffic accounting

Layer / File(s) Summary
Document platform-specific upload accounting
src/link/traffic.ts, docs-site/src/content/docs/guides/remote-link.md, structure/remote-link.md
The traffic-counter descriptions distinguish Linux and macOS send-buffer behavior from Windows behavior. On Windows, the full request body is counted when the operating system accepts the write, even if the Home reads only part.
Hold large writes in client tests
tests/helpers/held-socket-writes.ts, tests/clients/link-traffic.test.ts, tests/clients/link-request-zstd.test.ts
A helper holds large socket writes pending and restores the original write method. Client tests use the helper, restore writes during cleanup, and wait for active body-budget leases after cancelling the response reader.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Merge Risk: Minimal · previous review 0780b

This change adds a test helper and clarifies documentation on Windows upload accounting. It does not alter production behavior, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: test helpers that hold large socket writes so pending-upload test cases behave consistently on Windows. The changeset adds tests/helpers/held-socket-writes.ts and uses…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Full details: Title check

Explanation

The title names the main change: test helpers that hold large socket writes so pending-upload test cases behave consistently on Windows. The changeset adds tests/helpers/held-socket-writes.ts and uses it in the link tests, which matches the title. The title is concise and specific, and it follows the type(scope) convention.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b059991 and 0780b49.

Files selected for processing: 6

  • docs-site/src/content/docs/guides/remote-link.md
  • src/link/traffic.ts
  • structure/remote-link.md
  • tests/clients/link-request-zstd.test.ts
  • tests/clients/link-traffic.test.ts
  • tests/helpers/held-socket-writes.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.

Winsock may accept less than a full nonblocking send; CI only showed it taking whole 48 MiB bodies. Reword the traffic contract, structure doc, guide and helper comment accordingly.
@lidge-jun

Copy link
Copy Markdown
Owner Author

Maintainer judgment (dev integration, MAINTAINERS.md maintainer-integration exception): merging without a second maintainer approval, as part of the DEV-RED repair for dev batch run 43343080374 (windows 10/14 and 8/14).

  • Exact head: ea635bd275b6d7043da10b7de14c8fe71141a083. Every required PR check on this head passed.
  • Fresh independent review on this exact head: VERDICT: PASS, no findings. An earlier round on 0780b49644 raised one minor wording finding (Winsock may accept less than a full send); it was accepted and fixed in this head. The reviewer's fresh runs: both test files 36 / 0 normally and under the Windows-like eager-write preload; typecheck, structure:check, privacy:scan, layout and ratchet guards exit 0.
  • Scope: test helper and tests, plus comment and doc wording. No executable production change.
  • No outstanding change requests.
  • Not yet verified on a native Windows runner; the maintainer's next dev batch covers it.

@lidge-jun
lidge-jun merged commit 00f0792 into dev Nov 13, 2026
30 of 33 checks passed
@lidge-jun
lidge-jun deleted the fix/dev-red-link-held-socket-writes branch November 13, 2026 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant