Repository navigation
fix(agents): keep cli session binding facts session-stable - #99595
Merged
Merged
Conversation
Keep CLI session reuse hashes keyed to stable session prompt facts while preserving per-turn room-event message-tool delivery for execution and MCP scoping. Thread cliSessionBindingFacts from reply assembly through queued/followup CLI runs, make the stable CLI prompt delivery-neutral, and cover production-shaped room-event opts so forced message_tool_only delivery cannot poison binding identity. Fixes #99372 Release note: Telegram/room-event CLI backends can resume sessions across interactive turns again instead of replaying full history after system-prompt invalidations.
7 tasks
This was referenced Jul 3, 2026
Merged
This was referenced Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What Problem This Solves
Fixes #99372. On claude-cli deployments, CLI session resume was effectively dead for interactive turns: production logs showed most reply turns invalidating the stored binding (
cli session reset: reason=system-prompt,reuse=invalidated:system-prompt) and replaying full history into a fresh CLI session, with only heartbeats resuming reliably. Every interactive turn paid full history replay with zero provider-side prompt-cache reuse, and fresh sessions amplified #99371 (no in-context message-tool examples).Why This Change Was Made
The binding-reuse hashes (
extraSystemPromptHash,messageToolPolicyHash) were fed per-turn facts that legitimately vary by turn kind: room-event turns forcemessage_tool_only(dispatch), which flavors the group/direct chat context wording and the message-tool policy hash differently from addressed turns in the same session — so ambient and addressed turns ping-ponged each other's bindings.The fix gives session-stable facts one owner:
resolveSourceReplyVisibilityPolicynow returns both modes: the effective per-turn mode (with room-event forcing — still drives delivery enforcement, MCP scoping, and per-turn envelope directives, unchanged) and asessionStableSourceReplyDeliveryModeresolved from session-stable context only (chat type, provider, surface, config). Explicitly requested per-turn modes and explicit source commands keep the effective mode — those are real per-turn contracts, not room-event volatility.cliSessionBindingFacts, and the resumable CLI system prompt flavor all render from it. The facts are computed once and carried through the queue/followup paths so no execution path can drift.This holds for both deployment shapes: config-stable message-tool-only sessions get identical strong-flavored facts for ambient and addressed turns; automatic-config sessions get identical neutral facts, with room-event contracts carried per turn.
User Impact
claude-cli deployments regain session resume across interactive turns: prompt-cache reuse instead of full history replay each turn, and stable in-context behavior (which also stabilizes message-tool delivery reliability in groups).
Evidence
expected group:telegram:group:message_tool_only, received …:automatic), proving the one-sided-fix hole was real and is covered; per-message metadata changes leave hashes untouched; policy-owner tests pin the effective/stable split and the explicit-command exception.resolveCliSessionReusecomparisons are untouched — stale-system-prompt invalidation still works.node scripts/run-vitest.mjs(get-reply-run.media-only, prepare, groups, system-prompt, dispatch-from-config, source-reply-delivery-mode),pnpm tsgo,pnpm check:test-types, scoped oxlint,pnpm prompt:snapshots:check: exit 0.check:changedon the rebased branch: exit 0 (tbx_01kwkdcynfhc7pn1n4hjg9w4tn, ~9m).