Skip to content

feat(net)!: a reconnecting client is connected once the peer accepts its credential - #9038

Merged
kixelated merged 19 commits into
mainfrom
quest/m0/nightly/credential-established
Nov 18, 2026
Merged

kixelated merged 19 commits into
mainfrom
quest/m0/nightly/credential-established

Conversation

@kixelated

@kixelated kixelated commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

A reconnecting client now counts a session as established once the peer accepts the connection credential (or drains it with a GOAWAY), and only then reports it connected. Uptime stands in for that answer only on moq-lite 03/04, which have none: a lite-07 session the peer never answers stays unconnected however long it is up. A refused session never shows as connected, and established() returns the refusal. This finishes the credential-established quest. The binding tests that waited out the 1 s healthy bar now drop the session as soon as it reports connected.

  • Rust (moq-net): the auth link records an Acceptance per session (Accepted, Awaiting, Silent). A client's peer accepts with its SETUP on lite-05/06 and moq-transport, or with the AUTH_OK to the connection's own credential on lite-07. lite-01/02 and the legacy moq-transport handshake accept at connect. lite-03/04 have no acceptance message, so they are Silent.
  • Reconnect reports Action::Established, carrying the session, once per live session: the peer accepted it or drained it with a GOAWAY, or, on a silent version (lite-03/04, Session::is_silent), it stayed up past Backoff::healthy. A refused session never gets one. Until then, the session does not count as serving. A predecessor that retires meanwhile leaves the connection Offline, an idle predecessor is not closed for it, and no fallback probe moves off it.
  • moq-tokio's Connection publishes Connected, and established() resolves, on Action::Established instead of at dial time. established() resolves Ok once any session was established, even if a one-shot loop has since ended, and Err only when the loop stopped before one was.
  • Every binding follows through moq-tokio (moq-ffi, libmoq, Go, Python, Kotlin, Swift, Dart, C++, gstreamer). No binding API changes.
  • JS (js/net): Reload serves a session (status connected, the established signal) only once AuthSession.accepted says so or it drains with a GOAWAY, or, when AuthSession.silent (lite-03/04), it passes the healthy bar.
  • Binding tests: the 1 s waits are gone from Go (go/wrapper/reconnect_test.go), Python (py/moq-rs/tests/test_server.py), moq-ffi (rs/moq-ffi/src/test.rs, two places), and libmoq (rs/libmoq/src/test.rs). session_state_names_a_failing_first_dial again asserts what follows the server's close: the client saw the session connected, so it redials (Disconnected).
  • Handover.tla models the per-session Established step and checks a new ConnectedMeansEstablished rule. Its first run found that Reconnect::connected dropped the Offline a mid-dial retirement queued, which left the handle reporting a retired session. That is fixed here.
  • Docs on when Connected fires are updated: doc/lib/index.md, MoqConnectionPhase::Connected, MOQ_CONNECTION_PHASE_CONNECTED, Go ConnectionPhaseConnected, JS Reload.status, Status::Connected, Connection::established, and the Reconnect module docs.

For moq-dev/moq#9016 (OBS reconnect tests): once this lands, the OBS tests can drop their 1 s healthy-bar waits. Wait for the session to report Connected, then drop it, and the client redials instead of giving up.

Decisions

From the maintainer (comment):

  • How a binding observes acceptance: ✅ (a) Connected and established() wait for the peer's acceptance (or the 1 s bar on lite-03/04) (rejected: (b) an accepted flag in every binding's state snapshot, (c) keep the 1 s waits). Every binding follows, and the binding tests drop their waits.

