Skip to content

fix(net)!: a local session close cancels received tracks like a remote close - #7081

Merged
moq-bot[bot] merged 9 commits into
mainfrom
quest/m1/cut-audit/js-close-cause
Oct 30, 2026
Merged

moq-bot[bot] merged 9 commits into
mainfrom
quest/m1/cut-audit/js-close-cause

Conversation

@kixelated

@kixelated kixelated commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Finishes quest/m1/cut-audit/js-close-cause.md and deletes it with its link in the cut-audit epic.

moq-dev/moq#6978 left one choice open: whether a deliberately closed session's received tracks end cleanly or abort. The maintainer picked aborting, on a general rule: "I don't like stuff working differently locally and remotely." So a local close now ends received tracks exactly as the peer's clean close does, in Rust and JS, and moq-net's AGENTS.md states the rule.

What a session close looked like before

Measured with the integration tests below, before this change:

Remote clean close Local close
Rust track Error::Session(Cancel) clean end (Ok(None))
Rust unfinished group Error::Session(Cancel) lite: Error::Stream(StreamError::Session(Cancel)); IETF: Error::Session(Cancel)
JS track SessionError(SessionCode.Cancel) null, no end declared
JS unfinished group SessionError(SessionCode.Cancel) StreamError(StreamCode.Cancel)
JS lite fetch / setup exchange SessionError(SessionCode.Cancel) StreamError(StreamCode.SessionClosed)

After this PR, the local column matches the remote column everywhere: a session-cancel error, not a stream CANCELLED. The quest's alternative proposed StreamCode.Cancel; I went with the session code because the remote path produces it and the instruction was to match remote exactly.

Changes

  • Rust: the lite and IETF subscribers lose their separate close() path. A local close (drop or drain) now runs the same teardown a remote close does: drain what already arrived, then abort with Error::Session(SessionError::Cancel). Before, it skipped the drain, so a pending lite FETCH ended Error::Dropped. resume.rs no longer maps a copy that ended with Stream(Session(Cancel)) to a clean track end, and origin.rs drops its matching TrackIo::closed flag. The IETF filled head now settles to Fill::Done on any session end, not only a local one, so both paths leave it in the same state.
  • JS: lite Subscriber.close(err) aborts tracks, fetches, and setup exchanges with err, which defaults to SessionError(SessionCode.Cancel). Connection.abort() no longer ends received tracks itself; #run drains what arrived and then fails them with the session's close, as on a remote close, so a track whose SUBSCRIBE FIN was already in flight still finishes. #runSubscriptionUpdates's stopped promise also resolves when the subscribe stream errors: it used to reject with nothing listening once the session closed (an unhandled rejection on main too, when the peer closes), and the response stream still decides the track's error. The IETF subscriber's #localClose flag and close() are gone, so a local close goes through the same sessionCause path as a remote one.
  • Resume still continues past the cancelled copy: a session error is a route failure (route_failed / routeFailed), so a replacement route takes over. resume.test.ts "a replaced copy whose session closed binds no end" now cancels the copy with the session error.
  • Tests: subscription_end_integrity.rs and integration.test.ts assert that a remote and a local clean close give the same session-cancel error on the track and its open group (lite-03/05/07, IETF 18/22 in Rust; lite-03/05, IETF 18 in JS). In Rust, a pending lite-05/07 FETCH gets the same error from either side's close. In JS, connection.test.ts checks that a local close drains a SUBSCRIBE FIN sent first (lite-01 to 04). Both new tests fail without the drain. Lite fetch-cut and auth-close tests move to the session error.
  • rs/moq-net/AGENTS.md gets the rule: local and remote paths behave the same. It also drops "or the local session closing" from what counts as a clean end. js/net/AGENTS.md is new (no @moq/net agent file existed) and carries the same rule.

