Skip to content

fix(tmux): close subagent pane when background task completes (#4773)#4850

Open
EvangelosMoschou wants to merge 2 commits into
code-yeongyu:devfrom
EvangelosMoschou:fix/tmux-pane-close-bg-task-completion
Open

fix(tmux): close subagent pane when background task completes (#4773)#4850
EvangelosMoschou wants to merge 2 commits into
code-yeongyu:devfrom
EvangelosMoschou:fix/tmux-pane-close-bg-task-completion

Conversation

@EvangelosMoschou
Copy link
Copy Markdown

@EvangelosMoschou EvangelosMoschou commented Jun 5, 2026

Bug

Tmux subagent panes stay open for ~60 minutes after background task completion instead of closing within seconds.

Root Cause

BackgroundManager.tryCompleteTask() aborts the subagent session via client.session.abort(), but OpenCode does not reliably emit a session.deleted event for aborted sessions. The TmuxPollingManager only triggers pane cleanup for sessions with status === "idle" — not for "stopped"/"cancelled" terminal states. Result: orphaned panes accumulate until SESSION_TIMEOUT_MS (60 min) elapses.

Fix

Added an explicit onSubagentSessionDeleted callback from BackgroundManagerTmuxSessionManager, mirroring the existing onSubagentSessionCreated pattern. When tryCompleteTask() completes a task, after aborting the session, it now directly notifies TmuxSessionManager.onSessionDeleted() to close the pane immediately.

No double-close risk: if OpenCode's session.deleted eventually arrives, onSessionDeleted checks this.sessions.get(sessionID) and returns early since our callback already removed the tracked session.

3 files changed, +31/-1:

File Change
src/features/background-agent/manager.ts +14: Types (SubagentSessionDeletedEvent, OnSubagentSessionDeleted), config field, private field, callback call in tryCompleteTask()
src/features/background-agent/index.ts +1: Export new types
src/create-managers.ts +13: Wire callback → tmuxSessionManager.onSessionDeleted()

Fixes #4773


Summary by cubic

Close tmux subagent panes immediately when a background task completes. Adds a direct session-deleted callback so panes don’t linger for ~60 minutes when OpenCode misses the session.deleted event. Fixes #4773.

  • Bug Fixes
    • Introduced onSubagentSessionDeleted in BackgroundManager and invoke it after abortSessionWithLogging() in tryCompleteTask().
    • Wired the callback in create-managers to tmuxSessionManager.onSessionDeleted(); exported new types from background-agent/index.ts.
    • Idempotent cleanup: if a later session.deleted arrives, onSessionDeleted no-ops if already removed.
    • Added a unit test to verify the deleted callback fires on task completion.

Written for commit 17cbb90. Summary will update on new commits.

Review in cubic

BackgroundManager.tryCompleteTask() aborts the subagent session via
client.session.abort(), but OpenCode does not reliably emit a
session.deleted event for aborted sessions. The tmux polling fallback
only closes panes for idle status, leaving panes orphaned until
SESSION_TIMEOUT_MS (60 min) elapses.

Add an explicit onSubagentSessionDeleted callback that fires
immediately after abortSessionWithLogging(), directly notifying
TmuxSessionManager to close the pane. This mirrors the existing
onSubagentSessionCreated pattern.

Fixes code-yeongyu#4773
@EvangelosMoschou
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

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]: Tmux subagent panes stay open after background task completion

1 participant