fix(hook): prevent SessionEnd timeout on fresh installs#10
Merged
blackaxgit merged 2 commits intomainfrom Mar 19, 2026
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
tokio::time::timeoutaround entire handler, returns Ok(()) on timeoutprocess_transcript()takesollama_availableflag, returns fallback immediately when falseFiles changed
crates/clx-hook/src/hooks/session_end.rsβ timeout wrapper + health cache + time budgetcrates/clx-hook/src/transcript.rsβollama_availableparameter to skip LLMcrates/clx-hook/src/hooks/pre_compact.rsβ updatedprocess_transcript()call signatureTest plan
π€ Generated with Claude Code