openclaw - 💡(How to fix) Fix Context overflow during tool loop resets session instead of triggering compaction rescue [1 comments, 2 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#72676Fetched 2026-04-28 06:33:30
View on GitHub
Comments
1
Participants
2
Timeline
4
Reactions
0
Author
Participants
Timeline (top)
labeled ×2closed ×1commented ×1

When a long-lived OpenClaw session overflows context during a tool loop, the runtime resets the session and remaps the conversation to a new session instead of attempting a compaction rescue. The preflight compaction path exists, but this overflow path appears to bypass it entirely.

Root Cause

Either way, the current behavior is surprising because users reasonably expect the advertised compaction mechanism to protect them from exactly this kind of large-session failure.

Code Example

Local evidence:
- `openclaw logs` showed: `Context overflow: estimated context size exceeds safe threshold during tool loop.`
- The same diagnostic included `compactionAttempts=0`.
- The overflowing session transcript was archived as a `.jsonl.reset.<timestamp>` file.
- A replacement session began seconds later for the same conversation/session key.

Relevant built runtime observations from local install (`dist/agent-runner.runtime-*.js`):
- `runPreflightCompactionIfNeeded(...)` is invoked before `runEmbeddedPiAgent(...)`.
- On overflow, code reaches a branch that calls `resetSessionAfterCompactionFailure(...)` and returns a reset/fresh-start message.
- I did not find an equivalent rescue-compaction attempt in the `during tool loop` overflow branch.

If helpful, I can provide fuller log excerpts and exact local code line references.
RAW_BUFFERClick to expand / collapse

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

When a long-lived OpenClaw session overflows context during a tool loop, the runtime resets the session and remaps the conversation to a new session instead of attempting a compaction rescue. The preflight compaction path exists, but this overflow path appears to bypass it entirely.

Steps to reproduce

  1. Start a long-lived tool-enabled OpenClaw chat session.
  2. Let the session grow large enough that it is near the model context limit.
  3. Trigger a multi-step tool flow so the run enters a tool loop.
  4. Observe an overflow in the middle of the run rather than before the run starts.
  5. Send the next user message in the same conversation.

This has been observed across multiple chat channels, so it appears to live in shared embedded agent/session runner logic rather than a single channel integration.

Expected behavior

If the session is too large, OpenClaw should either:

  • trigger a compaction rescue before resetting the session, or
  • gracefully compact and continue/retry the run, instead of silently replacing the active chat mapping with a fresh session.

At minimum, compaction should be attempted on this overflow path when safe to do so, or the user-facing continuity break should be made explicit.

Actual behavior

The session overflowed during a tool loop and was reset immediately. The next inbound message in the same conversation started a brand new session, which lost the prior conversational context from the active transcript.

Evidence from local runtime/log inspection:

  • Runtime log reported: Context overflow: estimated context size exceeds safe threshold during tool loop.
  • Same log line reported compactionAttempts=0.
  • The old session transcript was archived as a .jsonl.reset.<timestamp> file.
  • A new session was created for the same conversation a few seconds later.

From inspecting the built runtime code, runPreflightCompactionIfNeeded(...) is called before the embedded run starts, but the overflow path later calls resetSessionAfterCompactionFailure(...) on context overflow instead of attempting a rescue compaction in that branch.

OpenClaw version

2026.4.23

Operating system

Linux 6.6.87.2-microsoft-standard-WSL2 (x64) under WSL2

Install method

npm global install

Model

gpt-5.4

Provider / routing chain

openai-codex / openai-codex-responses

Additional provider/model setup details

Embedded agent runtime, tool-enabled session, local gateway service running. This behavior has been observed on multiple chat channels (including Zalo and Discord), which suggests the implicated code path is shared embedded-agent runtime/session logic rather than transport-specific logic.

Logs, screenshots, and evidence

Local evidence:
- `openclaw logs` showed: `Context overflow: estimated context size exceeds safe threshold during tool loop.`
- The same diagnostic included `compactionAttempts=0`.
- The overflowing session transcript was archived as a `.jsonl.reset.<timestamp>` file.
- A replacement session began seconds later for the same conversation/session key.

Relevant built runtime observations from local install (`dist/agent-runner.runtime-*.js`):
- `runPreflightCompactionIfNeeded(...)` is invoked before `runEmbeddedPiAgent(...)`.
- On overflow, code reaches a branch that calls `resetSessionAfterCompactionFailure(...)` and returns a reset/fresh-start message.
- I did not find an equivalent rescue-compaction attempt in the `during tool loop` overflow branch.

If helpful, I can provide fuller log excerpts and exact local code line references.

Impact and severity

High impact for long-lived chat sessions. It causes an unexpected continuity break, makes the user think a new session started by itself, and can discard immediately relevant conversational context right when the agent is in the middle of a complex task.

Additional information

This may be either:

  1. a bug where overflow during tool loop should still trigger a compaction rescue path, or
  2. a design limitation where only preflight compaction exists today.

Either way, the current behavior is surprising because users reasonably expect the advertised compaction mechanism to protect them from exactly this kind of large-session failure.

I intentionally describe this as a shared runtime/session behavior rather than a channel-specific bug, because it has been observed outside a single transport integration.

extent analysis

TL;DR

The most likely fix involves modifying the overflow path during a tool loop to attempt a compaction rescue before resetting the session.

Guidance

  • Review the resetSessionAfterCompactionFailure function to determine why it's being called without attempting compaction, and consider adding a compaction attempt before resetting the session.
  • Investigate the runPreflightCompactionIfNeeded function to see if it can be adapted for use during the tool loop overflow path.
  • Verify that the compactionAttempts=0 log message is accurate and not a red herring, as it suggests no compaction attempts were made.
  • Consider adding logging or debugging statements to the overflow path to better understand the decision-making process that leads to session reset without compaction.

Example

No code snippet is provided due to the complexity of the issue and the need for more specific information about the resetSessionAfterCompactionFailure and runPreflightCompactionIfNeeded functions.

Notes

The issue may be due to a design limitation rather than a bug, and the fix may require changes to the overall architecture of the OpenClaw session management system.

Recommendation

Apply a workaround by modifying the overflow path to attempt compaction before resetting the session, as this is the most direct way to address the issue and prevent session continuity breaks.

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…

FAQ

Expected behavior

If the session is too large, OpenClaw should either:

  • trigger a compaction rescue before resetting the session, or
  • gracefully compact and continue/retry the run, instead of silently replacing the active chat mapping with a fresh session.

At minimum, compaction should be attempted on this overflow path when safe to do so, or the user-facing continuity break should be made explicit.

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 Context overflow during tool loop resets session instead of triggering compaction rescue [1 comments, 2 participants]