{"record":{"id":"3d00c01008255fee","repo":"thedotmack/claude-mem","slug":"worker-is-still-initializing-please-retry","errorCode":null,"errorMessage":"Worker is still initializing, please retry","messagePattern":"Worker is still initializing, please retry","errorType":"http","errorClass":null,"httpStatus":503,"severity":"warning","filePath":"src/services/server/Server.ts","lineNumber":251,"sourceCode":"        platform: process.platform,\n        pid: process.pid,\n        initialized: this.options.getInitializationComplete(),\n        mcpReady: this.options.getMcpReady(),\n        ai: this.options.getAiStatus(),\n        dependencies: dependencyHealth,\n        rateLimits: globalRateLimitStore.getMostRecentByWindow(),\n        ...(queueHealth ? { queue: queueHealth } : {}),\n      });\n    });\n\n    this.app.get('/api/readiness', (_req: Request, res: Response) => {\n      if (this.options.getInitializationComplete()) {\n        res.status(200).json({\n          status: 'ready',\n          mcpReady: this.options.getMcpReady(),\n        });\n      } else {\n        res.status(503).json({\n          status: 'initializing',\n          message: 'Worker is still initializing, please retry',\n        });\n      }\n    });\n\n    this.app.get('/api/version', (_req: Request, res: Response) => {\n      res.status(200).json({ version: BUILT_IN_VERSION });\n    });\n\n    this.app.get('/api/instructions', (req: Request, res: Response) => {\n      const topic = (req.query.topic as string) || 'all';\n      const operation = req.query.operation as string | undefined;\n\n      if (topic && !ALLOWED_TOPICS.includes(topic)) {\n        return res.status(400).json({ error: 'Invalid topic' });\n      }\n","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/server/Server.ts#L233-L269","documentation":"GET /api/readiness returns 503 with status 'initializing' until options.getInitializationComplete() flips true — the worker finishes database setup and boot-time caching before declaring ready. This is a designed transient signal, not a crash; readiness flips to 200 once initialization completes.","triggerScenarios":"Probing /api/readiness (or racing real API calls) during startup, especially first run with migrations; large databases or slow disks lengthen the window.","commonSituations":"Container orchestrators probing with initialDelaySeconds too small; test suites starting the server and immediately running requests; startup scripts chaining server start + first request with no wait.","solutions":["Poll /api/readiness until it returns 200 before sending traffic","Raise probe initialDelaySeconds / failureThreshold in Kubernetes or compose healthchecks","Gate integration tests on the readiness endpoint rather than a fixed sleep"],"exampleFix":"// before\nstartServer(); await sleep(1000); runTests(); // may hit 503\n\n// after\nstartServer();\nawait waitUntil(async () => (await fetch(`${base}/api/readiness`)).status === 200);\nrunTests();","handlingStrategy":"retry","validationCode":"async function waitForReady(base: string, timeoutMs = 30_000): Promise<void> {\n  const deadline = Date.now() + timeoutMs;\n  while (Date.now() < deadline) {\n    const res = await fetch(`${base}/api/readiness`);\n    if (res.status === 200) return;\n    const body = await res.json().catch(() => null);\n    if (!body || body.status !== 'initializing') throw new Error(`readiness probe failed: ${res.status}`);\n    await new Promise(r => setTimeout(r, 500)); // backoff between polls\n  }\n  throw new Error('server did not become ready in time');\n}","typeGuard":"function isInitializing(status: number, body: unknown): body is { status: 'initializing'; message: string } {\n  return status === 503 && typeof body === 'object' && body !== null && (body as { status?: string }).status === 'initializing';\n}","tryCatchPattern":"let res = await fetch(`${base}/api/readiness`);\nwhile (res.status === 503) {\n  await new Promise(r => setTimeout(r, 500)); // transient by design: retry with backoff\n  res = await fetch(`${base}/api/readiness`);\n}\nif (!res.ok) throw new Error(`server unhealthy: ${res.status}`);","preventionTips":["Gate all traffic on /api/readiness returning 200 instead of fixed sleeps","Set container probe initialDelaySeconds/failureThreshold to cover migrations","First-run and large databases init slower — size the retry budget accordingly"],"tags":["readiness","startup","http-503","health-check"],"backgroundTag":"service-not-ready","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}