chore: bump version to 9.1.0
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -254,20 +254,25 @@ export class WorkerService {
|
||||
next(); // Delegate to SearchRoutes handler
|
||||
});
|
||||
|
||||
// Early handler for /api/sessions/init to wait for database initialization
|
||||
// Fixes race condition where session-init hook is called before DB is ready
|
||||
// See: https://github.com/thedotmack/claude-mem/issues/XXX
|
||||
this.server.app.post('/api/sessions/init', async (req, res, next) => {
|
||||
const timeoutMs = 30000; // 30 second timeout for session init
|
||||
const timeoutPromise = new Promise((_, reject) =>
|
||||
// Guard ALL /api/* routes during initialization — wait for DB with timeout
|
||||
// Exceptions: /api/health, /api/readiness, /api/version (handled by Server.ts core routes before this middleware)
|
||||
// and /api/context/inject (handled above with fail-open)
|
||||
this.server.app.use('/api', async (req, res, next) => {
|
||||
if (this.initializationCompleteFlag) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
const timeoutMs = 30000;
|
||||
const timeoutPromise = new Promise<void>((_, reject) =>
|
||||
setTimeout(() => reject(new Error('Database initialization timeout')), timeoutMs)
|
||||
);
|
||||
|
||||
try {
|
||||
await Promise.race([this.initializationComplete, timeoutPromise]);
|
||||
next(); // Delegate to SessionRoutes handler
|
||||
next();
|
||||
} catch (error) {
|
||||
logger.error('HTTP', 'Session init failed waiting for initialization', {}, error as Error);
|
||||
logger.error('HTTP', `Request to ${req.method} ${req.path} rejected — DB not initialized`, {}, error as Error);
|
||||
res.status(503).json({
|
||||
error: 'Service initializing',
|
||||
message: 'Database is still initializing, please retry'
|
||||
|
||||
Reference in New Issue
Block a user