Skip to content

fix(cli): surface gateway→embedded fallback session divergence in --json output#111645

Merged
steipete merged 1 commit into
mainfrom
claude/fix-fallback-sessionkey
Jul 20, 2026
Merged

fix(cli): surface gateway→embedded fallback session divergence in --json output#111645
steipete merged 1 commit into
mainfrom
claude/fix-fallback-sessionkey

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

When the CLI↔gateway agent websocket drops or times out mid-turn, the CLI falls back to running the agent embedded. To avoid concurrently double-driving the caller's session (the gateway may still be resuming it — the hazard fixed in a428765), the fallback deliberately runs under a fresh gateway-fallback-<uuid> session rather than the caller's --session-key. That safety behavior is correct, but it was silent: the only signal was a human stderr line, and a --json caller got a different result with a different session and no structured way to detect that continuity was intentionally not preserved.

Why This Change Was Made

A script or integration passing --session-key X --json needs to know, programmatically, when a turn ran under a fallback session instead of the one it asked for. This adds that signal without changing the safety behavior.

User Impact

  • --json results for both fallback reasons (timeout, connection-closed) now carry meta.fallback: { reason, requestedSessionKey, sessionKey }, so callers can detect the divergence and the original vs actual session key.
  • The stderr warning now states explicitly that continuity was not preserved, to avoid double-driving the original session.
  • No change to when fallback triggers or to the deliberate fresh-session safety behavior; --session-key is intentionally still not reused in fallback.

Evidence

  • Rationale confirmed against a428765 (transport loss may leave the gateway driving the original session): src/commands/agent-via-gateway.ts:68,1005-1028.
  • Marker: src/agents/command/types.ts (fallback field); populated in src/commands/agent-via-gateway.ts.
  • Tests: src/commands/agent-via-gateway.test.ts assert the structured marker (requested vs actual key) for both fallback reasons.
  • Testbox focused 81/81, check:changed exit 0, AutoReview clean (0.91). No behavior change to selection/triggering.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Jul 20, 2026
@steipete steipete self-assigned this Jul 20, 2026
@steipete
steipete merged commit 1ee4242 into main Jul 20, 2026
145 of 147 checks passed
@steipete
steipete deleted the claude/fix-fallback-sessionkey branch July 20, 2026 04:27
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 20, 2026
steipete added a commit that referenced this pull request Jul 21, 2026
…law agent (#112074)

A Gateway timeout or closed connection now fails the command with an
actionable stderr hint instead of silently re-running the whole turn
embedded under a fresh gateway-fallback-* session. The silent fallback
could double-execute side effects (the Gateway may still finish an
accepted turn), returned context-free answers to --session-key callers,
and ran with the CLI host's local config. --local remains the only
embedded execution path.

Also deletes the resultMetaOverrides plumbing (the fallback was its only
writer) and the fallback marker fields added in #111645.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 22, 2026
…law agent (openclaw#112074)

A Gateway timeout or closed connection now fails the command with an
actionable stderr hint instead of silently re-running the whole turn
embedded under a fresh gateway-fallback-* session. The silent fallback
could double-execute side effects (the Gateway may still finish an
accepted turn), returned context-free answers to --session-key callers,
and ran with the CLI host's local config. --local remains the only
embedded execution path.

Also deletes the resultMetaOverrides plumbing (the fallback was its only
writer) and the fallback marker fields added in openclaw#111645.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling commands Command implementations maintainer Maintainer-authored PR size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant