Skip to content

fix(cli): keep gateway lifecycle commands working with an invalid config - #164158

Merged
steipete merged 1 commit into
mainfrom
upd/upd-gateway-stop-config-gate
Oct 3, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-gateway-stop-config-gate

Conversation

@steipete

@steipete steipete commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes Gateway recovery commands refusing to stop or inspect an installed service when an upgrade leaves invalid or retired keys in openclaw.json.

User Impact

Operators can stop, uninstall, or restart the recorded service and receive config warnings with openclaw doctor --fix guidance. Status and logs remain useful during config recovery. Startup still validates config, and restart still reports failed health checks honestly. Invalid-config restarts preserve the installed service definition and its health-check port instead of rebuilding it from unrepaired settings.

Why This Change Was Made

Service identity belongs to the native service adapter; unrelated agent, tool, memory, and plugin validation must not veto recovery. The lifecycle owner now reports those issues as diagnostics. Status preserves independently valid connection fields, logs recover from an unreadable local config, and update status reports validation warnings without rejecting the command. No config/CLI options, dependencies, or database schemas were added. Status config reads and logs formatting were moved into focused CLI siblings to satisfy the existing line caps; the status tests retain their coverage through a test-support sibling.

Every reported rejected key was accepted by the shipped v2026.7.35 schema and intentionally retired before v2026.9.7. Existing Doctor migrations already cover them; no current core or official-plugin writer was found emitting these retired paths, so this PR does not reintroduce runtime aliases or relax Doctor validation.

Reported key Verdict and existing Doctor repair
meta.lastTouchedAt Retired machine metadata; imports the old value into SQLite config.lastTouchedAt before removing it. Current writes use SQLite.
agents.defaults.memorySearch Retired path; migrates to root memory.search, preserving current-path precedence. Per-agent values migrate to the agent's memory.search.
agents.defaults.imageGenerationModel Retired path formerly written by official Fal/Vydra setup; migrates to agents.defaults.mediaModels.image, which current writers use.
tools.media.audio.models Retired per-capability list; migrates to tools.media.models with capabilities: ["audio"], preserving order.
commands.ownerDisplay Retired setting; Doctor removes it and ownerDisplaySecret. Owner IDs now render raw.
gateway.tailscale.resetOnExit Retired setting; Doctor removes it because managed routes follow the Gateway lifecycle.
memory.backend Retired backend selector; Doctor removes it with the QMD backend migration.
memory.qmd Retired settings; Doctor preserves external paths in memory.search.extraPaths and enabled session indexing in the current search settings, then removes QMD config.

The separate multi-agent ownership diagnostic also has an existing migration: legacy rosters become keyed entries with explicit ownership while historical default-agent roles are preserved.

Evidence

  • The three primary suites (lifecycle-core.config-guard, status.gather, lifecycle-readiness) passed three consecutive runs: 93 tests per run; wall times on the final tree 50.48s / 17.77s / 13.30s. Earlier individual focused runs took 21.83s / 29.04s / 45.95s, dominated by shared compiler preparation.
  • All 40 importer suites plus four additional suites passed in three batches: 1,353 passed, one existing platform skip; wall times 418.62s / 37.27s / 814.54s. After the line-cap extraction, all three primary suites passed 3× again and 10 affected status/logs sibling suites passed (123 tests, one existing platform skip; 27.76s). Unchanged updater-path results were retained.
  • node scripts/check-changed.mjs: passed (1,095.29s), including all core/test type graphs, lint, dead-export scans, import cycles, and guards. Eager-import closure and PR wrapper source-closure tests passed; export-name collisions and the update-restart swap fixture passed. The new files are outside the wrapper inventory closure, so no inventory addition was needed.
  • Fresh isolated Codex P1 review: scoped-clean, no actionable P0/P1 findings. An earlier review identified discarded valid connection fields and normal-restart port selection; both were corrected and covered by regressions.
  • CLI boundary proof used the built package entrypoint, a task-owned native macOS LaunchAgent with a synthetic TCP listener, a free port, and isolated config/state inside the worktree. A test account-home adapter kept native service files in that fixture. gateway stop --force --json exited 0, returned result: "stopped", unloaded the service, closed the listener, and warned about the invalid keys with Doctor guidance. doctor --lint --only core/doctor/final-config-validation --json then exited 1 with both unknown-key findings. Both commands preserved the config bytes; the fixture was removed.
  • Published-driver proof is waived for this CLI lifecycle change: the updater transaction implementation is unchanged.
  • One automatic runtime-preparation attempt failed before Vitest with Managed command exited while its process group remained active during diffs asset generation. The isolated asset command completed, then canonical runtime preparation passed in 83.05s. This is recorded as a preparation failure, not claimed as a repaired flake.
  • Existing slow suite src/cli/update-cli/update-command-service.integration.test.ts: 154.14s including approximately 137s of test time. Existing update routing/wizard cases in src/cli/update-cli.test.ts took 33.873s–89.136s; its infra batch took 700.80s. These pre-existing cases are retained under the slow-suite waiver; no timeouts, retries, or assertions were weakened. The existing Windows-only home-casing test is skipped on macOS.
  • The unchanged macOS provisioning case materializes full cold/warm PR siblings, then preserves native sparse transitions exceeded its existing 120s deadline at 124.94s. The mandatory three-file tooling run otherwise had 35 passed / one platform skip in 559.03s. This pre-existing host-sensitive timing failure is retained under the slow-suite waiver; no timeout or assertion was changed.
  • The final rendering regression for an absent daemon summary passed (29 tests / one Windows skip, 127.28s wall, including 101.44s shared compiler preparation; the changed case took 3ms).
  • Diff size: production +355/−213, tests and test support +411/−180, docs +10/−5, shrink-only lint baseline +0/−1.
  • Hosted CI timing: pending at author handoff. Auto-merge is off.

Control the recorded service independently of config validity and report
validation problems as recovery warnings. Preserve the installed definition
and its health target during invalid-config restarts, keep diagnostics usable,
and leave strict validation and retired-key migration with startup and Doctor.

Keep the status config reader, log formatter, and config test cases in focused
siblings to preserve the existing line caps without removing coverage.
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: XL labels Oct 3, 2026
@steipete
steipete marked this pull request as ready for review October 3, 2026 08:06
@clawsweeper

clawsweeper Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed October 3, 2026, 4:12 AM ET / 08:12 UTC (Revision 2).

ClawSweeper review

What this changes

The PR keeps Gateway service recovery and diagnostics available with invalid configuration, adds repair warnings, and preserves installed service settings during restart.

Merge readiness

⛔ Blocked before merge - 3 items remain

This remains useful work that current main does not implement, but the newly documented newer-config recovery case still encounters the native adapter’s version refusal. The earlier migration-proof concern does not apply because this patch changes no stored format.

Priority: P2
Reviewed head: a4f6f18f1962c8d98be681122e573280e260583d

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful recovery work has concrete native-stop evidence, but the documented newer-config case misses a final production guard.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured body reports the built CLI exercising the changed stop owner against an isolated real macOS LaunchAgent: service unloaded, listener closed, repair warnings emitted, and config bytes preserved. This supports invalid-config stop recovery; the newer-writer omission is a separate correctness finding. No stored-data contract changes, so the earlier migration-proof blocker is inapplicable.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured body reports the built CLI exercising the changed stop owner against an isolated real macOS LaunchAgent: service unloaded, listener closed, repair warnings emitted, and config bytes preserved. This supports invalid-config stop recovery; the newer-writer omission is a separate correctness finding. No stored-data contract changes, so the earlier migration-proof blocker is inapplicable.
Evidence reviewed 8 items Introduced recovery policy: The pinned introduction changes stop, restart, and uninstall from config admission to recovery diagnostics; invalid-config restart suppresses definition repair and requests definition preservation.
Final native boundary still refuses newer-written config: Every guarded native service mutation still calls assertFutureConfigActionAllowed before dispatch. That helper reads lastTouchedVersion and throws when it exceeds the running binary’s version unless the existing override is enabled. Converting the CLI preflight result into a warning does not bypass this owner.
Existing adapter regression contradicts the new promise: The service-owner test constructs newer-written config and verifies that resolveGatewayService().restart rejects. The PR’s new lifecycle tests instead supply a mocked service, so their successful newer-config cases never exercise the final adapter guard.
Findings 1 actionable finding [P2] Apply the newer-config recovery policy at the native boundary
Security None None.

