mirror of
https://github.com/rohitg00/agentmemory.git
synced 2026-09-14 20:16:33 +08:00
d626b4ea60
* perf(hooks): fire-and-forget telemetry hooks (closes #573) Telemetry hooks (notification, post-tool-failure, post-tool-use, prompt-submit, stop, session-end, subagent-start, subagent-stop, task-completed) previously `await fetch(..., AbortSignal.timeout(N))` inside a try/catch. The await kept the hook process alive until the response arrived — up to N ms per request — which blocks Claude Code's next-prompt boundary on every assistant turn. Switch to fire-and-forget: fetch(url, { signal: AbortSignal.timeout(N) }).catch(() => {}); setTimeout(() => process.exit(0), 500).unref(); The unawaited fetch dispatches the request; the unref'd setTimeout force-exits the process after the request has been flushed to the local daemon's socket buffer (~500ms is enough). Without the setTimeout Node keeps the event loop alive waiting for any in-flight fetch to settle, which means the hook still blocks Claude Code's next-prompt boundary for up to the AbortSignal duration. Context-injecting hooks (pre-tool-use, pre-compact, session-start) still use `await fetch` because Claude Code reads their stdout for context injection — left untouched. AGENTS.md updated with the two-pattern guidance. * chore(hooks): drop verbose comments on fire-and-forget hooks * fix(hooks): bump stop+session-end exit delay to 1500ms Multi-request hooks (stop fires 2, session-end up to 4) need more than 500ms to initiate all fetches when AGENTMEMORY_URL points to a remote daemon — DNS + TCP + TLS handshakes can eat the budget before the second/third fetch is even dispatched. Bump to 1500ms on those two hooks only; single-request hooks keep 500ms. AGENTS.md updated with the multi-request exception.
2.1 KiB
Executable File
2.1 KiB
Executable File