-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
FailoverError during cli-backend turn does not clear stale cliSessionIds from sessions.json, causing infinite retry loop #97887
Copy link
Copy link
Open
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.Issue affects a taxonomy feature currently scored M4/M5.no-staleExclude from stale automationExclude from stale automation
Description
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.clawsweeper:fix-shape-clearClawSweeper found a clear likely implementation shape for this issue.ClawSweeper found a clear likely implementation shape for this issue.clawsweeper:queueable-fixClawSweeper marked this issue as an existing queue_fix_pr work candidate.ClawSweeper marked this issue as an existing queue_fix_pr work candidate.clawsweeper:source-reproClawSweeper found a high-confidence source-level issue reproduction.ClawSweeper found a high-confidence source-level issue reproduction.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.Session, memory, transcript, context, or agent state can drift or corrupt.issue-rating: 🦞 diamond lobsterVery strong issue quality with high-confidence source-level or clear reproduction.Very strong issue quality with high-confidence source-level or clear reproduction.maturity:stableIssue affects a taxonomy feature currently scored M4/M5.Issue affects a taxonomy feature currently scored M4/M5.no-staleExclude from stale automationExclude from stale automation
Type
Fields
Priority
None yet
Summary
When a
claude-cliturn fails withFailoverError(e.g. because the session file no longer exists after a gateway restart), the stale CLI session ID is not removed fromsessions.json. Every subsequent message on that conversation then retries the dead session ID and fails again with⚠️ Something went wrong while processing your request.— an infinite failure loop with no self-healing.Steps to Reproduce
claude-clibackend.openclaw gateway restart). This creates a new claude CLI process; the old~/.claude/sessions/<uuid>.jsonlsession file is orphaned but the session ID stays persisted insessions.json.useResume=true), the claude CLI reportsNot logged in · Please run /login, which causes aFailoverError.GENERIC_EXTERNAL_RUN_FAILURE_TEXTand logsclaude live session close: reason=restart.Root Cause
In
agent-runner.runtime-C8N-o26U.js, theclearCliSessionBindingflag is set fromrunResult.meta?.agentMeta?.clearCliSessionBinding(line ~3361). This field is only populated from a successful run result — it isundefinedon aFailoverErrorpath. Consequently,clearCliSession(nextEntry, cliProvider)is never called, andupdateSessionEntryis never called with the clearedcliSessionIds/cliSessionBindings.The persisted
sessions.jsonstructure:All three fields survive the restart and point to a non-existent
~/.claude/sessions/<stale-uuid>.jsonl.Expected Behaviour
When a
FailoverError(or any error indicating the CLI session is gone) occurs during a claude-cli backend turn, openclaw should:clearCliSession(entry, cliProvider)on the active session entry.sessions.jsonviaupdateSessionEntry.This ensures the next message starts a fresh claude-cli session instead of re-attempting the dead one.
The error-recovery path in
agent-runner.runtime-C8N-o26U.jsthat deliversGENERIC_EXTERNAL_RUN_FAILURE_TEXTshould include this cleanup step, analogous to howclearCliSessionBinding: trueworks for the success path.Workaround
Manually patch
sessions.jsonand restart the gateway:Affected Scenario
This is triggered by two rapid
openclaw gateway restartcalls (e.g.openclaw config set+ manual restart), which invalidates the in-memory live session and creates a new gateway PID. The stale session ID survives insessions.jsonbut the corresponding session file does not.Environment
claude-cliRelated: #97553 (the "Not logged in" error not matching
isOAuthRefreshFailureMessage, causing generic error text instead of a specific message)