Skip to content

fix(net): kill resume route mutants; keep expired and draining copies' groups owed - #9750

Merged
kixelated merged 28 commits into
mainfrom
quest/m0/nightly/resume-route-mutants
Nov 28, 2026
Merged

kixelated merged 28 commits into
mainfrom
quest/m0/nightly/resume-route-mutants

Conversation

@kixelated

@kixelated kixelated commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Nightly's mutants shards still reported survivors in rs/moq-net/src/model/resume.rs and rs/moq-net/src/route/relay.rs. That covered the three #9619 left, plus the ones from Nightly 45867457463. Rerun against main (83e10f008a), 13 still survived, and two of them pointed at real bugs.

Approach

Each survivor gets a unit test that kills it, an exclusion with a proof, or a rewrite that removes it. Each new test fails with its mutant (or the old code) applied by hand.

Bug fixes, in Rust and JS:

  • An expired copy's unread groups stay owed to a wider budget. Subscriber::forget_past (JS forgetPast) judged replaced copies under the reader's current budget, so a hand-out while a replaced copy was expired forgot the gaps that copy's late groups fill, and a widened budget then found them written off, while a plain track keeps them owed. Each unread group a replaced copy holds is now judged fresh or stale on the read that holds it (track::Subscriber::lowest_owed, JS lowestBuffered(.., fresh)), at its track's max age, within that read's own window and cap, and through an inner front down to the leaf read. Tests: a_widened_budget_reads_an_expired_copys_groups_past_a_hand_out (plain and routed, both languages).
  • That owing never pins the fold for good. Judged under any budget, a lease on an expired copy kept its unread groups holding back the fold, so the reader's record grew one run per later gap on the serving route for as long as the lease lasted. A group stale at the track's max age is one no budget reads, so it no longer holds the fold back. Tests: an_expired_copy_past_its_max_age_bound_holds_back_no_gap (18 runs without the bound, 3 with it, in both languages) and a_widened_budget_reads_an_expired_copys_group_fresh_at_its_max_age, both also with the copy behind an inner front in Rust.
  • A group a replaced copy was left to drain is asked of the serving route once that copy no longer drains it. The drain walk used to remember a copy's eviction count, so a copy that stopped offering the group any other way (expired, judged it stale, failed, or was let go) left it undelivered. Each copy now keeps the keys the walk left it (Copy::drains), Reader::rescan_drains rechecks them with Copy::may_drain on a pass with nothing to hand out (so draining a backlog costs no rescan per group) and before any clean end, an ordered read rechecks those under the group it is about to hand out, and in JS that group too, since the JS take gives up a group held without its head (each copy's keys are ascending, so this costs the groups handed out since), and let_go re-arms the walk for a copy it lets go with one undelivered. JS's clean end from the serving copy's close callback asks any queued walk itself and judges again, as the Rust end path does. This removes track::Consumer::evicted and evicted_groups (JS hooks.evictions). ResumeReader.tla mirrors it (Rescan, LetGo). Tests: a_group_a_draining_copy_gives_up_is_backfilled (Rust: evicted, leased, and let go by a drop poll; JS: with and without a lease) an_ordered_read_asks_for_a_lost_drain_before_passing_it (both languages), and an_ordered_read_reads_a_drain_its_copy_got_again_without_its_head (both languages).

Killed:

  • Subscriber::key_after -> Some(0) / Some(1): a_fronts_held_groups_successor_bounds_it_by_key.
  • Reader::rescan_drops and Subscriber::rescan_drops -> (): an_untold_run_is_reported_again_after_a_rescan (plain and routed).
  • Subscriber::lowest_unread delete !: a_fronts_delivery_starts_at_a_group_any_copy_serves_whole.
  • Reader::reads || -> &&: an_expired_copys_late_groups_stay_unread.
  • Reader::poll_first replaced-refusal guard -> true: a_replaced_copys_refusal_leaves_the_read_to_the_serving_copy.
  • Copy::asked_for < -> <=: a_kept_out_key_above_a_finished_backfill_is_asked_from_itself.
  • Reader::backfill |= -> &=: a_backfill_widened_past_its_time_start_still_reads_the_group_holding_it.
  • Reader::backfill_gaps time < resumed -> <=: a_lost_drain_under_a_backfill_is_asked_with_a_time_start_at_the_resume_point.

