Repository navigation
fix(cli): never fall back to local state when a remote Gateway is unreachable - #159223
Conversation
Restrict automatic offline cleanup to the configured local Gateway. Pin the resolved RPC destination while preserving its authentication selection, so remote configurations and environment URL overrides cannot silently clean local stores when their connection fails. Regression: two refused-loopback-tunnel cases fail on the original code and pass with the fix. Blacksmith validation passed 191 focused tests and check-changed. The changed command suite took 18.684s wall with one worker. Independent review found no actionable issues through P2.
Share the pre-dispatch fallback decision with sessions cleanup under the Gateway call owner. Pin agent deletion to the classified config and URL; remote transport and credential failures now leave local agent state intact and explain how to restore the connection or run on the Gateway host. Preserve local credential fallback with skipped cron cleanup and keep ambiguous transport errors unchanged. Four remote-target regression cases failed before the fix against the agents-delete implementation identical to origin/main. Blacksmith Testbox passed all 227 tests across the agents deletion, sessions cleanup, and Gateway call suites (41.36s total), plus check-changed. The new regression cases took 0.5-0.7s each. Isolated review was clean through P2 after replacing an expired reviewer login with the existing Testbox API credential. Local hooks were skipped to honor the remote-only check requirement.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: blocked before merge. Reviewed September 26, 2026, 6:51 PM ET / 22:51 UTC. ClawSweeper reviewWhat this changesThe CLI checks the selected Gateway before allowing agent deletion or session cleanup to fall back to local state, pins the request URL, and documents the remote-failure behavior. Merge readiness⛔ Blocked before merge - 3 items remain Keep open. Current main still has the wrong-machine fallback. The proposed guard addresses it, but the newly surfaced remote session-cleanup error gives misleading local recovery advice, and the upgrade behavior needs direct confirmation. Priority: P0 Review scores
Verification
How this fits togetherThese CLI commands ask a Gateway to change agent or session state. If that request fails before connecting, the commands decide whether an offline write to this machine is safe. flowchart LR
A[Delete or cleanup command] --> B[Config and selected URL]
B --> C[Classify Gateway target]
C --> D[Gateway request]
D --> H[Gateway state updated]
D --> E{Preconnect failure?}
E -->|Implicit local| F[Local state cleanup]
E -->|Remote target| G[Error without local write]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +42, Tests +97, Docs +12. Total +151 across 9 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Keep the implicit-local fallback and explicit Do we have a high-confidence way to reproduce the issue? No live reproduction was performed in this read-only review. Current-main source establishes the remote-to-local fallback path, and the PR reports baseline-failing simulated cases. Is this the best way to solve the issue? Yes for target safety: the shared target check and URL pin address wrong-machine writes. The session-cleanup failure path also needs recovery advice that matches a remote target. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e9dc62b26f85. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…eachable (openclaw#159223) * fix(sessions): preserve remote cleanup destination on connection failure Restrict automatic offline cleanup to the configured local Gateway. Pin the resolved RPC destination while preserving its authentication selection, so remote configurations and environment URL overrides cannot silently clean local stores when their connection fails. Regression: two refused-loopback-tunnel cases fail on the original code and pass with the fix. Blacksmith validation passed 191 focused tests and check-changed. The changed command suite took 18.684s wall with one worker. Independent review found no actionable issues through P2. * fix(agents): preserve remote deletion targets on pre-connect failure Share the pre-dispatch fallback decision with sessions cleanup under the Gateway call owner. Pin agent deletion to the classified config and URL; remote transport and credential failures now leave local agent state intact and explain how to restore the connection or run on the Gateway host. Preserve local credential fallback with skipped cron cleanup and keep ambiguous transport errors unchanged. Four remote-target regression cases failed before the fix against the agents-delete implementation identical to origin/main. Blacksmith Testbox passed all 227 tests across the agents deletion, sessions cleanup, and Gateway call suites (41.36s total), plus check-changed. The new regression cases took 0.5-0.7s each. Isolated review was clean through P2 after replacing an expired reviewer login with the existing Testbox API credential. Local hooks were skipped to honor the remote-only check requirement. Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Two CLI commands try the configured Gateway first and, if it is unreachable, fall back to editing local state offline:
openclaw sessions cleanup --enforce(Gatewaysessions.cleanup, since 4967bcb)openclaw agents delete <id>(Gatewayagents.delete)The fallback did not check which Gateway failed. With a remote Gateway, typically reached through an SSH tunnel on a loopback URL, a dead tunnel produced the same pre-connect transport failure as a stopped local Gateway, so the CLI reported success after mutating the wrong machine:
sessions cleanuppruned the local session store andagents deletedeleted the agent's local config, workspace, and session state, while the remote Gateway the operator meant to change was untouched.agents deletedid the same when a remote Gateway required credentials.Why This Change Was Made
Both commands carried their own inline "this failure proves the Gateway never got the request" check, and neither asked whether the configured target was the local backend. They now share one decision,
resolveGatewayMutationFallback(src/gateway/call-mutation-fallback.ts), which combines the existing pre-connect/credentials checks withisImplicitLocalGatewayTarget. Offline fallback stays available only for the implicit local Gateway; the attempted URL is pinned (expectUrl) so the call cannot drift to another target. For a non-local target the command fails, leaves local state unchanged, and says to restore the connection/credentials or run the command on the Gateway host. Explicit offline repair (sessions cleanup --store <path>) is unchanged. Docs for both commands describe the rule.User Impact
With a remote Gateway, a broken connection no longer makes
sessions cleanup --enforceoragents deletesilently change this machine instead; the command fails with guidance. Local-Gateway users see no change.Evidence
sessions-cleanup.test.ts: remote/loopback-tunnel connection failure cases fail onmain("promise resolved instead of rejecting") and pass.mainand pass.src/gateway/call.test.tssuites passed;node scripts/check-changed.mjspassed.Production LOC: +52 / −10 (includes the shared 18-line decision). Tests: +128 / −31. Docs: +13 / −1.