Skip to content

test(server): wait for the activity holds state, not for one file event, in the link WebSocket fingerprints test - #8675

Merged
lidge-jun merged 1 commit into
devfrom
test/link-websocket-fingerprints-wait
Nov 13, 2026
Merged

lidge-jun merged 1 commit into
devfrom
test/link-websocket-fingerprints-wait

Conversation

@lidge-jun

Copy link
Copy Markdown
Owner

Summary

tests/server/link-websocket-fingerprints.test.ts, in "through a real Home: a cut WebSocket turn and its HTTP resend", waited for the Home's link/activity-holds.json write with a helper that armed fs.watch on the link directory just before the action that writes the file, and resolved on the first event naming the file. On macOS (Bun 1.4.4) a watcher is armed asynchronously, so the write can come before the watcher sees anything: the test then timed out at 5 s at await held, the line after ws.destroy(), and teardown produced an unhandled ENOENT from a late read. An instrumented copy showed the file already held exactly the expected mark at the timeout: the Home had written the hold, and only the event was missed.

Measured on macOS (30 fresh-copy runs of the link WebSocket server test files together, each tree): 2 failures in 30 on the tree with #8647, and 2 in 30 on dev before #8647 (3762722), every failure in this case. The race has been in the test since #8593 at the same rate, and #8647 did not change it. It has not been seen on Linux CI. The macOS shards run in the lane=all release-evidence batch, so it can turn a release run red.

The fix changes only the test. One watcher on the link directory is armed right after the test writes links.json, before the Home starts, so it is armed several network round trips before the first holds write it has to see. Each wait is for a state, never for one event: until(condition) checks the condition (the fingerprinted mark count read from the holds file, treating a not-yet-written file as "not yet") when the wait starts and again on every event, so a write that lands before the wait begins is still seen. The second wait (after an HTTP resend answered 200, for the count to reach 0) uses the same helper; a resend refused with 400 leaves the mark and needs no wait. The watcher is closed before teardown removes the directory, so no event reads a removed file. No sleeps, polling loops or timers.

No product seam was reachable from this test: the Home is started with startServer(0), whose deps do not reach the link listener (the holds book's writeHooks and the lifecycle's activityHoldsSettled() are not exposed through it), and adding one would change the product. The other link WebSocket test files have no fs.watch waits. tests/server/link-websocket-upgrade.test.ts waits for holds with a short polling loop (waitForHolds), which cannot miss an event; it is left as it is.

Verification

Only macOS shows the failure, and I could not run macOS: the failure could not be reproduced here first, and the fix is verified on Linux only.

  • bun run typecheck: exit 0
  • bun run privacy:scan: exit 0
  • bun scripts/test.ts --parallel=2 over every link-websocket-*.test.ts file (tests/server: drain, fingerprints, gate, holds, pump, traffic, transport-status, upgrade; tests/e2e-style: release-gate, rss) and tests/responses/responses-websocket-workflow-ceiling.test.ts: exit 0 (156 pass, 9 skip, the release-gate cases that need the pinned codex-rs binary, 0 fail)
  • bun test tests/server/link-websocket-fingerprints.test.ts, 8 runs in a row: 29 pass, 0 fail each

NOT RUN: macOS (where the race occurs); the full bun run test suite.

Checklist

  • Test-only change; no product code changes
  • No new test files (no layout entries needed)

@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Caution

Review failed

The pull request is closed.

  • 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

@github-actions

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
@lidge-jun

Copy link
Copy Markdown
Owner Author

macOS result for this head, measured by the coordinator (Bun 1.4.4, the merge tree of 0d1c6bd with dev, tree 3e587d35ca): 30 fresh-copy runs of the nine tests/server/link-websocket-*.test.ts files plus tests/responses/responses-websocket-workflow-ceiling.test.ts, 30 pass and 0 fail, 155 tests each. The same procedure before the fix gave 28 pass and 2 fail on dev and on the tree with #8647. Thirty clean runs do not prove a rate of zero (a 7% failure rate would give thirty clean runs about one time in nine), so the fresh review's reasoning carries the rest: the wait checks its condition when it starts and on every event, in the same synchronous step that registers it, and the Home's holds write is synchronous in the test's own process.

Fresh final review of this head: APPROVE WITH NITS, no P0-P2. One P3 is taken into a follow-up: a wrong mark count now fails as a 5000 ms timeout at the wait instead of "expected 1, received 2"; waiting for the state to change and keeping the exact check restores the message.

@lidge-jun
lidge-jun marked this pull request as ready for review November 13, 2026 08:46
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 08:46
@lidge-jun
lidge-jun merged commit 1784934 into dev Nov 13, 2026
26 checks passed
@lidge-jun
lidge-jun deleted the test/link-websocket-fingerprints-wait branch November 13, 2026 08:46
@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-13T08:48:03.797858Z 0d1c6bd Draft marked ready
ℹ️ 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.

lidge-jun added a commit that referenced this pull request Nov 13, 2026
…-gate-evidence

The layout maps (layout.json, layout-clients.json, test-layout-expected.json) are the union of both sides, checked key by key. structure/remote-link.md keeps both sides: this branch's paragraph is dev's plus the U11, real-Child, restart and Autobahn sentences. The gate file keeps this branch's version, in which #8668's labels and binary copy live in tests/helpers/link-gate-codex.ts.
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