How this fits together

The Gateway CLI controls OpenClaw’s installed background service and gathers connection and log diagnostics. Native service adapters select and mutate the recorded service, while config validation supplies startup admission and recovery warnings.

flowchart TD
  A[CLI recovery command] --> B[Recorded service discovery]
  C[Local configuration] --> D[Validation diagnostics]
  B --> E[Native service guards]
  E --> F[Stop uninstall or restart]
  D --> G[Repair warnings]
  F --> H[Service state and restart health]
  H --> G
Loading

Before merge

  • Apply the newer-config recovery policy at the native boundary (P2) - The newly documented newer-config exception does not reach the actual service adapter. With meta.lastTouchedVersion newer than this binary and the override unset, resolveGatewayService() still invokes assertFutureConfigActionAllowed() in src/daemon/service.ts:314, which throws before stop, uninstall, or restart reaches the native manager. The new lifecycle cases mock that service and miss this refusal; the existing src/daemon/service.test.ts case still asserts it. Carry the narrow recovery policy through the final guard while retaining protection for config-writing actions. This was visible at the preceding identical reviewed head and is a late discovery.
  • Complete next step (P2) - Carry the documented newer-config recovery exception through the native Gateway adapter and add a regression that exercises its real guard.
  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.

Findings

  • [P2] Apply the newer-config recovery policy at the native boundary — docs/cli/gateway/service.md:23-25
Agent review details

Security

None.

PR surface

Source +142, Tests +231, Docs +5, Other -1. Total +377 across 26 files.

View PR surface stats
Area Files Added Removed Net
Source 10 355 213 +142
Tests 12 411 180 +231
Docs 3 10 5 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 26 776 399 +377

Review metrics

Metric Value Why it matters
Production versus regression coverage production +142 net lines; tests and test support +231 net lines Growth is justified by recovery diagnostics and focused sibling extraction, but the native-adapter boundary still needs coverage.

Stored data model

Persistent data-model change detected: migration/backfill/repair: src/cli/daemon-cli/lifecycle-core.ts, migration/backfill/repair: src/cli/daemon-cli/status.print.ts, migration/backfill/repair: src/cli/update-cli/status.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Apply one typed Gateway recovery policy through the native service owner, preserving installed definitions and keeping startup, installation, and config-writing version guards strict.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: with a recorded native service and meta.lastTouchedVersion newer than the binary, recovery reaches the unchanged adapter guard and is refused unless the existing override is set. The service-owner regression already asserts this refusal; no code was executed during this review.

Is this the best way to solve the issue?

No, the recovery policy is incomplete at the final native boundary. The general separation of service control from unrelated config validation is sound, and no new migration is needed.

Full review comments:

  • [P2] Apply the newer-config recovery policy at the native boundary — docs/cli/gateway/service.md:23-25
    The newly documented newer-config exception does not reach the actual service adapter. With meta.lastTouchedVersion newer than this binary and the override unset, resolveGatewayService() still invokes assertFutureConfigActionAllowed() in src/daemon/service.ts:314, which throws before stop, uninstall, or restart reaches the native manager. The new lifecycle cases mock that service and miss this refusal; the existing src/daemon/service.test.ts case still asserts it. Carry the narrow recovery policy through the final guard while retaining protection for config-writing actions. This was visible at the preceding identical reviewed head and is a late discovery.
    Confidence: 0.98
    Late finding: first raised on code an earlier review cycle already covered.

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 31e85eeebcc1.

Labels

Label changes:

  • add P2: This repairs a bounded Gateway recovery failure, with one remaining newer-config case that prevents the promised behavior.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports the built CLI exercising the changed stop owner against an isolated real macOS LaunchAgent: service unloaded, listener closed, repair warnings emitted, and config bytes preserved. This supports invalid-config stop recovery; the newer-writer omission is a separate correctness finding. No stored-data contract changes, so the earlier migration-proof blocker is inapplicable.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The captured body reports the built CLI exercising the changed stop owner against an isolated real macOS LaunchAgent: service unloaded, listener closed, repair warnings emitted, and config bytes preserved. This supports invalid-config stop recovery; the newer-writer omission is a separate correctness finding. No stored-data contract changes, so the earlier migration-proof blocker is inapplicable.

Label justifications:

  • P2: This repairs a bounded Gateway recovery failure, with one remaining newer-config case that prevents the promised behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🐚 platinum hermit and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The captured body reports the built CLI exercising the changed stop owner against an isolated real macOS LaunchAgent: service unloaded, listener closed, repair warnings emitted, and config bytes preserved. This supports invalid-config stop recovery; the newer-writer omission is a separate correctness finding. No stored-data contract changes, so the earlier migration-proof blocker is inapplicable.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured body reports the built CLI exercising the changed stop owner against an isolated real macOS LaunchAgent: service unloaded, listener closed, repair warnings emitted, and config bytes preserved. This supports invalid-config stop recovery; the newer-writer omission is a separate correctness finding. No stored-data contract changes, so the earlier migration-proof blocker is inapplicable.

Evidence

Acceptance criteria:

  • [P1] pnpm test src/daemon/service.test.ts --maxWorkers=1.
  • [P1] pnpm test src/cli/daemon-cli/lifecycle-core.config-guard.test.ts src/cli/daemon-cli/lifecycle-action-preflight.test.ts src/cli/daemon-cli/lifecycle-readiness.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs.
  • [P1] git diff --check.

What I checked:

  • Introduced recovery policy: The pinned introduction changes stop, restart, and uninstall from config admission to recovery diagnostics; invalid-config restart suppresses definition repair and requests definition preservation. (src/cli/daemon-cli/lifecycle-core.ts:523, a4f6f18f1962)
  • Final native boundary still refuses newer-written config: Every guarded native service mutation still calls assertFutureConfigActionAllowed before dispatch. That helper reads lastTouchedVersion and throws when it exceeds the running binary’s version unless the existing override is enabled. Converting the CLI preflight result into a warning does not bypass this owner. (src/daemon/service.ts:314, a4f6f18f1962)
  • Existing adapter regression contradicts the new promise: The service-owner test constructs newer-written config and verifies that resolveGatewayService().restart rejects. The PR’s new lifecycle tests instead supply a mocked service, so their successful newer-config cases never exercise the final adapter guard. (src/daemon/service.test.ts:157, a4f6f18f1962)
  • Actual merge retains the final guard: Raw test-merge parents are exactly the pinned base followed by the PR head. Comparing that merge against its base shows no changes to service.ts or future-config-guard.ts; the missed boundary survives the three-way merge. (src/daemon/service.ts:314, f54d78b70ee3)
  • Current-main necessity: Fetched main still invokes blocking config preflight for uninstall, stop, and restart. No merged replacement is established. The supplied latest release is v2026.9.8, but its source object was unavailable locally, so release inclusion was not verified and no implemented close is proposed. (src/cli/daemon-cli/lifecycle-core.ts, 31e85eeebcc1)
  • Captured native recovery evidence and prior-review disposition: The supplied complete PR body records the built CLI stopping an isolated macOS LaunchAgent, returning result "stopped", closing its listener, issuing Doctor guidance, and preserving config bytes. Doctor subsequently rejected the unknown keys. This exercises the changed native-stop boundary, but not newer-written config. The body explicitly waives published-driver proof for the unchanged updater transaction. Inspection found no introduced schema, migration, or serialized-format change, so the prior review’s generic migration-proof request is inapplicable. (a4f6f18f1962)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Exercise newer-written config through resolveGatewayService() and cover recovery acceptance alongside continued rejection of config-writing actions.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-03T08:06:16.654Z sha a4f6f18 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 3, 2026
@steipete
steipete merged commit dd66b67 into main Oct 3, 2026
210 of 214 checks passed
@steipete
steipete deleted the upd/upd-gateway-stop-config-gate branch October 3, 2026 08:59
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 4, 2026
…fig (openclaw#164158)

openclaw gateway stop (and the other lifecycle/recovery commands) refused to act when openclaw.json carried unrecognized keys, leaving operators unable to stop a Gateway before repairing it. Lifecycle commands now resolve only the recorded service identity, act, and then warn with the config problems and point to openclaw doctor --fix; Doctor itself stays strict. Adds Doctor migrations for the retired keys seen in the report (tools.media.audio.models, commands.ownerDisplay, gateway.tailscale.resetOnExit, memory.backend/qmd, meta.lastTouchedAt). Reported on Discord by majorkarpati.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant