Bug Report
Summary
When a session approaches the context limit (~198k/200k tokens), the agent enters an infinite tool-call loop and never sends a final reply to the user. The chat appears dead — the user sees no response. Additionally, resetting the session by deleting/renaming the .jsonl file does not clear the in-memory session state in the gateway.
Environment
- OpenClaw version: 2026.3.13 (61d171a)
- OS: Ubuntu Linux 6.8.0-106-generic (x64)
- Node: v22.22.0
- Model: anthropic/claude-sonnet-4-6 (OAuth)
- Channel: Telegram (group/topic)
Steps to Reproduce
Bug 1: Agent hangs at ~198k tokens
- Have a long conversation in a Telegram group topic until context reaches ~198k tokens
- Send a message to the agent
- Agent starts executing tool calls (exec, process.poll, etc.) but never emits a
stop with a text reply
- User sees no response — chat appears dead
sessions_list shows stopReason: "toolUse" or stopReason: "aborted" as the last state
abortedLastRun: false — the session is not marked as broken
Bug 2: File-based session reset does not work
- Rename/delete the session
.jsonl file to reset the session
- Gateway creates a new (small)
.jsonl file on next message
- But
sessions_list still reports the OLD totalTokens: 198706 — the in-memory state was not cleared
- The session ID remains the same (
5f53d330-...)
- Agent continues from the old bloated state despite the file being replaced
Expected Behavior
Bug 1:
- When context approaches the limit, the agent should either:
- Auto-compact (trigger compaction before hitting the wall)
- Or gracefully stop tool calls and send a text reply like "Context limit reached, please start a new thread"
- The agent should NEVER silently hang with no user-visible output
Bug 2:
- Deleting/renaming the
.jsonl file should trigger the gateway to re-read from disk and reset the in-memory session state
- Or there should be an API/CLI command like
openclaw session reset <key> to properly reset a session
Actual Behavior
- Agent enters infinite tool loop, user gets no reply
- File deletion does not reset in-memory state
- Only
openclaw gateway restart clears the state (but kills ALL sessions)
Impact
- Critical for production use: users in Telegram/Discord groups see the bot go silent with no explanation
- No self-healing: the session stays broken until manual intervention
- Data loss risk: the only workaround is to delete the session file and lose all conversation history, or restart the entire gateway
Workaround
- Backup the session
.jsonl file
- Restart the gateway (
openclaw gateway restart)
- Inject a summary of the previous conversation to restore context
Session Details (for debugging)
- Session key:
agent:main:telegram:group:-1003829863617:topic:7524
- Session ID:
5f53d330-4186-4831-ac2d-be94c4685eb1
- Transcript:
5f53d330-4186-4831-ac2d-be94c4685eb1-topic-7524.jsonl
- Total tokens at hang: 198,706 / 200,000
- Last
stopReason: "aborted" with errorMessage: "Request was aborted."
Suggested Improvements
- Proactive compaction — trigger compaction at ~90% context usage, not at 100%
- Tool loop breaker — if agent does N consecutive tool calls without a text reply, force a text response
- Graceful degradation — send "context full" message to user instead of silent hang
- Session reset API —
openclaw session reset <key> that properly clears both disk and memory
- File watch — gateway should detect
.jsonl file changes and reload session state
Bug Report
Summary
When a session approaches the context limit (~198k/200k tokens), the agent enters an infinite tool-call loop and never sends a final reply to the user. The chat appears dead — the user sees no response. Additionally, resetting the session by deleting/renaming the
.jsonlfile does not clear the in-memory session state in the gateway.Environment
Steps to Reproduce
Bug 1: Agent hangs at ~198k tokens
stopwith a text replysessions_listshowsstopReason: "toolUse"orstopReason: "aborted"as the last stateabortedLastRun: false— the session is not marked as brokenBug 2: File-based session reset does not work
.jsonlfile to reset the session.jsonlfile on next messagesessions_liststill reports the OLDtotalTokens: 198706— the in-memory state was not cleared5f53d330-...)Expected Behavior
Bug 1:
Bug 2:
.jsonlfile should trigger the gateway to re-read from disk and reset the in-memory session stateopenclaw session reset <key>to properly reset a sessionActual Behavior
openclaw gateway restartclears the state (but kills ALL sessions)Impact
Workaround
.jsonlfileopenclaw gateway restart)Session Details (for debugging)
agent:main:telegram:group:-1003829863617:topic:75245f53d330-4186-4831-ac2d-be94c4685eb15f53d330-4186-4831-ac2d-be94c4685eb1-topic-7524.jsonlstopReason:"aborted"witherrorMessage: "Request was aborted."Suggested Improvements
openclaw session reset <key>that properly clears both disk and memory.jsonlfile changes and reload session state