Skip to content

fix(qmux): serialize credit updates and accept stale limits - #451

Merged
kixelated merged 4 commits into
moq-dev:mainfrom
spotdemo4:quest/a0/qmux-credit-updates
Oct 23, 2026
Merged

kixelated merged 4 commits into
moq-dev:mainfrom
spotdemo4:quest/a0/qmux-credit-updates

Conversation

@spotdemo4

@spotdemo4 spotdemo4 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Completes quest/a0/qmux-credit-updates and deletes it.

Mechanism

Credit::consume computed the new absolute limit under the credit mutex, but every caller queued the MAX_DATA / MAX_STREAM_DATA / MAX_STREAMS frame only after the lock was released. With concurrent consumers (for example, RecvStream drops on different worker threads), a smaller limit could be queued after a larger one. The receiver treated the non-increasing value as FlowControlError and closed the session with 1002.

Changes

  • Sender (Rust): Credit::consume(len, control, frame) now queues the update on the unbounded control channel before it releases the lock, then wakes waiters after unlocking. This covers all four call sites: report_consumed (MAX_STREAM_DATA and MAX_DATA), Drop for RecvStream (MAX_STREAMS), and the RESET_STREAM gap and reset-first retirement paths. The closure only builds a frame, and the unbounded send never blocks, so the only new lock edge is credit → channel. No path takes a credit lock while holding the channel.
  • Receiver (Rust and TS): increase_max / increaseMax now ignore a non-increasing limit without changing credit or waking waiters, as RFC 9000 §19.9–§19.11 require. TypeScript already discarded the old false return value, so its behavior there doesn't change. Transport-parameter seeding never relied on the error.
  • Validation applied before ignoring (Rust and TS): MAX_STREAMS above 2^60 is a FRAME_ENCODING_ERROR (§19.11), checked in both the bare-frame and record decoders. MAX_STREAM_DATA on a receive-only stream is rejected (§19.10); Rust reports InvalidStreamId, as it already does for STOP_SENDING. Genuine receive-side flow-control violations still error, and the existing tests for them pass.

Compatibility: no public API changes, and wire encodings are unchanged. Accepted peer input changes as follows: stale limits are now ignored instead of closing the session, while MAX_STREAMS > 2^60 and MAX_STREAM_DATA on a receive-only stream now close it. Main only: no 0.5 backport and no version bump.

Tests

Regression Fails without the fix?
credit::tests::concurrent_updates_are_queued_in_increasing_order: pauses the first consumer inside its frame closure, asserts the credit lock is still held, then checks that a racing second consumer queues after it Yes: a send-after-unlock variant of consume fails 20 out of 20 runs on the lock assertion (no timing dependence)
credit::tests::non_increasing_limits_are_ignored_without_waking Covers the receive-side increase_max change
session::credit_update_tests::*: scripted peer, QMux00/01/02, uni and bidi; lower, equal and higher MAX_STREAMS / MAX_DATA / MAX_STREAM_DATA; 2^60 bound; receive-only MAX_STREAM_DATA Yes, all 3 fail on main (the stale-limit test fails because the session closes)
wire_format_tests::max_streams_above_2_60_rejected New bound
TS credit.test.ts, frame.test.ts, session.test.ts The 4 new validation tests fail without the TS change; the stale-limit test documents existing TS behavior
tests/credit_updates.rs: TCP loopback, multi-thread runtime, 32 tasks × 100 rounds of bidi echo plus uni sends with small windows, QMux00/01/02 Under parallel load (8 concurrent binaries): 46 of 103 binaries failed on main (flow control error on all three versions, plus 10 stalls; see below). 0 of 104 failed with the fix.

The stalls on main matched the receive hang in the second half of #439, which #437 has since fixed on main for any terminal teardown with a retained Session. This PR removes the session close that triggered it in this scenario.

Benchmark

cargo bench -p qmux --bench credit: bidi echo with 16 MAX_STREAMS and a 16 KiB MAX_DATA window over an in-memory duplex, QMux02, release build. The table shows streams/s, two alternating runs each:

sessions tasks/session main fix
1 1 92k / 88k 83k / 92k
1 16 164k / 162k 155k / 159k
1 64 168k / 166k 166k / 156k
4 1 384k / 438k 429k / 408k
4 16 556k / 534k 535k / 550k
4 64 517k / 492k 510k / 504k
16 1 1.02M / 1.12M 1.09M / 0.93M
16 16 1.22M / 1.21M 1.28M / 1.25M
16 64 0.91M / 1.09M 1.09M / 1.09M

All differences are within run-to-run variance; holding the lock for the channel push costs nothing measurable.

Coordination

Validation

  • Passed: cargo test -p qmux --all-targets --all-features, qmux doctests, bun run --cwd js/qmux test (164), and test:interop.
  • Passed: cargo clippy -p qmux --all-targets --all-features -D warnings, cargo hack check --feature-powerset -p qmux, cargo fmt --check, cargo sort --check, cargo shear, and the Biome / tsc checks (Biome reports the same 3 warnings as on main).
  • After merging main (maintainer side): just fix (no changes), just check, just test, cargo test -p qmux --all-targets --all-features, bun run --cwd js/qmux test (166), test:interop, and quest check all pass.

Suggested follow-ups

  • Reject initial_max_streams_{bidi,uni} transport parameters above 2^60 with TRANSPORT_PARAMETER_ERROR (RFC 9000 §18.2), in both Rust and TS.
  • Apply the RFC 9000 §19.5/§19.10 stream-state checks to MAX_STREAM_DATA and STOP_SENDING for locally initiated streams that aren't open yet. Also add the TS STOP_SENDING direction check that Rust already has.

Closes #439

(written by claude-opus-5-5)

@spotdemo4

Copy link
Copy Markdown
Contributor Author

Implementation complete at 54c6637. No open design decisions. The contributor chose to proceed to review and merge (/quest-merge) and to keep the suggested follow-ups (transport-parameter 2^60 bound, stream-state checks) in the description only, without planning them as quests for now.

(written by claude-opus-5-5)

@spotdemo4
spotdemo4 marked this pull request as ready for review October 20, 2026 19:32
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 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 ⚠️ Failed 2026-10-23T22:58:10.934868Z
We couldn’t complete this review. Comment @codex review to try again.
084aa63 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.

Concurrent receive consumers computed a new MAX_DATA, MAX_STREAM_DATA or
MAX_STREAMS limit under the credit lock but queued the frame after
releasing it, so a smaller limit could overtake a larger one. The peer
rejected the non-increasing value as a flow-control error and closed the
session. `Credit::consume` now queues the update before unlocking.

Received non-increasing limits are ignored, as RFC 9000 §19.9-§19.11
require. MAX_STREAMS above 2^60 is rejected as a FRAME_ENCODING_ERROR and
MAX_STREAM_DATA on a receive-only stream is rejected, in both the Rust
and TypeScript peers.
@spotdemo4
spotdemo4 force-pushed the quest/a0/qmux-credit-updates branch from 54c6637 to 1bdcc78 Compare October 20, 2026 19:32
@spotdemo4

Copy link
Copy Markdown
Contributor Author

https://github.com/kixelated/quest is really cool btw

@coderabbitai

coderabbitai Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: a9756c04-253e-4ac9-b722-1228b36e1b22
📥 Commits

Reviewing files that changed from the base of the PR and between 1bdcc78 and 981c1d0.

📒 Files selected for processing: 1
  • rs/qmux/src/credit.rs

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

Walkthrough

Rust and TypeScript QMux credit handling now ignores non-increasing limits. Rust queues qualifying window-update frames through Credit::consume. Rust and TypeScript decoders reject MAX_STREAMS values above 2^60. Session handling rejects MAX_STREAM_DATA for receive-only streams. The changes add unit, session, wire-format, TCP stress, and benchmark coverage. The QMux credit-update quest and its README entry were removed.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 981c1

No actionable merge-blocking issue is established; the change is mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 52.94% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 51 functions across 12 files. 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 accurately summarizes the main changes: serializing credit updates and accepting stale limits.
Linked Issues check Passed Issue #439 requires ordered credit updates and stale-limit handling. Rust Credit::consume queues each update while holding the credit lock, which orders concurrent MAX_DATA, MAX_STREAM_DATA, and MAX…
Out of Scope Changes check Passed The MAX_STREAMS 2^60 validation and receive-only MAX_STREAM_DATA checks preserve related protocol validation while stale updates are accepted. Their tests support issue #439. The benchmark, stress t…
Description check Passed The pull request description directly matches the changeset. It explains serialized credit updates, stale-limit handling, validation changes, tests, benchmarks, and quest deletion.
Full details: Linked Issues check

Explanation

Issue #439 requires ordered credit updates and stale-limit handling. Rust Credit::consume queues each update while holding the credit lock, which orders concurrent MAX_DATA, MAX_STREAM_DATA, and MAX_STREAMS frames. Rust and TypeScript increase_max/increaseMax ignore non-increasing limits without changing credit or waking waiters. The added unit, session, wire-format, TypeScript, and TCP stress tests cover these behaviors. The reported stress result is 0 failures with the fix. Transport-parameter seeding remains handled separately from stale peer updates.

Full details: Out of Scope Changes check

Explanation

The MAX_STREAMS 2^60 validation and receive-only MAX_STREAM_DATA checks preserve related protocol validation while stale updates are accepted. Their tests support issue #439. The benchmark, stress tests, TypeScript coverage, and quest deletion support the stated implementation and completion scope. No unrelated change is demonstrated by the supplied evidence.

✨ Finishing Touches
✨ Simplify code
  • 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 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: 54c6637f97

ℹ️ About Codex in GitHub

Codex has been enabled to automatically 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 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread rs/qmux/src/credit.rs Resolved
…egression

Replace the bounded wait with a try_lock while the first consumer is paused
inside its frame closure, so a send-after-unlock implementation fails on
every run instead of only when the second thread is scheduled in time.
@spotdemo4

Copy link
Copy Markdown
Contributor Author

@kixelated this is ready for review. The CI workflows for this fork PR are waiting for maintainer approval (action_required); could you approve them? The one Codex finding (a timing-dependent regression test) is fixed in 981c1d0.

(written by claude-opus-5-5)

Resolve conflicts with moq-dev#437 and moq-dev#453:

- rs/qmux/src/session.rs: keep main's Streams::open, which seeds a new
  stream's send credit and refuses registration after teardown, and adapt
  its increase_max call to the infallible signature.
- quest/a0/README.md: drop both the Noq close cancellation entry (landed
  in moq-dev#453) and the QMux credit updates entry (completed here).

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

Copy link
Copy Markdown
Collaborator

Merge summary (maintainer-approved /quest-merge):

  • Merged main into the branch (084aa63) instead of rebasing, to keep the contributor's history. Conflicts:
  • PR body updated: fix(qmux): release stream waiters at terminal teardown #437 and fix(qmux): refuse over-limit stream creates #433 are merged, and the full workspace checks now ran.
  • Codex P1 (timing-dependent test): verified fixed in 981c1d0. The test asserts the credit lock is held via try_lock and doesn't sleep. Against a send-after-unlock consume it fails on that assertion. Thread resolved.
  • Local: just fix (no changes), just check, just test, cargo test -p qmux --all-targets --all-features, bun run --cwd js/qmux test (166 pass), test:interop, quest check. CI on 084aa63: all four checks pass after approving the fork runs.
  • Follow-ups from the description, not planned as quests yet: reject initial_max_streams_{bidi,uni} > 2^60 transport parameters, and add the RFC 9000 stream-state checks for MAX_STREAM_DATA / STOP_SENDING on not-yet-open local streams, including a TS STOP_SENDING direction check.

(Written by Opus 5.5)

@kixelated
kixelated merged commit cb0930e into moq-dev:main Oct 23, 2026
4 checks passed
@moq-bot moq-bot Bot mentioned this pull request Oct 23, 2026
@moq-bot moq-bot Bot mentioned this pull request Oct 23, 2026
kixelated added a commit that referenced this pull request Oct 24, 2026
* quest(a0): plan QMux RFC 9000 peer-input checks

Two follow-ups from #451: bound initial_max_streams transport
parameters at 2^60, and refuse MAX_STREAM_DATA/STOP_SENDING for
unopened locally initiated streams.

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

* quest(a0): pin 1002 close code and peer-stream scope in QMux checks

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

---------

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

qmux: MAX_STREAMS (and MAX_DATA) updates can be queued out of order, and a lower value is treated as a flow control error

2 participants