Fix agent shutdown lifecycle: no-op shutdown, orphaned LS processes, missing MCP cleanup#1195
Open
Asher- wants to merge 3 commits intooraios:mainfrom
Open
Fix agent shutdown lifecycle: no-op shutdown, orphaned LS processes, missing MCP cleanup#1195Asher- wants to merge 3 commits intooraios:mainfrom
Asher- wants to merge 3 commits intooraios:mainfrom
Conversation
…kit-lsp sourcekit-lsp was launched with no arguments, giving it no location to store its background index. Without --scratch-path, textDocument/references always returns empty because there is no index store for cross-file symbol resolution. - Pass --scratch-path <repo>/.build/sourcekit-lsp when launching - Increase local indexing delay from 5s to 10s (real projects need more time) - Add retry logic for local runs when references are empty, not just CI Fixes root cause of issue oraios#876. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
On macOS, bare sourcekit-lsp resolves to Command Line Tools version which has limited indexing capabilities. xcrun without DEVELOPER_DIR also resolves to CLT. Setting DEVELOPER_DIR=/Applications/Xcode.app/Contents/Developer gives the full Xcode sourcekit-lsp with proper background indexing support. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…missing MCP cleanup Three related bugs preventing proper cleanup of language server processes: 1. SerenaAgent.shutdown() checked `hasattr(self, "_is_initialized")` but that attribute was never set, making shutdown always return early (no-op). Replace with `hasattr(self, "_active_project")` which is set early in __init__ and correctly guards against __del__ on partial construction. 2. _activate_project() replaced self._active_project without shutting down the previous project first, orphaning its language server processes. Now calls old_project.shutdown() before switching. 3. MCP server_lifespan() logged "shutting down" but never called agent.shutdown(), so language servers were orphaned on MCP server exit. Now calls agent.shutdown() in a try/finally block.
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.
Problem
Three related bugs preventing proper cleanup of language server processes, found independently by 4 auditor agents (high confidence):
SerenaAgent.shutdown()was a no-op — checkedhasattr(self, "_is_initialized")but that attribute was never set, so shutdown always returned early. All language server subprocesses leaked on every session._activate_project()orphaned LS processes — replacedself._active_projectwithout shutting down the previous project first.MCP
server_lifespan()never calledagent.shutdown()— logged "shutting down" but didn't actually shut down.Fix
_is_initializedguard withhasattr(self, "_active_project")which correctly guards against__del__on partial construction while allowing shutdown to run on fully constructed agents.old_project.shutdown()before switching projects.agent.shutdown()intry/finallyin MCP lifespan.Verification
uv run poe format— cleanuv run poe type-check— cleanuv run poe test— 145 passed (1 pre-existing csharp env failure)