Skip to content

Compaction safeguard ignores provider contextWindow config override #17744

Description

@cmfinlan

Bug Summary

The compaction safeguard trigger ignores provider contextWindow overrides from config. The display path (via resolveContextWindowInfo()) correctly shows the configured 1M context window, but the compaction trigger reads the hardcoded 200k value from the pi-ai package and fires at ~180k tokens (90% of 200k).

Environment

  • Versions affected: v2026.2.12, v2026.2.14
  • Model: Claude Opus 4.6 (anthropic)
  • Config override: models.providers.anthropic.models[].contextWindow: 1000000

Steps to Reproduce

  1. Set contextWindow: 1000000 in config under models.providers.anthropic.models[]
  2. Start a session — session_status correctly shows 1.0M context window
  3. Continue conversation until token usage reaches ~180k
  4. Compaction fires unexpectedly at ~180k tokens (90% of 200k), despite the configured 1M window

Expected Behavior

Compaction should fire at 90% of the configured context window (900k tokens), not 90% of the hardcoded default (180k tokens).

Actual Behavior

Compaction fires at ~180k tokens because the compaction trigger reads the hardcoded 200k value from the pi-ai package rather than the user-configured override.

Root Cause

Two different code paths resolve the context window size:

  1. Display path (resolveContextWindowInfo()) — correctly reads the config override and shows 1.0M
  2. Compaction trigger path — reads the hardcoded value from pi-ai model definitions (200k for Claude models) and triggers at 90% of that

The config override is applied in one path but not the other.

Workaround

Monkey-patching the dist files to inject the config override into the compaction code path. Five files need patching (marked with [openclaw-patch] comments):

  • context-D5JPpgxa.js
  • pi-embedded-8DITBEle.js
  • reply-CrwRmeCr.js
  • reply-CYMZTXlH.js
  • pi-embedded-CM97XTkp.js

The patched locations are resolveModel() and MODEL_CACHE initialization in the context, reply, and pi-embedded dist files. The patches ensure these code paths also read the provider config contextWindow override.

Suggested Fix

Unify the context window resolution so that both the display and compaction trigger paths use the same logic — respecting user config overrides from models.providers.<provider>.models[].contextWindow.

Metadata

Metadata

Assignees

No one assigned

    Labels

    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