Conversation
Greptile SummaryImplemented automatic cleanup of idle child sessions to prevent history pollution. Added a global "reaper" that monitors Key changes:
The implementation handles empty responses gracefully and ensures tmux panes are properly closed when sessions are deleted. Confidence Score: 3/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant User
participant Plugin
participant BackgroundManager
participant TmuxSessionManager
participant GlobalReaper
participant SessionAPI
participant TUI
User->>Plugin: Launch background task
Plugin->>SessionAPI: Create child session
SessionAPI-->>Plugin: session.created event
Plugin->>TmuxSessionManager: onSessionEvent(session.created)
TmuxSessionManager->>TmuxSessionManager: Spawn tmux pane
Plugin->>BackgroundManager: Launch task in session
BackgroundManager->>SessionAPI: Send prompt to session
Note over BackgroundManager: Task executes...
BackgroundManager->>BackgroundManager: Poll for completion
BackgroundManager->>SessionAPI: Check session status
SessionAPI-->>BackgroundManager: Status: idle
BackgroundManager->>BackgroundManager: Mark task completed
SessionAPI-->>Plugin: session.idle event
Plugin->>GlobalReaper: Detect idle child session
GlobalReaper->>GlobalReaper: Wait 2 seconds
GlobalReaper->>SessionAPI: Get session details
SessionAPI-->>GlobalReaper: Session has parentID
GlobalReaper->>SessionAPI: Delete session (via deleteSession utility)
GlobalReaper->>TUI: Show toast notification
GlobalReaper->>TUI: Re-select parent session
SessionAPI-->>Plugin: session.deleted event
Plugin->>TmuxSessionManager: onSessionEvent(session.deleted)
TmuxSessionManager->>TmuxSessionManager: Close tmux pane
|
| const sessionID = event.properties.sessionID; | ||
|
|
||
| // Wait a bit to ensure the parent tool has time to read the result | ||
| setTimeout(async () => { |
There was a problem hiding this comment.
logic: setTimeout creates async cleanup that won't be awaited. If the event handler completes before the timeout fires, there's no guarantee the cleanup will execute.
| setTimeout(async () => { | |
| // Use async function but don't await (let it run in background) | |
| (async () => { | |
| await new Promise(resolve => setTimeout(resolve, 2000)); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/index.ts
Line: 126:126
Comment:
**logic:** `setTimeout` creates async cleanup that won't be awaited. If the event handler completes before the timeout fires, there's no guarantee the cleanup will execute.
```suggestion
// Use async function but don't await (let it run in background)
(async () => {
await new Promise(resolve => setTimeout(resolve, 2000));
```
How can I resolve this? If you propose a fix, please make it concise.| // Session might already be gone or other error | ||
| log(`[reaper] error during cleanup`, { sessionID, error: String(err) }); | ||
| } | ||
| }, 2000); |
There was a problem hiding this comment.
syntax: The closing })(); for the async IIFE is missing.
| }, 2000); | |
| }, 2000); | |
| })(); |
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/index.ts
Line: 155:155
Comment:
**syntax:** The closing `})();` for the async IIFE is missing.
```suggestion
}, 2000);
})();
```
How can I resolve this? If you propose a fix, please make it concise.| }).catch(() => {}); | ||
|
|
||
| // 3. Force TUI to refresh its session view/navigation by re-selecting parent | ||
| await (ctx.client.tui as any).selectSession({ body: { sessionID: parentID } }).catch(() => {}); |
There was a problem hiding this comment.
style: Check that selectSession method exists in the TUI client API to avoid runtime errors.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/index.ts
Line: 149:149
Comment:
**style:** Check that `selectSession` method exists in the TUI client API to avoid runtime errors.
How can I resolve this? If you propose a fix, please make it concise.
alvinreal
left a comment
There was a problem hiding this comment.
Reviewed the diff for PR #54 (Kill sessions).
Scope: This PR modifies background-manager.ts and tmux-session-manager.ts to handle session cleanup. Changes: (1) always mark tasks completed even with empty response, (2) refactors session event handling into unified onSessionEvent handler, (3) fixes URL origin handling.
Logic issues:
- Background manager now marks task completed even on empty — this could mark tasks complete prematurely if the agent simply hasn't responded yet. The original guard was intentional to prevent false completions.
- The self-kill bug the author mentioned (kills own session) is likely in the unified — there's no longer a check for before marking a session as tracked. If a parent session fires , it could incorrectly try to close its own tmux pane.
Tests: No test files modified or added. CI checks have not run on this branch.
Status: PR is marked CONFLICTING (needs rebase). Author noted POC with bugs. Recommend closing and reopening as a draft when ready.
Decision: Request changes. Please address the self-kill bug and the premature-completion logic before re-requesting review.
alvinreal
left a comment
There was a problem hiding this comment.
Reviewed the diff for PR #54 (Kill sessions).
Scope: This PR modifies background-manager.ts and tmux-session-manager.ts to handle session cleanup. Changes: (1) always mark tasks completed even with empty response, (2) refactors session event handling into unified onSessionEvent handler, (3) fixes URL origin handling.
Logic issues:
- Background manager now marks task completed even on empty responseText - this could mark tasks complete prematurely if the agent has not responded yet. The original guard
if (responseText)was intentional to prevent false completions. - The self-kill bug the author mentioned (kills own session) is likely in the unified onSessionEvent - there is no longer a check for parentID before marking a session as tracked. If a parent session fires session.deleted, it could incorrectly try to close its own tmux pane.
Tests: No test files modified or added. CI checks have not run on this branch.
Status: PR is marked CONFLICTING (needs rebase). Author noted POC with bugs. Recommend closing and reopening as a draft when ready.
Decision: Request changes. Please address the self-kill bug and the premature-completion logic before re-requesting review.
Related #50
POC implementation, need to be redone; has bugs, kills sometimes own session; tmux broke?