fix: clean up orphaned processes and LSP state on shutdown#20006
fix: clean up orphaned processes and LSP state on shutdown#20006nianyi778 wants to merge 2 commits into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Closes #12767
Related to #18632
Type of change
What does this PR do?
This fixes two shutdown paths that still look leaky on current
dev.First,
packages/opencode/src/index.tsdoes not register process-level handlers forSIGTERM,SIGHUP, orSIGPIPE. The TUI has its ownSIGHUPhandling, but commands likeopencode run,opencode acp, andopencode servedo not. This PR adds a smallsignal.tshelper that callsInstance.disposeAll()and then exits, with a 5 second timeout in case cleanup hangs.Second, LSP shutdown was stopping the child process but keeping in-memory state alive. This clears the LSP diagnostics map, file version map, and the top-level LSP client caches during shutdown.
I also clear the prompt
msgsarray right afterprocessor.process(...)returns, since that array can get large and is not needed for the rest of the loop iteration.I did not copy over older PR changes around plugin subscriptions or processor cleanup because current
devalready uses scoped Effect subscriptions there, andSessionProcessoralready runs cleanup throughEffect.ensuring(cleanup()).How did you verify your code works?
I tested the signal path locally with the ACP command, since it is a long-running non-TUI entrypoint:
bun run ./src/index.ts acpSIGHUPSIGTERMI also tried to run
bun typecheckinpackages/opencode, but this checkout currently does not havetsgoinstalled innode_modules/.bin, so the script exits before typechecking starts.Screenshots / recordings
N/A
Checklist