Skip to content

fix(memory): add regression tests for memory context preservation aft…#43778

Open
LifeJiggy wants to merge 2 commits into
NousResearch:mainfrom
LifeJiggy:fix/memory-context-compaction
Open

fix(memory): add regression tests for memory context preservation aft…#43778
LifeJiggy wants to merge 2 commits into
NousResearch:mainfrom
LifeJiggy:fix/memory-context-compaction

Conversation

@LifeJiggy

@LifeJiggy LifeJiggy commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

fix/memory-context-compaction

What does this PR do?
Adds 3 regression tests ensuring SUMMARY_PREFIX in agent/context_compressor.py keeps MEMORY.md and USER.md as "always authoritative and active" after context compaction. The fix for #17251 is already on main — these tests prevent regression by locking the behavioral contract at the test level.

Earlier versions labeled compacted content as "background reference, NOT active instructions" which caused the agent to ignore MEMORY.md/USER.md after compaction. The current SUMMARY_PREFIX explicitly carves out persistent memory as exempt.

Related Issue
Fixes #17251 (memory context deprioritized after compaction)

Type of Change
✅ Tests (adding or improving test coverage)

Changes Made
tests/agent/test_context_compressor.py: Added TestMemoryContextPreserved class with 3 tests:
test_summary_prefix_mentions_memory_stays_active: MEMORY.md/USER.md present and described as active/authoritative
test_summary_prefix_exempts_memory_from_compaction: memory files explicitly exempted from "background reference" label
test_summary_prefix_instructs_agent_not_to_ignore_memory: prefix tells agent to never deprioritize memory

How to Test
python -m pytest tests/agent/test_context_compressor.py::TestMemoryContextPreserved -q — 3/3 pass
Tests verify against SUMMARY_PREFIX in agent/context_compressor.py:37-61

Checklist
I've read the Contributing Guide
My commit messages follow Conventional Commits
I searched for existing PRs
My PR contains only changes related to this fix
I've run pytest and all tests pass
I've added tests for my changes
I've tested on Windows 11

…er compaction

SUMMARY_PREFIX already explicitly states MEMORY.md/USER.md remain
'always authoritative and active' after compaction (fix for NousResearch#17251).
Added 3 regression tests to lock this contract:

- test_summary_prefix_mentions_memory_stays_active: MEMORY.md/USER.md
  are present and described as active/authoritative
- test_summary_prefix_exempts_memory_from_compaction: memory files are
  explicitly exempted from the 'background reference' label
- test_summary_prefix_instucts_agent_not_to_ignore_memory: prefix tells
  agent to never deprioritize memory content

No code changes needed — the fix is already on main. Tests prevent
regression.
@alt-glitch alt-glitch added type/test Test coverage or test infrastructure comp/agent Core agent loop, run_agent.py, prompt builder tool/memory Memory tool and memory providers P3 Low — cosmetic, nice to have labels Jun 10, 2026
…ervation

- Fix test_summary_prefix_instucts -> instructs (missing 'r')
- 3 regression tests verify SUMMARY_PREFIX keeps MEMORY.md/USER.md
  as always-authoritative after compaction
- Tests guard against NousResearch#17251 regression (memory deprioritized)
@LifeJiggy LifeJiggy marked this pull request as ready for review June 11, 2026 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent loop, run_agent.py, prompt builder P3 Low — cosmetic, nice to have tool/memory Memory tool and memory providers type/test Test coverage or test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Context Compaction Demotes Memory to "Background Reference", Causing Memory Loss After Restart

2 participants