openclaw - 💡(How to fix) Fix [Bug]: direct session can exceed configured contextWindow without timely compaction [4 comments, 3 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#50065Fetched 2026-04-08 00:59:35
View on GitHub
Comments
4
Participants
3
Timeline
5
Reactions
0
Timeline (top)
commented ×4cross-referenced ×1

Direct chat sessions can grow past the configured/effective context window (observed around 223k/200k) without timely compaction, eventually causing unstable behavior such as non-replies or broken command lanes.

Root Cause

When compaction does not trigger in time, long-lived direct sessions can silently degrade and require manual reset, which is especially painful for always-on assistant accounts.

RAW_BUFFERClick to expand / collapse

Summary

Direct chat sessions can grow past the configured/effective context window (observed around 223k/200k) without timely compaction, eventually causing unstable behavior such as non-replies or broken command lanes.

Expected

  • Sessions nearing the active contextWindow should compact before crossing the limit.
  • compaction.mode = safeguard should prevent long-lived direct sessions from drifting beyond the configured token budget.

Actual

  • A direct session exceeded the apparent 200k window and reached roughly 223k/200k.
  • The session became unreliable: no reply / degraded behavior.
  • Another direct session later showed a cleared lane symptom and also needed reset.
  • Resetting the affected sessions restored normal behavior.

Environment

  • OpenClaw main agent
  • Telegram direct sessions (multi-account setup)
  • compaction.mode = safeguard
  • Legacy context engine path appears active

Notes

  • This does not appear to be a provider-token issue or bot token issue.
  • Account routing and messaging recovered after session reset, which suggests session state / compaction behavior rather than transport failure.
  • Runtime inspection suggests the fallback context window is 200000, but compaction did not reliably trigger before the session exceeded that threshold.

Why this matters

When compaction does not trigger in time, long-lived direct sessions can silently degrade and require manual reset, which is especially painful for always-on assistant accounts.

Possible directions

  • Re-check when safeguard compaction is triggered for direct sessions
  • Verify whether token estimation is undercounting until too late
  • Verify whether some direct-session paths bypass compaction or fail compaction silently
  • Consider earlier safety margins before the full context window is reached

extent analysis

Fix Plan

To address the issue of direct chat sessions exceeding the configured context window without timely compaction, we will:

  • Adjust the compaction trigger to occur before the session reaches the maximum context window
  • Implement a safety margin to prevent sessions from silently degrading
  • Verify token estimation accuracy to ensure it's not undercounting

Code Changes

# Adjust compaction trigger and add safety margin
compaction_trigger = 0.8  # Trigger compaction when 80% of context window is reached
safety_margin = 0.1  # Add 10% safety margin to prevent silent degradation

# Update compaction logic
def compact_session(session):
    if session.context_size > (compaction_trigger * context_window):
        # Trigger compaction
        compact_session_data(session)

# Verify token estimation accuracy
def estimate_token_count(session):
    # Implement accurate token estimation logic
    pass

Configuration Changes

  • Update compaction.mode to safeguard with adjusted trigger and safety margin
  • Verify context_window is set to the desired value (e.g., 200000)

Verification

  • Monitor direct chat sessions to ensure compaction triggers before exceeding the context window
  • Verify token estimation accuracy by comparing estimated token counts with actual counts

Extra Tips

  • Regularly review and adjust the compaction trigger and safety margin as needed to prevent silent degradation
  • Consider implementing automated testing to ensure compaction logic is working correctly

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

openclaw - 💡(How to fix) Fix [Bug]: direct session can exceed configured contextWindow without timely compaction [4 comments, 3 participants]