Refactor hooks and worker service for improved session management and logging

- Updated new-hook.js, save-hook.js, and summary-hook.js to enhance logging and session handling.
- Simplified session auto-creation logic in worker-service.ts to prioritize observation data preservation.
- Added a blocking wait in ensureWorkerRunning function to prevent race conditions during worker startup.
- Improved error handling and logging consistency across hooks.
This commit is contained in:
Alex Newman
2025-11-04 15:28:45 -05:00
parent 1b9cec2a95
commit 9fb43d8b06
6 changed files with 53 additions and 75 deletions
+8
View File
@@ -35,6 +35,14 @@ export function ensureWorkerRunning(): void {
cwd: packageRoot,
stdio: 'ignore'
});
// Give PM2 200ms to actually start the worker
// Prevents race condition where hooks fire before worker is ready
// Simple blocking wait - no complex health checks needed
const start = Date.now();
while (Date.now() - start < 200) {
// Busy wait
}
}
});
}