Plugins execute in shared TUI worker, causing per-instance env/session confusion #8337

Open
opened 2026-02-16 18:09:43 -05:00 by yindo · 1 comment
Owner

Originally created by @rickross on GitHub (Feb 2, 2026).

Originally assigned to: @thdxr on GitHub.

Summary

When multiple opencode instances are running with different environment variables and session IDs, plugins appear to execute inside a shared TUI worker process. As a result, plugins read the worker’s environment and session context rather than the per-instance values, leading to incorrect behavior across instances.

Impact

  • Plugins that rely on per-instance environment variables or session IDs can bind to the wrong context.
  • Events can be routed to the wrong instance/session.
  • Duplicate event handling can occur if plugins are initialized more than once in the shared worker.

Evidence

Plugin logs show:

  • process.argv indicates execution inside tui/worker.js
  • OPENCODE_SESSION_ID and other env values reflect the worker, not the active CLI instance

Steps to Reproduce

  1. Start opencode instance A with one set of env vars and session ID.
  2. Start opencode instance B with a different set.
  3. Observe plugin logs: they show the worker context rather than the instance context.
  4. Actions/events get routed to the wrong instance.

Expected

Plugins should execute with the correct per-instance context:

  • per-session worker, or
  • per-session plugin init context, or
  • plugin execution in the instance process

Possible Fix Directions

  • Scope the TUI worker per session/instance
  • Provide per-session plugin initialization context
  • Move plugin execution out of the shared worker
Originally created by @rickross on GitHub (Feb 2, 2026). Originally assigned to: @thdxr on GitHub. ## Summary When multiple opencode instances are running with different environment variables and session IDs, plugins appear to execute inside a shared TUI worker process. As a result, plugins read the worker’s environment and session context rather than the per-instance values, leading to incorrect behavior across instances. ## Impact - Plugins that rely on per-instance environment variables or session IDs can bind to the wrong context. - Events can be routed to the wrong instance/session. - Duplicate event handling can occur if plugins are initialized more than once in the shared worker. ## Evidence Plugin logs show: - process.argv indicates execution inside tui/worker.js - OPENCODE_SESSION_ID and other env values reflect the worker, not the active CLI instance ## Steps to Reproduce 1. Start opencode instance A with one set of env vars and session ID. 2. Start opencode instance B with a different set. 3. Observe plugin logs: they show the worker context rather than the instance context. 4. Actions/events get routed to the wrong instance. ## Expected Plugins should execute with the correct per-instance context: - per-session worker, or - per-session plugin init context, or - plugin execution in the instance process ## Possible Fix Directions - Scope the TUI worker per session/instance - Provide per-session plugin initialization context - Move plugin execution out of the shared worker
yindo added the opentui label 2026-02-16 18:09:43 -05:00
Author
Owner

@github-actions[bot] commented on GitHub (Feb 2, 2026):

This issue might be a duplicate of existing issues. Please check:

  • #9650: [FEATURE]: Support sessionID Filter for SSE Event Subscription - SSE event endpoint broadcasts all events without sessionID filtering, causing the same architectural problem of events from multiple sessions being sent to the same subscriber
  • #5627: ACP event subscription architecture causes cross-session pollution and duplicate events - demonstrates the same core issue with events from session B being sent to session A
  • #6573: Sessions hang indefinitely when Task tool spawns subagents via REST API - demonstrates consequences of shared worker/context confusion with subagent events mixed with parent session events
  • #6946: Desktop app session out of sync with TUI - potential symptom of shared worker state issues
  • #9156: Memory leak: Uncleaned timeouts, intervals, and subscriptions - event subscriptions are never cleaned up, contributing to per-instance context confusion
  • #9157: Memory leak: Instance disposal doesn't clean up plugins or cached resources - plugin cleanup not being handled per-instance

Feel free to ignore if none of these address your specific case.

@github-actions[bot] commented on GitHub (Feb 2, 2026): This issue might be a duplicate of existing issues. Please check: - #9650: [FEATURE]: Support `sessionID` Filter for SSE Event Subscription - SSE event endpoint broadcasts all events without sessionID filtering, causing the same architectural problem of events from multiple sessions being sent to the same subscriber - #5627: ACP event subscription architecture causes cross-session pollution and duplicate events - demonstrates the same core issue with events from session B being sent to session A - #6573: Sessions hang indefinitely when Task tool spawns subagents via REST API - demonstrates consequences of shared worker/context confusion with subagent events mixed with parent session events - #6946: Desktop app session out of sync with TUI - potential symptom of shared worker state issues - #9156: Memory leak: Uncleaned timeouts, intervals, and subscriptions - event subscriptions are never cleaned up, contributing to per-instance context confusion - #9157: Memory leak: Instance disposal doesn't clean up plugins or cached resources - plugin cleanup not being handled per-instance Feel free to ignore if none of these address your specific case.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#8337