Skip to content

fix: register API event listeners on tab providers created via commands#11510

Draft
roomote[bot] wants to merge 2 commits intomainfrom
fix/tab-provider-api-events-11507
Draft

fix: register API event listeners on tab providers created via commands#11510
roomote[bot] wants to merge 2 commits intomainfrom
fix/tab-provider-api-events-11507

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Feb 17, 2026

Related GitHub Issue

Closes: #11507

Description

This PR attempts to address Issue #11507. Feedback and guidance are welcome.

Root cause: When openClineInNewTab() is called from command handlers (popoutButtonClicked or openInNewTab in registerCommands.ts), the returned ClineProvider was discarded without calling API.registerListeners(). This meant events like taskCreated, message, taskCompleted etc. were never forwarded through the RooCodeAPI EventEmitter. In contrast, when called from API.startNewTask(), registerListeners() was properly called.

Fix: Added a callback hook mechanism:

  1. src/activate/registerCommands.ts: Added setOnTabProviderCreated(callback) function that stores a callback, and invokes it inside openClineInNewTab() after the tab provider is fully set up.

  2. src/extension/api.ts: During API construction, calls setOnTabProviderCreated() with a callback that invokes this.registerListeners(provider), ensuring every tab provider created via commands gets event listeners registered.

This approach is minimally invasive -- it adds a simple hook without changing the existing function signature of openClineInNewTab or requiring the API instance to be passed into command registration.

Test Procedure

  • Added src/extension/__tests__/api-tab-events.spec.ts with 3 tests:
    1. Verifies setOnTabProviderCreated is called during API construction
    2. Verifies registerListeners is called on tab providers created via commands
    3. Verifies registerListeners is called on the sidebar provider during construction
  • All tests pass: cd src && npx vitest run extension/__tests__/api-tab-events.spec.ts
  • Existing API tests (api-send-message.spec.ts) continue to pass

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: No documentation updates are required.
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - no UI changes.

Documentation Updates

No documentation updates are required.

Additional Notes

The fix ensures that tab providers created via any path (commands, API) will have their events forwarded through the RooCodeAPI EventEmitter.

Start a new Roo Code Cloud session on this branch

When opening Roo Code in a new tab via command palette (openInNewTab or
popoutButtonClicked), the returned ClineProvider was discarded without
calling registerListeners(). This meant events like taskCreated, message,
taskCompleted etc. were never forwarded through the RooCodeAPI EventEmitter.

This fix adds a callback hook (setOnTabProviderCreated) in registerCommands
that the API registers during construction. When openClineInNewTab creates
a new tab provider, it invokes this callback so the API can attach its
event forwarding listeners.

Fixes #11507
@roomote
Copy link
Contributor Author

roomote bot commented Feb 17, 2026

Rooviewer Clock   See task

All previously flagged issues have been resolved. No new issues found.

  • Double event listener registration: startNewTask({ newTab: true }) calls registerListeners explicitly after openClineInNewTab, but the new onTabProviderCreatedCallback also calls it, resulting in duplicate event emissions.
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

this.registerListeners(this.sidebarProvider)

// Ensure tab providers created via commands also get event listeners.
setOnTabProviderCreated((provider) => this.registerListeners(provider))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This callback now registers listeners on every tab provider created via openClineInNewTab, but startNewTask({ newTab: true }) (line ~188-189) also explicitly calls this.registerListeners(provider) after openClineInNewTab returns. The result is double-registration: every event from tab providers created through startNewTask will be emitted twice through the API EventEmitter. The explicit this.registerListeners(provider) call in startNewTask should be removed now that the callback handles it.

Fix it with Roo Code or mention @roomote and request a fix.

Copy link

Choose a reason for hiding this comment

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

@roomote fix this

Copy link
Contributor Author

@roomote roomote bot Feb 17, 2026

Choose a reason for hiding this comment

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

Fixaroo Clock   See task

Removed the duplicate registerListeners call in startNewTask since the setOnTabProviderCreated callback already handles it. All tests and checks pass.

View commit | Revert commit

The setOnTabProviderCreated callback already registers listeners on tab
providers created via openClineInNewTab. The explicit registerListeners
call in startNewTask caused double event registration for tab providers
created through that code path.
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.

[BUG] RooCodeAPI Events Not Emitted When Using "Open in New Tab" Command

2 participants

Comments