Skip to content

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

Description

@dzhang253

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:

{
  "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:

{
  "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.

{
  "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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.clawsweeper:needs-security-reviewClawSweeper marked this issue as needing security-sensitive review.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.enhancementNew feature or requestimpact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.impact:securitySecurity boundary, credential, authz, sandbox, or sensitive-data risk.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions