Skip to content

fix(tui): only apply vcs branch and session events for the local directory - #41842

Closed
BB-84C wants to merge 1 commit into
anomalyco:devfrom
BB-84C:fix/tui-event-directory-guards
Closed

BB-84C wants to merge 1 commit into
anomalyco:devfrom
BB-84C:fix/tui-event-directory-guards

Conversation

@BB-84C

@BB-84C BB-84C commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #39181

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

The TUI subscribes to the control-plane global event stream (/global/event), which broadcasts events from every workspace attached to a shared opencode serve. Two handlers in packages/tui/src/context/sync.tsx did not use the event envelope's directory field:

  • vcs.branch.updated only checked workspace === project.workspace.current(). With experimental workspaces disabled both sides are undefined, so the guard always matched and the branch of any attached workspace's repository overwrote the statusline branch of every attached TUI. The branch does not even need to be switched inside a TUI — switching it externally (GitHub Desktop, shell) produces the same cross-workspace display contamination, since the fs watcher publishes through the same global stream (repro added in TUI statusline shows git branches from other workspaces when multiple TUIs attach to one shared server #41839).
  • session.updated upserted every received session into the local session list, so sessions belonging to other directories entered the store and could be picked/continued, routing subsequent requests by that session's directory.

Both handlers now guard on the event's directory against the TUI's own instance directory (project.instance.directory()), which the event envelope already carries for exactly this purpose. The packages/app event consumer (server-sync.tsx) already routes events to per-directory stores by envelope directory, so no change is needed there.

#39181 additionally documents a related fan-out for plugin-driven events (tui.session.select, tui.toast.show, tui.command.execute, tui.prompt.append); that is not addressed here and remains tracked there.

How did you verify your code works?

  • Updated the existing vcs.branch.updated test to cover the foreign-directory case (foreign directory + active workspace is now rejected; own directory + active workspace is applied).
  • Added a test asserting that session.updated events from other directories do not enter the local session list, while events for the local directory do.
  • bun test test/cli/cmd/tui/ — 24 pass, 0 fail; tsgo --noEmit clean for packages/tui.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

…ctory

The TUI subscribes to the control-plane global event stream
(/global/event), which broadcasts events from every workspace attached
to a shared server. The vcs.branch.updated handler only checked the
workspace (always matching when workspaces are disabled), so the branch
of any workspace's repository overwrote the statusline branch of every
attached TUI. session.updated likewise upserted foreign sessions into
the local session list.

Guard both handlers on the event's directory against the TUI's own
instance directory, which the event envelope already carries.
@github-actions

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TUI applies events from other directories when several TUIs share one server

1 participant