#14021: feat(compaction): optional memory flush before manual /compact
docs
gateway
stale
size: S
Cluster:
Memory Management Enhancements
Adds an optional pre-compaction memory flush turn before manual /compact.\n\n- New config: agents.defaults.compaction.memoryFlush.onManualCompact (default: false)\n- When enabled, /compact runs a memory flush agent turn first, then compacts\n- Skips flush when workspace is read-only (sandbox workspaceAccess != rw) or when using CLI providers\n- Fail-open: if the flush run throws, compaction still proceeds\n\nDocs: updated configuration reference (EN + zh-CN).\nTests: added e2e coverage to ensure flush runs before compact when enabled.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds an optional pre-compaction memory flush feature for manual `/compact` commands. When `agents.defaults.compaction.memoryFlush.onManualCompact` is enabled (default: false), the system runs a memory flush agent turn before compacting the session, allowing the agent to store durable memories to disk. The feature intelligently skips the flush when the workspace is read-only or when using CLI providers (which don't support tool runs), and follows a fail-open pattern where compaction proceeds even if the flush fails.
Key changes:
- Added `onManualCompact` config field to `AgentCompactionMemoryFlushConfig` with proper TypeScript types and Zod validation
- Updated `commands-compact.ts` to conditionally run `runEmbeddedPiAgent` before compaction
- Implemented proper guard checks for workspace access (`rw` only) and CLI provider detection
- Added comprehensive e2e test coverage verifying flush runs before compact and ordering is correct
- Updated documentation in both English and Chinese (zh-CN)
<h3>Confidence Score: 5/5</h3>
- This PR is safe to merge with minimal risk
- The implementation is well-designed with proper guard rails, fail-open error handling, comprehensive test coverage, and follows existing codebase patterns. All changes are backward-compatible (feature is opt-in with default: false), and the code includes proper checks for edge cases like read-only workspaces and CLI providers.
- No files require special attention
<!-- greptile_other_comments_section -->
<sub>(2/5) Greptile learns from your feedback when you react with thumbs up/down!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#10644: feat: add runDuringHeartbeats option for memory flush (AI Assisted)
by tripphillips · 2026-02-06
83.6%
#14128: config: add readable durable/off mode for pre-compaction memory flush
by vpesh · 2026-02-11
81.7%
#14887: feat(compaction): configurable auto-compaction notifications with o...
by seilk · 2026-02-12
81.7%
#11089: feat(compaction): support customInstructions and model override for...
by p697 · 2026-02-07
81.5%
#20038: (fix): Compaction: preserve recent context and sync session memory ...
by rodrigouroz · 2026-02-18
81.2%
#15945: fix(memory-flush): only write memoryFlushCompactionCount when compa...
by aldoeliacim · 2026-02-14
80.4%
#18663: feat: progressive compaction escalation and mechanical flush fallback
by Adamya05 · 2026-02-16
79.9%
#10505: feat(compaction): add timeout, model override, and diagnostic logging
by thebtf · 2026-02-06
79.8%
#21547: feat: add compaction.announce config to notify users of compaction ...
by jlwestsr · 2026-02-20
79.7%
#8313: feat: auto-compaction support for spawned subagent sessions
by vishaltandale00 · 2026-02-03
79.6%