Skip to content

fix(memory): background memory jobs stop overwriting the chat's prompt cache - #5286

Merged
kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:claude/perf-side-slot
Oct 19, 2026
Merged

kovtcharov-amd merged 4 commits into
amd:mainfrom
kovtcharov:claude/perf-side-slot

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

Memory consolidation, reconciliation and skill distillation ran on the llama.cpp slot the conversation uses, so a background pass overwrote the chat's cached prompt and the user's next message re-read all ~19K tokens of it (~45 s on Gemma-4-E4B). These jobs now run on the side slot, as memory extraction already did, so the conversation's cache survives them.

The fix is one place: every background call goes through _side_request_kwargs(), which now names the side slot. A model loaded with a single slot still gets slot 0, because the provider drops a slot the model doesn't have.

Test plan

  • python -m pytest tests/unit/test_lemonade_chat_slots.py tests/unit/test_memory_mixin.py -q
  • With a two-slot Gemma load, trigger consolidation (start a session after several stored turns) and check that llama.cpp's log shows those requests on id 1, not id 0.

@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

Memory consolidation, reconciliation and skill distillation now run on the model's side slot instead of the chat's slot, so a background pass no longer wipes the conversation's cached prompt. This removes the ~45 s re-read on the user's next message. The fix lives in the one helper all three jobs already call, and memory extraction now goes through it too. I found no blocking issues.

Real-world evidence

N/A: no evidence bundle was produced. This is an internal change to which llama.cpp slot background requests use, and showing it needs a real two-slot model load, which this runner can't do. The verdict rests on static review. The PR's second test-plan item (llama.cpp log shows background requests on id 1) is the right on-hardware check before release.

🔍 Technical details

Issues found: none blocking.

What I checked

  • Every background send_messages call in memory.py (extraction ~1839, consolidation ~2330, reconciliation ~2564) and the distillation functools.partial in procedural_memory.py:740 all unpack **self._side_request_kwargs(). None of them still passes id_slot explicitly, so no call gets a duplicate-keyword TypeError after the extraction call's inline id_slot=SIDE_SLOT was removed.
  • Single-slot loads are safe. providers/lemonade.py:695-701 drops an id_slot the model doesn't have and falls back to CONVERSATION_SLOT, so pinning slot 1 can't hang. Cloud models are covered too: lemonade_client.py:3928 pops id_slot for them.
  • Removing the unused SIDE_SLOT import from memory.py is correct. It is now used only in procedural_memory.py.

Optional (🟢): the new test checks only the helper's return value. A test that patches self.chat.send_messages and runs one consolidation or reconciliation pass would also catch a future caller that stops using the helper. Not required: the existing extraction test already follows that pattern.

Strengths

  • The fix is in one place: the slot choice lives in the shared helper, so any new background call gets it automatically.
  • The CHANGELOG entry leads with the user-visible effect and gives a concrete before-state.

…t cache

Memory consolidation, reconciliation and skill distillation sent no llama.cpp
slot, so they ran on the conversation's slot 0 and replaced its cached
prompt; the user's next message then re-read the whole ~19K-token prompt
(~45 s on Gemma-4-E4B). Every side call made through _side_request_kwargs()
now names the side slot, as memory extraction already did. The provider still
drops the slot for a model loaded with a single slot.
Drives a real consolidation and reconciliation pass and checks each
background request carries the side slot alongside thinking-off, so a
caller that stops using the shared helper fails the suite.
@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 19, 2026
Merged via the queue into amd:main with commit d10b423 Oct 19, 2026
40 of 41 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/perf-side-slot branch October 19, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants