fix(memory): run extended-memory predictor concurrently with rerank#100
Merged
Conversation
The per-turn recall has a hard 5s budget, and queryAtomsWithPrediction ran two LLM calls sequentially: the paid rerank of literal-query results followed by predictor.Predict. A slow memory LLM (by default the main reasoning model) let the rerank consume most of the window, so Predict inherited a nearly-expired context and failed immediately: extended memory: predictor LLM failed: context deadline exceeded extended memory: predicted-intent generation failed: predictor: context deadline exceeded Run the predictor concurrently with the literal query instead, so both LLM calls share the full window in parallel. The predictor only touches the LLM (no shared state) and the store/index are mutex-guarded; the result channel is buffered so the early-error path cannot leak the goroutine. Adds TestPredictionRunsConcurrentWithRerank, which deadlocks under the old sequential behavior.
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
odek | 37c025e | Commit Preview URL Branch Preview URL |
Jul 25 2026, 02:21 PM |
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.
Problem
Every turn, extended-memory recall runs under a hard 5-second budget (
FormatExtendedContext). Inside that window,queryAtomsWithPredictionexecuted two LLM calls sequentially:predictor.Predictfor follow-up intent generationWhen the memory LLM is slow (by default it reuses the main reasoning model), the rerank consumed most of the 5s window, so
Predictinherited a nearly-expired context and failed before its LLM call could complete:Fix
Run the predictor concurrently with the literal query + rerank, so both LLM calls share the full window in parallel instead of splitting it sequentially.
-race).trackErr), and the follow-up sink behavior are unchanged.Testing
go test -race ./internal/memory/... -count=1— all passTestPredictionRunsConcurrentWithRerank: the rerank mock blocks until the predictor starts; under the old sequential behavior this deadlocks and fails the test.Note
If a single memory LLM call exceeds the 5s per-turn budget on its own, prediction still degrades gracefully to literal-query recall (intended latency cap). Operators hitting that should configure a cheaper dedicated model via
memory.extended.llm, as already recommended indocs/EXTENDED_MEMORY.md.