fix: resolve intermittent LLM unavailable prompts with layered defense#7
Merged
blackaxgit merged 7 commits intomainfrom Mar 18, 2026
Merged
fix: resolve intermittent LLM unavailable prompts with layered defense#7blackaxgit merged 7 commits intomainfrom
blackaxgit merged 7 commits intomainfrom
Conversation
Each CLX hook invocation is a separate OS process, so the in-memory ValidationCache is always empty. Add a persistent SQLite-backed cache so previously-validated commands skip Ollama entirely. - Migrate schema to v4 with validation_cache table and expiry index - Add get_cached_decision, cache_decision, cleanup_expired_cache methods - Export CachedDecision struct from storage module - Add cache_enabled, cache_allow_ttl_secs, cache_ask_ttl_secs config fields with env var overrides and sensible defaults
- Reduce health check timeout from 60s to 2s with 1 retry (Fix 1) - Use config default_decision instead of hardcoded "ask" on Ollama failure (Fix 2) - Integrate SQLite decision cache in PreToolUse hook so repeated commands skip Ollama entirely (Fix 3D) - Add file-based health cache to share Ollama status across hook processes (Fix 4)
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- 7 unit tests for SQLite validation cache (hit/miss/expiry/upsert/cleanup) - 2 integration tests verifying default_decision config is respected when Ollama is unavailable (allow and deny fallbacks)
- Integration test for default_decision: ask when Ollama unavailable - Unit test for stale health file (>30s) returning Unknown
evaluate_with_llm returns Ask("LLM unavailable") when ollama.generate()
fails — a third failure path distinct from is_available() and client
creation. Apply the same default_decision fallback and update health
cache to prevent repeated timeouts.
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
default_decisionfallback — all three LLM failure paths (client creation, health check, generation) now respect user's configureddefault_decisioninstead of hardcoding "ask"~/.clx/data/ollama_health(30s TTL)Details
Each hook invocation is a separate OS process with no shared in-memory state. When Ollama (Docker) is briefly unreachable, every command triggered a "requires confirmation" prompt. This PR implements 4 layered defenses per the runbook (
docs/runbook-llm-unavailable-fix.md).Files changed (10 files, +856/-30)
clx-core/src/ollama.rsclx-core/src/config.rscache_enabled,cache_allow_ttl_secs,cache_ask_ttl_secsfieldsclx-core/src/storage/migration.rsvalidation_cachetableclx-core/src/storage/validation_cache.rsclx-core/src/ollama_health.rsclx-core/src/lib.rsollama_healthmoduleclx-hook/src/hooks/pre_tool_use.rsclx-hook/tests/integration.rsTest plan
cargo test --workspace— 394+ tests)cargo clippy --workspacecleandefault_decision: allow→ auto-allowsdefault_decision: deny→ auto-denies🤖 Generated with Claude Code