feat: same-turn memory retrieval in provider mode #6

Merged
Pakobbix merged 1 commits from feature/same-turn-prefetch into main 2026-08-15 17:53:03 +00:00
Owner

In provider mode, prefetch() returned the previous turn's cached result, so memory context was always one turn behind. With ~40ms local retrieval there's no reason for the lag.

Changes:

  • prefetch(query) reuses the in-flight background search when it matches the current query, else searches synchronously — same-turn injection
  • _prefetch_query scopes cached results to their query; result is reset when a new search starts and thread writes are guarded, preventing stale cross-turn injection after a timed-out join
  • Sync prefetch capped at 3s total (split across both requests in case-insensitive mode) so a hung server can't stall the LLM hot path for 10s
  • LocalMem0Client gains optional per-request timeout override
  • AGENTS.md / README updated to match

Verified: py_compile passes; two review passes, all findings addressed.

In provider mode, prefetch() returned the previous turn's cached result, so memory context was always one turn behind. With ~40ms local retrieval there's no reason for the lag. Changes: - prefetch(query) reuses the in-flight background search when it matches the current query, else searches synchronously — same-turn injection - _prefetch_query scopes cached results to their query; result is reset when a new search starts and thread writes are guarded, preventing stale cross-turn injection after a timed-out join - Sync prefetch capped at 3s total (split across both requests in case-insensitive mode) so a hung server can't stall the LLM hot path for 10s - LocalMem0Client gains optional per-request timeout override - AGENTS.md / README updated to match Verified: py_compile passes; two review passes, all findings addressed.
ARIA added 1 commit 2026-08-15 17:52:37 +00:00
prefetch() now reuses the in-flight background search when it matches
the current query, or falls back to a synchronous search (capped at 3s,
split across both requests in case-insensitive mode) so memories are
injected on the same turn instead of one turn behind.

- Track _prefetch_query to scope cached results to their query
- Reset _prefetch_result when starting a new background search to
  prevent stale cross-turn injection after a timed-out join
- Guard background thread writes against superseded queries
- Add optional per-request timeout override to LocalMem0Client
- Update AGENTS.md and README to describe the same-turn flow
Collaborator

No issues found — changes look consistent with the stated intent. Ready to be merged.

✅ No issues found — changes look consistent with the stated intent. Ready to be merged.
Pakobbix merged commit 185eec75f4 into main 2026-08-15 17:53:03 +00:00
Pakobbix deleted branch feature/same-turn-prefetch 2026-08-15 17:53:04 +00:00
Sign in to join this conversation.