Skip to content

fix(net): a JS switch before any group drops the replaced copies as Rust does - #9436

Merged
kixelated merged 5 commits into
mainfrom
quest/m1/switch-no-boundary-parity
Nov 22, 2026
Merged

kixelated merged 5 commits into
mainfrom
quest/m1/switch-no-boundary-parity

Conversation

@kixelated

@kixelated kixelated commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Closes the gap moq-dev/moq#9276 left open on purpose: a route switch that finds nothing held and nothing handed out (no boundary) now drops the replaced copies in @moq/net as rs/moq-net does, so the same route change delivers the same groups in both. Finishes and deletes quest/m1/switch-no-boundary-parity.md.

Changes

The Rust and JS switches happen at different moments. The Rust origin splices a replacement only once it delivers a group (or the old copy ends), so a Rust reader keeps reading the old copy until then, and only that delivery reaches Reader::sync, which then drops every replaced copy if there is no boundary. The JS Route switches as soon as the replacement answers and covers the gap with route.incumbent. So the JS equivalent of the Rust sync is the serving copy's first delivery, not Route.serve. A plain drop in #sync changes nothing, because #joinIncumbent re-subscribes the incumbent right away (I tried it: every test still passed, behavior unchanged).

js/net/src/resume.ts:

  • #sync with no boundary keeps only the copy of route.incumbent, uncapped, and drops the rest: copies of routes replaced before they delivered, which the Rust front never splices for a reader.
  • Route.park now holds the serving source as the incumbent, as serve does, instead of clearing it. A park is a switch to no route, so after park → serve(B) the parked copy stays until B delivers, and #revert still falls back to it if B fails first (found by Pullfrog). A reader that joins after park → serve(B), before B delivers, now reads the parked source too, as Rust keeps the old copy until the replacement splices.
  • New #delivering: when the serving copy delivers (first hand-out in #observe, or already holding a group in #joinIncumbent) with nothing handed out and no other copy holding a group, it drops the uncapped replaced copies instead of capping them just below the delivered group. That matches the Rust sync with no boundary at splice time. With a boundary, the existing cap is unchanged.
  • New #dropCopies learns any declared end before dropping, as Rust's learn_end does before copies.clear().
  • Doc comments on #observe and #boundary updated.

Tests:

  • Ported a_switch_before_any_group_drops_the_replaced_copy as "a switch before any group drops the replaced copy once the new route delivers": with a long latency budget and a received (late-landing) old route, a group landing on the old route after the new one delivered is not read, and the old route is unsubscribed.
  • New "a switch before any group drops a replaced copy that never delivered": in A→B→C with no groups, B's subscription goes at the switch to C, while the incumbent A keeps serving until C delivers.
  • Deleted "a switch before any group leaves the replaced copy uncapped as the incumbent" (the no-boundary incumbent case).
  • The Rust test's doc now names its JS mirror. No Rust behavior changes.

The plan asked to check that #joinIncumbent still covers a reader joining before the new copy delivers: it does. "a reader joining before the replacement delivers keeps the incumbent when the replacement aborts" and "a replacement that aborts before any group was held leaves the incumbent serving" still pass, because the incumbent's copy is kept until the serving copy delivers.

Impact

Public API: none. Wire: none. Behavior: in @moq/net, a group that lands on the old route after the new route delivered first is no longer read when the reader had nothing yet (the new route, asked from the reader's own start, serves it if it has it), and a route replaced before it delivered stops being read at the next switch.

Decisions

Taken without asking (a later review can undo them):

  • Treat the serving copy's first delivery as the JS "switch moment", rather than dropping at Route.serve. Dropping at Route.serve would leave a JS reader reading nothing during the handover, where a Rust reader keeps the old copy, and #revert would lose the copy it falls back to. That would be a different divergence, not parity.
  • Keep the incumbent's existing copy at the switch rather than drop it and let #joinIncumbent re-subscribe: same groups, without a resubscribe per switch.
  • Scope stays at no boundary. With a boundary, JS still caps the incumbent at the first delivered group minus one where Rust caps at the boundary it computes at splice. That is outside this quest's Goal and not pinned by either model; not filed as a follow-up.

Validation

  • bun test src/ in js/net: 3638 pass, 0 fail.
  • Both new tests fail on the old resume.ts and pass on the new one (checked by swapping the file).
  • Differential check: resume.model.test.ts (random route flips, failures, joins, checked against one plain cursor) with MOQ_RESUME_CASES=1000 on seeds 11, 22, 33, 44: all pass. Instrumented once to confirm coverage: in 300 cases the first-delivery drop fired 30 times and the switch drop 10 times.
  • just check: everything passed (11224 Rust tests, JS check, biome, dead code) except check quest, which ran with a stale quest (eaee1d5) in my shell that still expects the skill stubs moq-dev/moq#9421 removed. nix develop --command quest check with the pinned quest a88c65b reports "516 documents ok".
  • After merging main (which deleted quest/m0/nightly/js-ended-reader-routed.md, the one file that linked this quest): bun test src/ 3642 pass, 0 fail. just check passed except the same stale-shell check quest, plus 4 moq-mux jitter::tests that timed out at 60s together under the full-suite load. This branch doesn't touch moq-mux, and all 64 jitter tests pass alone in 3.4s (sh/rs/nextest.sh cargo nextest run -p moq-mux --all-features -E 'test(/jitter::tests::/)').
  • Park regression (Pullfrog finding): "a switch before any group after a park keeps the parked copy until the new route delivers" and "a replacement after a park that aborts before any group leaves the parked copy serving" fail on 26672ff, pass on main, and pass on the fixed head. After the fix, bun test src/ passes 3644, and the model sweep (seeds 11, 22, 33, 44 × 1000 cases) passes. Coverage gap: instrumenting showed the model sweep never reaches Route.park (its up/down steps never resolve a route of the same instance without a front), which is how this got past it. I didn't add it, because that would change how the model drives the origin.
  • No TLA+ run: Rust's Reader::sync and the models are unchanged; this aligns JS to the shape ResumeReader's Sync already models.

Caused by

No single PR: the JS incumbent-until-delivery design predates the Rust drop, and moq-dev/moq#9276 kept the split on purpose and deferred it to this quest.

Follow-ups

None.

Models

Size: M
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm B)
Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate, M, arm B)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 2d4e2e9

  • Base: origin/main at 4e7205c

  • Risk: medium, What could break: `@moq/net` switch behavior changes, since a route switch before any group now drops replaced copies immediately, and a parked copy stays incumbent until the next route delivers, so JS consumers of the resume reader may see different groups during failover; the API, wire format, and Rust code (a doc-comment-only change) are unchanged, and a revert fully undoes it, so this is a fix to shipped code, not a high-tier break.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session b9c36a10-75f1-4766-b218-8e7f17edb3bf

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

  • Session: 01a204cf-0964-7671-b6fc-bbbfe3231a63, round 3

  • Score: 8/10, The incremental change preserves the parked incumbent through replacement delivery or failure, with focused regression coverage and no actionable findings; builds and tests were not run as instructed.

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

  • Findings: none

