[Bug]: memory.prefetch_search_topn is inert above 5 (call site omits limit), plus two docstrings state the wrong defaults
Summary
memory.prefetch_search_topn cannot raise the amount of memory content preloaded into the extraction prompt above 5, because the search call site omits limit while the method signature defaults to 5. The configured value only slices a list that can never exceed 5 entries. Two docstrings in the same path also state defaults that are the opposite of the code.
Both defects were measured against live traffic, not read off the source.
Environment
- OpenViking v0.5.2.1, container
ghcr.io/volcengine/openviking:v0.5.2.1 memory.eager_prefetch: defaulttrue(unset inov.conf)memory.prefetch_search_topn: unset, so default5- Inference backend:
Qwen3.8-Flash-Nextserved locally by oMLX 0.7.3
Defect 1: the knob is clamped by a hard-coded default
session/memory/session_extract_context_provider.py:
447: async def search_files(
448: self, query: str, search_uris: List[str] = None, limit: int = 5
567: search_uris = await self.search_files(
568: query=search_query,
569: search_uris=dir_list,
570: ) # no limit passed, so limit=5 applies
594: topn_files = files_to_read_from_search[: self._prefetch_search_topn]
prefetch_search_topn slices a list that search_files already truncated to 5. Setting it to 10 or 20 returns the same 5 files. The setting can only take effect by lowering it below 5, which is the opposite of its documented purpose.
Measured proof
URIs listed per prefetch message, counted across 49 logged extraction requests:
| URIs listed | requests |
|---|---|
| 1 | 2 |
| 2 | 6 |
| 3 | 8 |
| 4 | 9 |
| 5 (the cap) | 24 |
49 % of runs sit exactly on the ceiling, so the limit binds roughly half the time and headroom above 5 is unreachable.
Why it matters operationally
The preloaded set is all the extraction agent can see before it rewrites memory. Measured on our store (4517 memory files, 20.3 MB of markdown): mean 5.31 files preloaded per run, median 48565 injected characters, about 5 records out of 4517 files, roughly 0.1 % collection visibility, with no read tool available because get_tools() returns [] under eager_prefetch.
That is the dedup window. Consequences we measured:
- 34 of 1604
trajectoriespluscasesfiles share a normalized base name (2.1 %), one name recurring 6 times. - One batched search covers every multi-file schema directory for self plus each peer scope, competing for the same 5 slots, so per-directory visibility is a fraction of one file.
_build_prefetch_search_querysends one query per commit, concatenating user text parts (1000 chars each) and assistant parts (500 chars each), truncated to_PREFETCH_SEARCH_QUERY_MAX_CHARS = 5000. On a long session that is an average-of-everything blob, so the top hits follow the session's dominant topic rather than the memory about to be written.
Raising prefetch_search_topn is the obvious lever an operator reaches for here, and it silently does nothing.
Suggested fix
Make the documented knob authoritative at the call site:
search_uris = await self.search_files(
query=search_query,
search_uris=dir_list,
limit=max(5, self._prefetch_search_topn),
)
Worth considering separately: search per schema directory rather than one merged batch, so a single topic cannot consume all N slots. optimize_search_result already fetches limit + 10 and filters .abstract.md / .overview.md before cutting, so additional slots are real memory files rather than index noise.
Defect 2: two docstrings state the wrong defaults
openviking_cli/utils/config/memory_config.py:61-67:
eager_prefetch: bool = Field(
default=True,
description=(... "When disabled (default), LLM has read tool and reads files on-demand.")
)
The default is True, so the sentence describes the opposite of reality, including the trade-off it implies.
session/memory/extract_loop.py:
133: max_iterations: int = 3,
147: max_iterations: Maximum number of ReAct iterations (default: 5)
Signature default is 3, docstring says 5. This one has teeth, because the iteration budget is what caps extraction work per commit.
Suggested fix: correct both strings, and consider deriving one from the other so they cannot drift again.
Notes
- This is independent of the
Unknown toolloop reported separately, but the two share a root: the extraction phase runs with no tools advertised and a preloaded context whose size the operator cannot actually configure. - Minimal reproduction: a store with more than 5 topically relevant memory files, then observe the prefetch listing fewer URIs than the configured
prefetch_search_topn.
Report authored by an agent under human supervision, measured against a live single-tenant installation. Made under human guidelines with free tokens from local oMLX inference server.
Cross-reference: the companion report is #6922 (memory extraction executes tool calls that were never advertised, and elides the assistant turn so the model cannot self-correct). Independent defects, shared root cause: the extraction phase runs with no tools advertised and a preloaded context an operator cannot actually size.
Opened #6997 to pass limit=self._prefetch_search_topn into search_memories_by_Event() and fix the docstring defaults in config.py and session_extract_context_provider.py. It also covers the companion #6922 fix (guarding execute_tool against unadvertised tools and keeping the assistant tool_calls turn in the extraction loop history so the model can self-correct).