Skip to content

fix(js/net): an ended reader moves its open groups off a dying route - #9410

Merged
kixelated merged 6 commits into
mainfrom
quest/m0/nightly/js-ended-reader-routed
Nov 22, 2026
Merged

kixelated merged 6 commits into
mainfrom
quest/m0/nightly/js-ended-reader-routed

Conversation

@kixelated

@kixelated kixelated commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m0/nightly/js-ended-reader-routed.md and deletes it.

Problem

Once a logical track ended cleanly, a JS front reader stopped following its route. Reader.#conclude left the route, sync() returned early once #ended, and Recover.#replace threw on a failed group once reader.ended. So a group still being read, whose route then died, ended where the failed copy left it. Rust's front keeps moving those groups (Phase::Finished { routed } in rs/moq-net/src/model/resume.rs), and the JS resume sweep failed on seeds 4 and 7 (7 on main too).

Approach

All in js/net/src/resume.ts:

  • An ended reader keeps following the route. When the route moves and a group it handed out is still read (Reader.out), it subscribes the new source's copy from the lowest such group. These copies (#rerouted) only back recoveries: nothing is handed out from them, so the reader stays on the copy the track ended on, as Rust's does.
  • Reader.copy(generation) and Reader.holding also find rerouted copies, so Recover.#replace continues a group there (cache, subscription, or fetch) as it does for any newer route. A rerouted copy follows the reader's preferences and cursor like any copy. The reader.ended early throw is gone. A concluded front still ends the group with its failure, unless a copy holds the rest.
  • #unroute drops a rerouted copy once a newer route supersedes it and no recovered group leases it, and drops them all once no group is read. The reader leaves the route only once nothing is read and it holds no copy, so a group it later hands out from its backlog still follows the route.
  • The model oracle's carve-out "Unlike Rust, an ended JS reader follows no route" is deleted (js/net/src/resume.model.test.ts). Seeds 7 and 4 are added to the JS regressions.
  • Ported tests (js/net/src/resume.test.ts):
    • an ended track's group moves off a dying route, from Rust's a_finished_tracks_fetch_moves_off_a_dying_route, for a subscribed group: it continues from the copy served next, and fails with the route's error once the front concludes.
    • an ended track's reader hands out nothing from the copy served after the end, from a_reader_stays_on_the_copy_its_track_finished_on.
    • an ended track's group continues from a rerouted copy's cache once the front concluded (review round 1).

Decisions

My calls while the user was away. A review can undo each one:

  • Seed 10 is split into a follow-up instead of being fixed here. The quest put it in this class, but its reader never ends (#conclude never runs). A group continued by fetch onto slot 2 is closed short there and the route fails. JS ends the group at that close, and Rust continues it from the next route. It is a short-close judgment in group.ts, not routing after the end. js-resume-short-continuation waits on this PR, so I kept this diff to the ended-reader fix.
  • A rerouted copy is subscribed from the lowest group still read, with no cap. It covers every open group. The track's end bounds what it fetches. A group handed out below it later (backlog) falls back to a fetch.
  • Rerouted copies are created lazily, only while a group is read. Rust's front keeps a spliced copy for as long as any reader holds the finished track. JS subscribes nothing for an ended reader that reads no group, so it pays nothing for the common case.
  • An ended reader leaves the route once it holds no copy and reads no group, not at the end. As a result, the route's entry and any incumbent hold stay a little longer while an ended reader still drains its backlog.

Impact

Public API: none. Wire: none. Behavior (JS only): after a clean end, a group still read continues off a dying route, as in Rust, instead of failing with the route's error.

Alternatives

  • Hand out from the rerouted copy like any copy. This risks delivering after the end what the reader already accounted for. Rust's reader stays on its last copy (ResumeReader.tla's CleanEndIsComplete).
  • Stay on the route until close(). This is simpler, but it keeps the route registered as long as an app holds an ended subscriber.

Validation

  • JS sweep, MOQ_RESUME_SEED=1..24 at 4096 cases, with this branch's oracle (carve-out removed) and with main's:
    • main: fails 2, 4, 7, 9, 10, 14.
    • This branch: fails 2, 9, 10, 14.
    • 4 and 7 now pass, and nothing new fails. 2 and 14 are route-close shapes (moq-dev/moq#9391). 9 is js-resume-short-continuation. 10 is the new follow-up.
  • The new unit tests and the two new regressions fail without this change's resume.ts and pass with it. On main, the group ends with the route's error at once, in both the rerouted and the concluded case.
  • bun test src/resume src/group: 275 pass. just check passes on the head.

Caused by

No single PR introduced a defect. A JS ended reader has followed no route since moq-dev/moq#6136, which matched Rust at the time. moq-dev/moq#8896 added routing after the end to Rust only (found by check: the JS resume sweep, on moq-dev/moq#9396).

Follow-ups

  • quest/m0/nightly/js-resume-fetched-short-close.md [M]: a JS group continued by fetch keeps going past a failed route's short close (seed 10). No open decisions: its Plan asks the implementer to decide from the Rust reader between fixing group.ts and fixing the model.

Models

Size: L
Implementer: Claude Code, claude-opus-5-5, unknown effort
Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate, L)

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 3407606

  • Base: origin/main at fd59727

  • Risk: medium, It changes shipped JS resume code (js/net/src/resume.ts) so an ended reader keeps following a route for groups still being read and continues a failed group from a rerouted copy, which could alter what JS consumers of moq-net receive after a route failure, but it is a bug fix that keeps the public API and wire format, so it ships as a patch and a revert fully undoes it; the test and quest-doc changes are low risk.

  • Classified: medium by Claude Code, claude-haiku-5-5, low effort, session cd89e6ff-260c-48cf-9f91-90ae7f8facff

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

  • Session: 01a203b2-4e2a-7c83-98f9-3f3784265b83, round 2

  • Score: 10/10, Both recovery gaps are fixed and source review found no new issues in the incremental changes; builds and tests were not run.

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

  • Findings: none

  • The last round's findings, at 2bbe473:

    • Fixed: medium, js/net/src/resume.ts:703: Include rerouted copies in the recovery holder lookup; Reader.holding() at js/net/src/resume.ts:1203 now searches rerouted copies newest first, with the regression scenario covered by js/net/src/resume.test.ts:5323.
    • Fixed: medium, js/net/src/resume.ts:499: Mirror preference updates into recovery-only copies; #follow() now includes rerouted copies in preference updates at js/net/src/resume.ts:985 and cursor updates at js/net/src/resume.ts:1006, keeping recovered groups synchronized with the current budget.

kixelated and others added 3 commits November 22, 2026 05:58
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…low-up

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title An ended JS front reader still moves its open groups off a dying route fix(js/net): an ended reader moves its open groups off a dying route Nov 22, 2026
… reader's preferences

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

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Ended readers now retain rerouted copies while groups already handed out still need them. They can use a replacement route to continue those groups, but do not receive new groups from copies served after track end. Readers release obsolete copies and leave the route when no outstanding group needs remain. Regression tests cover route failures, replacement routes, and short-closed groups. The change also removes a proposal document and adds a short-close investigation document.

Merge Risk: Minimal · up to b5af6

This change makes the JS reader keep following its route after a clean track end while groups it already handed out still need data. Those groups can now continue from a replacement route instead of failing. The public API and wire format are unchanged. No concrete merge-blocking defect was established, and regression tests cover the changed behavior.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: an ended JS reader keeps moving its open groups off a route that is dying. The changeset matches this. The resume.ts change lets an ended reader follow the route for g…
Description check Passed The description is related to the changeset. It explains the problem in js/net/src/resume.ts, where an ended reader stopped following its route. It lists the approach, the ported tests in resume.test.…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: an ended JS reader keeps moving its open groups off a route that is dying. The changeset matches this. The resume.ts change lets an ended reader follow the route for groups still being read, and it adds rerouted recovery copies. The title is specific and uses the fix(js/net) convention.

Full details: Description check

Explanation

The description is related to the changeset. It explains the problem in js/net/src/resume.ts, where an ended reader stopped following its route. It lists the approach, the ported tests in resume.test.ts, the model oracle change in resume.model.test.ts, and the deleted quest doc. It also gives validation results and a follow-up for seed 10. The description is detailed and matches the summaries.

Finishing Touches

Simplify code

  • Commit to this branch
  • Create a new PR
  • 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

Recent review info

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: 8a9f77b4-b47a-4aeb-843f-d05f15606e58
Commits

Reviewing files that changed from the base of the PR and between 3d1bb40 and b5af62d.

Files selected for processing: 5

  • js/net/src/resume.model.test.ts
  • js/net/src/resume.test.ts
  • js/net/src/resume.ts
  • quest/m0/nightly/js-ended-reader-routed.md
  • quest/m0/nightly/js-resume-fetched-short-close.md
Files with no reviewable changes: 1

  • quest/m0/nightly/js-ended-reader-routed.md

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

@kixelated
kixelated enabled auto-merge November 22, 2026 14:54

@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 critical issues — two comment touch-ups only.

Approach: sound. The ended reader keeps lazily rerouted copies only for recoveries, and they never hand anything out. That matches Rust's Phase::Finished { routed } without paying anything for an ended reader that reads no group. Because Recover.#replace calls reader.sync() on every loop, a backlog group handed out after the rerouted copies were dropped still gets one on demand.

Reviewed changes

I reviewed the full diff at 3407606, including the interaction with #letGo, Route.leave, Recover.#replace, and the Rust phase it mirrors.

  • Rerouted copies: #reroute subscribes the serving route's copy from the lowest open group whenever the route moves past the reader's copies. #unroute drops superseded or unneeded copies and leaves the route once nothing is read or held.
  • Recovery lookup: Reader.copy() and Reader.holding() now also search #rerouted, and the reader.ended early throw in Recover.#replace is gone.
  • Preferences, cursor, and close: #follow and close() now include rerouted copies.
  • Tests: the model oracle carve-out is removed, seeds 7 and 4 are added to regressions, and three unit tests are ported from Rust.
  • Quests: the finished quest is deleted, and seed 10 is split into js-resume-fetched-short-close.md.

ℹ️ #conclude's doc still says it leaves the route

#conclude no longer calls route.leave(this), but its JSDoc at resume.ts:1717-1720 still reads "settle closed and leave the route". That line is outside the diff hunks, so I can't comment on it inline.

Technical details
# Stale `#conclude` JSDoc

## Affected sites
- js/net/src/resume.ts:1718 — "settle `closed` and leave the route" no longer holds; `#unroute` leaves later.

## Required outcome
- The doc says the reader keeps following the route for the groups still read, and leaves it via `#unroute` once it reads and holds nothing.

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

Comment thread js/net/src/resume.ts Resolved
@moq-bot
moq-bot Bot disabled auto-merge November 22, 2026 15:08
@moq-bot

moq-bot Bot commented Nov 22, 2026

Copy link
Copy Markdown
Contributor

quest land watch: ended this pull request's pick, disarming its auto-merge, since its head 3407606 is held by finding by pullfrog[bot]: This edit left line 43 at 142 characters, past biome's 120-character lineWidth. Biome doesn't reflow comments, so `jus (#9410 (comment)). Push a fix, or answer each by a thread reply or a comment linking its review or decision, then land it again.

(written by quest land watch)

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 critical issues — one earlier doc nit still stands.

Reviewed changes

I reviewed the delta since 3407606.

  • Module doc reflow: 930f0fd rewraps the resume.ts module doc to the line width. It is comment-only and has no behavioral surface.

ℹ️ #conclude's doc still says it leaves the route

#conclude no longer leaves the route, but its JSDoc at resume.ts:1718 still reads "settle closed and leave the route". This is the same note as in the prior review. It is outside the diff hunks, so there is no inline anchor.

Technical details
# Stale `#conclude` JSDoc

## Affected sites
- js/net/src/resume.ts:1718 — "settle `closed` and leave the route" no longer holds; `#unroute` leaves later.

## Required outcome
- The doc says the reader keeps following the route for the groups still read, and leaves it via `#unroute` once it reads and holds nothing.

Pullfrog  | Fix it ➔ | View workflow run | Using claude-sonnet-5-5 | 𝕏

…at its end

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

Copy link
Copy Markdown
Collaborator Author

Addressed Pullfrog's note in b5af62d: #conclude's JSDoc now says it settles closed and that the reader follows the route only for the groups still read, leaving it through #unroute once it reads and holds nothing. Comment-only; the line-width thread was fixed in 930f0fd and is resolved.

(Written by Claude Opus 5.5)

@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.

Reviewed changes

I reviewed the delta since 930f0fd.

  • #conclude doc: the JSDoc no longer says it leaves the route. It now says the reader follows the route only for the groups still read, and #unroute leaves it once it reads and holds nothing. This resolves the earlier doc note. The change is comment-only.

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 558c053 Nov 22, 2026
5 checks passed
@kixelated
kixelated deleted the quest/m0/nightly/js-ended-reader-routed branch November 22, 2026 19:42
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