Skip to content

fix(net): a takeover tells the route node its successor before the predecessor ends - #9299

Merged
kixelated merged 1 commit into
mainfrom
fix/restart-feeds-successor-first
Nov 21, 2026
Merged

kixelated merged 1 commit into
mainfrom
fix/restart-feeds-successor-first

Conversation

@kixelated

@kixelated kixelated commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

When a route at a path is replaced by one with a new instance (a publisher republishing while its old route still holds the path), OwnClaims sent the route node the old instance's Ended as soon as the cursor reported the Restart, and the new instance's Live only later, in feed() at the end of the poll. So every same-path takeover went on the wire as End(old), then Start(new).

A receiving node that reads both before one flush still serves a restart, because node.rs's flush serves staying broadcasts before going ones. One that reads them apart (a loaded relay, a slow socket) tells its viewers End, then Start, and an announcement-driven player stops on End. Measured downstream: a viewer two hops away saw End instead of Restart in 4 of 100 runs under CPU load.

Approach

apply no longer calls node.own for a removal. It records the claim in OwnClaims::gone, and feed sends those after the Lives of the same poll, skipping any instance that is best at its prefix again by then (a route that left and came back within one poll never reaches the node as ended). This is the order Node::own already uses for a claim moving between keys, and the order the JS publisher already sends (js/net/src/lite/publisher.test.ts: a successor starts before the one it replaces ends).

Impact

  • Wire: on a same-path instance takeover, a lite-07 peer now receives the successor's ANNOUNCE start before the predecessor's end. No message, field, or version changes.
  • No public API change.

Alternatives

  • Reorder exports in Router::refresh (relay.rs), which iterates dirty in (path, instance) order. Not the cause here: a non-routing peer's messages each refresh on their own, so order follows the wire. The defect is the order this node puts on the wire.
  • Make receivers coalesce an End followed shortly by a Start into a Restart: a timer guessing at intent, and a real end would be delayed.

Caused by

  • moq-dev/moq#8987 - per-instance own-claim tracking sent the replaced instance's End before the successor's Live (found by check: a downstream e2e failing under load)

Validation

  • New model::origin_impl::tests::a_takeover_tells_the_route_node_the_successor_first: fails before the fix with [(old, End), (new, Live)], passes after.
  • just ci: 10959 tests passed, 143 skipped.
  • End to end, as a second check: a real relay, a publisher that republishes a path while its first route still holds it, and a viewer session following announcements, run beside 48 busy-loop processes on a 32-core host. Before: 4 failures in 100 runs, each the viewer receiving End(old) then Start(new). With this commit cherry-picked: 0 failures in 260 runs.

Follow-ups

None.

Models

Size: S
Implementer: Claude, claude-opus-5-5, unknown effort

(Written by Opus 5.5)

Review

Rewritten by quest review after each round.

  • Head: 45c8a01

  • Base: origin/main at afa0ec7

  • Risk: medium, This changes route announcement ordering and could disrupt takeover visibility for connected peers, but preserves the API and wire format and is fully undone by a revert.

  • Classified: medium by Codex, gpt-6.1-sol, low effort, session 01a1fde0-5caf-7052-b176-65b5d8a80cca

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

  • Session: 01a1fde0-749b-7aa0-90c0-b6220c6423cc, round 1

  • Score: 9/10, Source review found no actionable defects in the successor-first claim ordering and suppression of withdrawals for claims restored within the batch, though builds and tests were not run as instructed.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

…edecessor ends

OwnClaims fed the route node the replaced instance's End as soon as the cursor
reported a Restart, but the successor's Live only at the end of the poll. So
every same-path instance swap went on the wire End(old) then Start(new). A
receiver reading both before one flush still served a restart; one reading
them apart told its viewers End, then Start, and a player stops on End.

Removals now wait for the poll's Lives, and one that came back since is not
sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 21, 2026 11:32

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

Approach: sound. Deferring the predecessor's Ended until after the same poll's Lives fixes the order where it's created, in OwnClaims. It matches the move-between-keys order Node::own already uses, and the order the JS publisher sends.

Reviewed changes

This run reviewed the single commit, which reorders how OwnClaims feeds the route node.

  • Deferred removals: apply now records ended, lost, and displaced claims in OwnClaims::gone instead of calling node.own right away.
  • Successor first: feed sends the changed prefixes' Live claims first, then drains gone. It skips any instance that is best at its prefix again, so a claim that leaves and comes back within one poll reaches the node only as Live.
  • Regression test: a_takeover_tells_the_route_node_the_successor_first checks that the route stream carries (new, Live) before (old, End).

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

@coderabbitai

coderabbitai Bot commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

OwnClaims now queues route-layer claim removals and replacements. During feed, it publishes changed live claims before applying queued removals. It skips a removal when the same prefix and instance remain live. A test checks that a takeover publishes the new instance before ending the previous instance.

Merge Risk: Minimal · up to 45c8a

This change makes a same-path takeover reach the route node as a restart (successor start before predecessor end) rather than an end followed by a start. No concrete merge-blocking risk was found, and the reported tests cover the new ordering.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a takeover now sends the successor's live update before the predecessor's end, matching the route-claim ordering change in origin.rs. It is specific and in one sentenc…
Description check Passed The description explains the problem, the approach of deferring removals after the poll's Lives, the wire impact, alternatives considered, validation, and the causing PR. It is directly related to the…
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.
Full details: Title check

Explanation

The title names the main change: a takeover now sends the successor's live update before the predecessor's end, matching the route-claim ordering change in origin.rs. It is specific and in one sentence. The title is 83 characters, which is longer than ideal but still readable.

Full details: Description check

Explanation

The description explains the problem, the approach of deferring removals after the poll's Lives, the wire impact, alternatives considered, validation, and the causing PR. It is directly related to the changeset.

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

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: d5280f87-10eb-4ac1-b654-7f4271e14034
Commits

Reviewing files that changed from the base of the PR and between afa0ec7 and 45c8a01.

Files selected for processing: 1

  • rs/moq-net/src/model/origin.rs

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

@kixelated
kixelated added this pull request to the merge queue Nov 21, 2026
Merged via the queue into main with commit 14edf61 Nov 21, 2026
7 checks passed
@kixelated
kixelated deleted the fix/restart-feeds-successor-first branch November 21, 2026 11:47
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