Skip to content

Context pruning mode 'off' not preventing compactions (Anthropic API key, cache-ttl smart defaults) #48579

Description

@adeydas

Summary

Context pruning set to mode: "off" with ttl: "999h" and keepLastAssistants: 999, but compactions continue to fire aggressively (~82 compactions in a single day) at only 12-16% context usage (120-160k of 1M tokens).

Environment

  • OpenClaw version: 2026.2.17 (4134875)
  • Model: anthropic/claude-opus-4-6 (1M context window)
  • Auth: Anthropic API key (multiple profiles: anthropic:default, anthropic:second, anthropic:bhide)
  • OS: Linux (Ubuntu)

Config

{
  "agents": {
    "defaults": {
      "contextTokens": 1000000,
      "contextPruning": {
        "mode": "off",
        "ttl": "999h",
        "keepLastAssistants": 999
      },
      "compaction": {
        "mode": "default",
        "reserveTokensFloor": 200000
      }
    }
  }
}

Expected Behavior

With contextPruning.mode: "off" and reserveTokensFloor: 200000, compaction should only trigger when context usage exceeds ~800k tokens (1M - 200k reserve).

Actual Behavior

Compactions fire constantly — even at 12-16% context usage (120-160k tokens). The Post-Compaction Audit fires on nearly every message, indicating context is being reset.

Investigation

Smart defaults code path (applyContextPruningDefaults)

The code in daemon-cli.js checks:

if (defaults.contextPruning?.mode === void 0) {
    nextDefaults.contextPruning = {
        ...contextPruning,
        mode: "cache-ttl",
        ttl: defaults.contextPruning?.ttl ?? "1h"
    };
}

Since mode: "off" is explicitly set, this guard should prevent the smart defaults from overriding. Verified in both config-BseT0AMx.js and daemon-cli.js.

Config file verification

The config file on disk is correct — contextPruning.mode is "off", confirmed via grep and JSON parsing. No per-agent overrides exist.

Session file evidence

Multiple session JSONL files are created per hour, suggesting new sessions are being spawned rather than continuing existing ones. Auth tokens alternate between anthropic:default and anthropic:second within a single session file.

Config-audit.log

Shows config being rewritten periodically (~85 writes total), each potentially triggering a daemon restart via SIGUSR1, which resets the session context.

Hypotheses

  1. Anthropic prompt cache TTL expiry — When the server-side prompt cache (5-min TTL) expires between messages, the uncached token cost may trigger compaction logic even when total context is well under the threshold.

  2. Auth profile rotation — Requests route through different Anthropic auth profiles (default vs second). If cache-ttl pruning is applied per-profile or cache state isn't shared across profiles, each profile switch may effectively reset the cache window.

  3. Config rewrites triggering restarts — The config-audit log shows periodic config writes that cause daemon restarts, which reset session context regardless of pruning settings.

  4. Compaction mode default may have additional triggers beyond just reserveTokensFloor that aren't documented.

Reproduction

  1. Configure anthropic/claude-opus-4-6 with API key auth (multiple profiles)
  2. Set contextPruning.mode: "off", contextTokens: 1000000, reserveTokensFloor: 200000
  3. Have a conversation with gaps > 5 minutes between messages
  4. Observe compaction counter incrementing despite low context usage

Impact

  • Session continuity is broken — context is lost every few messages
  • The Post-Compaction Audit fires on every message, requiring file re-reads
  • Estimated cost impact: compactions multiply API token usage significantly (re-sending context on every compaction)

Requested

  • Clarification on what triggers compaction in mode: "default" beyond reserveTokensFloor
  • Whether Anthropic prompt cache TTL expiry interacts with compaction logic
  • Whether auth profile rotation affects cache/pruning state
  • A way to fully disable compaction except at a hard context limit

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.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:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:data-lossCan lose, corrupt, or silently drop user/session/config data.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.staleMarked as stale due to inactivity

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions