-
-
Notifications
You must be signed in to change notification settings - Fork 80.7k
CLI session binding churns on mention-state toggles: ExplicitlyMentionedBot leaks into extraSystemPromptStatic #99696
Copy link
Copy link
Closed
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.agentsAgent runtime and toolingAgent runtime and toolingbugSomething isn't workingSomething isn't workingclawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.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.maintainerMaintainer-authored PRMaintainer-authored PR
Description
Metadata
Metadata
Assignees
Labels
P1High-priority user-facing bug, regression, or broken workflow.High-priority user-facing bug, regression, or broken workflow.agentsAgent runtime and toolingAgent runtime and toolingbugSomething isn't workingSomething isn't workingclawsweeper:needs-maintainer-reviewClawSweeper marked this issue as needing maintainer review before automation.ClawSweeper marked this issue as needing maintainer review before automation.clawsweeper:no-new-fix-prClawSweeper does not recommend queueing a new automated fix PR for this issue.ClawSweeper does not recommend queueing a new automated fix PR for this issue.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.maintainerMaintainer-authored PRMaintainer-authored PR
Type
Fields
Priority
None yet
What happened
CLI-backend session resume (
claude-cli) invalidates withreuse=invalidated:system-promptwhenever consecutive group messages toggle between "explicitly @-mentions the bot" and "doesn't mention the bot". Each invalidation abandons the resumed CLI session and spawns a fresh one, dropping continuity and re-paying warm-up.This is the same disease as #99372 / #99595 / #99633 (per-turn facts leaking into the session-stable reuse fingerprint), on a new axis: per-message mention state. With the
senderIsOwneraxes fixed, this becomes the dominant remaining churn source — "hi @bot" followed by an un-mentioned follow-up is the most common two-message pattern in group chats.Root cause
buildGroupChatContextbakes a per-message fact into the group context block:src/auto-reply/reply/groups.ts(buildGroupChatContext): whensessionCtx.ExplicitlyMentionedBot === true, it appends "The incoming message explicitly mentions your channel identity @...".ExplicitlyMentionedBotis a property of the current inbound message, not the session.src/auto-reply/reply/get-reply-run.ts(extraSystemPromptStatic):groupChatContextis one of the parts joined intoextraSystemPromptStatic, which feedscliSessionBindingFactsand is hashed intoextraSystemPromptHash.src/agents/cli-session.ts(resolveCliSessionReuse): a changedextraSystemPromptHashreturnsinvalidatedReason: "system-prompt", which deletes the stored binding and forces a fresh CLI session.So the "static" prompt hash flips on every mention↔no-mention transition.
Related, same file:
groupIntrois conditionally included inextraSystemPromptStatic(shouldInjectGroupIntro = isFirstTurnInSession || sessionEntry?.groupActivationNeedsSystemIntro,get-reply-run.ts). A fresh session's first turn hashes with the intro and the second turn without, guaranteeing one extra invalidation early in every new session. Same class: turn-varying input inside the session-stable hash.Production evidence
Observed 2026-07-03 on a live Telegram group deployment running
fix/cli-binding-tool-scope(abc6ee5) with temporary per-hash attribution logging inresolveCliSessionReuse:2dba…5ac0…2dba…vs current5ac0…)5ac0…promptToolNamesHashandmessageToolPolicyHashstayed constant across all three turns, isolating the mention line as the changing content. The hash tracked mention state, not sender: the owner→non-owner flip at 23:10:05 did not flip the hash back.Expected
The reuse fingerprint should only include session-stable facts. Per-message facts (mention state) belong in per-turn context —
inboundMetaPromptalready exists for exactly this and is correctly excluded fromextraSystemPromptStatic.Fix shape
buildGroupChatContextinto the per-turn inbound context (buildInboundMetaSystemPromptpath) soextraSystemPromptStaticstops depending onExplicitlyMentionedBot.groupIntro's contract: either include it unconditionally in the binding facts (stable content) or exclude it from the static hash; today's conditional inclusion churns turn 2 of every fresh session.extraSystemPromptHashthroughout.Environment
abc6ee5633087a87207865aa2332c26c63f878c6(main + fix: CLI agent session resume churns when owner and non-owner alternate in a group #99640)