Skip to content

feat: add auto-context recall to UserPromptSubmit hook#5

Merged
blackaxgit merged 11 commits intomainfrom
feat/auto-recall-impl
Mar 13, 2026
Merged

feat: add auto-context recall to UserPromptSubmit hook#5
blackaxgit merged 11 commits intomainfrom
feat/auto-recall-impl

Conversation

@blackaxgit
Copy link
Copy Markdown
Owner

@blackaxgit blackaxgit commented Mar 13, 2026

Summary

  • Add automatic context recall to the UserPromptSubmit hook — on every user prompt, the hook runs hybrid search (semantic + FTS5) against stored snapshots and injects top-K relevant results as additionalContext
  • Extract shared RecallEngine in clx-core used by both MCP clx_recall tool and the hook, eliminating code duplication
  • Add AutoRecallConfig with 8 tuneable fields, env var overrides, and dashboard Settings UI (9th section)
  • Add SQLite busy_timeout(5s) for safe multi-session concurrency

Changes

File Change
clx-core/src/config.rs AutoRecallConfig struct, defaults, apply_f32_override, 8 env overrides
clx-core/src/recall.rs NEWRecallEngine, RecallHit, RecallQueryConfig, hybrid_merge, format_recall_context
clx-core/src/lib.rs pub mod recall
clx-core/src/storage/migration.rs busy_timeout(5s) in configure_pragmas()
clx-core/src/embeddings.rs busy_timeout(5s) in EmbeddingStore::new() and with_dimension()
clx-core/src/storage/tests.rs test_busy_timeout_is_set
clx-core/tests/integration.rs test_concurrent_storage_access (multi-thread write test)
clx-hook/src/types.rs prompt: Option<String> field on HookInput
clx-hook/src/hooks/subagent.rs build_recall_context + do_recall with timeout, graceful degradation
clx-mcp/src/tools/recall.rs Refactored to delegate to RecallEngine
clx/src/dashboard/settings/ Auto Recall as 9th section (sections, fields, config_bridge)
README.md Document auto-recall feature and configuration

Key design decisions

  • Hybrid search: semantic weight 0.6 + FTS5 weight 0.4, dedup by snapshot_id
  • FTS5-first query order: FTS5 runs first (<10ms) before slow Ollama embedding, ensuring results within 500ms timeout
  • Graceful degradation: Ollama down → FTS5 fallback; any error → orchestrator context only
  • 500ms timeout: wraps entire recall operation; OllamaClient gets timeout−50ms with 0 retries
  • UTF-8 safe: floor_char_boundary() for all string truncation
  • Multi-session safe: busy_timeout(5s) on all SQLite connections prevents SQLITE_BUSY errors
  • No OnceLock: hook is short-lived, direct construction avoids lifetime issues

Test plan

  • cargo test --workspace — all tests pass (597 total)
  • cargo clippy --workspace -- -D warnings — zero warnings
  • Unit tests: score formula, hybrid merge dedup/weights/sorting/top-k, format budget, UTF-8 safety, early returns
  • Unit test: test_busy_timeout_is_set verifies PRAGMA returns 5000ms
  • Integration test: test_concurrent_storage_access — 2 threads, 20 writes each, zero SQLITE_BUSY
  • Manual: hook returns recall context within default 500ms timeout (3/3 runs)
  • Deployed locally and verified with real Ollama + FTS5 data

🤖 Generated with Claude Code

blackaxgit and others added 11 commits March 12, 2026 22:00
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…udget overflow

- Use floor_char_boundary for all string slicing in format_recall_context
- Weight all hybrid_merge hits consistently (0.6 semantic, 0.4 FTS)
- Clamp FTS scores to [0.0, 1.0] before weighting
- Add budget overflow protection in format_recall_context
- Add CLX_AUTO_RECALL_MIN_PROMPT_LEN env override in config
- Derive Storage and EmbeddingStore from same db_path in hook
- Add MCP threshold divergence comment
- Add tests for multibyte UTF-8, budget overflow, single-source weighting
Reorder RecallEngine::query() to execute FTS5 search first (<10ms)
before the potentially slow Ollama embedding for semantic search.
This ensures results are available within the default 500ms timeout.
Set 5-second busy_timeout on all SQLite connection open paths (Storage
and EmbeddingStore) to prevent SQLITE_BUSY errors when multiple CLX
processes share the database concurrently.
Cover AutoRecallConfig defaults, YAML parsing (all 8 fields),
missing-section serde(default) behaviour, partial YAML field defaults,
serialization roundtrip, and apply_f32_override for valid/boundary/
out-of-range/invalid inputs.
@blackaxgit blackaxgit merged commit a555886 into main Mar 13, 2026
6 checks passed
@blackaxgit blackaxgit deleted the feat/auto-recall-impl branch March 13, 2026 17:39
@blackaxgit blackaxgit mentioned this pull request Mar 19, 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.

1 participant