MemOS icon indicating copy to clipboard operation
MemOS copied to clipboard

Fix #1913: turn.start injection collapses to empty when top hits are dominated by near-dupl

Open Memtensor-AI opened this issue 5 months ago • 1 comments

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, leaving injectedContext: "" even though memory.search for 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-trivial summary/reflection/agentText) and chatter (acknowledgement-only / near-duplicate question traces), then keeps the top-K ordered informative-first up to llmFilterMaxKeep. A new outcome label "llm_filtered_refilled" and a debug log llm_filter.collapsed_refill { filteredAll: true, ranked, rescued, informative, chatter } make the safety net diagnosable from the Logs viewer. sufficient is forced to false so downstream callers know the injection is weak. llmFilterMaxKeep: 0 is 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 the RetrievalStats.llmFilterOutcome union), 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 --noEmit clean. 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.

  • [x] Bug fix (non-breaking change which fixes an issue)
  • [ ] New feature (non-breaking change which adds functionality)
  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • [ ] Refactor (does not change functionality, e.g. code style improvements, linting)
  • [ ] Documentation update

How Has This Been Tested?

Automated tests are pending.

  • [ ] Unit Test
  • [ ] Test Script Or Test Steps (please provide)
  • [ ] Pipeline Automated API Test (please provide)

Checklist

  • [ ] I have performed a self-review of my own code
  • [ ] I have commented my code in hard-to-understand areas
  • [ ] I have added tests that prove my fix is effective or that my feature works
  • [ ] I have created related documentation issue/PR in MemOS-Docs (if applicable)
  • [x] I have linked the issue to this PR (if applicable)
  • [x] I have mentioned the person who will review this PR

@MatthewZhuang, @CarltonXiang, @syzsunshine219 please review this PR.

Reviewer Checklist

  • [x] closes #1913
  • [ ] Made sure Checks passed
  • [ ] Tests have been provided

Memtensor-AI avatar Jun 15 '26 09:06 Memtensor-AI

✅ Automated Test Results: PASSED

All tests passed (35/35 executed, 35 skipped). memos_local_plugin/smoke: 0/0, memos_local_plugin/contract: 35 passed, 35 skipped. Duration: 4s

Branch: bugfix/autodev-1913

Memtensor-AI avatar Jun 15 '26 10:06 Memtensor-AI