Removed: Reader::backfill_gaps match guard partial -> true. The per-copy drain keys replace the eviction count that guard refreshed, so the guard is gone.

Excluded:

  • Router::closest_of < -> <=: the existing (reselect|closest) exclusion predates the closest_of split. Every key ends in its claimant, and claimants holds those in a BTreeSet, so no two keys tie.
  • Copy::may_drain key < end -> <=: the old backfill_gaps exclusion, moved with the code. may_take already confines a drained key to the copy's ranges, which end at its cap.
  • Reader::rescan_drains ordered bound key < below -> <=: that also checks the candidate itself. In Rust the candidate is the reserved group and is handed out as it is (the headless parity test pins this), so a re-arm there asks at most a walk whose gap the hand-out fills.

Cleanups:

  • Removed the dead :\d+:13: replace || with && in Reader::poll_first exclusion. That condition moved into Reader::reads, where it is now killed.
  • track::Subscriber::rescan_drops no longer sets the logical record's rescan flag. No drop scan reads that flag: each copy scans its own drops.
  • Moved Reader::backfill_gaps' doc comment back onto it from reopen_folded, which main had slipped between them.
  • Finished the quest: quest/m0/nightly/resume-route-mutants.md is deleted and its links point here.

Impact

  • Public API: none.
  • Wire: none.
  • Behavior: a front no longer loses an expired copy's late groups once the budget widens, no longer loses a group a draining copy stopped offering, and no longer grows its delivery record while a lease holds an expired copy.

Caused by

  • moq-dev/moq#9529 - added forget_past's judgment of replaced copies under the reader's current budget (found by check: mutants).
  • moq-dev/moq#9564 - re-armed the drain walk only on eviction, not when the copy stopped draining otherwise (found by check: mutants).

Decisions

  • Decided 2026-11-27 (agent): ported both fixes to JS here, superseding the earlier decision to leave JS parity to a follow-up quest. The review flagged both as JS bugs, and the ports were small.
  • Decided 2026-11-27 (agent): rebuilt the drain tracking as per-copy keys rechecked on the poll, superseding the earlier decision to leave the partial guard survivor in the quest. It is the fix that quest recommended, and it also answers the review finding that a leased copy could stop draining without a re-arm.
  • Decided 2026-11-27 (agent): bounded an expired copy's owing by its track's max age rather than tracking its unread keys as exceptions to the fold. Past that bound no budget reads a group, so it is the plain track's rule. Refined after review round 2: each group is judged on the read that holds it, within that read's window and cap, rather than the copy as a whole, so a capped copy or an inner front's group is judged as its own route would judge it.
  • Decided 2026-11-27 (agent, review round 2): rescan_drains runs only on a pass with nothing to hand out and before a clean end, not on every poll, as a plain cursor asks a fill only once it holds nothing buffered. Rejected: rescanning every poll (costs O(backlog) per group handed out).
  • Decided 2026-11-27 (agent, maintainer away): kept the JS #letGo re-arm (the copy.drains check before #drop) as the mirror of Rust's let_go re-arm. No JS test reaches it, but #conclude and #judging call #letGo on paths no test or model rules out. Rejected: deleting it (simpler, but leaves those paths relying on an unchecked argument).
  • Decided 2026-11-27 (agent, maintainer away, review round 3): the JS clean-close callback asks the re-armed backfill itself (one line, matching Rust's end path), verified by reading only, since the unit harness settles a copy's close only after a read took it to its end. Rejected: declining it as unreachable on that argument alone.
  • Decided 2026-11-27 (agent, maintainer away, review rounds 3 and 4): an ordered read rechecks the drains under its candidate before it hands the candidate out, in Rust and JS. Round 4 showed the idle-only rescan had regressed JS: on the merge base, a group the serving route already caches was read first. The recheck restores that in both languages. The case where the backfill is still in flight, which is also on main at 065a4c1843 with or without a drain, moved to its own quest: it needs a new hold on ordered candidates above an outstanding backfill. Rejected: the full hold here (outside this quest's scope) or deferring the recheck too (leaves the JS regression).
  • Decided 2026-11-27 (agent, maintainer away, review round 4): two rounds of fixes left the JS clean-close findings open, so quest review asked for a maintainer pick. I took fix-as-recommended: #conclude asks any queued walk, not just one re-armed this pass, and judges again after letting go, so a backfill a cache answers synchronously leaves nothing to wait on. Rejected: accepting the findings (a reader awaiting only the close could end short of a group) or dropping the PR.
  • Decided 2026-11-27 (agent, maintainer away, review round 5): at the stop, took fix-as-recommended for the JS ordered take that gives up a headless candidate. The JS recheck now includes the candidate's own drain, so a group the copy lost and got back without its head is asked of the serving route. Rust keeps the exclusive bound, because its reserved candidate is handed out as it is. Rejected: accepting it (it skips a group the serving route holds) or limiting the take to the candidate and reselecting (more machinery for the same result).
  • Decided 2026-11-27 (agent): left the resume model's sync commit at c53243d095 with the branch's modeled changes listed beside it. Moving it to the base means auditing every main change to the covered functions since, which is the next coverage change's job.
  • Decided 2026-11-27 (agent): #9623 covers route/node.rs and route/reader.rs mutants, so it doesn't overlap this PR.

Follow-ups

Validation

  • cargo mutants through quest gate just rs mutants:
    • Over every line this branch changes in resume.rs and the route code (--in-diff), at 6c5d9dea72: 79 mutants, 54 caught, 25 unviable, 0 missed.
    • Over the quest's targeted mutants (asked_for, backfill, backfill_gaps, the poll_first guards, both rescan_drops, forget_past, lowest_unread, key_after, reads, Router::named): 44 mutants, 44 caught. Router::closest_of is excluded above, and the partial guard no longer exists.
    • Over the review rounds' Rust changes (resume.rs from cc3065a1c7 to 6960a22a1d, --in-diff): 12 mutants; the 3 missed were all on resume::Subscriber::lowest_owed. The nested-front test variants in f1f94640eb catch them: a rerun over every lowest_owed (Rust track.rs and resume.rs) gave 29 mutants, 29 caught.
    • Over the ordered drain recheck (--in-diff of its commit): 18 mutants, 11 caught, 6 unviable, 1 missed, which is the boundary excluded above.
  • verify-resume, all three configs pass after the idle-only rescan: default (20.1M states), ThreeRoutes (5.0M), Evict (14.4M).
  • The max-age tests fail without the change in both languages (18 delivery runs instead of 3).
  • The ordered recheck's tests fail without it, in both languages, and the JS headless test fails with the exclusive bound. The in-flight ordered case behaves the same on this branch and on main at 065a4c1843 (see the new quest).
  • No JS unit test reaches the close-callback end. In this harness a copy's close settles only after a read has taken it to its end, and that read hands out every group a replaced copy drains. That change is verified by reading the code and by the full suite passing.
  • js/net bun test passes (4010 tests) and moq-net nextest passes (4663 tests) at 9ad8675dca. quest gate just check passes at 9ad8675dca. quest gate just ci passes at 9ad8675dca. One earlier run on the same head failed only in js/publish (three drift tests timed out and a backlog encode refusal aborts its rendition when demand arrives failed at load average 40), and that package passes on rerun. This branch does not touch it.

Models

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

Review

Rewritten by quest review after each round.

  • Head: 9ad8675

  • Base: origin/main at 0275260

  • Risk: medium, A mistake in the resume reader's drain and backfill logic (rs/moq-net/src/model/resume.rs, track.rs, js/net/src/resume.ts) could hand a reader a wrong, missing, or reordered group for resumed subscriptions, reaching relay and client users only through the next release cut; it is easy to undo by reverting the commits, and the change keeps the public API, the wire format, and the release and auth paths intact, so it is a shipped fix rather than a break.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session 00c38fd0-54b2-4438-804b-dd9561a5fb55

  • Risk file: bb7b1c0de60b

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

  • Session: 01a21f13-3a5d-78b0-b74e-61c558faac99, round 6

  • Score: 10/10, The inclusive JavaScript rescan fixes the reported ordered-read loss, and the head is ready to land.

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

  • Findings: none

  • Notes, the author's to take or leave:

    • rs/moq-net/src/model/resume.rs:10863: Assert which copy supplied the reserved group
  • The last round's findings, at dc24e03:

    • Fixed: medium, js/net/src/resume.ts:1482: Limit an ordered take to the group checked for backfill; The JavaScript rescan now includes the peeked key, so a headless drain re-arms backfill and retries selection before the take can skip it (`js/net/src/resume.ts:1849`, `js/net/src/resume.ts:1874`, `js/net/src/resume.ts:1477`).

kixelated and others added 12 commits November 27, 2026 00:18
… mutants

Exclude Router::closest_of's tie with the rest of the pick keys, whose
claimant ends every key. Drop the logical record's rescan flag, which no
drop scan reads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A backfill flagged only for a time start at the serving copy's resume point
would hand out a group under its floor from the route's cache instead of
asking the route for it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An expired replaced copy's late groups, fresh by their own successors
there, stay unread; a replaced copy refusing a time start leaves the read
to the serving copy. Drops the stale poll_first exclusion whose proof
claimed an expired copy's groups were always past the budget: the new
test shows otherwise, and the mutant moved into Reader::reads.

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

Kill two resume.rs mutants: Copy::asked_for's end bound (a finished
backfill ending at the kept-out key goes, so the route is asked from that
key) and Reader::backfill's flag merge (a raised backfill widened by a
plain ask still reads the group holding its time under its floor).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A backfill flagged only for a time start at the serving copy's resume point
would hand out a group under its floor from the route's cache instead of
asking the route for it.

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

