Skip to content

test(net): count only the client's yield as a datagram end's routing - #9238

Merged
kixelated merged 2 commits into
mainfrom
quest/m0/flaky/a-session-close-right-after-a-datagram-tracks-end-keeps-the-2
Nov 21, 2026
Merged

kixelated merged 2 commits into
mainfrom
quest/m0/flaky/a-session-close-right-after-a-datagram-tracks-end-keeps-the-2

Conversation

@kixelated

@kixelated kixelated commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the flaky @moq/net test moq-lite-06: a session close right after a datagram track's end keeps the end at its root cause and removes its skip. Finishes quest/m0/flaky/a-session-close-right-after-a-datagram-tracks-end-keeps-the-2.md and deletes the now-empty quest/m0/flaky epic (the land watcher recreates it for the next disabled test).

Root cause

The test aborts the client while its subscriber waits a host task to route the datagrams that arrived with the track's end. To find that moment it spied on clock.yieldNow and aborted at the first call anywhere in the process after datagrams.finish(). Other yields share that function: the publisher's (lite/publisher.ts:1828, after a SUBSCRIBE_UPDATE), and an earlier test's session that resumes on a late host timer (a timer armed by an ended test fails nobody, clock/src/host.ts:13). Under CI load one of those landed first, so the abort hit while the client's subscription was still running, before it took the end. The CI logs show exactly that: subscribe error: id=1 ... error=remote error: 0 (the subscription body threw) instead of subscribe close, then (fail) in about 3ms.

The production behavior is fine. The spy just observed the wrong yield.

Change

js/net/src/lite/datagram-tracks.test.ts: the client's connect, consume, and datagrams calls run inside an AsyncLocalStorage context, and the spy counts only a yield made in that context. By elimination, the end routing (lite/subscriber.ts:3145) is then the only client yield the spy can count after finish():

  • #routeHeld never runs, because the test sends no datagram.
  • The receive loop's Budget is mocked.
  • AuthSession's yield happens only at setup.

The lite-06 skip is gone, so all three versions run again.

Validation

  • Reproduced the CI failure: with one foreign clock.yieldNow() injected right before datagrams.finish(), the old test fails all three versions with the CI signature (subscribe error ... remote error: 0, (fail) in about 3ms). The fixed test passes with the same injection.
  • The test still catches a real regression: with a subscriber mutant that races the end routing against the session's close (Promise.race([this.#datagramsRouted(id), this.#quic.closed...])), both the old and the fixed test fail all three versions.
  • Ownership: logging each spy hit's context over 100 isolated reruns and 8 parallel full-suite runs showed every counted yield came from the client (own) at subscriber.ts:3145.
  • Stability: the whole datagram-tracks.test.ts file passed 300 reruns (12,000 tests, 0 failures).
  • Local repro attempts: I could not reproduce the CI flake without the injection. I tried at this head and at the failing commit a4fa80a747, with 2,100 isolated reruns, 8 parallel full-suite runs, and fuzzed host-task ordering. CI's full-workspace load is what exposes the stray yield.
  • just check passed.

Caused by

  • moq-dev/moq#8357 - replaced the microtask drain with a process-wide yieldNow spy, which any other session's or the publisher's yield trips (found by queue)

Public API

None. Test-only change.

Follow-ups

None.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)

Review

Rewritten by quest review after each round.

  • Head: d2b27f3

  • Base: origin/main at bc9ff0d

  • Risk: low, Only a test and quest documentation change, so a mistake could disrupt contributors’ test runs without affecting consumers or deployed peers, and a revert fully undoes it.

  • Classified: low by Codex, gpt-6.1-sol, low effort, session 01a1fa74-89e6-7c93-bbb8-9ee9249eafcc

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a1fa74-9ab5-7bd0-8ebc-b69cd959c627, round 1

  • Score: 9/10, The focused change prevents unrelated publisher or prior-session yields from triggering test synchronization, with no actionable defects found by source inspection, though tests were not run as instructed.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

kixelated and others added 2 commits November 20, 2026 10:19
…gram-tracks-end-keeps-the-2.md

Quest-Claim: 4e50e0120235a1b3
The close-after-end test spied on every yieldNow in the process, so the
publisher's yield, or an earlier test's session woken by a late host timer,
tripped it before the client took the end. Tag the client's tasks with
AsyncLocalStorage and count only theirs, and drop the lite-06 skip.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Fix the flaky test a-session-close-right-after-a-datagram-tracks-end-keeps-the test(net): count only the client's yield as a datagram end's routing Nov 20, 2026
@kixelated
kixelated marked this pull request as ready for review November 20, 2026 19:35
@coderabbitai

coderabbitai Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

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 30 minutes.

Check out review usage here.

View limit details

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

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 5cfb85ea-132c-4a91-8f44-997c0505420b
Commits

Reviewing files that changed from the base of the PR and between 9828a20 and d2b27f3.

Files selected for processing: 3

  • js/net/src/lite/datagram-tracks.test.ts
  • quest/m0/flaky/README.md
  • quest/m0/flaky/a-session-close-right-after-a-datagram-tracks-end-keeps-the-2.md
  • 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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Approach: sound. It fixes the spy's cause, since it only counts yields made inside the client's async context. It doesn't add timing slack to hide the flake.

Reviewed changes

Reviewed the full diff of 3 files.

  • Client-scoped yield spy — js/net/src/lite/datagram-tracks.test.ts runs the client's connect, consume, and datagrams calls inside an AsyncLocalStorage. The yieldNow spy now resolves received only when clientTask.getStore() is set. A publisher yield or a stray yield from an earlier test's session can no longer trigger the abort early.
  • Skip removed — the skipIf(alpn === ALPN_06) is gone, so the test runs for all three ALPNs again.
  • Quest cleanup — the resolved flaky quest and its now-empty epic README are deleted.

Pullfrog  | View workflow run | Using claude-sonnet-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit d02174a Nov 21, 2026
12 checks passed
@kixelated
kixelated deleted the quest/m0/flaky/a-session-close-right-after-a-datagram-tracks-end-keeps-the-2 branch November 21, 2026 00:35
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