kixelated and others added 3 commits November 22, 2026 11:25
…ust does

A switch with nothing held nor handed out keeps only the incumbent's copy,
and the serving copy's first delivery (when the Rust front splices it) drops
that one too instead of capping it below the delivered group. Ports
`a_switch_before_any_group_drops_the_replaced_copy` and deletes the JS
no-boundary incumbent test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A switch before any group drops the replaced copies in both languages fix(net): a JS switch before any group drops the replaced copies as Rust does Nov 22, 2026
…undary-parity

# Conflicts:
#	quest/m0/nightly/js-ended-reader-routed.md
@kixelated
kixelated marked this pull request as ready for review November 22, 2026 20:04
@coderabbitai

coderabbitai Bot commented Nov 22, 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 10 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: 3ac11347-fe57-4f7b-a4ca-c5f7d876988d
Commits

Reviewing files that changed from the base of the PR and between 558c053 and 2d4e2e9.

Files selected for processing: 4

  • js/net/src/resume.test.ts
  • js/net/src/resume.ts
  • quest/m1/switch-no-boundary-parity.md
  • rs/moq-net/src/model/resume.rs
  • 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.

Important

The no-boundary drop keys on route.incumbent, which Route.park() clears. So a park then serve switch now drops the parked copy before the new route delivers. That is the "drop at Route.serve" divergence the PR's Decisions section rejects.

Approach: sound in shape. Treating the serving copy's first delivery as the JS splice moment, and keeping only the incumbent at the switch, is the right mapping onto the Rust front. But the "who is the incumbent" test misses the between-routes path.

Reviewed changes

The full diff at 26672ff was reviewed against main, along with Route (serve/park/revert/resubscribe), #joinIncumbent, #observe, #revert, and the Rust Reader::sync/park/origin splice path.

  • Reader.sync no-boundary branch: drops every copy whose source isn't route.incumbent, after #learnEnd, instead of leaving them uncapped.
  • #delivering: on the serving copy's first delivery with nothing handed out and no other copy holding a group, it drops uncapped replaced copies instead of capping them below the delivered group.
  • #dropCopies: a new helper that learns a declared end before letting copies go, mirroring Rust's learn_end before copies.clear().
  • Tests: the Rust no-boundary test is ported, an A→B→C test checks that the never-delivered middle copy is dropped, and the JS incumbent no-boundary test is deleted.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using claude-opus-5-5 | 𝕏

Comment thread js/net/src/resume.ts Resolved
A no-boundary switch after Route.park() dropped the parked copy at once,
since park cleared the incumbent. Park now holds the serving source as a
replacement would, so the copy stays until the next route delivers and
#revert still falls back to it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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 fix at the root in Route.park keeps the JS switch aligned with Rust, where the old copy keeps serving until the replacement splices.

Reviewed changes

Reviewed the delta since 26672ff (commit 2d4e2e9).

  • Route.park holds the serving source as incumbent: a park is now a switch to no route that keeps the serving copy as the incumbent, so the no-boundary rule keeps it until the next route delivers and #revert can still fall back to it. This resolves the earlier thread on the park→serve drop.
  • Tests: added "a switch before any group after a park keeps the parked copy until the new route delivers" and "a replacement after a park that aborts before any group leaves the parked copy serving".

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

@kixelated
kixelated added this pull request to the merge queue Nov 22, 2026
Merged via the queue into main with commit 92449df Nov 22, 2026
9 checks passed
@kixelated
kixelated deleted the quest/m1/switch-no-boundary-parity branch November 22, 2026 21:32
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