fix: add timeout + fail-open to recall search path#1455
Open
kagura-agent wants to merge 1 commit intoMemTensor:mainfrom
Open
fix: add timeout + fail-open to recall search path#1455kagura-agent wants to merge 1 commit intoMemTensor:mainfrom
kagura-agent wants to merge 1 commit intoMemTensor:mainfrom
Conversation
Fixes MemTensor#1452 — auto-recall can block gateway startup / first-turn path long enough to fail health checks when embedding or LLM calls are slow. Changes: - Add configurable `recall.timeoutMs` (default 10s) - Wrap embedder.embedQuery() with timeout in RecallEngine.search(); falls back to FTS-only results on timeout - Wrap LLM skill relevance judgment with timeout in searchSkills(); falls back to returning all candidates on timeout - Add top-level timeout in memory_search tool handler; returns empty results with `timedOut: true` flag on timeout - All timeouts fail-open: partial/empty results, never throw - Recall exceptions never propagate to gateway top level
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
Fixes #1452 — auto-recall can block gateway startup / first-turn path long enough to fail health checks when embedding or LLM calls are slow.
Problem
With
auto-recallenabled and existing memories, the recall search path can block for 30-40 seconds when:This is enough to trip health checks and cause restart loops.
Solution
Add configurable timeout + fail-open semantics at three layers:
1. Recall engine (
recall/engine.ts)withTimeout()helper: races any promise against a deadline, returns fallback on timeoutembedder.embedQuery()wrapped with timeout → falls back to FTS-only search (no vector candidates)judgeSkillRelevance()(LLM call) wrapped with timeout → returns all candidates on timeout2. Tool handler (
tools/memory-search.ts)memory_searchhandlertimedOut: truein meta on timeout3. Configuration (
types.ts,config.ts)recall.timeoutMsoption (default: 10000ms, 0 = no timeout)Key Principles
Testing
tsc --noEmit)timeoutMs