fix: Close sub-agents, preventing them from becoming orphan processes#520
fix: Close sub-agents, preventing them from becoming orphan processes#520alex-alecu merged 4 commits intodevfrom
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge OverviewThis PR adds graceful signal-based shutdown to the The implementation is clean and correct:
Key correctness observations:
Files Reviewed (4 files)
|
|
Are you sure that this is only a subagent problem? Could also be that this happens for the main CLI alltogether right? |
3 similar comments
|
Are you sure that this is only a subagent problem? Could also be that this happens for the main CLI alltogether right? |
|
Are you sure that this is only a subagent problem? Could also be that this happens for the main CLI alltogether right? |
|
Are you sure that this is only a subagent problem? Could also be that this happens for the main CLI alltogether right? |
Wrap Instance.disposeAll() and server.stop() in try/finally so abort.abort() always fires, preventing the process from hanging if either call rejects.
Wrap Instance.disposeAll() and server.stop() in try/finally so abort.abort() always fires, preventing the process from hanging if either call rejects.
Context
Fix sub-agents becoming orphan processes.
Implementation
All 4 fixes implemented and typechecked. Here's a summary of what was changed:
src/cli/cmd/serve.tsInstanceimportawait new Promise(() => {})+ unreachableserver.stop()with an AbortController pattern: registersshutdownonSIGTERM,SIGINT,SIGHUPthat callsInstance.disposeAll()thenserver.stop(true)then abortssrc/cli/cmd/web.tsInstanceimportsrc/cli/cmd/tui/thread.tsSIGHUPandSIGTERMhandlers after the existingSIGUSR2handler (line 129), callingclient.call("shutdown", undefined)with.catch(() => {})to handle the case where the worker has already exitedSIGINT— the TUI handles Ctrl+C as a keyboard eventsrc/index.tsInstanceimportawait Instance.disposeAll()in thefinallyblock after telemetry shutdown and beforeprocess.exit()as a safety net (no-op if already disposed by signal handlers)Screenshots
How to Test
Run CLI and implement something - ask Kilo to spawn multiple sub-agents for each task - and look in Activity Monitor for "kilo" processes being closed after the implementation is done.
Get in Touch
We'd love to have a way to chat with you about your changes if necessary. If you're in the Kilo Code Discord, please share your handle here.