Skip to content

claude-cli session binding invalidated on nearly every reply turn (reuse=invalidated:system-prompt) #99372

Closed as not planned

Description

@obviyus

What happened

On a production deployment tracking latest main (Telegram group, claude-cli backend), nearly every reply turn discards the stored CLI session binding and starts a fresh CLI session with history replay:

cli session reset: provider=claude-cli reason=system-prompt
cli exec: … trigger=user useResume=false session=none resumeSession=none reuse=invalidated:system-prompt historyPrompt=present

Observed alternation over one hour of group traffic:

  • primary reply turns: reuse=invalidated:system-prompt, historyPrompt=present
  • coalesced/followup turns seconds later: session=none reuse=none historyPrompt=none
  • heartbeat turns: reuse=reusable, resume works
  • occasionally two user turns 15s apart do reuse (reuse=reusable), so the hash inputs are not purely per-turn volatile — different reply execution paths appear to write incompatible bindings.

Impact

CLI resume is effectively dead for interactive turns: every turn pays full history replay in fresh context (no provider-side prompt cache reuse), and transcript continuity inside the CLI harness is lost. This defeats the append-only/cache-hit design of the session transcript.

Where to look

resolveCliSessionReuse (src/agents/cli-session.ts) invalidates with reason system-prompt when any of extraSystemPromptHash, messageToolPolicyHash, or promptToolNamesHash differs from the stored binding. Those inputs are assembled in src/agents/cli-runner/prepare.ts (extraSystemPromptStatic fast-path at ~line 352, messageToolPolicyHash at ~line 358) and fed differently by the primary reply path (get-reply-run.ts), the followup/queue path (followup-runner.ts, queue/drain.ts), and heartbeats.

Expected

Binding-reuse hash inputs must be session-stable facts, resolved identically for every trigger and execution path of the same session. Per-message metadata must never reach them; policy facts (sourceReplyDeliveryMode, requireExplicitMessageTarget, prompt tool names) must not flap between primary/followup/heartbeat flavors. Fix at the parameter-assembly owner; do not loosen the reuse comparison itself (stale-system-prompt invalidation must keep working).

Activity

  1. added
    bug
    on Jul 3, 2026
  2. clawsweeper commented on Jul 3, 2026

    @clawsweeper
    Contributor

    Thanks for the context here. I swept through the related work, and this is now duplicate or superseded.

    Close as duplicate: this latest-main report is another instance of the Claude CLI system-prompt false-invalidation class already tracked by the open canonical issue, including the prompt-policy and live-session variants discussed there.

    Root-cause cluster
    Relationship: duplicate
    Canonical: #69118
    Summary: This report is a latest-main instance of the Claude CLI system-prompt/session-fingerprint false-invalidation class already tracked by the canonical open issue.

    Members:

    Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Canonical path: #69118 is open and its existing review/comment history identifies it as the canonical tracker for Claude CLI extraSystemPromptHash/session-fingerprint false-invalidation variants.

    So I’m closing this here and keeping the remaining discussion on #69118 and #83250.

    Review details

    Best possible solution:

    Keep the canonical issue as the active tracker, preserve this latest-main evidence there, and review or split the linked fix candidates from that cluster.

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

    Yes from source at medium confidence: current main still compares the exact prompt-policy hash fields named in the report, and the canonical issue already documents live/source reproductions for the same false-invalidation class.

    Is this the best way to solve the issue?

    Yes for triage: routing this latest-main report to the canonical issue is the best path because the remaining variants and open fix candidates are already tracked there.

    Security review:

    Security review: No patch is under review, and the issue is not a security report.

    AGENTS.md: found and applied where relevant.

    What I checked:

    Likely related people:

    • zijunl: Prior canonical review and PR history identify the merged static extraSystemPrompt hashing split as central to this false-invalidation class. (role: introduced adjacent behavior; confidence: medium; commits: a0297fa0d674, 6db1b5165d5c; files: src/auto-reply/reply/get-reply-run.ts, src/agents/cli-runner/prepare.ts)
    • steipete: History ties this person to CLI session preservation and prompt forwarding around the same session-reuse surface. (role: merger and adjacent contributor; confidence: medium; commits: 3e2489869069, b81b855bb34d, c470885a0ba6; files: src/auto-reply/reply/get-reply-run.ts, src/agents/cli-runner/prepare.ts, src/agents/cli-session.ts)
    • obviyus: Live GitHub commit history shows recent changes in cli-runner preparation and auto-reply prompt/session paths that still carry the current hash inputs. (role: recent area contributor; confidence: medium; commits: 5e4d8eda1971, 568be74e159e, 3ad465d32b3b; files: src/agents/cli-runner/prepare.ts, src/auto-reply/reply/get-reply-run.ts)
    • sumitaich1998: Authored the open PR targeting the canonical issue's groupIntro static-hash drift. (role: open fix candidate author; confidence: medium; commits: 85acdd415334; files: src/auto-reply/reply/get-reply-run.ts, src/auto-reply/reply/get-reply-run.media-only.test.ts)

    Codex review notes: model internal, reasoning high; reviewed against 8604dbdc93fb.

  3. added
    P1
    impact:session-state
    on Jul 3, 2026
  4. added a commit that references this issue on Jul 3, 2026
    48e8965
  5. added a commit that references this issue on Jul 4, 2026
    74a78a1
  6. locked as resolved and limited conversation to collaborators on Jul 24, 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

    P1bugimpact:session-state

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions