Fix stale process cache after spawning bridge process#167
Merged
Conversation
On Windows, `isProcessAlive()` uses a 2-second cached `tasklist` snapshot populated when `stopBridge()` runs. When `restartSession` subsequently spawns a new bridge, the new PID is not in the cache, causing `ensureBridgeReady()` to misclassify the freshly spawned bridge as dead and trigger a spurious double-restart via `restartBridge()`. Unlike the explicit `restartSession` path, `restartBridge` passes `mcpSessionId` for resumption, so the second bridge silently resumes the old MCP session and `sessions.json` never records a new session ID. This caused two E2E tests to fail on Windows: - sessions/mcp-session #6: mcpSessionId unchanged after explicit restart - sessions/restart #9: `.capabilities` missing from `restart --json` Fix by resetting the tasklist cache immediately after spawning the bridge so the next `isProcessAlive()` check runs a fresh `tasklist`. The only `spawn()` call in src/ is in `startBridge`, so one invalidation site covers every bridge startup path. https://claude.ai/code/session_014w5QYdwZKHA5REd2pTEXwP
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.
Summary
This PR fixes an issue where the Windows tasklist cache used by
isProcessAlive()could return stale results after spawning a new bridge process, causing spurious double-restart failures.Changes
invalidateProcessAliveCache()export insrc/lib/utils.ts: New public function to clear the Windows tasklist cache and reset its TTL timersrc/lib/bridge-manager.ts: Immediately after spawning the bridge process, invalidate the cache so subsequentisProcessAlive()checks can observe the newly spawned PID instead of relying on a pre-spawn snapshotImplementation Details
The Windows process alive check uses a 2-second TTL cache to avoid excessive
tasklistcommand invocations. However, when a new bridge process is spawned, the cache may still contain a snapshot from before the spawn, causingisProcessAlive()to incorrectly returnfalsefor the new PID. This triggered spurious double-restart behavior in health checks that run immediately after spawning.By invalidating the cache right after spawning, we ensure the next
isProcessAlive()call will fetch a fresh tasklist that includes the newly spawned process.https://claude.ai/code/session_014w5QYdwZKHA5REd2pTEXwP