-
-
Notifications
You must be signed in to change notification settings - Fork 69.2k
Pre-compaction memoryFlush: larger default threshold, workspace-level flush instructions, and post-compaction audit #31435
Copy link
Copy link
Open
Description
Problem
The pre-compaction memoryFlush feature exists and works, but the default configuration leads to context loss in long-running agent sessions.
Root causes
- softThresholdTokens default (4000) is too small. Not enough headroom for a thorough flush that updates multiple workspace files (e.g. session state, daily logs, and spec files).
- Default prompt is generic. It says 'store durable memories' but does not specify which files are critical. Every workspace has different critical files, and the model has no way to know which ones matter most.
- No feedback loop. After the flush turn, there is no verification that critical context was actually persisted. If the model skips a file or runs out of tokens mid-flush, that context is gone.
Current behaviour
- memoryFlush fires at
contextWindow - reserveTokens - 4000tokens - Generic prompt: 'Store durable memories now, use memory/YYYY-MM-DD.md'
- Model gets one turn to flush, then compaction runs
- No post-compaction verification
Suggested improvements
- Increase default softThresholdTokens to 8000. This gives the model enough room for multiple file writes during the flush turn.
- Support a workspace-level flush instructions file (e.g.
FLUSH.md). This file would be injected into the flush prompt, so each workspace can specify exactly which files MUST be updated before compaction. Different projects have different critical state files. - Post-compaction audit. After compaction completes, verify that the workspace's critical files were updated during the flush turn. If not, inject a system message warning the model that context may have been lost.
- Expose token count to the model. Give the model a way to know how much context it has used (e.g. via session_status or a periodic system message), so it can flush proactively rather than only reactively when the threshold fires.
Workaround
Custom flush prompt via config:
{
"agents": {
"defaults": {
"compaction": {
"memoryFlush": {
"enabled": true,
"softThresholdTokens": 8000,
"prompt": "Pre-compaction memory flush. MANDATORY: 1) Update SESSION-STATE.md with all current context. 2) Append new facts to today's daily log. 3) Update relevant spec files."
}
}
}
}
}This works but should be default behaviour, not a workaround.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.