fix(tmux): close subagent pane when background task completes (#4773)#4850
Open
EvangelosMoschou wants to merge 2 commits into
Open
fix(tmux): close subagent pane when background task completes (#4773)#4850EvangelosMoschou wants to merge 2 commits into
EvangelosMoschou wants to merge 2 commits into
Conversation
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
Author
|
I have read the CLA Document and I hereby sign the CLA |
…s on task completion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 viaclient.session.abort(), but OpenCode does not reliably emit asession.deletedevent for aborted sessions. TheTmuxPollingManageronly triggers pane cleanup for sessions withstatus === "idle"— not for "stopped"/"cancelled" terminal states. Result: orphaned panes accumulate untilSESSION_TIMEOUT_MS(60 min) elapses.Fix
Added an explicit
onSubagentSessionDeletedcallback fromBackgroundManager→TmuxSessionManager, mirroring the existingonSubagentSessionCreatedpattern. WhentryCompleteTask()completes a task, after aborting the session, it now directly notifiesTmuxSessionManager.onSessionDeleted()to close the pane immediately.No double-close risk: if OpenCode's
session.deletedeventually arrives,onSessionDeletedchecksthis.sessions.get(sessionID)and returns early since our callback already removed the tracked session.3 files changed, +31/-1:
src/features/background-agent/manager.tsSubagentSessionDeletedEvent,OnSubagentSessionDeleted), config field, private field, callback call intryCompleteTask()src/features/background-agent/index.tssrc/create-managers.tstmuxSessionManager.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.deletedevent. Fixes #4773.onSubagentSessionDeletedinBackgroundManagerand invoke it afterabortSessionWithLogging()intryCompleteTask().create-managerstotmuxSessionManager.onSessionDeleted(); exported new types frombackground-agent/index.ts.session.deletedarrives,onSessionDeletedno-ops if already removed.Written for commit 17cbb90. Summary will update on new commits.