Skip to content

Safeguard compaction ignores compaction.model config — uses session model instead #57901

Description

@joeykrug

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:linked-pr-openClawSweeper found an open linked pull request for this issue.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.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.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