Skip to content

Session state corrupted to 'unknown' after provider 503, permanently blocks new messages #108331

Closed

Description

@Enominera

Bug type

Behavior bug — session state corruption after provider failure, blocking new session creation

Environment

  • OpenClaw v2026.6.11 (e085fa1)
  • macOS (darwin arm64)
  • Node 24.8.2
  • Model: minimax-portal/MiniMax-M3 (via api.minimaxi.com)
  • Channel: Feishu (direct DM)

Summary

When a third-party model provider returns 503 errors or times out, the session enters a corrupted state (unknown/1049k (?%) token count) that permanently blocks new messages on the same session key. The gateway does not automatically recover, and the session state prevents new session creation — requiring manual deletion of session files.

Steps to reproduce

  1. Configure a Feishu channel with a model backed by a flaky provider (e.g., minimax-portal/MiniMax-M3)
  2. Send a message that triggers a model call
  3. Provider returns 503 "server is busy" or hangs for 120s+
  4. Gateway logs show stalled session, active_work_without_progress, per-chat task exceeded 300000ms cap
  5. Session state becomes unknown/1049k (?%) in openclaw sessions output
  6. Send another message to the same session key

Expected behavior

  • Session should either:
    • Retry with fallback model (if configured)
    • Clean up stale session state after timeout
    • Create a new session when the existing one is dead
  • Token count should not become "unknown" — at minimum show "stale" or "error"

Actual behavior

  • Session state corrupted to unknown/1049k (?%)
  • No active Claude process for the session
  • New messages dispatched to the dead session, never processed
  • No automatic recovery — requires manual deletion of session file + sessions.json entry
  • All subsequent messages to the same session key are silently dropped

Logs

[diagnostic] long-running session: sessionId=... state=processing age=137s queueDepth=1 reason=active_model_call_without_prog
[diagnostic] stalled session: ... state=processing age=252s reason=active_work_without_progress classification=stalled_agent_run
[diagnostic] per-chat task exceeded 300000ms cap; evicting from queue so later same-key messages can proceed

After eviction, session remains in store with unknown token count. New messages find the existing session entry and try to resume it, but no process is running to handle them.

Workaround

Manual cleanup:

# 1. Delete session file
rm ~/.openclaw/agents/claude/sessions/<session-id>.jsonl

# 2. Remove from sessions.json
python3 -c "
import json
path = '~/.openclaw/agents/claude/sessions/sessions.json'
with open(path) as f: data = json.load(f)
del data['<session-key>']
with open(path, 'w') as f: json.dump(data, f, indent=2)
"

Related issues

Impact

This affects any session backed by an unreliable provider. In our case:

  • 10+ sessions stuck in unknown state (all MiniMax-M3)
  • Multiple Feishu users affected (third, fourth, fifth accounts)
  • Cron jobs silently failing
  • No user-visible error — messages just disappear

Suggested fix

  1. Session timeout cleanup: When per-chat task exceeded 300000ms cap fires, also clean up the session state in sessions.json (set to "dead" or remove)
  2. Dead session detection: Before dispatching to an existing session, check if there's an active process; if not, create a new session
  3. Token count resilience: Never show "unknown" — show "stale", "error", or "0" instead
  4. Provider fallback for all sessions: Even if the model was user-selected, have a fallback for 503/timeout scenarios

Activity

  1. added
    P0
    impact:message-loss
    impact:session-state
    impact:ux-release-blocker
    issue-rating: 🦐 gold shrimp
    clawsweeper:needs-info
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    on Jul 16, 2026
  2. clawsweeper commented on Jul 16, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I did a careful shell check against current main, and this is already implemented.

    Close as implemented: current main turns a force-cleared stalled run into a terminal session state and re-admits the next visible message, removing the reported permanent same-key block. Automatic fallback for a user-selected model and unknown token display are distinct tracked concerns.

    I found the merged PR that appears to have closed this: #112166: fix(agents): persist terminal session state after force-clearing stuck embedded runs.

    So I’m closing this as already implemented rather than keeping a duplicate issue open.

    Review details

    Best possible solution:

    Keep the terminal-state writer and next-turn recovery path, while handling explicit-model fallback policy in #84865 and token accounting in #66263.

    Do we have a high-confidence way to reproduce the issue?

    No — current main records a force-cleared run as terminal and re-admits a later visible turn; focused source coverage exercises that recovery boundary.

    Is this the best way to solve the issue?

    Yes — persisting terminal state at forced-clear ownership and recovering it at visible-turn admission fixes the producer-side invariant without fabricating token data or overriding an explicit model choice.

    Security review:

    Security review: This is issue triage without a proposed patch.

    AGENTS.md: found and applied where relevant.

    What I checked:

    Likely related people:

    • xialonglee: Authored the merged terminal-state recovery PR that directly addresses the stuck-run persistence path. (role: introduced recovery behavior; confidence: high; commits: 87b76d0cd050; files: src/agents/embedded-agent-runner/runs.ts, src/auto-reply/reply/dispatch-from-config.lifecycle.ts)
    • steipete: Current checked-out recovery lines trace to Peter Steinberger in local blame; the shallow graft prevents deeper line-history attribution. (role: recent area contributor; confidence: medium; commits: b5d99c1f0675; files: src/agents/embedded-agent-runner/runs.ts)

    Codex review notes: model internal, reasoning high; reviewed against 637de7d37945; fix evidence: merged PR #112166, commit 87b76d0cd050, main fix timestamp 2026-07-27T10:55:57Z.

  3. obviyus commented on Jul 27, 2026

    @obviyus
    Collaborator

    Reopening: #112166 fixes only force-clear terminal-state persistence. The broader provider fallback, token-display, session-recreation, and current-main reproduction questions remain unresolved.

  4. added
    issue-rating: 🦪 silver shellfish
    clawsweeper:needs-product-decision
    clawsweeper:not-repro-on-main
    and removed
    clawsweeper:needs-info
    issue-rating: 🦐 gold shrimp
    clawsweeper:no-new-fix-pr
    clawsweeper:needs-maintainer-review
    clawsweeper:needs-product-decision
    on Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P0clawsweeper-recovery-stuckclawsweeper:not-repro-on-mainimpact:message-lossimpact:session-stateimpact:ux-release-blockerissue-rating: 🦪 silver shellfish

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions