Skip to content

fix(js/net): announce-close test counts a lite-07 removal once answered - #9177

Merged
kixelated merged 2 commits into
mainfrom
quest/m0/test-flakes-3/announce-consumer-close
Nov 19, 2026
Merged

kixelated merged 2 commits into
mainfrom
quest/m0/test-flakes-3/announce-consumer-close

Conversation

@kixelated

@kixelated kixelated commented Nov 19, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes the flake in moq-lite-07-wip: closing an announce consumer ends the peer's announce stream (js/net/src/integration.test.ts). Finishes quest/m0/test-flakes-3/announce-consumer-close.md.

Cause

Load wasn't the cause. The test hangs about 1 in 800 runs on an idle host, and every failure took exactly the 1 s until deadline. It was a race in the test itself.

The lite-07 case counted a removal when the peer handled the edit removing the prefix. The client acts on that removal only when the peer's ANNOUNCE_OK arrives: until then it keeps showing the prefix's claims, and it holds back its next edit because one is still unanswered. When the next cycle's routes() opened in that gap, the client:

  1. fed the new reader the still-cached claims, so next() returned start right away;
  2. saw the reader close before the OK arrived, so it sent nothing new: add-then-remove coalesced into no edit at all.

The peer never heard of that cycle, so the removal the test waited for never came. The debug log of a failing run shows it: the third cycle's start has no announced: remove= add=room edit before it.

The client behavior is correct (it sends nothing the peer doesn't need). The test's assumption was wrong.

Change

  • A lite-07 removal now counts when the client receives the ANNOUNCE_OK that answers it (a spy on Routed.prototype.receive, paired with the edits the peer saw). The next cycle can't start until the client has dropped the stale claims, so each cycle sends its own add and remove.
  • The wait is now an event (a promise resolved on each count) instead of polling against a 1 s wall-clock deadline. A real hang now fails at the suite timeout.

Validation

  • Before: bun test src/integration.test.ts -t "closing an announce consumer" --rerun-each 300 gave 3 failures in 2400 runs, all lite-07, each at exactly 1000 ms.
  • After: --rerun-each 1000 passes 8000/8000.
  • Mutation: when I removed the #ask() that Routed.attach runs when a reader closes (so the client never gives the prefix back), the lite-07 test fails (it times out at 5 s). The test still catches the leak it guards against.
  • just check passes.

Caused by

  • moq-dev/moq#8835: added the lite-07 case, counting a removal when the peer handled it rather than when the client had its answer (found by check).

Decisions

  • Kept the shared until helper (21 other uses) as it is. Its 1 s deadline wasn't the cause here, and the other tests are out of scope.
  • Left one client behavior alone: a reader opened while its prefix's removal is unanswered is shown the stale claims, and they end when the OK arrives. On a quick re-watch that can show start, end, start. That's correct protocol behavior, not this flake, so I added no follow-up.

Impact

Public API: none. Wire: none. Test-only.

Follow-ups

None.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, medium effort

(Written by Claude Opus 5.5 with medium)

Review

Rewritten by quest review after each round.

  • Head: a91f65c

  • Base: origin/main at 03bfeea

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

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

  • Session: 01a1f426-dd3c-7973-a95f-2f22ed617caa, round 1

  • Score: 9/10, The test waits for removal acknowledgments before reopening discovery, avoiding stale claims without wall-clock polling; source review found no actionable defects, and 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 19, 2026 06:07
The lite-07 case counted a removal when the peer handled the edit, but the
client drops the removed prefix's claims and sends its next edit only once the
peer's ANNOUNCE_OK arrives. A cycle that opened its reader in that gap was fed
the stale claims, closed before any new edit went out, and the removal the test
waited for never came. Count the removal once its ANNOUNCE_OK is in, and wait
on the count as an event instead of a 1 s wall-clock poll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Closing a JS announce consumer ends the peer's stream under load fix(js/net): announce-close test counts a lite-07 removal once answered Nov 19, 2026
@kixelated
kixelated marked this pull request as ready for review November 19, 2026 14:13
@coderabbitai

coderabbitai Bot commented Nov 19, 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 22 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: c621febb-0f7d-4ed6-aa84-717ff7843a7b
Commits

Reviewing files that changed from the base of the PR and between 03bfeea and a91f65c.

Files selected for processing: 2

  • js/net/src/integration.test.ts
  • quest/m0/test-flakes-3/announce-consumer-close.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

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge pick (maintainer away, granted the coordinator merges it confidently recommends): ✅ /quest-merge (test-only fix, standing pick), accepting the decisions listed in the PR body.

(Written by Claude Opus 5.5 with high)

@kixelated
kixelated enabled auto-merge November 19, 2026 14:13

@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. The race was in the test's own idea of "done", and the fix counts a lite-07 removal once the client has applied the ANNOUNCE_OK that answers it. That is the point where it drops the stale claims and can send its next edit. The fix does not just stretch the deadline.

Reviewed changes

This review covers the whole PR at a91f65c.

  • Lite-07 removal counted on ANNOUNCE_OK: the Routed.prototype.receive spy calls end(removing.shift() ?? 0) after #ok() has already run. receive has no await before the switch, so #ok() runs synchronously. Removals are summed per finished edit (more === false) in the request spy and paired with OKs first-in, first-out. Lite-07 keeps only one edit unanswered at a time, so the pairing holds.
  • Event-driven wait: while (ended < i) await changed.promise replaces the 1 s until poll. A real hang now fails at the suite timeout, and expect(ended).toBe(i) still catches counting too many.
  • Quest file removed: quest/m0/test-flakes-3/announce-consumer-close.md is deleted now that the quest is finished.

Spies are restored by the file-level afterEach(() => mock.restore()). The older lite drafts never reach Routed.receive, so their counting is unchanged.

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

@kixelated
kixelated added this pull request to the merge queue Nov 19, 2026
Merged via the queue into main with commit 965aac8 Nov 19, 2026
10 checks passed
@kixelated
kixelated deleted the quest/m0/test-flakes-3/announce-consumer-close branch November 19, 2026 14:31
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