Skip to content

fix(net): end moq-transport requests stalled on send credit - #7016

Merged
kixelated merged 6 commits into
mainfrom
quest/m1/ietf-request-cancel
Oct 29, 2026
Merged

kixelated merged 6 commits into
mainfrom
quest/m1/ietf-request-cancel

Conversation

@kixelated

@kixelated kixelated commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Every request write in rs/moq-net/src/ietf/subscriber.rs awaited its first encode_message before it watched for cancellation. A peer that withholds send credit could therefore pin a cancelled SUBSCRIBE, FETCH (group or joining), TRACK_STATUS, or SUBSCRIBE_NAMESPACE, along with its state, until the session died. Established REQUEST_UPDATEs and held-subscription pauses had the same blind await.

Approach

  • Each request buffers its message (buffer_message) and flushes it inside the wait that already watches its terminals: validity, gate, demand, live, the joining cancel, or the entry going away. This is the pattern subscribe_tracks already used. The paused SUBSCRIBE in tracks.rs gets the same treatment.
  • The Established loop and the held watch loop flush a buffered update or pause at the top of each wake, so they never block their other ends. write_update and write_forward become the sync buffer_update and buffer_forward, and pause is no longer async.
  • A request cancelled before its message fully left is reset, never FINed: a FIN would hand the peer a truncated message.
    • Writer::close resets with CANCELLED and returns Err(Cancel) when bytes are still buffered. That covers cancel_subscribe, TRACK_STATUS, and joining FETCH.
    • Writer::is_flushed lets the SUBSCRIBE_NAMESPACE and SUBSCRIBE_TRACKS cancel paths reset and skip waiting for the peer's half, since the peer holds nothing.
  • When PUBLISH_DONE ends an Established subscription while an update is still buffered, the cleanup resets instead of FINing. Codex found this in review.
  • A held subscription is handed to a resuming reader only once its writer has flushed, so reader churn under withheld credit buffers at most one resume and its pause. The resumer's handoff wait now also ends when nobody wants the track. Codex found this growth in review.
  • The JoiningTask comment saying a committed header "must still reach the peer" dated from drafts 14/15. Draft 18 limits INVALID_REQUEST_ID to a wrong low bit or a duplicate, and Control::accept tolerates gaps, so a reset is safe. The comment is updated.

Tests use a new ScriptedSession::with_send_window(bytes): each request stream takes 1 byte, then parks for good.

  • The invalid_setup matrix gains SubscribeWrite, StatusWrite, and FetchWrite stages on drafts 18 and 22, each across all four invalidation causes. Every stage asserts the work finishes, sends a CANCELLED reset plus STOP_SENDING, and never sends a FIN. On origin/main all three hang (Pending).
  • New tests cover SUBSCRIBE_NAMESPACE (drafts 18 and 22), joining FETCH (draft 18), and Writer::close.
  • a_stalled_update_resets_when_the_publisher_ends (draft 22) covers an update stalled behind PUBLISH_DONE. Without the guard it panics with finish with unflushed bytes.
  • churn_under_withheld_credit_buffers_one_resume_and_pause (drafts 18 and 22) churns three readers over a held track whose peer stopped reading. The peer drains exactly one resume and one pause; without the gate it drains six updates.

just check passes.

Impact

  • Public API: none.
  • Wire: none. A request cancelled before its message fully left is now reset (CANCELLED) rather than held waiting for credit.

Alternatives

  • Race each first write against a duplicate of the terminal checks. Rejected: it copies every terminal list a second time, which is the drift the lease quest is meant to remove.
  • Have Writer::finish reset when unflushed. Rejected: finish keeps the stream for later poll_closed, so a reset there would leave a dangling writer. Only the consuming close resets.

Choices made without asking

  • Scope reaches past "the first message": Established REQUEST_UPDATEs and held pauses now flush inside their waits too. Without that, cancelling an Established SUBSCRIBE whose update is stalled still pinned it.
  • The held-subscription pause flush has no dedicated stalled-credit test. The Established update flush is covered by the PUBLISH_DONE test above.

Follow-ups

  • The publisher side (rs/moq-net/src/ietf/publisher.rs) has the same blind await: advertise_namespace awaits its PUBLISH_NAMESPACE (and its updates) before watching withdrawal. That was left out to avoid colliding with moq-dev/moq#6999. It is also a candidate for the lease quest.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

kixelated and others added 2 commits October 27, 2026 22:25
Every request write in the IETF subscriber awaited its first message before
watching for cancellation, so a peer withholding send credit pinned a
cancelled SUBSCRIBE, FETCH, TRACK_STATUS, or SUBSCRIBE_NAMESPACE. Each
request now buffers its message and flushes it inside the wait that already
watches its terminals, as SUBSCRIBE_TRACKS did. Established REQUEST_UPDATEs
and held pauses flush the same way.

A request cancelled before its message fully left resets its stream: a FIN
would hand the peer a truncated message. `Writer::close` resets in that case,
and the cancel paths that wait for the peer's half skip the wait.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A cancelled moq-transport request stops writing fix(net): end moq-transport requests stalled on send credit Oct 28, 2026
@kixelated
kixelated marked this pull request as ready for review October 28, 2026 06:03
@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 15 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: c7b23a28-cdc1-4780-9983-c43b81de40a4
Commits

Reviewing files that changed from the base of the PR and between d0145f2 and 1296b87.

Files selected for processing: 7
  • quest/m1/README.md
  • quest/m1/ietf-request-cancel.md
  • quest/m2/ietf-request-lease.md
  • rs/moq-net/src/coding/writer.rs
  • rs/moq-net/src/ietf/subscriber.rs
  • rs/moq-net/src/ietf/subscriber/tracks.rs
  • rs/moq-net/src/lite/test_transport.rs

No actionable comments were generated in the recent review.

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: 8dc18423-af23-4000-97c9-cbf6d45903ed
Commits

Reviewing files that changed from the base of the PR and between bea4214 and d0145f2.

Files selected for processing: 7
  • quest/m1/README.md
  • quest/m1/ietf-request-cancel.md
  • quest/m2/ietf-request-lease.md
  • rs/moq-net/src/coding/writer.rs
  • rs/moq-net/src/ietf/subscriber.rs
  • rs/moq-net/src/ietf/subscriber/tracks.rs
  • rs/moq-net/src/lite/test_transport.rs
Files with no reviewable changes: 2
  • quest/m1/README.md
  • quest/m1/ietf-request-cancel.md

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

Walkthrough

Writer close now aborts when buffered bytes remain. Subscriber request and update paths buffer messages and flush them during response polling. Cancellation before a request is fully flushed resets the stream instead of finishing a partial message. The changes add send-window test support and tests for stalled requests, updates, and track-listing handoffs. Quest documents remove the cancelled-request requirement and update prior-fix references.

Priority: Normal

Merge Risk: Minimal · previous review d0145

No actionable issue was established that would prevent merging after normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title "fix(net): end moq-transport requests stalled on send credit" describes the main change. The PR makes IETF subscriber requests (SUBSCRIBE, FETCH, TRACK_STATUS, SUBSCRIBE_NAMESPACE, REQUEST_U…
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.
Description check Passed The pull request description directly explains the subscriber cancellation, buffering, stream reset, writer, test, and scope changes described in the changeset.
Full details: Title check

Explanation

The title "fix(net): end moq-transport requests stalled on send credit" describes the main change. The PR makes IETF subscriber requests (SUBSCRIBE, FETCH, TRACK_STATUS, SUBSCRIBE_NAMESPACE, REQUEST_UPDATE) stop blocking when a peer withholds send credit, and resets cancelled requests instead of FINing them. The title is concise, specific, and follows conventional commit style.

Full details: Docstring Coverage

Explanation

Docstring coverage is 71.43% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 7 functions across 3 files. (2 skipped: 1 unsupported, 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

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

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 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-29T16:04:53.425805Z 1296b87 New commits
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: daf16d96ec

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread rs/moq-net/src/ietf/subscriber.rs Resolved

@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: daf16d9

Confirmed the existing buffered-update termination finding, rather than duplicating its inline comment: in rs/moq-net/src/ietf/subscriber.rs, an Established REQUEST_UPDATE can remain buffered when End::Done reaches the unconditional writer.finish() cleanup. This violates the writer invariant and panics in debug builds. Use the flushed-versus-reset handling already present in the held watcher, and add a stalled-update + peer-end regression test.

Overall direction is sound: flushing inside the existing terminal-aware waits avoids duplicating cancellation checks, and resetting incomplete requests is preferable to FINing truncated messages. No additional actionable bugs found in the changed paths.

Verification: static inspection of the changes, surrounding cancellation/cleanup paths and new tests only. I did not run tests; the new stalled-initial-write tests do not exercise the Established-update termination above.

…update

PUBLISH_DONE can end an Established subscription while a REQUEST_UPDATE the
peer's send window held back is still buffered. The cleanup FINed the
stream regardless, tripping Writer::finish's unflushed assertion and, in
release builds, handing the peer a truncated update. Reset instead, as the
held watcher does.

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 55e9adf17c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@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: 55e9adf

Fixed: the previously referenced buffered-update termination panic. The Established cleanup now checks is_flushed() before FIN and otherwise resets, with a regression covering a partially sent update followed by PUBLISH_DONE.

Still actionable: I confirm the independent P2 held-handoff buffer growth finding. tracks.rs hands off a writer despite pending flush; repeated resume/cancel cycles append more forward/pause updates to that same stalled stream. Bound or coalesce those updates while retaining prompt cancellation, and test repeated churn under withheld credit. This was already present in the prior reviewed head, not introduced by this fix; my earlier review missed it. Referencing the existing thread rather than duplicating an inline comment.

Direction: the targeted cleanup fix is appropriately small and reuses the held-watcher invariant. No additional actionable bugs found in this delta. Verification was static inspection of the one-commit delta, regression test, and related handoff paths; I did not run tests.

Under withheld send credit, each resume a reader abandoned appended another
REQUEST_UPDATE pair to the held stream's buffer, growing it with subscriber
churn. The held watcher now hands the subscription over only once its
writer has flushed, bounding the buffer to one resume and its pause, and the
resumer stops waiting for that handoff once nobody wants the track.

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

@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: d0145f2

The previously referenced held-handoff buffer growth finding is addressed: the watcher now requires a flushed writer before handing it over, while the waiting resumer can abandon on lost demand. The new draft-18/22 churn regression checks prompt abandonment and only one resume/pause pair. The earlier termination-panic fix remains intact.

No new actionable bugs found in this delta. Backpressuring the handoff is a focused, simpler alternative to rewriting partially sent messages; cancellation and entry-removal handling remain available while flushing is stalled.

Verification: static inspection of the one-commit delta, surrounding handoff/demand cleanup and regression tests. I did not run tests.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merging at d0145f2 (maintainer picked merge).

  • Request writes (SUBSCRIBE, FETCH, joining FETCH, TRACK_STATUS, SUBSCRIBE_NAMESPACE) plus Established REQUEST_UPDATEs and held pauses now flush inside the wait that watches their terminals, so withheld send credit can no longer pin a cancelled request. A request cancelled before its message fully left is reset with CANCELLED, never FINed.
  • Both Codex findings are fixed and resolved: the PUBLISH_DONE cleanup resets when an update is still buffered (55e9adf), and a held subscription is handed off only once flushed, bounding churn to one resume and pause (d0145f2). Codex re-reviewed the head with no findings.
  • Public API and wire: none.
  • Follow-up: the publisher side (advertise_namespace in rs/moq-net/src/ietf/publisher.rs) has the same blind await, left out to avoid colliding with moq-dev/moq#6999.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 28, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Oct 28, 2026
kixelated added a commit to michaelstuurman/moq that referenced this pull request Oct 28, 2026
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated

Copy link
Copy Markdown
Collaborator Author

Merged main to clear the conflict that took this out of the merge queue (1296b87).

  • One textual conflict in next_namespace_message (rs/moq-net/src/ietf/subscriber.rs): kept this PR's flush before reading.
  • Semantic fixes for moq-dev/moq#7042, which made Writer::poll_flush take a &kio::Waiter: the PR's poll_fn(|cx| …poll_flush(cx)) calls became kio::wait(|waiter| …poll_flush(waiter)), the in-poll calls pass the waiter they already had, and the Writer::close test polls with kio::Waiter::noop().

No behavior change. cargo test -p moq-net, cargo clippy -p moq-net --all-targets -D warnings, and cargo fmt --check pass.

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit e072cf6 Oct 29, 2026
11 checks passed
@kixelated
kixelated deleted the quest/m1/ietf-request-cancel branch October 29, 2026 19:53
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