openclaw - 💡(How to fix) Fix Large session context causes 'An unknown error occurred' with Kimi-K2.5 [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

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#51397Fetched 2026-04-08 01:11:41
View on GitHub
Comments
2
Participants
3
Timeline
4
Reactions
0
Author
Timeline (top)
commented ×2mentioned ×1subscribed ×1

When the Feishu session context grows large (77k+ tokens, 181KB session file), the AI model (Kimi-K2.5 via Tencent Coding Plan provider) returns a generic "An unknown error occurred" error, causing message handling to fail.

Error Message

"event":"embedded_run_agent_end"
"isError":true
"error":"An unknown error occurred"
"model":"kimi-k2.5"
"provider":"tencent-coding-plan"

Session stats when error occurred:

  • Session file size: 181KB
  • inputTokens: 77,305
  • contextTokens: 262,144 (max for Kimi-K2.5)

Root Cause

Actual Behavior

  • Generic error: "An unknown error occurred"
  • User has to manually investigate logs to find the root cause
  • Only solution is manually backing up and resetting the session file

Fix Action

Workaround

Reset the session by:

mv ~/.openclaw/agents/main/sessions/<session-id>.jsonl <session-id>.jsonl.backup
openclaw gateway restart

Code Example

"event":"embedded_run_agent_end"
"isError":true
"error":"An unknown error occurred"
"model":"kimi-k2.5"
"provider":"tencent-coding-plan"

---

mv ~/.openclaw/agents/main/sessions/<session-id>.jsonl <session-id>.jsonl.backup
openclaw gateway restart
RAW_BUFFERClick to expand / collapse

Bug Report: Large session context causes "An unknown error occurred" with Kimi-K2.5

Summary

When the Feishu session context grows large (77k+ tokens, 181KB session file), the AI model (Kimi-K2.5 via Tencent Coding Plan provider) returns a generic "An unknown error occurred" error, causing message handling to fail.

Environment

  • OpenClaw version: 2026.3.13
  • Model: tencent-coding-plan/kimi-k2.5
  • Channel: Feishu (Lark)
  • OS: macOS

Steps to Reproduce

  1. Use OpenClaw with Feishu channel enabled
  2. Have a long conversation with many tool calls (session accumulates ~77k tokens)
  3. Send a new message via Feishu
  4. Observe the error: "An unknown error occurred"

Expected Behavior

  • OpenClaw should either:
    • Automatically compact/trim the session context
    • Show a clear error message indicating context length issues
    • Suggest resetting the session

Actual Behavior

  • Generic error: "An unknown error occurred"
  • User has to manually investigate logs to find the root cause
  • Only solution is manually backing up and resetting the session file

Logs

"event":"embedded_run_agent_end"
"isError":true
"error":"An unknown error occurred"
"model":"kimi-k2.5"
"provider":"tencent-coding-plan"

Session stats when error occurred:

  • Session file size: 181KB
  • inputTokens: 77,305
  • contextTokens: 262,144 (max for Kimi-K2.5)

Workaround

Reset the session by:

mv ~/.openclaw/agents/main/sessions/<session-id>.jsonl <session-id>.jsonl.backup
openclaw gateway restart

Suggested Improvements

  1. Better error messages: Detect context length issues and report them clearly instead of "unknown error"
  2. Session size monitoring: Log warnings when sessions approach token limits
  3. Automatic compaction: Auto-trim or summarize old session context when approaching limits
  4. User-facing guidance: Provide clear instructions when session reset is needed

Related Issues

May be related to how error messages from the Tencent Coding Plan provider are propagated.


Additional Context: The same model works fine with smaller sessions and direct API testing succeeds, confirming the issue is related to context size rather than API connectivity or model availability.

extent analysis

Fix Plan

To address the issue of large session context causing "An unknown error occurred" with Kimi-K2.5, we will implement the following steps:

  • Detect and report context length issues: Modify the error handling to check for context length limits and provide clear error messages.
  • Implement session size monitoring: Add logging to warn when sessions approach token limits.
  • Automatic compaction of session context: Develop a mechanism to auto-trim or summarize old session context when approaching limits.

Example Code

# Check context length and provide clear error message
def check_context_length(context):
    max_tokens = 262144
    if len(context) >= max_tokens:
        raise ValueError("Session context exceeds maximum allowed tokens")

# Log warnings when sessions approach token limits
def log_session_warning(session):
    max_tokens = 262144
    warning_threshold = 0.8
    if len(session) >= max_tokens * warning_threshold:
        logging.warning("Session approaching token limit")

# Auto-trim session context when approaching limits
def compact_session_context(session):
    max_tokens = 262144
    if len(session) >= max_tokens:
        # Trim or summarize old session context
        session = session[-max_tokens:]
    return session

Verification

To verify the fix, follow these steps:

  1. Test with a large session context (~77k tokens) and verify that a clear error message is provided.
  2. Monitor logs for warnings when sessions approach token limits.
  3. Test automatic compaction by creating a large session and verifying that it is trimmed or summarized correctly.

Extra Tips

  • Consider adding a configuration option to allow users to adjust the maximum allowed tokens for session context.
  • Implement a mechanism to notify users when session reset is needed, providing clear instructions on how to reset the session.

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