fix(session-end): remove .unref() so process force-exits after 1500ms#1070
fix(session-end): remove .unref() so process force-exits after 1500ms#1070dnraitzyk wants to merge 1 commit into
Conversation
Pending fetch() calls keep the Node.js event loop alive until their AbortSignal timeouts fire (30s normally, up to 120s with CONSOLIDATION_ENABLED). With .unref(), the setTimeout becomes passive and never fires while those fetches are in flight, so the hook process outlives Claude Code's hook timeout and gets killed with 'Hook cancelled'. Removing .unref() makes the timer active: the process exits after 1500ms regardless of in-flight fetches. The fetches are fire-and-forget to the local daemon anyway, so exiting before they settle is correct behavior.
|
@dnraitzyk is attempting to deploy a commit to the rohitg00's projects Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughUpdated both session-end implementations to use referenced 1500ms exit timers, ensuring the process terminates after the timeout regardless of pending fetch requests. Inline comments document the event-loop behavior. ChangesSession-end process termination
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related issues
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #1069.
What
Remove
.unref()from thesetTimeoutinsession-end.mjs/session-end.ts.Why
The
session-endhook fires fire-and-forgetfetch()calls to the local daemon, then does:AGENTS.mddocuments the intent: the process should force-exit after 1500ms so it does not block Claude Code's shutdown. But.unref()makes the timer passive — Node.js does not keep the event loop alive for an unref'd timer, but it also will not fire it while other handles (the pendingfetch()calls) are keeping the loop alive.The fetches use
AbortSignal.timeout()values of 30s, 60s, and 120s. Those pending requests keep the event loop alive the entire time. Claude Code's hook deadline fires first and kills the process with:This is intermittent because when the daemon responds fast the event loop drains before the deadline; when it is slow the race is lost.
Fix
Remove
.unref(). An active timer is the only handle that keeps the event loop alive after the fetches are dispatched, so the process exits after exactly 1500ms regardless of whether the fetches have settled. This matches the documented intent and the fire-and-forget patternAGENTS.mdprescribes.Summary by CodeRabbit