Skip to content

Fix agent shutdown lifecycle: no-op shutdown, orphaned LS processes, missing MCP cleanup#1195

Open
Asher- wants to merge 3 commits intooraios:mainfrom
Asher-:fix/agent-shutdown-lifecycle
Open

Fix agent shutdown lifecycle: no-op shutdown, orphaned LS processes, missing MCP cleanup#1195
Asher- wants to merge 3 commits intooraios:mainfrom
Asher-:fix/agent-shutdown-lifecycle

Conversation

@Asher-
Copy link

@Asher- Asher- commented Mar 21, 2026

Problem

Three related bugs preventing proper cleanup of language server processes, found independently by 4 auditor agents (high confidence):

  1. SerenaAgent.shutdown() was a no-op — checked hasattr(self, "_is_initialized") but that attribute was never set, so shutdown always returned early. All language server subprocesses leaked on every session.

  2. _activate_project() orphaned LS processes — replaced self._active_project without shutting down the previous project first.

  3. MCP server_lifespan() never called agent.shutdown() — logged "shutting down" but didn't actually shut down.

Fix

  • Replace _is_initialized guard with hasattr(self, "_active_project") which correctly guards against __del__ on partial construction while allowing shutdown to run on fully constructed agents.
  • Call old_project.shutdown() before switching projects.
  • Add agent.shutdown() in try/finally in MCP lifespan.

Verification

  • uv run poe format — clean
  • uv run poe type-check — clean
  • uv run poe test — 145 passed (1 pre-existing csharp env failure)
  • Re-audited by 4 independent agents — zero regressions found

Asher- and others added 3 commits March 20, 2026 19:07
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant