opencode-mission-control icon indicating copy to clipboard operation
opencode-mission-control copied to clipboard

bug: notifications route to active session instead of launching session

Open nigel-dev opened this issue 9 months ago • 0 comments

Description

Mission Control tracks a single global activeSessionID that gets overwritten by whichever session the user interacts with last. When a job completes or needs attention, the notification is sent to activeSessionID — not to the session that launched the job. If the user switched sessions between launching and completion, the notification goes to the wrong session.

Steps to Reproduce

  1. In session A, launch a job: mc_launch(name: "my-job", prompt: "...")
  2. Switch to session B (or create a new session)
  3. Job completes → notification fires
  4. Notification appears in session B instead of session A

Root Cause

src/index.ts has a single mutable variable that gets overwritten on every interaction:

// line 131 — ONE global variable for all sessions
let activeSessionID: string | undefined;

// line 222-224 — overwritten by command execution
'command.execute.before': (input) => {
  if (isValidSessionID(input.sessionID)) {
    activeSessionID = input.sessionID;
  }
}

// line 228-229 — overwritten by tool execution
'tool.execute.before': async (input) => {
  if (input.sessionID && isValidSessionID(input.sessionID)) {
    activeSessionID = input.sessionID;
  }
}

The notify callback (lines 178-190) calls getActiveSessionID() which returns this global — not the session that launched the job.

Proposed Fix

  1. Add launchSessionID field to JobSchema — captured at mc_launch / mc_plan time from the calling session
  2. Route notifications to job.launchSessionID instead of getActiveSessionID()
  3. Fallback to activeSessionID if the launch session is no longer available (user closed it)
  4. For plan-level notifications (not job-specific), use the session that created the plan

Files Involved

  • src/index.ts — activeSessionID global, setSharedNotifyCallback
  • src/lib/schemas.ts — JobSchema needs launchSessionID field
  • src/lib/orchestrator.ts — showToast and notify callbacks need session routing
  • src/tools/launch.ts — capture sessionID at launch time
  • src/tools/plan.ts — capture sessionID at plan creation time

Impact

This is a prerequisite for:

  • #50 (Two-way job messaging) — messages must route to the correct session
  • #65 (Serve-based orchestration) — question relay must target the launching session

Without this fix, any session-aware communication feature will deliver messages to the wrong session when users multitask.

nigel-dev avatar Feb 14 '26 17:02 nigel-dev