Skip to content

fix(memory): detach SessionEnd index so the hook can't be "Hook cancelled" - #191

Closed
sandstream wants to merge 1 commit into
mainfrom
claude/headroom-kit-integration-cmjw7t
Closed

sandstream wants to merge 1 commit into
mainfrom
claude/headroom-kit-integration-cmjw7t

Conversation

@sandstream

Copy link
Copy Markdown
Owner

What

kit memory hook session-end could surface as:

SessionEnd hook [.../kit memory hook session-end] failed: Hook cancelled

(observed live in a real Claude Code session.)

Why

The hook ran its work inline: runSessionEndIndex() followed by an opt-in tryAutoPush(). On most exits the index is a fast Claude-Code-only pass, but on a periodic all-harness sweep it calls indexAllHarnesses() (walks opencode/cursor/codex/gemini/… stores), and an enabled push_on_end adds an encrypt-and-push. Either can overrun Claude Code's SessionEnd shutdown window, and Claude Code then cancels the still-running hook. It's fail-soft (no corruption; the next SessionStart recovery re-indexes the tail) — just noisy.

Fix

Branch the session-end handler on whether a push is actually configured:

  • Common path (no push_on_end) — detach the index into a fire-and-forget child (spawnDetachedIndex, the same trick the mid-session debounce already uses) and return immediately. Nothing for Claude Code to cancel; the index still completes in the background.
  • Ephemeral path (push_on_end = true) — keep indexing inline so the push observes this session's freshly-indexed rows before the container is reclaimed. Gated by a new cheap, fail-safe isAutoPushConfigured().

Fail-open throughout (a session is never blocked on exit).

Tests

3 new tests for isAutoPushConfigured (unconfigured / configured-without-flag → false; push_on_end = true → true; malformed config → fail-safe false, so a bad config never forces an inline push). Full suite 1984 green, prettier clean.

🤖 Generated with Claude Code

https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg


Generated by Claude Code

…lled"

The session-end hook ran runSessionEndIndex() inline; on a periodic all-harness
sweep (indexAllHarnesses over opencode/cursor/codex/gemini/…) — or a hung opt-in
push_on_end — it could overrun Claude Code's shutdown window and surface as
"SessionEnd hook … failed: Hook cancelled".

- Common path (no push_on_end): detach the index into a fire-and-forget child
  (spawnDetachedIndex, mirroring the mid-session debounce) so the hook returns
  instantly. The index still completes; next SessionStart recovery re-indexes any
  missed tail.
- Ephemeral path (push_on_end = true): keep indexing inline so the push observes
  this session's rows before the container is reclaimed — gated by the new
  isAutoPushConfigured().

Fail-open throughout. 3 new tests (isAutoPushConfigured: unconfigured/no-flag →
false, push_on_end → true, malformed config → fail-safe false). Suite 1984 green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015ERHw6bVUz39sAuoQZ1iyg

Copy link
Copy Markdown
Owner Author

Closing as a duplicate — #190 already merged the same fix and is the better version.

#190 detaches the entire SessionEnd worker (index and the opt-in push) via an internal session-end-run event, so the hook returns instantly for every user, including those with push_on_end. This PR only detaches the index and keeps the push inline, which means push_on_end users would still hit "Hook cancelled" — strictly worse. #190 also has the inline-fallback fail-safes when the worker can't spawn.

Nothing here to salvage. Closing.


Generated by Claude Code

@sandstream sandstream closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants