From ed444dfec7158b64de07462002aca48bbc34f33f Mon Sep 17 00:00:00 2001 From: nimesh-kumar-sh Date: Fri, 27 Mar 2026 12:52:02 -0700 Subject: [PATCH 1/3] fix: SessionStart hooks fail on cold start due to worker race condition The worker-start hook's `start` subcommand forks a daemon then SIGKILLs its own process group, killing bun-runner.js before it can report exit 0. Since all SessionStart hooks run in parallel, the context hook also fails because the worker isn't listening yet. Fix: - worker-start: continue after the SIGKILL via `;`, poll the worker health endpoint until ready, then output valid JSON (exit 0) - context: wait for worker health before attempting to fetch context Fixes #1505 --- plugin/hooks/hooks.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin/hooks/hooks.json b/plugin/hooks/hooks.json index 01a6b719..381d3599 100644 --- a/plugin/hooks/hooks.json +++ b/plugin/hooks/hooks.json @@ -24,12 +24,12 @@ }, { "type": "command", - "command": "_R=\"${CLAUDE_PLUGIN_ROOT}\"; [ -z \"$_R\" ] && _R=\"$HOME/.claude/plugins/marketplaces/thedotmack/plugin\"; node \"$_R/scripts/bun-runner.js\" \"$_R/scripts/worker-service.cjs\" start", + "command": "_R=\"${CLAUDE_PLUGIN_ROOT}\"; [ -z \"$_R\" ] && _R=\"$HOME/.claude/plugins/marketplaces/thedotmack/plugin\"; node \"$_R/scripts/bun-runner.js\" \"$_R/scripts/worker-service.cjs\" start; for i in 1 2 3 4 5 6 7 8; do curl -sf http://localhost:37777/health >/dev/null 2>&1 && break; sleep 1; done; echo '{\"continue\":true,\"suppressOutput\":true}'", "timeout": 60 }, { "type": "command", - "command": "_R=\"${CLAUDE_PLUGIN_ROOT}\"; [ -z \"$_R\" ] && _R=\"$HOME/.claude/plugins/marketplaces/thedotmack/plugin\"; node \"$_R/scripts/bun-runner.js\" \"$_R/scripts/worker-service.cjs\" hook claude-code context", + "command": "_R=\"${CLAUDE_PLUGIN_ROOT}\"; [ -z \"$_R\" ] && _R=\"$HOME/.claude/plugins/marketplaces/thedotmack/plugin\"; for i in 1 2 3 4 5 6 7 8; do curl -sf http://localhost:37777/health >/dev/null 2>&1 && break; sleep 1; done; node \"$_R/scripts/bun-runner.js\" \"$_R/scripts/worker-service.cjs\" hook claude-code context", "timeout": 60 } ] From 368daddd88274ce60aea385c9c4f485335a76899 Mon Sep 17 00:00:00 2001 From: nimesh-kumar-sh Date: Fri, 27 Mar 2026 12:52:36 -0700 Subject: [PATCH 2/3] fix(bun-runner): treat signal-based exits for 'start' as success Defense-in-depth for #1505. When the 'start' subcommand forks a daemon, the parent bun process may be killed by signal (exit > 128). If the close handler fires, treat this as success since the daemon started fine. Note: the primary fix is in hooks.json since the SIGKILL often kills the entire process group before this handler fires. --- plugin/scripts/bun-runner.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugin/scripts/bun-runner.js b/plugin/scripts/bun-runner.js index 90ee0997..e1d9bafa 100644 --- a/plugin/scripts/bun-runner.js +++ b/plugin/scripts/bun-runner.js @@ -171,6 +171,12 @@ child.on('error', (err) => { process.exit(1); }); -child.on('close', (code) => { +child.on('close', (code, signal) => { + // Fix #1505: When the "start" subcommand forks a daemon, the parent bun + // process may be killed by signal (e.g. SIGKILL, exit code 137). The daemon + // is running fine — treat signal-based exits for "start" as success. + if (signal || (code > 128 && args.includes('start'))) { + process.exit(0); + } process.exit(code || 0); }); From a48bf89963f75f92ae96be6ff1ca96e4c7a71ea4 Mon Sep 17 00:00:00 2001 From: nimesh-kumar-sh Date: Fri, 27 Mar 2026 13:03:05 -0700 Subject: [PATCH 3/3] fix: fail worker-start hook if worker never becomes healthy Address CodeRabbit review: add a final health check after the retry loop so genuine worker startup failures surface as hook errors instead of being silently masked. --- plugin/hooks/hooks.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin/hooks/hooks.json b/plugin/hooks/hooks.json index 381d3599..352dd1ee 100644 --- a/plugin/hooks/hooks.json +++ b/plugin/hooks/hooks.json @@ -24,7 +24,7 @@ }, { "type": "command", - "command": "_R=\"${CLAUDE_PLUGIN_ROOT}\"; [ -z \"$_R\" ] && _R=\"$HOME/.claude/plugins/marketplaces/thedotmack/plugin\"; node \"$_R/scripts/bun-runner.js\" \"$_R/scripts/worker-service.cjs\" start; for i in 1 2 3 4 5 6 7 8; do curl -sf http://localhost:37777/health >/dev/null 2>&1 && break; sleep 1; done; echo '{\"continue\":true,\"suppressOutput\":true}'", + "command": "_R=\"${CLAUDE_PLUGIN_ROOT}\"; [ -z \"$_R\" ] && _R=\"$HOME/.claude/plugins/marketplaces/thedotmack/plugin\"; node \"$_R/scripts/bun-runner.js\" \"$_R/scripts/worker-service.cjs\" start; for i in 1 2 3 4 5 6 7 8; do curl -sf http://localhost:37777/health >/dev/null 2>&1 && break; sleep 1; done; curl -sf http://localhost:37777/health >/dev/null 2>&1 || exit 1; echo '{\"continue\":true,\"suppressOutput\":true}'", "timeout": 60 }, {