Fix #1913: turn.start injection collapses to empty when top hits are dominated by near-dupl#1923
Open
Memtensor-AI wants to merge 1 commit into
Open
Fix #1913: turn.start injection collapses to empty when top hits are dominated by near-dupl#1923Memtensor-AI wants to merge 1 commit into
Memtensor-AI wants to merge 1 commit into
Conversation
… to empty (#1913) When the LLM relevance filter returned selected: [] for a non-empty ranked candidate list, the kept set was emptied verbatim and the turn.start packet collapsed to injectedContext: "". This reproduced whenever the top retrieval hits were dominated by near-duplicate question traces (e.g. the user re-asked the same fact across several sessions): the filter prompt's "drop scaffolding chatter / surface- similar wrong sub-problem" rubric was applied to every candidate and swept the answer-bearing trace along. Add a rescue path in llm-filter.ts (rescueFromEmptySelection) that partitions candidates into informative (skill / episode / experience / world-model, or a trace whose summary / reflection / agentText is longer than a short-ack heuristic) and chatter, then keeps the top-K ordered informative-first up to llmFilterMaxKeep. A new outcome label "llm_filtered_refilled" plus a debug log llm_filter.collapsed_refill { filteredAll: true, ... } make the safety net diagnosable from the Logs viewer. sufficient is forced to false so downstream callers know the injection is weak. The explicit escape hatch (llmFilterMaxKeep: 0) still honours an empty selection for operators who want hard drop. - core/retrieval/llm-filter.ts: rescue helper + new outcome variant - core/retrieval/types.ts: widen RetrievalStats.llmFilterOutcome union - viewer/src/views/LogsView.tsx: count the new variant under "LLM ran" in finalLlmRan - tests/unit/retrieval/llm-filter.test.ts: 4 new tests (regression + edge cases) + replace the prior "honour empty" test - tests/unit/retrieval/integration.test.ts: regression covering turn_start packet shape end-to-end Closes #1913 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Collaborator
Author
✅ Automated Test Results: PASSEDAll tests passed (35/35 executed, 35 skipped). memos_local_plugin/smoke: 0/0, memos_local_plugin/contract: 35 passed, 35 skipped. Duration: 4s Branch: |
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.
Description
Fixed issue #1913: turn.start injection collapsing to empty when the LLM relevance filter returned
selected: []over a non-empty ranked candidate list. The reproduction described in the issue happens when the top retrieval hits are dominated by near-duplicate question traces from previous sessions — the filter prompt's "drop scaffolding chatter / surface-similar wrong sub-problem" rubric applies to every candidate and the answer-bearing trace gets swept along, leavinginjectedContext: ""even thoughmemory.searchfor the same query still returns the same 4 hits.The fix adds a rescue path in
apps/memos-local-plugin/core/retrieval/llm-filter.ts(rescueFromEmptySelection+isInformativeCandidate). When the LLM empties the kept set, the rescue partitions ranked candidates into informative (skill / episode / experience / world-model, or a trace with a non-trivialsummary/reflection/agentText) and chatter (acknowledgement-only / near-duplicate question traces), then keeps the top-K ordered informative-first up tollmFilterMaxKeep. A new outcome label"llm_filtered_refilled"and a debug logllm_filter.collapsed_refill { filteredAll: true, ranked, rescued, informative, chatter }make the safety net diagnosable from the Logs viewer.sufficientis forced tofalseso downstream callers know the injection is weak.llmFilterMaxKeep: 0is preserved as the explicit "drop everything" escape hatch.Implementation touched 5 files:
core/retrieval/llm-filter.ts(rescue + new outcome),core/retrieval/types.ts(widen theRetrievalStats.llmFilterOutcomeunion),viewer/src/views/LogsView.tsx(count the new variant as "LLM ran" in the Logs viewer heuristic),tests/unit/retrieval/llm-filter.test.ts(4 new tests + replace the prior "honour empty" test),tests/unit/retrieval/integration.test.ts(turn_start end-to-end regression). All retrieval / bridge / pipeline unit tests pass (146 / 146);tsc --noEmitclean. Two pre-existing unrelated storage unit failures reproduced on the base branch and are outside this PR's boundary.Related Issue (Required): Fixes #1913
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Automated tests are pending.
Checklist
@MatthewZhuang, @CarltonXiang, @syzsunshine219 please review this PR.
Reviewer Checklist