-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
Irreversible context compaction when swapping to a model with a smaller context window #98426
Copy link
Copy link
Closed as not planned
Closed as not planned
Copy link
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper 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 marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper 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.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.Issue affects a taxonomy feature currently scored M4/M5.staleMarked as stale due to inactivityMarked as stale due to inactivity
Description
Metadata
Metadata
Assignees
Labels
P2Normal backlog priority with limited blast radius.Normal backlog priority with limited blast radius.clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.ClawSweeper 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 marked this issue as needing maintainer review before automation.clawsweeper:needs-product-decisionClawSweeper marked this issue as needing a product or behavior decision.ClawSweeper 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.ClawSweeper does not recommend queueing a new automated fix PR for this issue.impact:auth-providerAuth, provider routing, model choice, or SecretRef resolution may break.Auth, provider routing, model choice, or SecretRef resolution may break.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.Good issue quality with a plausible reproduction path needing some confirmation.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.Issue affects a taxonomy feature currently scored M4/M5.staleMarked as stale due to inactivityMarked as stale due to inactivity
Type
Fields
Priority
None yet
Bug Report / Feature Request: Irreversible Context Compaction on Model Swap
Filed: 2026-07-01
Project: OpenClaw Gateway
Type: Bug + Feature Request
Severity: Medium-High (silent data loss, affects all multi-model fallback chains)
Summary
When the fallback chain swaps from a large-context model (e.g. DeepSeek V4 Flash, 1M tokens) to a smaller-context model (e.g. Kimi K2.6 at 128K, GPT 5.4 Mini at 128K, Haiku 4.5 at 200K), the session context is compacted and permanently truncated to fit the smaller window. When the chain later swaps back to a large-context model (e.g. GPT 5.4 at 1M, Opus 4.8 at 200K), the compacted context does not regrow — the lost tokens are gone forever.
This creates a one-way compaction trap that disproportionately punishes users who strategically use cheaper large-context models for data gathering and then swap to premium reasoning models for judgment.
Problem Detail
The Fallback Chain
What Happens
Why This Is Wrong
The current behavior assumes context compaction is monotonic shrinking — once you compact, you stay small. But in a multi-model fallback chain where later models have larger or equal context windows, this assumption is incorrect. The user loses value because:
Expected Behavior
Option A (Ideal — backward compatible): Each model in the fallback chain should receive context truncated to its maximum window, but the pre-compaction full context should be preserved in the session store. When the chain routes to a model with a larger window, the full context should be restored.
Option B (Minimal fix): Provide a configurable
compaction.preserveFullContext: trueflag that prevents permanent truncation. When enabled, the session store retains the original uncompressed tokens and re-hydrates them for any subsequent model whose context window supports it.Option C (Documentation/API): At minimum, emit a diagnostic warning when compaction discards more than 50% of context, including "X tokens discarded — Y% of session context lost due to fallback to [model name]"
Current Workaround (In-House)
Before swapping to a "bigger brain" premium model (higher reasoning, smaller context window), the session context is pre-split into digestible chunks sized to fit the target model's window. The premium model receives structured, self-contained chunks rather than a single compacted blob. All information is preserved — it's divided into pieces the target model can process, rather than blindly compressed into a smaller window.
Downsides: Requires pre-processing logic to split and rejoin cleanly; doesn't cover the automatic fallback chain; adds latency before the swap.
Reproduction Steps
deepseek/deepseek-v4-flash → moonshot/kimi-k2.6Environment
Suggested Implementation Sketch
Related
docs/context-handoff-protocol.md