openclaw - 💡(How to fix) Fix Telegram direct session can become unrecoverable after context overflow and auto-compaction hangs [2 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#70744Fetched 2026-04-24 05:54:10
View on GitHub
Comments
2
Participants
3
Timeline
2
Reactions
0
Author
Timeline (top)
commented ×2

A long-lived Telegram direct chat became permanently non-responsive after hitting context overflow. The gateway and Telegram provider both restarted normally, but the same Telegram direct session immediately re-entered auto-compaction and never recovered enough to send a reply. Repeated gateway restarts did not fix it. The only effective recovery was to back up and quarantine/reset the session JSONL so a fresh Telegram session could be created.

Error Message

[agent/embedded] [context-overflow-diag] sessionKey=agent:main:telegram:direct:8365774449 provider=openai-codex/gpt-5.4 source=assistantError messages=239/240/241 sessionFile=/home/.../a6154fac-955a-40ca-b04d-90ff98dd9f20.jsonl ... error=Context overflow: estimated context size exceeds safe threshold during tool loop.

  • emit a visible error or fallback reply to the user instead of hanging indefinitely

Root Cause

Additional notes

  • This same chat appears to have overflowed previously and recovered once, so the issue may be tied to transcript growth plus a compaction edge case rather than a one-off Telegram outage.
  • There were also occasional Telegram network fallback warnings (ETIMEDOUT, ENETUNREACH, UND_ERR_SOCKET), but those did not appear to be the root cause here because the provider started successfully and the failure reproduced specifically on the same session transcript.

Code Example

[telegram] [default] starting provider (@Cooter_the_bot)
[agent/embedded] [context-overflow-diag] sessionKey=agent:main:telegram:direct:8365774449 provider=openai-codex/gpt-5.4 source=assistantError messages=239/240/241 sessionFile=/home/.../a6154fac-955a-40ca-b04d-90ff98dd9f20.jsonl ... error=Context overflow: estimated context size exceeds safe threshold during tool loop.
[agent/embedded] context overflow detected (attempt 1/3); attempting auto-compaction for openai-codex/gpt-5.4
typing TTL reached (2m); stopping typing indicator
RAW_BUFFERClick to expand / collapse

Summary

A long-lived Telegram direct chat became permanently non-responsive after hitting context overflow. The gateway and Telegram provider both restarted normally, but the same Telegram direct session immediately re-entered auto-compaction and never recovered enough to send a reply. Repeated gateway restarts did not fix it. The only effective recovery was to back up and quarantine/reset the session JSONL so a fresh Telegram session could be created.

Environment

  • OpenClaw: 2026.4.14
  • Host OS: Ubuntu 24.04
  • Runtime: Node 22.22.2
  • Model in affected session: openai-codex/gpt-5.4
  • Channel: Telegram direct chat

Affected session

  • sessionKey: agent:main:telegram:direct:8365774449
  • session file: ~/.openclaw/agents/main/sessions/a6154fac-955a-40ca-b04d-90ff98dd9f20.jsonl
  • size at failure: about 5.1 MB
  • message count shown in logs around failure: 239-241

Symptoms

  • Telegram bot stopped replying in that direct chat
  • Gateway restart succeeded
  • Telegram provider startup succeeded
  • On each fresh start, the same session immediately hit context overflow again
  • No reply was ever emitted back to Telegram
  • The typing indicator eventually expired, but the session remained wedged

Relevant log pattern

Observed repeatedly after restart:

[telegram] [default] starting provider (@Cooter_the_bot)
[agent/embedded] [context-overflow-diag] sessionKey=agent:main:telegram:direct:8365774449 provider=openai-codex/gpt-5.4 source=assistantError messages=239/240/241 sessionFile=/home/.../a6154fac-955a-40ca-b04d-90ff98dd9f20.jsonl ... error=Context overflow: estimated context size exceeds safe threshold during tool loop.
[agent/embedded] context overflow detected (attempt 1/3); attempting auto-compaction for openai-codex/gpt-5.4
typing TTL reached (2m); stopping typing indicator

There was no visible recovery message such as auto-compaction succeeded, and the chat remained non-responsive.

What did NOT fix it

  • Restarting the gateway
  • Letting the provider reconnect
  • Sending new Telegram messages into the same chat

What DID fix it

  1. Back up the affected session JSONL
  2. Move/quarantine/reset the stuck session file
  3. Restart the gateway
  4. Let Telegram create/use a fresh session

After that, Telegram replies resumed immediately.

Expected behavior

If a session overflows and auto-compaction cannot recover it, OpenClaw should fail more gracefully. Examples:

  • automatically fork/reset the session after repeated compaction failure
  • emit a visible error or fallback reply to the user instead of hanging indefinitely
  • avoid reloading the same poisoned session into an endless overflow/compaction loop on startup

Additional notes

  • This same chat appears to have overflowed previously and recovered once, so the issue may be tied to transcript growth plus a compaction edge case rather than a one-off Telegram outage.
  • There were also occasional Telegram network fallback warnings (ETIMEDOUT, ENETUNREACH, UND_ERR_SOCKET), but those did not appear to be the root cause here because the provider started successfully and the failure reproduced specifically on the same session transcript.

If helpful, I can provide a sanitized copy of the failing session transcript or more exact timestamps from logs.

extent analysis

TL;DR

Resetting the stuck session file and allowing Telegram to create a fresh session resolves the issue, suggesting a problem with session management during context overflow and auto-compaction.

Guidance

  • Identify and quarantine problematic sessions: Regularly monitor session sizes and logs for context overflow errors to prevent similar issues.
  • Implement graceful failure handling: Modify OpenClaw to automatically fork/reset sessions after repeated compaction failures or emit a visible error/fallback reply to the user.
  • Review auto-compaction logic: Investigate why auto-compaction failed to recover the session and consider improvements to handle large transcripts and edge cases.
  • Consider transcript size limits: Evaluate setting size limits for sessions to prevent excessive growth and associated issues.

Example

No specific code snippet is provided due to the lack of direct code references in the issue, but a potential solution might involve modifying the session management and auto-compaction logic in OpenClaw.

Notes

The exact cause of the context overflow and auto-compaction failure is unclear, but it appears related to transcript growth and potential edge cases in the compaction process. Providing a sanitized copy of the failing session transcript or more exact timestamps from logs might help in further diagnosis.

Recommendation

Apply a workaround by implementing a process to regularly monitor and reset stuck sessions, and consider upgrading OpenClaw if a future version addresses the underlying issue with context overflow and auto-compaction.

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 a session overflows and auto-compaction cannot recover it, OpenClaw should fail more gracefully. Examples:

  • automatically fork/reset the session after repeated compaction failure
  • emit a visible error or fallback reply to the user instead of hanging indefinitely
  • avoid reloading the same poisoned session into an endless overflow/compaction loop on startup

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 Telegram direct session can become unrecoverable after context overflow and auto-compaction hangs [2 comments, 3 participants]