fix: implement two-stage readiness to prevent fresh install timeout #521
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
Fresh plugin installations fail with "operation was aborted" timeout errors because hooks wait for full worker initialization including MCP connection, which can take 10-30+ seconds on first run (downloading dependencies, creating database, etc.).
The 15-second hook timeout is insufficient for this initialization time.
Error seen by users:
Root Cause Analysis
The Windows stability fix (PR #378) changed hooks to use
/api/readinesswhich waits for full initialization including MCP connection. However, hooks only need database and SearchManager to function - they don't use MCP at all.Initialization Timeline
The coupling meant MCP initialization (the slow part) blocked hooks that don't need it.
Solution: Two-Stage Readiness
Introduce staged initialization to separate what hooks need from full readiness:
/api/healthwaitForHealth()(start command)/api/core-readyisWorkerHealthy()(hooks)/api/readinessChanges
src/services/worker-service.ts:
coreReadyflag alongside existingmcpReadyandinitializationCompleteFlag/api/core-readyendpoint that returns 200 when database+SearchManager readywaitForHealth()to use/api/health(server listening check only)coreReady=trueafter SearchManager initialization, before MCP connectionsrc/shared/worker-utils.ts:
isWorkerHealthy()to use/api/core-readyinstead of/api/readinessplugin/hooks/hooks.json:
Benefits
/api/readinessunchanged for diagnostics/toolingTest Plan
rm -rf ~/.claude-mem+ new Claude session