ctx_search ranks stale cross-session memory above fresh same-session captures
Summary
ctx_search can rank stale cross-session auto-captured memory above fresh same-session captures, so a query that closely matches labels the agent just indexed in the current session returns unrelated older memory instead of the content it's looking for. The agent then abandons ctx_search and works from in-context text, which defeats the purpose of the search round-trip.
Observed behavior
Within a single session:
- Agent runs
ctx_batch_executewith descriptivelabels, indexing fresh content (the labels become the FTS5 chunk titles). - Agent immediately calls
ctx_searchwith a query that closely matches those just-created labels. - The top hits are prior-session auto-captured session memory, not the freshly-indexed batch chunks.
Agent's own words at the failure point:
"The search hit unrelated session memory, not my batch output. I already have both full texts in my context from the cat output, so I can compare directly without further searching."
i.e. the search round-trip was wasted and the agent fell back to working from raw context — the opposite of the intended workflow.
Why it matters
The whole value proposition is "index large output → ctx_search to pull focused snippets without rereading raw bytes." When fresh same-session captures are out-ranked by older cross-session memory, the agent learns the search is unreliable and stops using it, losing the context savings.
Suggested fix (any one)
- Recency / same-session boost in BM25 ranking so captures from the current session (or most recent N minutes) outrank older cross-session memory for closely-matching queries.
- Optional
scopeparam onctx_search(e.g.scope: "session"vs"all") so the agent can restrict to the current session's captures when it knows it just indexed the target. - At minimum, surface the capture's session/recency in results so a consumer can disambiguate.
Environment
- context-mode
v1.0.168 - Observed across multiple real Claude Code sessions (subagents that had just indexed content via
ctx_batch_execute).
(Filed from observed production usage; no minimal seed repro, but the pattern — index fresh via batch, then search matching labels, get older memory — was reproducible across sessions.)
Source: mksglu/context-mode