Skip to content

core: located Bus events visit unrelated Location subscribers #52921

Open

Description

@pascalandr

Description

User impact: With many project directories loaded, compaction can leave TUI
refreshes and live updates seconds behind. CodeNomad can suffer even more:
background recovery can load many old directories, and its extra event relay
can further delay updates, making conversations appear frozen while the server
is still working.

Location-scoped Bus subscriptions filter after shared PubSub delivery. Events
therefore visit unrelated loaded Location consumers, increasing native CPU and
delaying network-backed TUI operations during streaming/compaction.

A real PubSub regression with 220 unrelated Locations, 24 consumers each and
30 located publications records 159,180 subscriber visits on the baseline,
versus 780 with pre-delivery Location/type routing (zero unrelated visits).

Three alternating real CLI/ConPTY pairs under the same synthetic shared-server
recipe reduced Worktrees Ctrl+R from 3.626/12.736/13.438 s to
0.805/0.566/1.394 s. Those runs deliberately preloaded 220 native graphs and ran
22 traffic sessions; they do not represent ordinary two-tab startup. Local
input did not improve, and five restored tabs loaded only five graphs.

Related to #36443, but this is the narrower internal Location fanout bug,
not the requested public SSE client-interest API or a complete freeze fix.

Plugins

No additional plugins in the isolated reproduction.

OpenCode version

2.0.22; source baseline d9d094a; Bun 1.4.2.

Steps to reproduce

  1. Keep many native Location graphs loaded and stream events at one Location.
  2. Refresh Worktrees in the real TUI during that streaming/compaction workload.
  3. Compare native subscriber visits and network latency with few loaded graphs.

The deterministic regression is available on pascalandr:bus-location-fanout:
from packages/core, run bun test test/bus-fanout.test.ts.
Running its two unrelated-visit checks against the original Bus fails; the
candidate passes while preserving all matching/global deliveries.

Screenshot and/or share link

Logic/network issue; the proposed fix changes no TUI layout.

Operating System

Windows 11 x64, build 26200; PowerShell 7.6.6.

Terminal

Official CLI in Windows ConPTY, 120x40.

Activity

  1. github-actions commented on Oct 3, 2026

    @github-actions
    Contributor

    Potential overlap with existing event fan-out work—please compare:

    For keybind-related issues, please also check our pinned keybinds documentation: #4997

  2. opencodejr commented on Oct 27, 2026

    @opencodejr

    Thanks for the detailed write-up and the measurements!

    In short, you're asking for the core Bus to route Location-scoped events by Location and event type before PubSub delivery. Right now every live event goes through one shared PubSub and each Location subscriber filters afterwards, so unrelated loaded Locations still get visited. I checked packages/core/src/bus.ts and that's how it works today. Delivery is still correct, so I've filed this as a performance improvement rather than a bug. Maintainers will consider it, and your branch and the test/bus-fanout.test.ts regression test should make it easy to evaluate.

    Related:

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions