Repository navigation
fix: bound inline embedding so a slow provider cannot fail the write - #99
Merged
Merged
Conversation
Closes #79. `_embed_created_neurons` runs inside the write path so a fresh memory is semantically recallable immediately. It was already fail-soft about a *missing* provider — "keyword-only memory, no error, no slowdown", as its docstring promises — but a *slow* provider was treated differently: the call blocked until the provider's own timeout. Against a remote or rate-limited endpoint that pushes `smem_remember` past the 30s tool-call cap MCP hosts impose. The neuron has already been persisted at that point, so the caller sees a timeout and cannot tell whether the write landed — precisely the loss this tool exists to prevent. The same content via the CLI succeeds, because nothing caps it there. The embedding call now runs under `asyncio.wait_for` with a 10s budget: well above a local endpoint (bge-m3 via llamastash answers in ~15 ms) and well below the 30s cap. On timeout the memory stays keyword-only and logs a warning naming `smem reindex` as the back-fill, which is the same outcome the method already produced when no provider was available. Set `SURREAL_MEMORY_INLINE_EMBED_TIMEOUT` to tune it, or to <= 0 to restore the previous unbounded behaviour. This is the minimal form of option 2 in the issue. It does not implement ack-first/async back-fill (option 1) — that is a larger change and worth its own discussion; this closes the data-loss window in the meantime.
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.
Closes #79.
Problem
_embed_created_neuronsruns inside the write path so a fresh memory is semantically recallable immediately. It is already fail-soft about a missing provider — "keyword-only memory, no error, no slowdown", as its own docstring promises — but a slow provider was treated differently: the call blocked until the provider's own timeout.Against a remote or rate-limited endpoint (the reporter runs a proxied Gemini endpoint) that pushes
smem_rememberpast the 30s tool-call cap MCP hosts such as Claude Code and Claude Desktop impose. The neuron has already been persisted by then, so the caller sees a timeout and cannot tell whether the write landed — precisely the loss this tool exists to prevent. The same content through the CLI succeeds, because nothing caps it there.Verified still present on
main(d8233b1) before changing anything:encoder.py:438awaits_embed_created_neurons, which awaitsprovider.embed_batchwith no bound. No async/pending-embedding path exists (git grep pending_embeddingis empty).Change
The embedding call runs under
asyncio.wait_forwith a 10s budget — well above a local endpoint (bge-m3 via llamastash answers in ~15 ms) and well below the 30s cap, so the bound only ever fires on a provider that would have broken the call anyway.On timeout the memory stays keyword-only and logs a warning naming
smem reindexas the back-fill. That is the same outcome the method already produced when no provider was available — this extends an existing guarantee to a case it did not cover, rather than inventing new behaviour.SURREAL_MEMORY_INLINE_EMBED_TIMEOUTtunes it;<= 0restores the previous unbounded behaviour for anyone who prefers it.Scope
This is the minimal form of option 2 in the issue. It deliberately does not implement ack-first with async back-fill (option 1) or a
pending_embeddingstate (option 3) — both are larger changes worth their own discussion. This closes the data-loss window in the meantime, and does not foreclose either.Test plan
tests/unit/test_inline_embed_timeout.py— 5 cases: default sits under the 30s cap, env override,<= 0disables, garbage falls back instead of raising, and a hanging provider does not block the writeSURREAL_MEMORY_INLINE_EMBED_TIMEOUT=0— the call never returns), so this fails without the fixpytest tests/unit— 6563 passed, 48 skippedruff check/ruff format --checkclean acrosssrc/andtests/