openclaw - ✅(Solved) Fix Safeguard compaction ignores compaction.model config — uses session model instead [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#57901Fetched 2026-04-08 01:56:18
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1referenced ×1

Root Cause

In the safeguard extension's session_before_compact handler, the model is resolved as:

const model = ctx.model ?? runtime?.model;

This prefers ctx.model (the session's main model, e.g., Opus) over runtime?.model (the configured compaction model from agents.defaults.compaction.model). Since ctx.model is always set for active sessions, the configured compaction model is never used.

Fix Action

Workaround

Patch the dist file directly: swap ctx.model ?? runtime?.model to runtime?.model ?? ctx.model in the safeguard extension.

PR fix notes

PR #57903: fix: safeguard compaction should prefer configured model over session model

Description (problem / solution / changelog)

Summary

One-line fix: swap model precedence in the safeguard compaction extension so the user-configured compaction.model takes priority over the session's main model.

Problem

When compaction.mode: "safeguard" is enabled with compaction.model: "anthropic/claude-sonnet-4-6", the safeguard extension ignores it and uses the session's main model (e.g., Opus) instead.

The model is resolved at line 615 of compaction-safeguard.ts:

const model = ctx.model ?? runtime?.model;

Since ctx.model (session model) is always set for active sessions, runtime?.model (configured compaction model) is never reached.

Fix

const model = runtime?.model ?? ctx.model;

This matches the behavior of the legacy compaction path, which correctly reads compaction.model as an override.

Impact

  • Users can now use a cheaper/faster model for compaction summaries (e.g., Sonnet instead of Opus)
  • No behavioral change when compaction.model is not configured (falls back to session model as before)
  • One line changed, zero risk to other codepaths

Fixes #57901

Changed files

  • src/agents/pi-hooks/compaction-safeguard.ts (modified, +1/-1)

Code Example

const model = ctx.model ?? runtime?.model;

---

const model = runtime?.model ?? ctx.model;
RAW_BUFFERClick to expand / collapse

Bug

When compaction.mode: "safeguard" is enabled with a custom compaction.model (e.g., anthropic/claude-sonnet-4-6), the safeguard extension ignores it and uses the session's main model instead.

Root Cause

In the safeguard extension's session_before_compact handler, the model is resolved as:

const model = ctx.model ?? runtime?.model;

This prefers ctx.model (the session's main model, e.g., Opus) over runtime?.model (the configured compaction model from agents.defaults.compaction.model). Since ctx.model is always set for active sessions, the configured compaction model is never used.

Expected Behavior

The configured compaction.model should take precedence over the session model:

const model = runtime?.model ?? ctx.model;

Impact

  • Users configuring a cheaper/faster model for compaction (e.g., Sonnet instead of Opus) see no effect
  • Compaction runs on the expensive session model, increasing costs
  • The compaction.model config option is effectively broken in safeguard mode

Environment

  • OpenClaw 2026.3.28
  • compaction.mode: "safeguard"
  • compaction.model: "anthropic/claude-sonnet-4-6"

Workaround

Patch the dist file directly: swap ctx.model ?? runtime?.model to runtime?.model ?? ctx.model in the safeguard extension.

extent analysis

Fix Plan

To fix the issue, update the session_before_compact handler in the safeguard extension to prioritize the configured compaction model.

  • Replace the line:
const model = ctx.model ?? runtime?.model;

with:

const model = runtime?.model ?? ctx.model;

This change ensures that the configured compaction.model takes precedence over the session's main model.

Verification

After applying the fix, verify that the configured compaction model is used by checking the model name in the compaction logs or by monitoring the cost and performance metrics to confirm that the cheaper/faster model is being utilized.

Extra Tips

  • Consider submitting a pull request to the OpenClaw repository to incorporate this fix into the main codebase.
  • When configuring custom models for compaction, ensure that the compaction.model option is correctly set and that the model is compatible with the safeguard extension.

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