Skip to content

fix(hook): prevent SessionEnd timeout on fresh installs#10

Merged
blackaxgit merged 2 commits intomainfrom
fix/session-end-hook-cancelled
Mar 19, 2026
Merged

fix(hook): prevent SessionEnd timeout on fresh installs#10
blackaxgit merged 2 commits intomainfrom
fix/session-end-hook-cancelled

Conversation

@blackaxgit
Copy link
Copy Markdown
Owner

Summary

Fix "SessionEnd hook failed: Hook cancelled" error on fresh installs caused by Ollama health checks exceeding Claude Code's 1.5s SessionEnd timeout.

Root Cause

Claude Code enforces a 1.5 second timeout on SessionEnd hooks. CLX's handler was calling ollama.is_available() which has a 2-4 second health check timeout β€” guaranteed cancellation when Ollama isn't running.

Fix

Layered defense ensuring SessionEnd always completes in < 1 second:

  1. 1s timeout wrapper β€” tokio::time::timeout around entire handler, returns Ok(()) on timeout
  2. Health cache check β€” reads file-based health cache before any Ollama calls; skips LLM ops if unavailable
  3. Time-budget check β€” skips embedding generation if > 500ms has elapsed
  4. Skip LLM summarization β€” process_transcript() takes ollama_available flag, returns fallback immediately when false

Files changed

  • crates/clx-hook/src/hooks/session_end.rs β€” timeout wrapper + health cache + time budget
  • crates/clx-hook/src/transcript.rs β€” ollama_available parameter to skip LLM
  • crates/clx-hook/src/hooks/pre_compact.rs β€” updated process_transcript() call signature

Test plan

  • All workspace tests pass
  • New integration test: SessionEnd completes < 1.5s with unreachable Ollama
  • 0 clippy warnings
  • Binary built and installed locally

πŸ€– Generated with Claude Code

Claude Code enforces a 1.5s timeout on SessionEnd hooks. The handler
was exceeding this due to Ollama health checks (2-4s) and LLM calls.

Layered defense:
- Wrap handler in 1s tokio timeout (guaranteed return)
- Check health cache before any Ollama operations (skip if unavailable)
- Time-budget check before embedding generation (skip if >500ms elapsed)
- Skip LLM summarization when ollama_available flag is false
@blackaxgit blackaxgit merged commit 8a3aa3c into main Mar 19, 2026
7 checks passed
@blackaxgit blackaxgit deleted the fix/session-end-hook-cancelled branch March 19, 2026 19:41
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.

1 participant