openclaw - 💡(How to fix) Fix Agent loses prior conversation context when auth-profile rotation triggers a new CLI session [1 comments, 2 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#78541Fetched 2026-05-07 03:35:36
View on GitHub
Comments
1
Participants
2
Timeline
1
Reactions
2
Timeline (top)
commented ×1

When the gateway performs an OAuth token refresh for a claude-cli backend agent, it emits a cli session reset: reason=auth-profile event and starts a new live CLI session. The new session starts without prior conversation history injected into the prompt, causing the agent to respond as if it is the first message in the conversation.

This happens multiple times per day as a routine part of normal OAuth token refresh cycles, so any long-running agent session is repeatedly at risk.

Error Message

Observed 10+ times in a single day across multiple agents using the claude-cli backend. The auth-profile reset appears to be a normal OAuth refresh mechanism, not an error condition — making this a structural issue rather than an edge case.

Root Cause

When the gateway performs an OAuth token refresh for a claude-cli backend agent, it emits a cli session reset: reason=auth-profile event and starts a new live CLI session. The new session starts without prior conversation history injected into the prompt, causing the agent to respond as if it is the first message in the conversation.

This happens multiple times per day as a routine part of normal OAuth token refresh cycles, so any long-running agent session is repeatedly at risk.

Fix Action

Fix / Workaround

Workaround (agent-side)

On session start, the agent can call sessions_history to detect and recover lost context. This is a partial mitigation — it catches the case where the user provides enough signal to trigger recovery, but does not prevent the loss.

Code Example

[agent/cli-backend] cli session reset: provider=claude-cli reason=auth-profile
[agent/cli-backend] cli exec: provider=claude-cli model=opus promptChars=NNN
[agent/cli-backend] claude live session start: provider=claude-cli model=claude-opus-4-7 activeSessions=N

---

[agent/cli-backend] cli exec: provider=claude-cli model=opus promptChars=NNN
[agent/cli-backend] claude live session reuse: provider=claude-cli model=claude-opus-4-7
RAW_BUFFERClick to expand / collapse

Environment

  • OpenClaw version: 2026.4.26 (be8c246)
  • Platform: macOS
  • Backend: claude-cli (Anthropic OAuth mode)
  • Gateway mode: local

Summary

When the gateway performs an OAuth token refresh for a claude-cli backend agent, it emits a cli session reset: reason=auth-profile event and starts a new live CLI session. The new session starts without prior conversation history injected into the prompt, causing the agent to respond as if it is the first message in the conversation.

This happens multiple times per day as a routine part of normal OAuth token refresh cycles, so any long-running agent session is repeatedly at risk.

Steps to reproduce

  1. Start a claude-cli-backed agent session and exchange several messages.
  2. Wait for an OAuth token refresh cycle to occur (observed roughly every 10–30 minutes in practice).
  3. The gateway emits: [agent/cli-backend] cli session reset: provider=claude-cli reason=auth-profile
  4. The gateway then emits: [agent/cli-backend] claude live session start: provider=claude-cli ...
  5. Send any message to the agent.
  6. Observed: Agent responds with no awareness of prior conversation turns.
  7. Expected: Agent response incorporates prior conversation history.

Gateway log pattern (sanitized)

[agent/cli-backend] cli session reset: provider=claude-cli reason=auth-profile
[agent/cli-backend] cli exec: provider=claude-cli model=opus promptChars=NNN
[agent/cli-backend] claude live session start: provider=claude-cli model=claude-opus-4-7 activeSessions=N

Compare to normal (no context loss):

[agent/cli-backend] cli exec: provider=claude-cli model=opus promptChars=NNN
[agent/cli-backend] claude live session reuse: provider=claude-cli model=claude-opus-4-7

The key difference: live session start (new process, no prior context) vs live session reuse (existing process, context intact).

Frequency

Observed 10+ times in a single day across multiple agents using the claude-cli backend. The auth-profile reset appears to be a normal OAuth refresh mechanism, not an error condition — making this a structural issue rather than an edge case.

Also observed: cli session reset: reason=auth-epoch (less frequent), which similarly triggers a new live session start.

Impact

  • Any agent conversation longer than a single token-refresh interval loses context mid-session.
  • The agent silently treats the continuation message as a new session opener.
  • User-visible symptom: agent asks "what are you referring to?" or gives context-unaware responses mid-conversation, requiring manual recovery.

Workaround (agent-side)

On session start, the agent can call sessions_history to detect and recover lost context. This is a partial mitigation — it catches the case where the user provides enough signal to trigger recovery, but does not prevent the loss.

Expected behavior

When live session start fires due to auth-profile rotation, the gateway should re-inject prior conversation history into the new CLI process's prompt (equivalent to live session reuse behavior), so the agent's context is continuous from the user's perspective.

Question

Is there a gateway configuration option to control prior-turn injection on session start? A search of the available config schema did not surface one, but it may exist undocumented.

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

When live session start fires due to auth-profile rotation, the gateway should re-inject prior conversation history into the new CLI process's prompt (equivalent to live session reuse behavior), so the agent's context is continuous from the user's perspective.

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 Agent loses prior conversation context when auth-profile rotation triggers a new CLI session [1 comments, 2 participants]