← Back to PRs

#14021: feat(compaction): optional memory flush before manual /compact

by phenomenoner open 2026-02-11 10:05 View on GitHub →
docs gateway stale size: S
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