Skip to content

Broadcast unexpected behavior fix#997

Open
Aryan-Railtown wants to merge 4 commits intomainfrom
aryan_887_braodcast_bug
Open

Broadcast unexpected behavior fix#997
Aryan-Railtown wants to merge 4 commits intomainfrom
aryan_887_braodcast_bug

Conversation

@Aryan-Railtown
Copy link
Contributor

Closes #887

What does this add?

This PR improves the reliability of the pubsub system by changing subscriber execution from concurrent to sequential inside the publisher.

Previously, subscribers were executed using:

await asyncio.gather(*contracts)

During session shutdown, this could result in subscriber tasks being cancelled before completion, causing certain callbacks (e.g., broadcast callbacks used for observability) to silently fail.

This PR changes execution to:

for contract in contracts:
    await contract

This ensures subscribers complete deterministically and prevents callbacks from being interrupted during shutdown.


Type of changes

  • 🐛 Bug fix (non-breaking change which fixes an issue)

Background context

While investigating issues with rt.broadcast(), we discovered that pubsub subscribers were executed concurrently via asyncio.gather. During session shutdown this could lead to subscriber tasks being cancelled before they finished executing, causing broadcast callbacks to never trigger.

Although rt.broadcast() is moving away from being exposed as a public API (with the newer Flow-based execution model handling observability), sequential subscriber execution improves overall reliability of the pubsub pipeline and prevents silent callback failures.


Checklist for Author

Code Quality

  • Code follows the project's style guidelines (run ruff check . and ruff format .)
  • Code is commented, particularly in hard-to-understand areas

Testing

  • Tests added/updated and pass locally (pytest tests)
  • Test coverage maintained

Documentation

  • Documentation updated if needed (bot will verify)

Git & PR Management

  • PR title clearly describes the change

@Aryan-Railtown Aryan-Railtown self-assigned this Mar 11, 2026
@Aryan-Railtown Aryan-Railtown added the bug This is an issue outlining a bug in the framework label Mar 11, 2026
soulFood5632
soulFood5632 previously approved these changes Mar 12, 2026
Copy link
Member

@soulFood5632 soulFood5632 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for the investigation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug This is an issue outlining a bug in the framework

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Broadcast Function does not work outside of a node

2 participants