Subscriber::forget_past judged replaced copies under the reader's current
budget, so a hand-out while a copy was expired forgot the gaps its unread
late groups fill. A later widened budget then read the copy again but
found those groups already written off, where one track keeps a skipped
group owed to a wider budget. Judge the copy under any budget instead.

The copy.replaced check is dropped: only the last copy, the serving
route's own, is ever unreplaced, and the newest is skipped first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A replaced copy a switch left a group to drain could be let go without
handing it out, once its own read gave the group up, and nothing asked the
serving route for it, though that route still offered it. Had the copy's
cache evicted the group instead, the walk re-armed and the reader got it.
Letting such a copy go now re-arms the walk too, and poll_first walks at
once. ResumeReader.tla mirrors it in LetGo; all three configs pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A replaced copy a switch left a group to drain could be let go without
handing it out, once its own read gave the group up, and nothing asked the
serving route for it, though that route still offered it. Had the copy's
cache evicted the group instead, the walk re-armed and the reader got it.
Letting such a copy go now re-arms the walk too, and poll_first walks at
once. ResumeReader.tla mirrors it in LetGo; all three configs pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y late groups and JS parity

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Since a copy let go with a group to drain re-arms the walk, losing the
backfill flag no longer loses the group: the serving route is asked for it
again. Pin that the backfill holding it hands it out without that ask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title No resume or relay route mutant survives fix(net): kill resume route mutants; keep expired and draining copies' groups owed Nov 27, 2026
kixelated and others added 9 commits November 27, 2026 04:53
The backfill walk now records, per replaced copy, the groups it left that
copy to drain (each one the copy held then, so a peer can't grow the set
past the copy's cache). Every poll rechecks the drain predicate for them
(`Copy::may_drain`, `Reader::rescan_drains`) and re-arms the whole-route
walk once one stops draining: evicted, given up as stale, or the copy
failed or spent its budget, even while a read of another of its groups
still leases the copy. Letting a copy go with such a group also re-arms.

This replaces the track eviction count (`Consumer::evicted`, JS
`hooks.evictions`) and the `partial` guard on it, which missed a copy
kept by a lease whose left group went stale. The JS reader gets the same
tracking (`#rescanDrains`, `#mayDrain`, `#letGo`).

ResumeReader.tla models the per-copy set (`Rescan`, `DrainsBy`) in place
of `Evicted`; all three configs pass and ReArm = FALSE still fails
CleanEndIsComplete.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A poll of the read's drops judges replaced copies without the group
poll's rescan, so it can let one go while it still holds a group left
to drain that no longer drains. Covers that case, which is the only path
reaching the re-arm in `Reader::let_go` (cargo-mutants left three
survivors there). The JS test closes the serving group it reads, as the
Rust one drops it.

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

Mirrors the Rust forget_past fix: forgetPast now passes over only a copy
whose channel ran out, not one merely past the reader's budget, since a
widened budget reads it again. A spent copy needs no check: lowestBuffered
stops at the copy's cap and skips delivered keys.

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

# Conflicts:
#	js/net/src/resume.ts
#	rs/moq-net/src/model/resume.rs
A lease on a replaced copy kept its unread groups pinning the fold under
any budget, so a reader's record of the serving route's later gaps grew
one run per gap for as long as the lease lasted. No budget reads past the
track's max age bound, so a copy expired under it no longer holds the fold
back. Rust and JS.

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

# Conflicts:
#	.claude/skills/verify-resume/SKILL.md
No targeted resume or relay route mutant survives: the drain restructure
removed the partial guard, and every other targeted mutant is caught.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated and others added 7 commits November 27, 2026 14:54
…s max age; backfill before a clean end

forget_past judged a whole replaced copy past the track's max age bound,
but a group landing late there can stay fresh by its own successor past
that point, and a wider budget still reads the copy. Each unread group is
now judged by its own freshness at the max age instead, so the fold stays
bounded without losing it. Rust and JS.

The JS reader could also end cleanly right after letting go of a copy with
a group left to drain, before asking the serving route for it: tryGroup
now asks before judging the end, as the Rust poll_first does, and a clean
end that lets such a copy go waits for the next read to ask.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…rescan drains only when idle

forget_past now asks each replaced copy for its lowest unread group some
budget still reads (track::Subscriber::lowest_owed): the read holding it
judges it at its track's max age within its own window and cap, so a group
outside a capped copy's window never convicts one inside it, and a nested
front asks the route that holds the group. JS judges with the copy's own
drift too.

Drains are rescanned only on a pass with nothing to hand out, as a cursor
asks a fill only once it holds nothing to read, so draining a backlog of N
groups costs no rescan per group. ResumeReader.tla follows. The JS clean
end rescans drains first, so a leased copy that stopped draining is asked
of the serving route before the track ends.

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

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he ordered-read gap

The serving copy's close callback re-armed the walk on a lost drain but left the
backfill to a read, so a later callback pass could end the track first. It now
asks the backfill itself, as the Rust end path does.

An ordered read passing a group a replaced copy lost is the same on main, so it
moves to its own quest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…JS clean end asks any queued walk

An ordered hand-out passes every key below it, so a group a replaced copy was left
to drain and lost there is asked of the serving route before it goes out, read
first when that route's cache holds it. Rust and JS recheck only the drains under
the candidate, which costs the groups handed out since.

JS's clean end asks a walk an earlier pass queued, not only one this pass
re-armed, and judges again after a backfill a cache answers at once.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The JS take gives up a group its copy holds without its head, so a candidate a
replaced copy lost and got again headless was passed with the group above. The
ordered recheck now includes the candidate. Rust hands out the reserved group as
it is, which a parity test pins.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 28, 2026 07:17
@coderabbitai

coderabbitai Bot commented Nov 28, 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 17 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: f938c4e5-27f9-4394-b954-6bb02f35fd08
Commits

Reviewing files that changed from the base of the PR and between 4ec8386 and 9ad8675.

Files selected for processing: 13

  • .cargo/mutants.toml
  • .claude/skills/verify-resume/SKILL.md
  • js/net/src/internal.ts
  • js/net/src/resume.test.ts
  • js/net/src/resume.ts
  • js/net/src/track.ts
  • quest/m0/nightly/README.md
  • quest/m0/nightly/resume-route-mutants.md
  • quest/m1/expired-copy-late-groups.md
  • quest/m1/ordered-read-lost-group.md
  • rs/moq-net/src/model/resume.rs
  • rs/moq-net/src/model/track.rs
  • rs/moq-net/verify/resume/ResumeReader.tla
  • 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
kixelated added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit 22e3f0a Nov 28, 2026
7 checks passed
@kixelated
kixelated deleted the quest/m0/nightly/resume-route-mutants branch November 28, 2026 07:36
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