Skip to content

fix(agents): keep cli session binding facts session-stable - #99595

Merged
obviyus merged 1 commit into
mainfrom
fix/cli-binding-stability
Jul 3, 2026
Merged

obviyus merged 1 commit into
mainfrom
fix/cli-binding-stability

Conversation

@obviyus

@obviyus obviyus commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

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 force message_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:

  • resolveSourceReplyVisibilityPolicy now 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 a sessionStableSourceReplyDeliveryMode resolved 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.
  • Dispatch threads the stable mode to the reply run; group/direct chat prompt context, 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.
  • Non-message-tool-only prompt wording defers to current-turn delivery context (which message_tool_only addressed turns carry no per-turn delivery contract; visible replies silently swallowed #99371's per-turn directive now carries), so a single session-stable system prompt is valid for every turn kind.

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

  • Fail-confirmed regressions: cross-path equality (room-event / user-request / heartbeat) of both binding hashes for BOTH config shapes — the config-stable message-tool shape fails against the first-cut fix that nulled the mode downstream by turn kind (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.
  • resolveCliSessionReuse comparisons 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.
  • Blacksmith Testbox check:changed on the rebased branch: exit 0 (tbx_01kwkdcynfhc7pn1n4hjg9w4tn, ~9m).

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.
@obviyus
obviyus merged commit 48e8965 into main Jul 3, 2026
21 of 23 checks passed
@obviyus
obviyus deleted the fix/cli-binding-stability branch July 3, 2026 16:01
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant