openclaw - ✅(Solved) Fix feat: add model override for memoryFlush (like compaction.model) [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#66802Fetched 2026-04-15 06:24:20
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1referenced ×1

Fix Action

Fixed

PR fix notes

PR #66846: feat(memory): add model override for memoryFlush

Description (problem / solution / changelog)

Summary

  • Implements #66802 — allow configuring a different model for the memoryFlush prompt
  • The flush prompt fires before compaction to save important context to memory files. Currently it uses the session model, which wastes expensive tokens on a simple "save your notes" prompt
  • Adds compaction.memoryFlush.model config field (e.g., "anthropic/claude-haiku-4-5")

Changes

  • Config schema: Added model?: string to AgentCompactionMemoryFlushConfig type, zod schema, and generated JSON schema
  • Help & labels: Added help text and label for the new field
  • Runtime: Added resolveMemoryFlushModelOverride() following the same pattern as resolveEmbeddedCompactionTarget for compaction.model
  • Tests: 9 new tests (3 integration + 6 unit) covering override, fallback, and edge cases

Config example

{
  "compaction": {
    "memoryFlush": {
      "enabled": true,
      "model": "anthropic/claude-haiku-4-5"
    }
  }
}

Test plan

  • Model override is used when configured
  • Falls back to session model when not configured
  • All agent-runner-memory tests pass

🤖 Generated with Claude Code

Changed files

  • docs/.generated/config-baseline.sha256 (modified, +3/-3)
  • src/auto-reply/reply/agent-runner-memory.test.ts (modified, +238/-3)
  • src/auto-reply/reply/agent-runner-memory.ts (modified, +36/-3)
  • src/config/schema.base.generated.ts (modified, +11/-0)
  • src/config/schema.help.ts (modified, +2/-0)
  • src/config/schema.labels.ts (modified, +1/-0)
  • src/config/types.agent-defaults.ts (modified, +4/-0)
  • src/config/zod-schema.agent-defaults.ts (modified, +1/-0)

Code Example

{
  "compaction": {
    "model": "google/gemini-2.5-flash",
    "memoryFlush": {
      "enabled": true,
      "softThresholdTokens": 50000
    }
  }
}

---

{
  "compaction": {
    "model": "google/gemini-2.5-flash",
    "memoryFlush": {
      "enabled": true,
      "model": "anthropic/claude-sonnet-4",
      "softThresholdTokens": 50000
    }
  }
}
RAW_BUFFERClick to expand / collapse

Problem

The memory flush (pre-compaction agentic turn that persists session context to files) always uses the session's primary model. When running an expensive model like Opus ($15/M input, $75/M output), each flush costs ~$2.10 — which is the dominant cost in the compaction cycle.

Compaction already supports a compaction.model override (e.g., google/gemini-2.5-flash), reducing summarization cost to ~$0.05. But the flush — an architecturally identical silent agentic turn — lacks this override.

Current Behavior

{
  "compaction": {
    "model": "google/gemini-2.5-flash",
    "memoryFlush": {
      "enabled": true,
      "softThresholdTokens": 50000
    }
  }
}
  • compaction.model → works, compaction uses Gemini Flash ✅
  • memoryFlush.model → does not exist, flush uses session model (Opus) ❌
  • The memoryFlush schema uses .strict(), so adding unknown keys causes validation errors

Desired Behavior

{
  "compaction": {
    "model": "google/gemini-2.5-flash",
    "memoryFlush": {
      "enabled": true,
      "model": "anthropic/claude-sonnet-4",
      "softThresholdTokens": 50000
    }
  }
}

Allow specifying a separate model for the flush turn. The flush task (extract key facts from conversation and write to files) is structured extraction — it doesn't require top-tier reasoning.

Cost Impact

ComponentCurrent (Opus)With Override (Sonnet)With Override (Flash)
Flush input (~100K tokens)$1.50$0.30$0.015
Flush output (~2K tokens)$0.15$0.03$0.001
Total per flush~$1.65~$0.33~$0.02

For users running 3-5 compaction cycles per session, this saves $4-8/session.

Implementation Notes

Based on source analysis, three changes needed:

  1. Schema (zod-schema): Add model: z.string().optional() inside the memoryFlush object
  2. Flush plan (memory-core/index.js buildMemoryFlushPlan): Read and pass through the model field
  3. Runtime (agent-runner.runtime): Override resolveModelFallbackOptions with flush plan model when present

The pattern is identical to how compaction.model already works.

Environment

  • OpenClaw version: 2026.2.1

extent analysis

TL;DR

To reduce the cost of memory flush in compaction cycles, add support for overriding the model used by the flush task, similar to the existing compaction.model override.

Guidance

  • Update the memoryFlush schema to include an optional model field, allowing users to specify a separate model for the flush turn.
  • Modify the buildMemoryFlushPlan function in memory-core/index.js to read and pass through the specified model field.
  • Override the resolveModelFallbackOptions function in agent-runner.runtime to use the flush plan model when present, following the same pattern as the existing compaction.model override.
  • Verify the changes by testing the updated configuration with different models and monitoring the cost impact.

Example

{
  "compaction": {
    "model": "google/gemini-2.5-flash",
    "memoryFlush": {
      "enabled": true,
      "model": "anthropic/claude-sonnet-4",
      "softThresholdTokens": 50000
    }
  }
}

Notes

The proposed changes require updating the schema, flush plan, and runtime to support the new memoryFlush.model override. The cost savings will depend on the specific models used and the number of compaction cycles per session.

Recommendation

Apply the workaround by adding support for the memoryFlush.model override, as it can significantly reduce the cost of memory flush in compaction cycles.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING