Skip to content

A replaced copy's short group continues from the replacement - #9277

Draft
kixelated wants to merge 3 commits into
mainfrom
quest/m1/switch-partial-close
Draft

kixelated wants to merge 3 commits into
mainfrom
quest/m1/switch-partial-close

Conversation

@kixelated

@kixelated kixelated commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m1/switch-partial-close.md and deletes it.

A group that a copy closes with a bare FIN (no GROUP_END) may hold more frames. Before this PR, a read that reached that FIN ended the group, even when the front had already replaced the copy and the replacement held the rest. Whether the reader got the rest depended on arrival order: it did only if it parked on the next frame before the FIN landed.

Now a read that reaches a short close on a copy the front replaced, or whose route failed, asks the replacement for the next frame, as a stall does. The group ends where it closed only once no route can supply more: the replacement refuses the rest, the group goes stale under the reader's budget, or no front is left to replace the copy. A group read to a GROUP_END is whole and ends as before. Rust and @moq/net match.

Changes

  • rs/moq-net/src/model/resume.rs: Recover::poll takes a Cause (Stalled, Closed, Failed) instead of an optional error. Closed is settled like a failure, so a refusal concludes it, but where nothing replaces the copy, or the copy still serves with no front to replace it, its close stands (NotFound, which the group reads as a clean end). wants also looks past a copy that closed short on a route that failed since.
  • rs/moq-net/src/model/group.rs: poll_resumed recovers a short-closed read (closed_short) instead of ending it, ends it cleanly when the recovery says the close stands or the group expired, and poll_finished counts a short close the same way.
  • js/net/src/group.ts, js/net/src/resume.ts, js/net/src/internal.ts: the same in JS. Recover.replace takes a RecoverCause. A front-handed group's closed and readable() decide a short close only when a read or an awaited closed asks, so a wait for readability (such as a track mirror) does not end the group before a route move can continue it. Internal watchers use a new quiet hooks.groupClosed that never decides.
  • Resume models in both languages (resume_model.rs, resume.model.test.ts) gain a Close op that closes a route's group short, optionally failing the route right after. Their oracle now requires that a group ends short only at a frame count some route closed it at, and, under an hour's budget with a route left and the group not expired, only where a live route closed it.
  • Tests that meant whole groups but ended them with bare finish() now use finish_at (producer_replaced in route_change.rs, two in group.test.ts, one in resume.rs).

Public API: none. Wire: none.

Validation

  • New reproductions, Rust (model::resume::test): a_replaced_copys_short_group_continues_from_the_replacement, a_short_group_on_a_failed_route_waits_for_the_next, a_short_group_the_replacement_lacks_is_fetched, a_short_group_ends_where_it_closed_once_stale, a_short_group_ends_once_no_route_holds_more.
  • New reproductions, JS (resume.test.ts): a replaced copy's short group continues from the replacement (closing before and after the swap), reads on once the rest lands on the replacement, waits for the next route after its route failed, and ends once no route holds more, while its copy still serves, or once no route is left to ask.
  • Differential check of the models: with the fix disabled, both the sweep and the new regression case fail in both languages (group N ended after 1 frames where a failed route closed it); with it, the Rust model passes 3000 cases at seeds 2026 and 777, and the JS model 3000 cases at seeds 1, 7, 2026, 99991, 31337, and 4242.
  • cargo nextest run -p moq-net --all-features: 4133 passed after merging main. bun test in js/net: 3445 passed. just check: passed.
  • The TLA+ ResumeReader spec models whole groups only (no frames, no Recover), so it does not cover this; its "Not covered" note already says so.

Caused by

Recovery has ended a group at any end its copy reported since it landed: Rust in #4741, JS in #5836. Once a group's end could say it is whole (finish_at, GROUP_END), a bare FIN stopped meaning the group is complete, but recovery kept reading it that way. Found by the 2026-11-20 audit of the subscription rules before the lite-07 cut.

Models

Size: M
Implementer: Claude, claude-opus-5-5, high effort (arm B)

Follow-ups

None.

Waiting

  • Maintainer: accept the wait a bare-FIN group can cost on a failed copy. A group a producer ends with bare finish() and whose route then fails before the reader sees the FIN now waits on the replacement like a mid-group failure: it continues if the replacement holds more, and otherwise ends when the replacement refuses the rest or the group goes stale. An encoder restart that starts the new producer at the next group leaves that group waiting until it goes stale, which producer_replaced hit until its groups used finish_at. A reader reading groups concurrently is unaffected; a strictly sequential one stalls. Recommended: accept, since a bare FIN says the group may hold more and media producers use finish_at. The alternative is to reopen a short close only once the front has already moved to another route, which keeps the old ending when the copy fails right after its FIN but loses the rest whenever the failure lands first.
  • Maintainer: accept that JS judges a front-handed short close lazily. On a group handed out by a front with recovery, closed and readable() no longer settle at the FIN: a short close is decided when a read or an awaited closed asks, so a route move landing just after the FIN still continues the group. Rust reads lazily already. Recommended: accept, for parity with Rust.
  • Maintainer: accept the arrival-order window that remains. A FIN read before the front learns its copy was replaced or failed still ends the group there, as nothing then says another route holds more. Recommended: accept; a copy that fails mid-group resets its stream rather than sending a FIN, so this needs a copy that really closed the group and a route change racing the read.

(Written by Claude Opus 5.5 with high)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 9856e36, named in full once no reviewer reports a finding

  • Base: origin/main at b4496b1

  • Risk: medium, The change alters Rust and JS group recovery and completion behavior during route changes, potentially causing consumers to miss frames or wait incorrectly, but preserves public APIs and wire formats and is fully undone by a revert.

  • Classified: medium by Codex, gpt-6.1-sol, low effort, session 01a1fc45-d41a-73a0-a6de-15bf904376b7

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

  • Session: 01a1fc45-ea61-72b3-a17d-a66c92e027a4, round 1

  • Score: 6/10, The fix needs rework because cache release and close monitoring can still disable recovery prematurely and cause consumers to miss frames.

  • Rounds: 1; first round 3 (medium 3); findings 3 (medium 3): fixed 0, refuted 0, open 3

  • Findings, open until the next round settles them:

    • Medium, rs/moq-net/src/model/group.rs:4638: Preserve short-close recovery after cache release
    • Medium, js/net/src/group.ts:1080: Move publisher monitors onto the non-reading close view
    • Medium, js/net/src/group.ts:980: Stop judging closes after their observers unsubscribe

kixelated and others added 3 commits November 20, 2026 17:28
…ement

A group a copy closes with a bare FIN (no GROUP_END) may hold more frames.
When the front replaced that copy, or its route failed, the read now asks
the replacement for the next frame, as a stall does, instead of ending the
group where the old copy closed it. The group ends where it closed only once
no route can supply more: the replacement refuses the rest, the group goes
stale, or no front is left to replace the copy. Groups read to a GROUP_END
end as before. Rust and @moq/net match.

The resume models in both languages gain a Close op, and their oracle
requires a short group to end only where a live route closed it.

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

This branch has not been deployed

No deployments
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