Made by the agent, please check:

  • Uptime establishes only where the version has no acceptance message (from the maintainer, comment round 2, which overrides the agent's earlier pick): ✅ uptime only on lite-03/04 (rejected: uptime on every version). On lite-07 a session reads as connected only on its AUTH_OK or a GOAWAY, never on the 1 s bar. The agent read "lite-07" as every version with an answer, so lite-05/06 and moq-transport, which accept with their SETUP, wait for it too; the code already marks those Awaiting, the same as lite-07. A lite-07 session up for minutes without an AUTH_OK now never reads as connected, and its close ends the policy as a refusal. Every lite-07 session presents the connection's own credential (empty when anonymous), so an honest relay always answers.
  • A new Action::Established variant in moq_net::reconnect::Action: ✅ the policy reports it (rejected: moq-tokio polling acceptance itself, which would duplicate the healthy timer and need Session::poll_accepted made public). Action is exhaustive on purpose, so this is a breaking change for any external Reconnect driver. The title carries !.
  • established() latches: ✅ Ok once any session was established, even after the one-shot loop ended (rejected: Err(Stopped) once the loop has stopped). Without this, a one-shot client whose peer accepts and drains at once (a draining relay) got Ok or Stopped depending on timing. A refusal still returns its error.
  • Backoff pacing is unchanged (carried from the first round): only uptime resets the delay and timeout. Acceptance only decides fail-fast vs. retry.
  • Tests that read a GOAWAY right after acceptance: the relay drain tests' mid-drain arrival (shutdown_signal.rs, runtime_uring.rs) now use a reconnecting connection, which keeps the drained session readable as the predecessor. A one-shot loop ends on the GOAWAY, as reconnect::Config::once promises, and they only passed before because Connected was published ahead of the GOAWAY. Other moq-tokio and relay tests now hold the server's session open, or wait until the client is established before the server acts.

Public API and wire impact

  • Breaking (Rust): moq_net::reconnect::Action gains Established(Box<Session>). Migration: an external driver of Reconnect handles Action::Established(session) and publishes that session as serving there, not when it reports Reconnect::connected. The action carries the session because a GOAWAY in the same pass may already have moved it out of Reconnect::session().
  • Additive (Rust): moq_net::Session implements Debug (its version), which Action's derived Debug needs.
  • Behavior (every language): Connected (moq-tokio Status::Connected, every binding's Connected phase, JS Reload.status) now fires once the peer accepts the session, not when the transport handshake finishes. A refused session never reports it, connects doesn't count it, and established() returns its error. established() returns Ok after a one-shot session that was established has ended. Backoff::healthy (and JS Backoff.healthy) establishes a session only on moq-lite 03/04; on a version that answers the credential, a session the peer never answers is not established however long it is up, and its close fails fast instead of retrying.
  • Wire: none.

Validation

  • Real binaries: just test interop --all passes (all cells; the chromium route-key case skips as before). Its WebSocket refused-session case now asserts the refused session never reads as connected. Against the previous behavior it reported connecting, connected, disconnected. One earlier full run missed finish python -> gst (the gst late reader got 0 of 10 frames, after it was online). It passed in two isolated runs and in a full rerun, so it's load-dependent and outside this change.
  • Model: Handover.tla passes with 19.2M distinct states (Handover.cfg, 4 min) and 3.4M (RestartHandoff.cfg), with the ConnectedMeansEstablished rule. Each session now picks whether its version answers the credential, and uptime establishes only a silent one. Restoring the old rule (uptime on every version) fails ConnectedMeansEstablished in 6 steps. Before the mid-dial retirement fix, TLC found a StatusTruthful violation in 11 steps.
  • Binding tests without the waits: go/just check (Go wrapper suite incl. TestReconnectAcrossRelayRestart), py/just test (124 passed), cargo test -p moq-ffi -p libmoq all pass.
  • Rust: moq-net reconnect tests include an_early_goaway_establishes_the_session_it_drains (lite-04 GOAWAY before any answer, the round-1 review finding), an_unanswered_replacement_does_not_serve (Retired, then Offline at the handover, still not Established 10 s later, then Established on the AUTH_OK), an_unanswered_session_is_not_established_by_uptime (a lite-07 session up 10 s without an AUTH_OK is not Established, and its close ends the policy), and an Established at the bar on lite-04. moq-tokio (unit and integration) and moq-relay (lib and integration) pass 3 times each. reconnect_ends_on_a_first_session_rejection asserts connects() == 0.
  • JS: bun test src/ passes (3349). New: a lite-07 Reload up 5 s without an AUTH_OK never reads connected, then does on the AUTH_OK; it fails against the previous reload.ts. Two lite-06 tests that relied on uptime establishing an unanswered session now establish the URL with an accepted session first. The refused-session test asserts status never reads connected, and it fails against the previous reload.ts.
  • Round 3: just test interop --all passes again (204 checks; the chromium route-key case skips as before). cargo test -p moq-net --all-features -p moq-tokio -p moq-ffi -p libmoq -p moq-relay -p moq-gst passes. moq-tokio's a_token_is_presented_on_every_session stopped accepting at the token and could skip the connection credential's AUTH_OK, so it relied on uptime; it now answers both.
  • just check passes. The drill mutation patches still apply.
  • Unrelated to this change, under heavy machine load: libmoq's audio_abort_unwanted_keeps_a_late_reader (an audio test with no connection) hung once in a plain cargo test run and passed 3/3 alone. libmoq's route_broadcast_survives_id_reuse fails under plain cargo test because it relies on nextest's process-per-test (its own comment says so), and passes alone.

Follow-ups

  • None.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort (arm A)
Implementer: Claude Code, claude-opus-5-5, unknown effort (iterate, S, arm A)
Implementer: Claude Code, claude-opus-5-5, high effort (iterate, S, arm A)

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 2bf3599

  • Base: origin/main at 16880c8

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

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

  • Session: 01a1ecbf-6c7b-7cd3-ae19-4e58cae0c797, round 3

  • Score: 10/10, The incremental changes consistently restrict uptime-based establishment to silent versions in Rust, JS, and the model, with no new findings; builds and tests were not run as instructed.

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

  • Findings: none

kixelated and others added 7 commits November 17, 2026 17:07
… its credential

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A reconnecting client is established by the credential's answer feat(net): a reconnecting client is established by the peer accepting its credential Nov 18, 2026
@kixelated

Copy link
Copy Markdown
Collaborator Author

Maintainer decision on how bindings see acceptance:

✅ (a) moq-tokio's Connection reports Connected, and established() resolves, only once the peer accepts the session's credential (or after the 1 s uptime bar on lite-03/04, which send no acceptance); every binding follows. A refused session never shows as connected. Then drop the binding tests' 1 s waits.
❌ (b) a new accepted flag in every binding's state snapshot.
❌ (c) keep the 1 s waits.

(Written by Claude Opus 5.5 with high)

kixelated and others added 7 commits November 17, 2026 18:06
… session

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… replacement is established

Handover.tla models the per-session Established step and checks that a
connection reads as connected only once its session is established.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…in tests read an arrival's GOAWAY deterministically

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title feat(net): a reconnecting client is established by the peer accepting its credential feat(net)!: a reconnecting client is connected once the peer accepts its credential Nov 18, 2026
kixelated and others added 3 commits November 17, 2026 20:58
…WAY moves out of the live slot

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

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

coderabbitai Bot commented Nov 18, 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 4 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: a238aac9-77b3-41ca-afb9-a4d67f4e25aa
Commits

Reviewing files that changed from the base of the PR and between 789ece4 and 1d2ab40.

Files selected for processing: 50

  • .claude/skills/verify-reconnect/SKILL.md
  • dart/moq/lib/src/aliases.dart
  • dart/moq/lib/src/client.dart
  • doc/bin/gstreamer.md
  • doc/lib/cpp/index.md
  • doc/lib/dart/index.md
  • doc/lib/go/index.md
  • doc/lib/index.md
  • doc/lib/kt/index.md
  • doc/lib/py/index.md
  • doc/lib/swift/index.md
  • go/wrapper/client.go
  • go/wrapper/reconnect_test.go
  • go/wrapper/session.go
  • js/net/src/auth_session.ts
  • js/net/src/connection/reload.test.ts
  • js/net/src/connection/reload.ts
  • js/net/src/lite/connection.ts
  • kt/moq/src/jvmAndAndroidMain/kotlin/dev/moq/Aliases.kt
  • py/moq-rs/README.md
  • py/moq-rs/moq/_records.py
  • py/moq-rs/tests/test_server.py
  • quest/m0/nightly/credential-established.md
  • rs/libmoq/src/api.rs
  • rs/libmoq/src/test.rs
  • rs/moq-ffi/src/session.rs
  • rs/moq-ffi/src/test.rs
  • rs/moq-gst/src/sink/session.rs
  • rs/moq-net/src/auth.rs
  • rs/moq-net/src/auth/tokens.rs
  • rs/moq-net/src/ietf/peer.rs
  • rs/moq-net/src/lite/session.rs
  • rs/moq-net/src/lite/setup.rs
  • rs/moq-net/src/reconnect.rs
  • rs/moq-net/src/reconnect/tests.rs
  • rs/moq-net/src/session.rs
  • rs/moq-net/verify/reconnect/Handover.cfg
  • rs/moq-net/verify/reconnect/Handover.tla
  • rs/moq-net/verify/reconnect/RestartHandoff.cfg
  • rs/moq-relay/src/shutdown.rs
  • rs/moq-relay/tests/integration/runtime_uring.rs
  • rs/moq-relay/tests/integration/shutdown_signal.rs
  • rs/moq-tokio/src/connection.rs
  • rs/moq-tokio/tests/integration/backend.rs
  • rs/moq-tokio/tests/integration/broadcast.rs
  • swift/Sources/Moq/Aliases.swift
  • swift/Sources/Moq/Client.swift
  • test/drill/mutations/reconnect-stops-after-session-loss.patch
  • test/interop/README.md
  • test/interop/clients/js/src/close.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

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

ℹ️ Two rough edges worth a look: a doc regression for moq-lite 03/04 across the bindings, and a stale sync commit in the model skill.

Approach: sound — acceptance is latched on the auth link that already owns the credential verdict, so every layer (policy, driver, bindings, JS) reads one signal instead of re-deriving it, and the model encodes the same rule.

Reviewed changes

  • Acceptance per session (rs/moq-net/src/auth.rs, lite/session.rs): accepted: bool becomes Acceptance { Accepted, Awaiting, Silent } with Link::poll_accepted / Session::poll_accepted; the peer's SETUP (lite-05/06) and the AUTH_OK to the session's own credential (lite-07) latch Accepted, lite-03/04 are Silent, and lite-01/02 plus moq-transport accept at connect. Link::close keeps the entry, so an acceptance survives the close it precedes.
  • Reconnect policy (rs/moq-net/src/reconnect.rs): Action::Established(Box<Session>) is reported once per live session, checked before the close so an accepted-then-dropped session is an outage; Live::established gates the idle-predecessor close, the fallback probe, and the Offline after a mid-dial retirement, and connected() no longer strips that queued Offline.
  • moq-tokio (rs/moq-tokio/src/connection.rs): Status::Connected and established() move to Action::Established through a held pending transport; stopped() latches Ok once any session connected.
  • JS (js/net): AuthSession.accepted plus a silent prop; Reload serves a session only once accepted, draining, or past the bar, and #settle reads the session's acceptance rather than uptime alone.
  • Model (Handover.tla, both configs): Establish, OnEstablished, Serving, per-session accepted/served, and the ConnectedMeansEstablished rule.
  • Tests and docs: binding reconnect tests drop their 1 s waits, relay drain tests read the GOAWAY through a reconnecting connection, the interop refused-WebSocket case asserts the refused session never reads connected, and the Connected docs in moq-ffi/libmoq name the lite-03/04 bar.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash | 𝕏

Comment thread rs/moq-ffi/src/session.rs Resolved
@kixelated

Copy link
Copy Markdown
Collaborator Author

Decision from the maintainer:

  • ❌ Decision 1 (uptime counts on every version): on lite-07, a session reads as connected only on an explicit acceptance (or a GOAWAY), never on the 1 s uptime bar. The uptime bar stays for lite-03/04, which have no acceptance.
  • ✅ Then merge.

(Written by Claude Opus 5.5 with high)

kixelated and others added 2 commits November 17, 2026 23:44
…tablishes a session

A lite-07 session reads as connected only once the peer sends the AUTH_OK to the
connection's own credential (or a SETUP on lite-05/06 and moq-transport) or drains it
with a GOAWAY. The 1 s healthy bar establishes a session only on moq-lite 03/04, which
never answer the credential. Applied to the Rust policy (`Reconnect`), JS `Reload`, and
`Handover.tla`, which now picks per session whether its version answers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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 new issues found. Both earlier findings are fixed, and the uptime rule now applies only to moq-lite 03/04, consistently across Rust, JS, the model and the docs.

Approach: sound. The healthy-bar deadline now exists only when Session::is_silent() is true. Reconnect::established is set only where Action::Established is reported, so the policy flag and the reported state can no longer drift apart.

Reviewed changes

Two commits since the last pullfrog review: 51e8538a8 limits uptime to versions that never answer the credential, and 2bf3599f4 updates the model skill to match.

  • Silent-only uptime (rs/moq-net/src/reconnect.rs, auth.rs, session.rs): Added Link::is_silent and Session::is_silent. The Live branch computes the healthy deadline only for a silent session. On a version that answers, it waits on poll_accepted and the handover timer, however long the session has been up.
  • One place establishes the policy: Removed the tenure-based established from end() and the extra sets in probed() and follow(). This is safe because a probe starts only on an established live session (live.probe.filter(|_| live.established)). The healthy pacing reset through retry.settle is unchanged.
  • JS Reload (js/net/src/connection/reload.ts, auth_session.ts): Added the AuthSession.silent getter. The uptime sleep in the serve race, and the uptime branch of #settle, now apply only when auth.silent.
  • Model (Handover.tla): Each session now picks silent non-deterministically, and Healthy(s) requires it. FirstWalkFailsFast now also checks established => \E s : served. FollowPred, EndClosed and ProbeGetsThrough no longer set established.
  • Tests: Renamed the uptime test to an_unanswered_session_is_not_established_by_uptime; it now asserts a lite-07 session up 10× the bar is never established and its close ends the policy. an_unanswered_replacement_does_not_serve now waits 10× the bar before the AUTH_OK. A new JS test covers a lite-07 session up 5 s without an AUTH_OK. The lite-06 tests now establish through an accepted session first. a_token_is_presented_on_every_session answers the connection credential too.
  • Docs: Every binding's Backoff, once and connect sentence, and doc/bin/gstreamer.md for both elements, now carry the moq-lite 03/04 uptime caveat. The verify-reconnect sync commit moved to 51e8538a84, with the state counts updated.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@kixelated
kixelated added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit 4a6f522 Nov 18, 2026
4 of 5 checks passed
@kixelated
kixelated deleted the quest/m0/nightly/credential-established branch November 18, 2026 08:13
kixelated added a commit that referenced this pull request Nov 18, 2026
… fixed the close flake

The client's close returned SESSION_NOT_FOUND when the server closed the accepted
session first: before #9038 a session closed within 1s of uptime ended the
reconnect loop, racing the test's close. #9038 establishes a session once its
SETUP is answered, so the client now redials. Drop the comments that still
describe the old rule, and the finished quest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
riedlse pushed a commit to riedlse/moq that referenced this pull request Nov 18, 2026
… comments it outdated (moq-dev#9078)

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.

1 participant