MemOS
MemOS copied to clipboard
fix(auto-recall): add timeout + fail-open so slow LLMs cannot stall startup or first turn
Summary
With auto-recall enabled and an existing memory database, a slow LLM on the recall/filter path could block the gateway critical path for 30-40 seconds — long enough to trip health checks and cause restart loops (#1452).
This PR wraps the recall/filter LLM work in a configurable timeout and ensures any exception in the auto-recall path fails open rather than propagating to the gateway top level.
Changes
- New
withTimeouthelper that resolves tonullon timeout (clean fail-open semantics). - Auto-recall LLM filter now races against
recall.autoRecallTimeoutMs(default 8000 ms). - Top-level try/catch around the auto-recall block; on any error or timeout we log a warning and return an empty memory set so the prompt build proceeds normally.
- New config key documented:
recall.autoRecallTimeoutMs.
Behavior
- Healthy LLM: indistinguishable from before — recall + filter happen, memories injected.
- Slow LLM (timeout): warning logged, prompt builds with no auto-injected memories, gateway proceeds.
- LLM error: same as timeout — warning logged, fail open.
- Startup
readyis unaffected; auto-recall was never on that path, but the timeout + fail-open guarantees it stays that way.
Fixes #1452
Thanks — both addressed in the latest commit:
index.ts:1905(config not wired):resolveConfig()(insrc/config.ts) now passescfg.recall.autoRecallTimeoutMsthrough to the resolvedrecallblock. Without this the user-facing config key was effectively dead and the default always won — good catch.with-timeout.test.ts:48(flaky timers): Switched tovi.useFakeTimers()+vi.advanceTimersByTimeAsync()so the timeout behavior is asserted deterministically. The previous wall-clockelapsed < 500mscheck was the obvious flake risk under CI load. Test suite now finishes in ~5ms and the 30s-hang case is verified by advancing fake time past 8001ms instead of measuring real elapsed time.
This PR has been automatically marked as stale due to inactivity.