Skip to content

docs(net): say who owns the broadcast behind Announce.Broadcast.active - #2640

Merged
kixelated merged 2 commits into
mainfrom
claude/announced-active-ownership
Aug 4, 2026
Merged

docs(net): say who owns the broadcast behind Announce.Broadcast.active#2640
kixelated merged 2 commits into
mainfrom
claude/announced-active-ownership

Conversation

@kixelated

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #2617, from a review that landed after it merged.

Announce.Broadcast.active hands out the same Broadcast.Consumer type that consume() returns, so nothing stops a caller from closing it. If they do, the handle doesn't notice: active keeps pointing at the closed consumer and every later read fails, while the path is still announced and a fresh conn.consume(path) works.

2. active still points at it: true
3. that consumer is closed: true
4. subscribe after caller close FAILED: Error: broadcast is closed: null
5. fresh conn.consume works: hi

No in-tree caller does this (js/watch mirrors active and subscribes off it without closing), so this is an API-misuse hazard rather than a live bug.

Why a doc change and not a type change

Two stronger options were suggested and both have a real downside:

  • Strip close() from the exposed type. It is the same Broadcast.Consumer that consume() returns, and callers legitimately clone() it, so a narrowed view complicates the type for everyone to stop one misuse.
  • Observe the consumer and reacquire on close. That races a caller who keeps closing: close, reacquire, close, reacquire.

The repo already has an idiom for the underlying question (refcounted handles, clone() when you want an independent lifetime, closing a borrowed handle is a holder bug). So this says which side of that idiom active is on, and points at clone().

Happy to take the stronger version instead if the view-type cost is acceptable.

Public API changes

None. Doc comment only.

Test plan

bun run --filter='@moq/net' check and just js fix clean. No behavior change, so no test; a test here would only codify the misuse.

(written by Opus 5)

`active` hands out the same `Broadcast.Consumer` type that `consume()`
returns, so nothing stops a caller from closing it. Doing so leaves
`active` pointing at a dead consumer and every later read fails, while
the path is still announced and a fresh consume() works.

No in-tree caller does this, and the repo already has an idiom for the
question (refcounted handles, clone() for an independent lifetime), so
say which side of it `active` is on rather than reshaping the type.

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

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@kixelated, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 9 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: e364b8cd-9091-41e6-b47d-1bb4d6aa5460

📥 Commits

Reviewing files that changed from the base of the PR and between 575ab7b and 7bd6a4a.

📒 Files selected for processing (1)
  • js/net/src/announced.ts

Walkthrough

Expanded the Broadcast.active documentation. It now states that the returned consumer is borrowed, can be replaced on republish, and should not be closed directly. It also documents closure effects and recommends cloning the consumer or closing the Broadcast handle.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the documentation change about ownership of Announce.Broadcast.active.
Description check ✅ Passed The description accurately explains the API misuse risk, documentation rationale, and absence of behavior or public API changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch claude/announced-active-ownership

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.

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@js/net/src/announced.ts`:
- Around line 192-195: Update the documentation for the handle’s borrowed
consumer and republish behavior to state that redundant announcements may retain
the existing live consumer, replacing it only when the consumer closes or the
path goes offline. Qualify the close guidance to note that
broadcast.Consumer.close() is reference-counted, so cloned consumers may keep
the shared state usable; do not imply every republish changes active identity or
every close causes reads to fail.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: c266b150-aaf0-4685-bb93-36ee317912dd

📥 Commits

Reviewing files that changed from the base of the PR and between 797d629 and 575ab7b.

📒 Files selected for processing (1)
  • js/net/src/announced.ts

Comment thread js/net/src/announced.ts Outdated
Consumers are reference-counted, so closing the one read from `active`
only kills the shared broadcast when it was the last reference; with a
clone outstanding, reads through the closed handle still work. Say that
rather than promising reads fail.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@kixelated
kixelated merged commit 2f3bf70 into main Aug 4, 2026
1 check passed
@kixelated
kixelated deleted the claude/announced-active-ownership branch August 4, 2026 20:59
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