Skip to content

fix: prevent autoRecall context inflation (#345)#353

Merged
rwmjhb merged 1 commit intoCortexReach:masterfrom
AliceLJY:fix/345-autoRecall-context-inflation
Mar 27, 2026
Merged

fix: prevent autoRecall context inflation (#345)#353
rwmjhb merged 1 commit intoCortexReach:masterfrom
AliceLJY:fix/345-autoRecall-context-inflation

Conversation

@AliceLJY
Copy link
Collaborator

Summary

  • Fixes bug: autoRecall causes severe context inflation and frequent compaction loops #345 — autoRecall injected memory blocks caused context to balloon and trigger compaction loops
  • Three compounding root causes addressed:
    1. Session state leak: recallHistory and turnCounter Maps never cleaned on session_end, causing unbounded growth
    2. No hard per-turn safety cap: Added maxRecallPerTurn config (default 10) as a ceiling on autoRecallMaxItems
    3. Injection blocks not ephemeral: Added ephemeral: true flag so compaction can safely discard <relevant-memories> blocks

Changes

  • index.ts: Add maxRecallPerTurn config + parsing, apply Math.min(configMaxItems, maxPerTurn) cap, add ephemeral: true to hook return, add session_end handler to clean recallHistory/turnCounter/lastRawUserMessage
  • openclaw.plugin.json: Add maxRecallPerTurn schema definition + settings hint

Test plan

  • All 17 existing test suites pass (0 failures)
  • Plugin manifest regression test passes
  • Manual test: 10+ turn conversation with autoRecall=true confirms no duplicate injection
  • Confirm maxRecallPerTurn config is respected when set lower than autoRecallMaxItems
  • Confirm session state Maps are cleaned after session_end

🤖 Generated with Claude Code

…ion cap + ephemeral marking

Fixes CortexReach#345 — autoRecall could cause context to balloon and trigger
compaction loops due to three compounding issues:

1. Session state leak: recallHistory and turnCounter Maps were never
   cleaned on session_end, causing unbounded growth across sessions.
   Added session_end handler to clean up auto-recall Maps.

2. No hard per-turn safety cap: Added maxRecallPerTurn config (default
   10) that acts as a ceiling on top of autoRecallMaxItems to prevent
   misconfiguration from causing context inflation.

3. Injection blocks persisted in transcript: Added ephemeral: true flag
   to the returned hook result so the host framework's compaction logic
   can safely discard injected <relevant-memories> blocks instead of
   persisting them into the session transcript.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@rwmjhb rwmjhb merged commit 0350475 into CortexReach:master Mar 27, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: autoRecall causes severe context inflation and frequent compaction loops

2 participants