Skip to content

fix(net): session auth replies revoke and stay bounded - #8198

Merged
kixelated merged 8 commits into
mainfrom
quest/m1/auth-stream-bounds
Nov 8, 2026
Merged

kixelated merged 8 commits into
mainfrom
quest/m1/auth-stream-bounds

Conversation

@kixelated

@kixelated kixelated commented Nov 7, 2026 •

Copy link
Copy Markdown
Collaborator

Completes quest/m1/auth-stream-bounds.md: moq-net's session-side auth keeps four promises it left to callers.

Changes

  • An AUTH_ERROR revokes its grant. When an AUTH_OK is too large to encode, both drivers (lite/publisher.rs, ietf/auth.rs) send AUTH_ERROR and now call Issue::refused(). That clears the outbox and calls finish(), so the grant reply() recorded leaves the session's scope. Before, they set done = true directly and the grant kept admitting requests. Issue::outbox and Issue::done are now private, so a driver can no longer end a stream without finish().

  • Queued replies are bounded. Issue::queue replaces a grant that is still queued (the peer never saw it) instead of appending. The app's Issued::update and the default acceptor's re-sent grants both go through it, so a peer that withholds stream credit holds at most one reply. queue also ignores replies once the stream is done, so the default acceptor cannot write an AUTH_OK after the AUTH_ERROR.

  • Replaced tokens are withdrawn even when never answered. State::hold keeps a replaced token presented (retiring) only while it holds a grant on some session. A token that was refused, never answered, or is still retrying adds nothing to the grant, so it is withdrawn at once. Repeated Tokens::set calls while a backend fails transiently no longer pile up retrying AUTH streams.

  • Swapping the acceptor cannot deadlock. Handle::requests now takes out the earlier queue under the state lock and closes it after releasing the lock. Pending::close takes the queued Requests out before dropping them. Dropping a queued AUTH-token Request refuses it, and refusing takes the handle's lock again.

  • JS counterpart (js/net). IssuedGrant.update replaces a grant still waiting to be written instead of chaining another write, and a revocation replaces it too. Held withdraws a replaced token that holds no grant at once. It uses a new @internal Handle.present, which returns the credential before the peer answers (add now wraps it), so a pending token can be withdrawn. JS has no session scope built from issued grants, and requests() cannot be taken twice, so the other two fixes have no JS counterpart.

Each fix has a unit test that fails (or hangs, for the deadlock) on main: a_refused_grant_leaves_the_scope, a_blocked_stream_queues_one_grant, an_unanswered_replacement_is_withdrawn_when_replaced, a_new_acceptor_refuses_the_queue_without_deadlock, plus a_token_granted_after_a_requests_answer_retires. JS: "grants issued while a reply is blocked replace the one still queued" and "a token replaced before its answer is withdrawn at once".

Impact

No public API or wire change. Only crate-private items in moq_net::auth changed, plus the @internal Handle.present and Pending type in @moq/net. On the wire, a peer now sees only the latest of several queued AUTH_OKs, and a refusal replaces a still-queued AUTH_OK instead of following it. Each AUTH_OK already replaced the last one, so the final state is the same.

Choices made without asking

  • A refusal (revoke or reject) also replaces a still-queued grant, rather than following it. The peer never saw that grant, and this keeps the bound at one reply.
  • A replaced token stays retiring only while it holds a grant right now. A granted token that is mid-retry, or has no live session, holds none and is withdrawn at once, since there is no grant in force for it to keep wide.
  • Kept the fix minimal for quest/m1/explicit-state/net-phases.md, which will redesign the auth state machine.

Overlap

moq-dev/moq#8063 only adds Permit methods to auth.rs and touches routing in lite/publisher.rs. It does not overlap this PR.

Caused by

  • moq-dev/moq#4039 - the oversize AUTH_OK refusal set done without revoking the grant, and the acceptor swap closed the old queue under the handle's lock
  • moq-dev/moq#5148 - grant updates were appended to the outbox without bound
  • moq-dev/moq#6834 - Tokens::set kept unanswered replaced tokens retiring until every new token was answered

Validation

  • just check: passed.
  • The new tests fail on the old code: the first three by assertion, the deadlock one by nextest timeout.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, medium effort
Implementer: Claude Code, claude-opus-5-5, low effort (iterate, XS)

🤖 Generated with Claude Code

(Written by Claude Opus 5.5 with medium effort)

Review

Rewritten by quest review after each round.

  • Reviewer: Codex, gpt-6.1-sol, medium effort
  • Session: 01a1b9a1-e177-7e93-91aa-05e5a202ceec, round 1
  • Head: 03e1aab
  • Base: origin/main at be1c32f
  • Score: 9/10, The authorization fixes appear consistent across Rust and JavaScript, with no actionable defects identified; builds and tests were not run, as instructed.
  • Findings: none

