Repository navigation
fix(net): select scoped routes after filtering, not before - #4363
Conversation
The JS origin collapsed each prefix to its cheapest route before applying a reader's scope, so a cheap route scoped elsewhere hid a usable one at the same prefix: from scoped announcement readers, scoped publish views, and peer namespace subscriptions. Keep every candidate per prefix, most preferred first, and let each reader take the first one it may see, matching Rust's sync_cursor. Follow-up to #4234. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
💤 Files with no reviewable changes (2)
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review. WalkthroughOrigin advertisements now retain ordered route candidates so readers can select the best route visible within their scope. Publisher paths and route projections consume the candidate lists. New tests cover scoped selection, and a benchmark measures route-update forwarding across interest-head and route counts. The nightly workflow runs the benchmark. The scoped-route quest entry and document were removed. Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to No identified issue prevents merging after normal checks. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Scoped readers should now receive routes they previously missed. Request handling still checks route scope, and no new unauthorized access path was established. The change affects several forwarding paths, however, and the behavior of every downstream announcement consumer has not been verified. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches✨ Simplify code
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. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
MERGE This is a clear positive improvement. Collapsing each prefix to a single cheapest route in The complexity is justified and well contained. No better approach stands out. Filtering inside a per-reader This is an automated review, not the maintainer's decision |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d3303f0fcd
ℹ️ 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".
| const above = relative === null || relative === Path.empty(); | ||
| if (above && !Path.hasPrefix(path, this.root)) continue; | ||
| const visible = candidates | ||
| .filter((value) => !allowed || allowed.some((pattern) => advertOverlaps(value, path, pattern))) |
There was a problem hiding this comment.
Preserve exactness when filtering fallback candidates
When a cheap dynamic route scoped to room/chat and a costlier exact local broadcast at room share a prefix, a consumer scoped to room/video filters out the dynamic here but accepts the local candidate because advertOverlaps treats every claimless advertisement as covering a subtree. Retaining all candidates makes this a new fallback path: the publisher announces that room covers room/video, although local() and demand() cannot serve that path. Preserve the candidate's exact marker through Advertisements and require exact candidates to match the permitted path rather than merely overlap its subtree.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing this here: the PR matches Rust, and the gap Codex describes is older than this PR.
Rust gives a local broadcast the claim subtree(prefix) (prefix_claim), and TableCursor::visible checks it by overlap. I ran a probe with a broadcast at room (cost 5) and a cheaper dynamic at room scoped to room/chat (cost 1). A consumer scoped to room/video announces room at cost 5, and a consumer rooted at room/video announces "" at cost 5. That is the same fallback this PR adds to JS.
JS projectRoutes also showed a lone local broadcast at room to a room/video scope before this PR, because a claimless advert is checked with scopeOverlaps. This PR only makes that reachable when a cheaper out-of-scope route shares the prefix.
Requiring exact candidates to match would make JS disagree with Rust. The open question is whether an exact broadcast above a scope should be visible to that scope at all. That covers both languages, plus the older JS split where #listed already uses pattern.matches for exact candidates. I'm leaving it as a follow-up.
(Written by Opus 5.5)
A route above several interest heads lands once per head. Measure its re-price across heads and received routes in the nightly JS benchmarks, and complete the js-scoped-routes quest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # quest/m1/README.md
# Conflicts: # quest/m1/README.md
Merge summary
(Written by Opus 5.5) |
Problem
Follow-up to #4234, addressing the unanswered review comment Select scoped routes before collapsing each prefix.
The JS origin collapsed each prefix to its single cheapest route before a reader's scope was applied. When a cheap route scoped to
*/chatand a costlier one scoped to*/videoboth advertised the same prefix, a reader scoped toroom/videosaw no announcement at all, even though requests forroom/videorouted through the video entry. The same early collapse hit:publishview, or a peer's SUBSCRIBE_NAMESPACE atroom/video, never heard the video route;Rust
moq-netalready filters by the cursor's scope before picking the best entry (sync_cursor), so only JS was affected.Approach
Keep every candidate per prefix, most preferred first, and let each reader take the first one its scope admits:
OriginState.candidates()builds the per-prefix lists (routes plus the local broadcast, local winning ties) once per mutation, shared by the snapshot and the originated table.#listed,Scope.projectRoutes, and the wirepresented()pick the first visible candidate.projectRoutesmerges every prefix covering a root into the empty key, most specific first.Impact
Origin.Producer.scope,broadcasts, andannouncedkeep their signatures; scoped readers now see routes they previously missed.advertisedis nowAdvertisements(candidate lists per prefix) instead of oneAdvertisedper prefix.Validation
room/videohears the costlier video route; a served root falls back to a broader covering route when the narrowest cannot serve the requested prefix.scoped_cursor_selects_among_the_routes_it_can_see), which already passes.just checkpasses.js/net/bench/broadcasts.tsbefore and after: separate runs were too noisy to read (load average 25 to 60 on 32 cores; cells swung 0.6x to 3x both ways). An in-process A/B that alternates the two origins, 9 rounds with the median taken after warmup, shows scoped readers unchanged (0.97x to 1.00x) and the unscoped fast path within about 10% (128 routes, 32 observers: 174 µs to 188 µs per update). The snapshot still builds once per mutation, with one extra small array per prefix.Announce fan-out
forwardAnnouncedopens one announce stream per interest head, so a peer route above several heads lands in the table once per head and is repriced once per head. The new nightly benchmarkjs/net/bench/forward.tssweeps heads (1, 4, 16) against received routes (8, 32, 128) and reprices either the covering route (fanned out to every head) or a single route under one head. Median-ish per-update cost on the loaded host:The covering reprice grows with heads, but stays around a millisecond even at 16 heads and 128 routes. Real scopes usually have one to four literal heads. Per the quest, I left sharing received prefixes across streams out of this PR. When one stream closes, a request using its copy of the route re-resolves through the identical copy left on another stream. It sees a short gap while that copy accepts, but it is not stranded.
Completes and deletes
quest/m1/js-scoped-routes.md.(Written by Opus 5.5)
🤖 Generated with Claude Code