From b8b88d998c77cb20d468577d544bfd1f9f130332 Mon Sep 17 00:00:00 2001 From: Rod Boev Date: Thu, 5 Feb 2026 09:02:16 -0500 Subject: [PATCH] fix: fail open on /api/context/inject during initialization The /api/context/inject endpoint previously blocked for up to 5 minutes (300s timeout) waiting for initializationComplete, which includes MCP connection setup. On Windows, the MCP connection can hang indefinitely, causing the context hook to never return and blocking Claude Code startup. This change makes the endpoint fail open: if the worker hasn't finished initializing, return empty context immediately instead of blocking. The hook completes fast, and context becomes available on subsequent prompts once initialization finishes in the background. Closes #958 --- src/services/worker-service.ts | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/services/worker-service.ts b/src/services/worker-service.ts index b7ade857..cad3da4c 100644 --- a/src/services/worker-service.ts +++ b/src/services/worker-service.ts @@ -200,17 +200,11 @@ export class WorkerService { this.server.registerRoutes(new SettingsRoutes(this.settingsManager)); this.server.registerRoutes(new LogsRoutes()); - // Early handler for /api/context/inject to avoid 404 during startup + // Early handler for /api/context/inject — fail open if not yet initialized this.server.app.get('/api/context/inject', async (req, res, next) => { - const timeoutMs = 300000; // 5 minute timeout for slow systems - const timeoutPromise = new Promise((_, reject) => - setTimeout(() => reject(new Error('Initialization timeout')), timeoutMs) - ); - - await Promise.race([this.initializationComplete, timeoutPromise]); - - if (!this.searchRoutes) { - res.status(503).json({ error: 'Search routes not initialized' }); + if (!this.initializationCompleteFlag || !this.searchRoutes) { + logger.warn('SYSTEM', 'Context requested before initialization complete, returning empty'); + res.status(200).json({ content: [{ type: 'text', text: '' }] }); return; }