fix: address CodeRabbit review feedback on PR #1491

- Update POST_SPAWN_WAIT test assertion from 5000 to 15000 to match
  the constant change in hook-constants.ts
- Remove redundant readPidFile() from aggressiveStartupCleanup() —
  start() writes the new PID before this runs, so it always returns
  process.pid (already protected)
- Add waitForReadiness() to the reused-worker path in
  ensureWorkerStarted() to prevent concurrent hooks from racing
  past a cold-starting worker's initialization guard

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Ryan Malia
2026-03-25 15:02:09 -07:00
parent 88b47f9e9c
commit 83f61177c7
4 changed files with 93 additions and 87 deletions
+5
View File
@@ -985,6 +985,11 @@ async function ensureWorkerStarted(port: number): Promise<boolean> {
// than a dead worker. Users must manually restart after genuine plugin updates.
// See also: #566, #665, #667, #669, #689, #1124, #1145 (same pattern across 8+ releases).
if (await waitForHealth(port, 1000)) {
// Health passed — worker is listening. Also wait for readiness in case
// another hook just spawned it and background init is still running.
// This mirrors the fresh-spawn path (line ~1025) so concurrent hooks
// don't race past a cold-starting worker's initialization guard.
await waitForReadiness(port, getPlatformTimeout(HOOK_TIMEOUTS.READINESS_WAIT));
logger.info('SYSTEM', 'Worker already running and healthy');
return true;
}