Skip to content

cli-backend: stale systemSent on session entries survives gateway restart — fresh spawns (esp. after /new) run WITHOUT the agent system prompt (identity loss) #107761

Closed

Description

@chrislro

Summary

After a gateway restart (or any event that kills live claude-stdio processes), cli-backend session entries in agents/<id>/sessions/sessions.json retain systemSent: true. The next turn that spawns a fresh claude process (most visibly after the /new chat command, whose new session entry inherits systemSent from the reusable entry) is then executed without the agent's system/identity prompt. The model falls back to its raw CLI persona and denies having the agent's tools/memory — to the end user it looks like the assistant was "wiped".

Environment

  • OpenClaw 2026.7.1 (2d2ddc4), macOS 12.7.6, Node 22.23.1
  • cli-backend: claude-cli (claude-stdio live sessions, sessionMode: always), claude CLI 2.1.209

Reproduction (observed live)

  1. Gateway restart at 16:47 (drain-safe, detached-handoff) — live claude processes die; sessions.json entries keep systemSent: true.
  2. User sends /new on WhatsApp at 17:31 → new session entry created, systemSent inherited as true.
  3. First real message at 17:34 → cli exec: … trigger=user useResume=false session=none resumeSession=none reuse=none historyPrompt=none promptChars=906 — fresh spawn, no system prompt sent (906 chars = wrapper + user text only).
  4. Reply comes back in the raw "I'm Claude Code, a CLI coding assistant…" persona, denying the agent's tools and history.
  5. Subsequent turns that hit the resume path (useResume=true historyPrompt=present) recover identity, because the resumed claude session still contains the original system prompt — which masks the bug intermittently.

Code pointers (dist, 2026.7.1)

agent-runner.runtime-*.js / get-reply-*.js:

  • send-gate: …systemSent === true || params.entry?.sessionId !== params.sessionId) return false
  • inheritance: systemSent = reusableEntry.systemSent ?? false

The flag describes a property of a process/claude-session, but it is persisted on the gateway-side session entry and survives the death of the process it described. Suggested fix: key systemSent to the spawned claude sessionId (reset whenever session=none/fresh spawn), or always send the system prompt when useResume=false && reuse=none.

Workaround

Stop the gateway, set "systemSent": false on all entries in agents/*/sessions/sessions.json, start the gateway. Verified: the next fresh spawn re-sends the system prompt and the persona returns.

Impact

High user-visible severity: the assistant appears amnesiac/identity-less after every gateway restart + /new (also reproduced this morning after the 2026.5.27→2026.7.1 auto-update restarts, before any manual restarts).

Activity

  1. added
    P0Emergency: data loss, security bypass, crash loop, or unusable core runtime.
    impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.
    impact:ux-release-blockerA non-technical user is blocked without terminal, logs, config, or support.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.
    clawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.
    on Jul 15, 2026
  2. clawsweeper commented on Jul 15, 2026

    @clawsweeper
    Contributor

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

    Current main prevents stale session metadata from suppressing a Claude CLI system prompt on either fresh or resumed processes, so this issue no longer needs active backlog attention.

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

    Review details

    Best possible solution:

    Keep the current process-bound prompt delivery rule: fresh CLI processes always receive the prompt, and the bundled Anthropic backend re-emits it for resumed turns.

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

    No on current main: fresh CLI invocations send the prompt whenever they are not resumed, and the bundled Claude backend also uses always mode for resumed turns. The historical live environment was not rerun because the current source rules out the reported mechanism.

    Is this the best way to solve the issue?

    Yes: current code removes the stale-state dependency at the CLI prompt-delivery boundary instead of attempting to repair every persisted session entry after restart.

    Security review:

    Security review: This issue reports prompt-delivery behavior, not a security-sensitive change.

    AGENTS.md: found and applied where relevant.

    What I checked:

    Likely related people:

    • JanusAsmussen: Authored the historical Claude CLI system-prompt repair that changed the backend and CLI runner surfaces. (role: introduced related prompt-delivery repair; confidence: high; commits: 84e62824f683; files: extensions/anthropic/cli-backend.ts, src/agents/cli-runner/execute.ts, src/agents/cli-runner/helpers.ts)
    • Peter Steinberger: Current-main blame attributes the active prompt-send lines to the main baseline authored by Peter Steinberger. (role: recent current-main source contributor; confidence: medium; commits: 56f594aa97b5; files: extensions/anthropic/cli-backend.ts, src/agents/cli-runner/execute.ts, src/agents/cli-runner/helpers.ts)

    Codex review notes: model internal, reasoning high; reviewed against 08786d32b21b; fix evidence: commit 56f594aa97b5, main fix timestamp 2026-08-16T16:20:56Z.

  3. added
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    and removed
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    on Jul 16, 2026
  4. added
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    and removed
    issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.
    clawsweeper:needs-live-reproClawSweeper needs live local, crabbox, or manual validation to confirm this issue.
    issue-rating: 🐚 platinum hermitGood issue quality with a plausible reproduction path needing some confirmation.
    on Jul 30, 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

    P0Emergency: data loss, security bypass, crash loop, or unusable core runtime.clawsweeper:not-repro-on-mainClawSweeper found high-confidence evidence that this issue no longer reproduces on main.impact:session-stateSession, memory, transcript, context, or agent state can drift or corrupt.impact:ux-release-blockerA non-technical user is blocked without terminal, logs, config, or support.issue-rating: 🦪 silver shellfishThin issue quality; more reproduction proof or environment detail is needed.

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions