{"record":{"id":"3a2c302d20c97063","repo":"thedotmack/claude-mem","slug":"service-initializing","errorCode":"Service initializing","errorMessage":"Database is still initializing, please retry","messagePattern":"Database is still initializing, please retry","errorType":"http","errorClass":null,"httpStatus":503,"severity":"info","filePath":"src/services/worker-service.ts","lineNumber":400,"sourceCode":"    this.server.app.use(['/api', '/v1'], async (req, res, next) => {\n      if (\n        req.path === '/chroma/status' ||\n        req.path === '/health' ||\n        req.path === '/readiness' ||\n        req.path === '/version' ||\n        req.path === '/settings/dependency-health'\n      ) {\n        next();\n        return;\n      }\n\n      if (this.initializationCompleteFlag) {\n        next();\n        return;\n      }\n\n      logger.debug('WORKER', `Request to ${req.method} ${req.path} rejected — DB not initialized`);\n      res.status(503).json({\n        error: 'Service initializing',\n        message: 'Database is still initializing, please retry'\n      });\n      return;\n    });\n\n    this.server.registerRoutes(new ViewerRoutes(this.sseBroadcaster, this.dbManager, this.sessionManager));\n    const sessionRoutes = new SessionRoutes(this.sessionManager, this.dbManager, this.sdkAgent, this.geminiAgent, this.openRouterAgent, this.sessionEventBroadcaster, this, this.completionHandler);\n    this.server.registerRoutes(sessionRoutes);\n    attachIngestGeneratorStarter((sessionDbId, source) =>\n      sessionRoutes.ensureGeneratorRunning(sessionDbId, source),\n    );\n    this.server.registerRoutes(new DataRoutes(this.paginationHelper, this.dbManager, this.sessionManager, this.sseBroadcaster, this, this.startTime));\n    this.server.registerRoutes(new SettingsRoutes(this.settingsManager));\n    this.server.registerRoutes(new LogsRoutes());\n    this.server.registerRoutes(new MemoryRoutes(this.dbManager, 'claude-mem'));\n    this.server.registerRoutes(new ServerV1Routes({\n      getDatabase: () => this.dbManager.getConnection(),","sourceCodeStart":382,"sourceCodeEnd":418,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/worker-service.ts#L382-L418","documentation":"The worker service gates all HTTP routes behind an initializationCompleteFlag middleware. Until database initialization finishes, any request is rejected with 503 and code 'Service initializing', instructing the client to retry.","triggerScenarios":"Any HTTP request to the worker during the window between process start and DB init completion; requesting immediately after a worker restart while the database is being opened/migrated.","commonSituations":"Health checks or UI hitting the worker right after restart; orchestrators starting clients and worker simultaneously; slow DB init on cold storage.","solutions":["Retry the request with backoff until initialization completes","Wait for a readiness/health signal before sending real requests","Check worker logs for DB init failures if the condition persists"],"exampleFix":"// before\nfetch('http://127.0.0.1:37777/api/observations')  // immediately after start\n// after\nawait waitForWorkerReady('http://127.0.0.1:37777');\nfetch('http://127.0.0.1:37777/api/observations');","handlingStrategy":"retry","validationCode":"async function isWorkerReady(baseUrl: string) {\n  const r = await fetch(`${baseUrl}/health`);\n  return r.ok;\n}","typeGuard":null,"tryCatchPattern":"async function withRetry<T>(fn: () => Promise<T>, attempts = 10): Promise<T> {\n  for (let i = 0; i < attempts; i++) {\n    try { return await fn(); }\n    catch (e) {\n      if (i === attempts - 1) throw e;\n      await new Promise(r => setTimeout(r, 500 * (i + 1)));\n    }\n  }\n  throw new Error('unreachable');\n}","preventionTips":["Gate clients on a readiness/health endpoint before real calls","Use exponential backoff for all early-startup requests","Monitor DB init logs; alert if 503s persist beyond expected startup"],"tags":["http","startup","retry"],"backgroundTag":"request-timeout","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}