You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In src/hooks/session-end.ts (built to scripts/session-end.mjs), the hook fires best-effort POSTs to the local engine and then defers exit:
setTimeout(()=>process.exit(0),1500).unref();
Two problems:
Outlives the shutdown grace. On exit, Claude Code gives SessionEnd hooks only a short grace window. The 1.5s deferred exit (plus any pending fetch socket keeping the event loop alive) means the hook process is still running when the harness tears down → the harness kills it and surfaces Hook cancelled. The session-end telemetry POST usually still goes out, so it's cosmetic — but it's noisy on every exit.
.unref() defeats the intended cap. Because the in-flight fetch sockets keep the loop alive, the unref'd timer is the only thing forcing exit; if the engine is slow/unreachable the process can linger longer than expected before the timer fires.
Reproduction
Node 22, agentmemory 0.9.27, Claude Code plugin install.
Exit a session (exit). Intermittently shows the Hook cancelled line.
Fix that worked locally
Shorten the deferred exit so the hook quits well inside the harness grace, while still giving the localhost POST time to flush:
setTimeout(()=>process.exit(0),500);
This eliminated the Hook cancelled message in my testing while preserving the fire-and-forget POST. A more robust option would be to exit as soon as the primary /session/end request settles, with a small hard cap.
Minor adjacent note
scripts/session-end.mjs uses global fetch, which is absent on Node < 18 (e.g. Node 12 → ReferenceError: fetch is not defined, unhandled rejection). A typeof fetch === 'function' guard (or an explicit Node version requirement) would fail more gracefully on systems where the hook is spawned under an older node on PATH.
Affects: same pattern likely applies to other hook scripts that use the setTimeout(...).unref() exit idiom.
Activity
fix: SessionEnd hook exit grace + stop hook (rohitg00#991)
merge: fix SessionEnd hook exit grace + stop hook (rohitg00#991)
fix: auto-restore from snapshot on daemon startup (rohitg00#1007)
fix: drain upstream bug backlog (28 issues)