kixelated and others added 2 commits November 7, 2026 14:36
An AUTH_OK the driver cannot encode now withdraws its grant from the
session's scope along with the AUTH_ERROR that replaces it. A newer reply
replaces a grant still queued, so a peer withholding stream credit holds at
most one. Tokens::set withdraws a replaced token at once unless it was
granted, so sets during a failing backend never pile up retrying streams.
Handing the request queue to a new acceptor refuses the queued tokens after
releasing the handle's lock, which refusing takes again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Session auth grants and replies stay consistent and bounded fix(net): session auth replies revoke and stay bounded Nov 7, 2026
kixelated and others added 2 commits November 7, 2026 15:42
A replaced token keeps the grant wide only while it holds a grant on some
session, not by its first answer. The JS IssuedGrant replaces a queued
grant rather than chaining another write, and Held withdraws a replaced
token that holds no grant at once, through an internal Handle.present that
returns the credential before its answer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Pending.held reports a grant on any session the handle backs, so a token
still granted on a session draining after a GOAWAY keeps the grant wide
until its replacement answers, as Rust's State::hold does.

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

coderabbitai Bot commented Nov 7, 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 35 seconds.

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: cbc5fd65-bf6e-46e9-acb2-ff5a7a8e69b6
Commits

Reviewing files that changed from the base of the PR and between 1a53132 and 5412356.

Files selected for processing: 10

  • js/net/src/auth.test.ts
  • js/net/src/auth_session.ts
  • js/net/src/connection/tokens.test.ts
  • js/net/src/connection/tokens.ts
  • quest/m1/README.md
  • quest/m1/auth-stream-bounds.md
  • rs/moq-net/src/auth.rs
  • rs/moq-net/src/auth/tokens.rs
  • rs/moq-net/src/ietf/auth.rs
  • rs/moq-net/src/lite/publisher.rs
  • 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 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 head 246ad5e.

No actionable findings. Revoking the enforced grant when a reply cannot be encoded, coalescing unsent updates, and dropping queued requests outside the handle lock address the underlying state and resource problems. Token replacement now distinguishes a currently held grant from an unanswered/retrying presentation; checking every attached session preserves grants on draining sessions while their successor waits. The Rust and JS paths follow that distinction consistently.

Verification limits: GitHub-only static review of all ten changed files and surrounding issuance, withdrawal, token rotation and writer lifecycles. No tests, builds, race stress or protocol interoperability checks run. GitHub reports merge conflicts, so this is not a claim of merge readiness. Rechecked open/non-draft state, full head/base and published reviews immediately before posting.

@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 documentation nit inline.

Reviewed changes

Reviewed the session-side auth bounds fix at head 3ba52cb24 (the only change since 246ad5ed5 is a merge of main), covering the Rust Issue/Pending lifecycle, both AUTH drivers, and the js/net counterpart.

  • A refused AUTH_OK revokes its grant — Issue::refused() clears the outbox and finish()es, so the grant reply() recorded leaves the session scope; both drivers use it and outbox/done are now private.
  • Queued replies coalesce — Issue::queue replaces a still-queued grant and ignores replies after finish(), so a peer withholding stream credit holds one queued grant plus the in-flight write.
  • Replaced tokens withdraw promptly — State::hold retires a replaced token only while some session's slot holds its grant, so refused/unanswered/retrying tokens no longer pile up AUTH streams.
  • Acceptor swap cannot deadlock — Handle::requests closes the replaced Pending after releasing the state lock and Pending::close drops its requests after releasing its own, removing the handle → pending → issue → handle cycle.
  • JS parity — IssuedGrant coalesces queued writes and clears its queue on revocation; Held withdraws non-granted replacements at once; the @internal Handle.present/Pending expose a token before its answer so a pending one can be withdrawn.
  • Quest completed — quest/m1/auth-stream-bounds.md is deleted with its m1 README bullet and no remaining references.

I verified the new Rust tests (105 auth::, 138 lite::publisher), the two JS suites (127 and 9), tsc --noEmit and the declaration build, all pass. The wire behavior stays within what drafts/draft-lcurley-moq-auth.md already allows: fewer AUTH_OKs is permitted, and AUTH_ERROR after AUTH_OK revokes.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

Comment thread js/net/src/auth_session.ts Resolved

@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

Reviewed the delta since the prior pullfrog review at 3ba52cb24, which is documentation-only.

  • Restored Token's doc comment — 03e1aab7d moved /** A token the application added to a {@link Handle} ... */ back directly above class Token, so the new @internal Pending block documents only Pending and Token is documented again. This resolves the one nit from the previous review.

The merge commits (3ba52cb24, 82eeb6ab9) carry no PR-side changes beyond the base branch.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 8, 2026
Merged via the queue into main with commit 1f038c4 Nov 8, 2026
7 checks passed
@kixelated
kixelated deleted the quest/m1/auth-stream-bounds branch November 8, 2026 07:44
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