Skip to content

test(link): report the Child's HTTP relay waiting for its reader to a test-only observer - #8680

Merged
lidge-jun merged 5 commits into
devfrom
test/link-child-relay-wait-observer
Nov 13, 2026
Merged

lidge-jun merged 5 commits into
devfrom
test/link-child-relay-wait-observer

Conversation

@lidge-jun

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

Copy link
Copy Markdown
Owner

Summary

The Child's memory acceptance (design 6.3) compares the Child's memory while its readers stall on the WebSocket and on HTTP. The Home already tells a test when each relayed HTTP response is waiting for its reader (setLinkRelayWaitObserverForTests, #8600), so a load can wait until every reader has stalled before it reads the peak. The Child's HTTP relay (src/client/link-relay.ts) had no such signal, so the HTTP half of the Child's acceptance could not tell when its stall had begun.

This adds the Child-side counterpart. src/client/link-websocket-limits.ts gains setLinkChildRelayWaitObserverForTests(observer) and linkChildRelayWaitObserver(). Only while a test has set an observer, relayLinkDataRequest passes each relayed response body (SSE and ordinary bodies alike) through a pass-through stream with a high-water mark of 0, so it reads only when its reader does. The observer is told true after a chunk is handed to the reader, and false when the reader asks for the next chunk, cancels, or when the relay itself ends. The relay's own cleanup (the Home's body finished or failed, a caller abort, the 300-second SSE idle limit) tells false at once and suppresses every later true, so a relay that has ended is never counted as waiting. An observer that throws is ignored. structure/remote-link.md describes the Child's signal next to the Home's.

The signal follows the relay's lifetime, as the Home's does. The relay streams underneath read one chunk ahead, so when the Home's body finishes, the relay can end (and report false) while the reader still holds the last chunk; the relay holds nothing at that point. A Home failure that the relay has not read yet (its read-ahead chunk queued, nothing reading the Home) keeps it reported as waiting, because the relay still holds that chunk and its request until its next read, a caller abort or (for SSE) the idle limit ends it.

What keeps it inert

No production code sets the observer, and it starts as null. With no observer, relayLinkDataRequest passes the same cleanup function and returns the same response body stream as before; the only added work is one null check per relayed response. No HTTP behaviour, byte counting, header, limit or cleanup path changes.

Tests

tests/clients/link-relay-wait-observer.test.ts (new) relays through relayLinkDataRequest with a stand-in fetch, an injected manual clock for the SSE idle limit, and a recorder whose nextFalse() settles on the first false after it is called. It never waits on a sleep, a real timer or polling; the relay's own 300-second header-deadline and SSE idle timers are armed on its default clock in seven of the eight cases and cleared before each case ends. It checks:

  • JSON and SSE: the test sends each chunk and the end itself and sees exactly [true], then [true, false, true], then [true, false, true, false] once the Home's body ends, with nothing more after the final read
  • a reader's cancel ends the wait
  • a caller abort while the reader holds a chunk ends the wait (JSON and SSE), and nothing afterwards reports a wait again
  • the SSE idle limit firing while the reader holds a chunk ends the wait
  • a throwing observer still yields the whole body; no observer is set by default

Failed first: with the two exports in place and link-relay.ts unchanged, the original cases that expect events failed with expected [true], received [] (no events at all); the default case and the throwing-observer case pass without the change. Against the first version of the wrapper, which ended a wait only when the reader asked again, the stalled-reader cases (caller abort for JSON and SSE, the SSE idle limit) and the two step-by-step cases failed by the runner's timeout while waiting for the false that marks the relay's end. With the fix, all 8 pass.

Verification

  • bun run typecheck: exit 0
  • bun run privacy:scan: exit 0
  • bun run structure:check: exit 0
  • TMPDIR=/tmp bun scripts/test.ts --parallel=2 over link-relay-wait-observer, client-link-relay, link-relay-bound-transport, client-link-tunnel, link-peer-compatibility, link-request-zstd, link-route-proof-relay, link-traffic, client-home-unreachable and link-boundary (all under tests/clients/), plus tests/test-layout.test.ts, tests/test-layout-tooling.test.ts, tests/ci-workflows/file-size-ratchet.test.ts, structure-ssot.test.ts and import-cycle-ratchet.test.ts: exit 0, 289 pass, 1 skip (macOS only), 0 fail

NOT RUN: the full suite (resource limits on the build machine; test changed and CI cover the rest), macOS and Windows.

Checklist

  • Test-first: the new cases failed on the base for the stated reasons
  • The new test file is registered in scripts/test-layout/layout-clients.json and tests/fixtures/test-layout-expected.json
  • structure/remote-link.md updated for the owned area
  • Inert by default: nothing in production sets the observer

@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
lidge-jun marked this pull request as ready for review November 13, 2026 09:39
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner November 13, 2026 09:39
@lidge-jun
lidge-jun merged commit 23a7e18 into dev Nov 13, 2026
36 checks passed
@lidge-jun
lidge-jun deleted the test/link-child-relay-wait-observer branch November 13, 2026 09:39
@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-13T09:41:52.809150Z 13c52bb 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.

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