Back to Paid GitHub Issues

Paid GitHub Issues

[Feature]: Compaction: configurable model override + flush-then-reset mode

openclaw/openclaw

78
Score
Summary
USD 25.00
Repository
openclaw/openclaw
Stars
381798
Comments
3
Platform
GitHub
Difficulty
Medium
Scam risk
Low
Status
open
JavaScriptTypeScriptenhancementP2clawsweeper:no-new-fix-prclawsweeper:fix-shape-clearclawsweeper:needs-maintainer-reviewclawsweeper:needs-product-decisionclawsweeper:needs-security-reviewclawsweeper:source-reproimpact:session-stateimpact:securityimpact:auth-providerissue-rating: ? diamond lobster

Description

### Summary Compaction: configurable model override + flush-then-reset mode ### Problem to solve ### Problem Compaction and memory flush both use the session model with no override. For Opus sessions ($5/$25 per MTok), housekeeping costs dominate: - **Compaction (default mode):** ~$0.90-1.13 per cycle (100k history, includes `reasoning: "high"` thinking tokens billed at output rate) - **Compaction (safeguard mode):** ~$1.25-2.90 per cycle (2-3 chunked summarization calls + merge, each with reasoning:high) - **Memory flush:** ~$0.25-0.93 per cycle (full agent turn on session model) - **Flush + compaction combined:** ~$1.15-4.00+ per cycle For sessions that compact 3-5x/day, that's $3-20/day in pure housekeeping on a single Opus agent. ### Proposed solution ### Proposed Solutions #### 1. `compaction.model` - Override the summarization model Allow specifying a cheaper model for compaction summarization calls: ```jsonc { "agents": { "defaults": { "compaction": { "model": "anthropic/claude-sonnet-4-6" // or haiku } } } } ``` Summarization is not a hard reasoning task. Sonnet ($3/$15) or Haiku ($1/$5) can produce structured checkpoint summaries at 60-95% cost reduction. The `reasoning: "high"` flag on compaction calls could also be made configurable or removed entirely for summarization. **Estimated savings:** Sonnet compaction ~$0.15-0.30/cycle vs Opus ~$0.90-1.13/cycle. #### 2. `memoryFlush.model` - Override the flush model Same pattern for the pre-compaction memory flush turn: ```jsonc { "agents": { "defaults": { "compaction": { "memoryFlush": { "model": "anthropic/claude-sonnet-4-6" } } } } } ``` Flush is a simple "write memories to disk" task - doesn't need the most capable model. #### 3. `memoryFlush.resetAfterFlush` - Flush then reset instead of flush then compact This is the highest-impact change. Currently the flow is: flush → compact. But if flush writes everything important to disk, compaction is redundant. The agent can just reset and boot fresh from its workspace files. ```jsonc { "agents": { "defaults": { "compaction": { "memoryFlush": { "enabled": true, "resetAfterFlush": true // hard reset after flush, skip compaction entirely } } } } } ``` **Flow:** context hits threshold → flush writes durable memories to disk → session resets → agent boots fresh with full context headroom, reads workspace files to pick up context. ### Alternatives considered No way for agent to change models or self-reset after memory flush... ### Impact **Why this works:** - Agents with good workspace discipline (daily memory files, AGENTS.md, MEMORY.md) already have everything they need to resume after a reset - Compaction summaries die at daily session reset anyway (4 AM default) - they're ephemeral - Disk-based memory is durable, searchable, and survives across sessions - Eliminates the most expensive step entirely (compaction with reasoning:high) **Cost comparison per cycle (Opus):** | Approach | Cost | |---|---| | Compaction only (current default mode) | ~$0.90-1.13 | | Flush + compaction (safeguard) | ~$1.25-4.00+ | | Flush + reset on Opus (proposed) | ~$0.25-0.93 | | Flush + reset on Sonnet (proposed with model override) | ~$0.05-0.15 | | Flush + reset on Haiku (proposed with model override) | ~$0.02-0.06 | Combined with model override, flush-then-reset on Haiku would be **15-50x cheaper** than the current safeguard compaction flow. ### Evidence/examples _No response_ ### Additional information ### Context - Compaction model is hardcoded: `generateSummary()` in `pi-coding-agent/dist/core/compaction/compaction.js` passes the session model directly - Safeguard extension in `pi-embedded` also uses `ctx.model ?? runtime?.model` with no override path - Compaction forces `reasoning: "high"` (extended thinking), generating expensive thinking tokens billed at output rate ($25/MTok for Opus) - Memory flush runs via `runMemoryFlushIfNeeded()` which uses `runWithModelFallback()` inheriting the session model - Agents cannot programmatically reset their own sessions - `/reset` is a user-facing command only - Tested: sending `/reset` via `openclaw message send` from the bot itself is rejected (not authorized sender) ### Environment - OpenClaw 2026.2.26 - Primary model: claude-opus-4-6 (200k context) - 5-agent setup (1 Opus + 2 Sonnet + 2 GPT)

Open original source