Impact

  • Public API (breaking, Rust and JS): after a deliberate local session close, received tracks, their unfinished groups, and pending lite fetches end with the session-cancel error (Error::Session(SessionError::Cancel) / SessionError with SessionCode.Cancel), as on a remote clean close, not cleanly. To migrate, treat a session-cancel error on a track as the session going away, as you already have to for the remote case. JS lite Subscriber.close() (internal) takes an optional error; the IETF Subscriber.close() (internal) is removed.
  • Wire: none.

Decisions

  • Received track on a deliberate local session close:
    • Keep the clean, end-less route close.
    • ✅ Abort it the way a remote close does (maintainer's pick: local and remote must not differ).
  • Error the local close uses: the brief named StreamCode.Cancel, but a remote close yields the session-cancel code in both languages, so local uses that to match remote exactly.

Follow-ups

  • The earlier follow-up ("JS vs Rust on a peer's clean session close") is dropped: the probes show both already give the session-cancel error. Rust's clean mapping only matched the local close's Stream(Session(Cancel)).

Review

  • Reviewer: Codex (T3 delegate), GPT-6.1 Sol, high effort. The installed quest has no review command, so this stands in for /quest-review.
  • 0adb5ca6a6: two findings, both fixed in 137291761d:
    • JS lite local abort ended received tracks before draining, so a track whose FIN was queued aborted. Fixed: abort() leaves them to #run's drain-then-fail.
    • Rust lite local close skipped poll_drain, so a pending FETCH ended Dropped. Fixed: Rust lite and IETF drain on either side's close.
  • 137291761d: no significant findings.

Checks on 137291761d: just check passes, cargo test -p moq-net passes, and bun test in js/net passes (2641/2641).

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

@kixelated kixelated changed the title Settle received-track termination on a local session close quest: keep a locally closed session's received tracks ending cleanly Oct 28, 2026
@kixelated kixelated changed the title quest: keep a locally closed session's received tracks ending cleanly fix(net)!: a local session close cancels received tracks like a remote close Oct 30, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

Design change: this PR now implements the alternative instead of keeping the clean local close. The maintainer's rule: "I don't like stuff working differently locally and remotely."

A deliberate local session close now ends received tracks, their unfinished groups, and pending lite fetches the way the peer's clean close does, in Rust and JS. Measured, that is the session-cancel error (Error::Session(SessionError::Cancel) / SessionError with SessionCode.Cancel), not StreamCode.Cancel as the earlier body proposed, so local uses the session code to match remote exactly. Local close also runs the remote path's drain now, so a track whose end already arrived still finishes and a pending fetch is cut off the same way. Rust's resume.rs / origin.rs clean-end mappings for the locally closed copy are gone. Resume still treats the cancelled copy as a failed route and continues on a replacement. rs/moq-net/AGENTS.md and a new js/net/AGENTS.md state the rule: local and remote paths behave the same.

(Written by Claude Opus 5.5)

@kixelated
kixelated marked this pull request as ready for review October 30, 2026 04:22
@coderabbitai

coderabbitai Bot commented Oct 30, 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 47 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: dd7fc27f-1ede-4f45-a4fa-4002d82b37eb
Commits

Reviewing files that changed from the base of the PR and between 6aad622 and 1372917.

Files selected for processing: 29
  • js/net/AGENTS.md
  • js/net/src/auth.test.ts
  • js/net/src/goaway-requests.test.ts
  • js/net/src/ietf/connection.ts
  • js/net/src/ietf/peer-violations.test.ts
  • js/net/src/ietf/subscriber.test.ts
  • js/net/src/ietf/subscriber.ts
  • js/net/src/integration.test.ts
  • js/net/src/lite/connection.test.ts
  • js/net/src/lite/connection.ts
  • js/net/src/lite/subscriber.test.ts
  • js/net/src/lite/subscriber.ts
  • js/net/src/request-deadline.test.ts
  • js/net/src/resume.test.ts
  • js/net/src/session-limits.test.ts
  • js/net/src/track.ts
  • quest/m1/cut-audit/README.md
  • quest/m1/cut-audit/js-close-cause.md
  • rs/moq-net/AGENTS.md
  • rs/moq-net/src/ietf/session.rs
  • rs/moq-net/src/ietf/subscriber.rs
  • rs/moq-net/src/lite/session.rs
  • rs/moq-net/src/lite/subscriber.rs
  • rs/moq-net/src/model/origin.rs
  • rs/moq-net/src/model/resume.rs
  • rs/moq-net/src/model/track.rs
  • rs/moq-net/src/session.rs
  • rs/moq-net/tests/integration/subscription_end_integrity.rs
  • test/interop/ietf-compression.ts
  • 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

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-30T04:23:36.463453Z 1372917 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed commit: 137291761d93a4149b7c86c18abcd19752186363.

No actionable bugs found. Using the session-cancel cause for both deliberate local and peer clean closure implements the stated parity decision without inventing a content end. Draining buffered streams before aborting preserves an already-arrived FIN and pending FETCH cleanup; resume still treats the cancellation as a failed route eligible for replacement. The subscription-update stop promise now handles stream rejection without overriding the response path's terminal cause.

Direction: consolidating teardown is simpler than preserving a local-only clean-end exception. The added local/remote track/group and pending-FETCH regressions, plus the local FIN-drain check, target the important boundaries. This is an intentional observable API change, not a wire change.

Verification limits: GitHub-only static review of Rust/JS teardown, fill/resume behavior and tests, with an independent Rust pass. I did not run builds, tests or live transport/browser checks; author-reported results were not reproduced.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge summary for head 137291761d93a4149b7c86c18abcd19752186363:

  • Review: the PR body's ## Review record covers this head (Codex, GPT-6.1 Sol, high effort; no significant findings), and the automated OpenAI review and Codex connector on this head found nothing actionable. CodeRabbit was rate-limited and is optional.
  • quest check --base origin/main on the head passes (672 documents), and the head merges cleanly into current main.
  • No open decisions: the maintainer picked aborting received tracks on a local close (see the Design change: comment), and picked /quest-merge for this PR.

Queuing for the merge queue.

(Written by Claude Opus 5.5)

kixelated and others added 9 commits October 30, 2026 08:32
* chore(quest): claim quest/m1/resume-model-test.md

Quest-Claim: 7bff411939571787

* test(net): check resume against a model of one logical track

A seeded proptest drives an origin's fronts through route flips, route
failures, give-ups, ranges, cache expiry, a newer epoch, and reader joins
and leaves on the simulated clock, and checks every reader's groups,
frames, drops, and end against a plain cursor on the logical track.

Fixes what it found:
- An ordered reader never ended once a finished track left nothing in
  its range, or the rest of the range was given up.
- A drop poll with local bounds below the subscription's floor built a
  reversed span and panicked.
- A resumed reader held a drop back for a replaced copy kept only to back
  a group still read, and was not woken once that read finished.

* test(net): check JS resume against the logical-track model

Mirror rs/moq-net's resume model as a fast-check property over the same
ops, constants and checks, seeded by MOQ_RESUME_SEED and sized by
MOQ_RESUME_CASES (default 64).

It found three bugs, each fixed with a regression case:
- A replacement copy's refusal ended a group the serving route still
  delivered; it is a verdict only once that route won't land it either.
- A failed copy's cache eviction released a group recovering from
  another copy; only the copy a mirror reads from reclaims it.
- A reported drop was final, so a group a later copy delivered was
  never handed out; the report is now once and not final.

* ci: sweep the resume model nightly from a fresh seed

* test(net): answer route fetches in the resume model

A real route forwards a fetch for a group it lacks to the publisher. The
model's routes refused every fetch, so a group continued across a
failover read NotFound although the instance carried it.

* test(net): let model routes hold a tail fill beside the live copy

A frame-bounded fetch caches a partial copy of a group, so a later
whole-group fetch must still be answered. A group a reader stitched
from two copies is complete once any copy wrote its last frame.

* fix(net): keep a recovered group when its old copy is let go

Releasing a copy's subscription released every mirror it cached,
including a group recovery had already moved to another copy, which
then ended cleanly short of its frames. The JS model's routes now
answer fetches, which exposed it.

* quest: finish resume-model-test, plan delivering late groups below the resume point

The maintainer kept the resume point policy on #6947; delivering the
late lower groups is a nice-to-have follow-up in m2.

* test(net): request the model's broadcast through the renamed origin API

* test(net): resume readers only on a route Up or Down actually changes

* test(net): restore Recover's refusal wait, and resume Rust readers only when the cheapest route changes

The main merge took main's whole resume.ts and dropped the PR's Recover hunk.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(quest): claim quest/m1/quic-api/streams.md

Quest-Claim: 3067217ff870abc5

* wip(quic): namespace moq-quic streams as send, recv, and stream

send::{Stream, Offset, End, Options, Group, Groups, Error}, recv::{Stream,
Lease, Chunks, Error}, and stream::{Id, Dir}. Writes take Buf, a lease moves
its chunks out and holds no borrow, send ends stay queryable until released,
and datagrams chain chunks without copying.

* wip(qmux): use moq-quic send ends and Buf writes

* wip(tokio): namespace the QUIC driver as send, recv, and stream

send::{Stream, Finished, Group, Options, Offset, Error} with finish(self)
typestate and consuming resets, recv::{Stream, Lease, Error} with a lease
that owns its bytes and holds no lock, Buf writes and BufMut reads, and
datagrams that chain a header. quic::web collapses onto one error per
direction. moq-quic only reruns the stuck pass on restore when an out lease
held it off.

* wip(uring): namespace the QUIC driver as send, recv, and stream

* wip(uring): port tests and moq-relay to the namespaced driver

* wip(uring): format

* wip(quic): name the namespaced stream API in the fork notes

* wip(quic): fix a stale doc link

* chore(quest): finish quic-api/streams

* fix(quic): keep terminal stream state across the review's lifecycle gaps

- moq-tokio and moq-uring cache a reset `received_reset` reports, since
  moq-quic frees the stream then, so later reads and leases fail with it
  instead of panicking.
- moq-uring's web `poll_closed` observes a clean FIN again through an empty
  read, instead of a reset-only query that waits forever.
- moq-uring's web `finish` keeps a finished stream's handle when called again.
- qmux resets an unfinished stream on drop before releasing its ID, which
  refused the reset.

* fix(quic): size a datagram before taking its payload

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
… on moq-dev pairs (#7073)

* chore(quest): claim quest/m0/smoke-released.md

Quest-Claim: 1a9318c095d636e0

* fix(smoke): hold the Cloudflare probe's track reader

The probe dropped its TrackReader, so when the relay rejected an early
SUBSCRIBE with DoesNotExist, cloudflare/moq-rs failed to close the track
and resolved the subscription as done. The harness then failed the cell
instead of retrying the readiness race.

Also rewrite the smoke-released quest to the classified runner failures.

* fix(smoke): gate the upstream runner on moq-dev pairs only

Only moq-dev-rs and moq-dev-js against this checkout's relay fail the
Upstream Docker interoperability job; every other pair is reported, as
relays.sh treats non-moq-dev relays. A required pair the registry stops
pairing fails too. With the Cloudflare probe fix this finishes the quest,
so delete it.

* fix(smoke): annotate optional runner failures; record the moq-rs close bug

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(quest): claim quest/m0/nightly/quic-rustdoc.md

Quest-Claim: 0a0d799823f82f7f

* fix(quic): unbreak moq-quic's all-features rustdoc

The fuzz-gated bench map linked to the private SentPackets type, which
fails rustdoc under -D warnings. Nightly's features lane already builds
workspace rustdoc with --all-features, so no new lane is needed.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(quest): claim quest/m0/ci/tracing-filter.md

Quest-Claim: a26a0b73687228f9

* wip: stop forcing tracing-test's no-env-filter

* chore(quest): finish quest/m0/ci/tracing-filter.md

* test: keep captured spans enabled beside parallel tests

With one dispatcher registered, tracing-core caches a callsite's interest
from the thread that first hits it. A parallel test without a subscriber
then disabled the `srt` ingest span for the capturing test, so
`publisher_reports_a_silent_pid` failed about two runs in three under
`cargo test`. A second, no-op dispatcher makes every callsite ask the
current thread's subscriber.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore: point quest and rust2 references at moq-dev

Both repositories moved from the kixelated account to the moq-dev
organization. The flake input keeps the same revision and hash.
Generated quest skills refresh with the next quest bump.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
* chore(quest): claim quest/m0/ci/mbx-r2-verify.md

Quest-Claim: 9a556a77ba203b39

* quest(m0/ci): record the first mbx 1.28 Nightly in the R2 verify quest

The bump's checks passed: every hosted Nightly job writes, macOS refused
only an already oversized manifest, and the merge queue shows no E0463.
Reuse is still absent on every platform; record the lockfile-identity
evidence and narrow the quest to what remains.

* ci(platform): install uniffi-bindgen-cpp after the Rust build

The Nightly Windows build loaded the install's 124-prediction mbx
manifest under its own identity on 2026-10-27 and 2026-10-28, which
blocked inheriting the previous lockfile's manifest. Installing after
the build lets the build inherit first. Reported upstream as
jdx/mr-boxington#869.

* quest(m0/ci): record upstream's CRLF cause for the Windows cache miss

jdx/mr-boxington#870 traced the Windows miss to CRLF lockfile digests,
not the uniffi-bindgen-cpp install, and the macOS build did inherit.

* quest(m0/ci): revert the uniffi-bindgen-cpp step move, record settled decisions

#870 showed the Windows miss comes from CRLF lockfile digests, not the
install order, so platform.yml keeps main's order. Windows now waits on an
mbx release with #870 and a pin bump; Linux full history waits on Windows
hitting; lockfile churn past 8 states counts under the rebuild item.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…pshot before parsing (#7072)

* chore(quest): claim quest/m0/ci/stats-oversize.md

Quest-Claim: 4a6d2df5874a8c48

* perf(json): refuse an oversized snapshot before parsing or compressing it

* chore(quest): finish quest/m0/ci/stats-oversize.md

* feat(json): a public snapshot group budget, refusing a snapshot past it before parsing

snapshot::Config gains max_group_bytes (JS maxGroupBytes, no longer
internal), clamped to moq-net's cache limit. The encoder refuses a
snapshot past it before the baseline parse, so moq-stats' oversize tests
lower it to 64 KiB under test instead of building 32 MiB of stats.

* chore(json): regenerate the API report for maxGroupBytes

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…e close (#7081)

* chore(quest): claim quest/m1/cut-audit/js-close-cause.md

Quest-Claim: a1a64f23c30db61e

* quest: keep a locally closed session's received tracks ending cleanly

The received track's local-close outcome already mirrors Rust and is pinned by
tests, so the quest has nothing left to implement.

* fix(net)!: a local session close cancels received tracks like a remote close

A deliberate local close now ends received tracks, their open groups, and
pending lite fetches with the session-cancel error a peer's clean close
produces, in Rust and JS. moq-net's AGENTS.md (and a new js/net/AGENTS.md)
state the rule: local and remote paths behave the same.

* fix(net): a local close drains what arrived, as a remote close does

Rust lite and IETF and JS lite skipped the receive drain on a local close,
so a pending lite fetch ended Dropped and a track whose FIN was already
buffered aborted instead of finishing. Both closes now share one teardown.
The lite JS update loop no longer leaves a rejected stopped promise
unobserved when the session closes under it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@moq-bot
moq-bot Bot force-pushed the quest/m1/cut-audit/js-close-cause branch from 1372917 to 83e1479 Compare October 30, 2026 08:33
@moq-bot
moq-bot Bot merged commit 83e1479 into main Oct 30, 2026
8 checks passed
@moq-bot
moq-bot Bot deleted the quest/m1/cut-audit/js-close-cause branch October 30, 2026 08:33
kixelated added a commit that referenced this pull request Oct 31, 2026
Keep the always-abort cleanup path and drop SubscriberDriver::close, which
#7081 folded into abort.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant