Skip to content

fix(cli): let setup run while a Gateway owns state - #185109

Merged
RomneyDa merged 1 commit into
mainfrom
fix/setup-running-gateway
Oct 26, 2026
Merged

RomneyDa merged 1 commit into
mainfrom
fix/setup-running-gateway

Conversation

@RomneyDa

@RomneyDa RomneyDa commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

Related: #168417 (regression source). Evidence run: https://github.com/openclaw/openclaw/actions/runs/40391338974 (windows-node-context).

What Problem This Solves

Fixes: Windows companion app setup fails with openclaw setup failed (exit 1): Cannot admit setup for agent roster and workspace ... requires exclusive offline state ownership when it runs openclaw setup --baseline --workspace <abs> after onboarding, while its managed Gateway is running. Every Windows setup hits this; it worked on 2026.10.7, and the released Windows app cannot change.

User Impact

User impact: openclaw setup --baseline (with --workspace, --skip-bootstrap, --json) succeeds again with the local Gateway running and saves the same config the offline command would. An unchanged config is not written. The Gateway stays the only config writer.

Accepted limits: with a running Gateway, setup does not seed workspace files itself (the Gateway seeds missing files on the agent's first run), and creating the first config or overriding a value inherited from an included config file still asks you to stop the Gateway.

Why This Change Was Made

Follows the config set routing precedent (#182951/#184194). setupCommand now passes an onForeignOwner callback: setup computes its config change with the same plan the offline path uses, prepares it the way the offline writer would save it, and commits only that diff with config.get → config.patch (baseHash). The change is refused instead of approximated if the Gateway's writer would save something different. CLI-routed patches already return restartPending instead of failing when a restart is needed.

Steps that touch the state database stay with the Gateway: workspace bootstrap (its setup state lives in SQLite) runs on the agent's first turn, Gateway startup already finishes the runtime-pin migration, and agent creation during onboarding already provisioned the proactive job. Setup still creates the session transcripts directory.

The config.get/path-identity/config.patch binding moved from config-cli.ts into bindConfigOwner in config-cli-owner-patch.ts, so config set and setup share it. docs/cli/setup.md describes the new behavior.

Evidence

  • New process test in src/cli/config-owner-route.process.test.ts, with a real Gateway owning the state: setup --baseline --workspace <abs> succeeds and its config (minus meta) equals an offline run from the same starting config. A rerun with --json reports configStatus: "unchanged" and leaves the file byte-identical. --skip-bootstrap --json routes agents.defaults.skipBootstrap. The Gateway keeps running without a restart. Without the fix, the same test fails with the reported exclusive offline state ownership error.
  • pnpm test on config-owner-route.process, agent-roster-owner.process, commands/setup, config-cli-owner-patch, config-cli, config-cli.integration: all pass. pnpm tsgo:core, pnpm tsgo:core:test, check:line-cap-ratchet --staged, check:test-mock-exports, oxlint/oxfmt on touched files, docs format/lint: all clean. deadcode:full reports only 4 existing unused exports outside this change.
  • Autoreview (codex, P2 threshold): scoped-clean.
  • Data compatibility: no schema, state-database, or config-shape change. Setup reads the existing config and writes only the leaves the offline command already wrote (agents.defaults.workspace, agents.entries, gateway.mode, agents.defaults.skipBootstrap) through the Gateway's existing config.patch; the routed setup never opens the state database. The process test and built-CLI proof both start from an existing onboarded config and leave it byte-identical when nothing changes.
Built-CLI proof on macOS (isolated HOME, free port)
pnpm build
# isolated HOME=<proof>/home, `openclaw` on PATH -> node <worktree>/openclaw.mjs
openclaw onboard --non-interactive --accept-risk --workspace <proof>/home/.openclaw/workspace \
  --auth-choice skip --skip-skills --skip-channels --skip-ui --skip-health --no-install-daemon \
  --gateway-port 62148 --gateway-auth token --gateway-token <synthetic> --json   # exit 0
openclaw gateway run --port 62148 &                                               # Listening: 127.0.0.1:62148

# exact Windows companion script (default workspace case)
set -e
if openclaw setup --help 2>&1 | grep -q -- '--baseline'; then
    openclaw setup --baseline --workspace '<proof>/home/.openclaw/workspace' >/dev/null
else
    openclaw setup --workspace '<proof>/home/.openclaw/workspace' >/dev/null
fi
# -> exit 0; openclaw.json byte-identical to before (no-op)

openclaw setup --baseline --workspace <proof>/home/.openclaw/workspace --json
# {"ok":true,...,"configStatus":"unchanged",...}  exit 0
openclaw setup --baseline --workspace <proof>/home/ws2
# Updated config: ~/.openclaw/openclaw.json (set agents.defaults.workspace)  exit 0
openclaw setup --baseline --workspace <proof>/home/ws2 --skip-bootstrap --json
# {"ok":true,...,"configStatus":"updated",...}  exit 0
# agents.defaults = {"workspace":"<proof>/home/ws2","skipBootstrap":true}, gateway.mode = local

# Gateway log:
# [reload] config hot reload applied (agents.entries.main.workspace, agents.defaults.workspace)
# [gateway] config.patch write actor=cli ... changedPaths=agents.defaults.skipBootstrap
# [reload] config hot reload applied (agents.defaults.skipBootstrap)
# Gateway kept running throughout.

The non---baseline fallback branch (openclaw setup --workspace, only for releases whose help lacks --baseline) runs onboarding, which needs a TTY with or without a Gateway. Current releases always take the --baseline branch.

@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@RomneyDa

Copy link
Copy Markdown
Member Author

@clawsweeper review

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes commands Command implementations size: L labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

This PR routes baseline setup config changes through the running Gateway while sharing config planning with offline setup.

Example: Run openclaw setup --baseline --workspace /Users/alice/workspace while the local Gateway is running.

  • Before: Setup exits 1 because it requires exclusive offline state ownership.
  • After: Setup sends the config change through the Gateway, or succeeds without writing when the config already matches.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A focused, source-supported repair with shipped CLI evidence and no actionable code finding, pending existing-installation compatibility validation.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Windows companion-app setup exits unsuccessfully after onboarding because its managed Gateway already owns state.
Reason: The maintainer-authored direction restores an existing setup workflow and explicitly accepts the narrower online behavior.

Regression provenance

Regression provenance — verified: source commit 2bf99df55c7e by Peter Steinberger; canonical PR #168417 (blame-to-merge-commit).

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this PR open: it restores a source-confirmed companion-app setup failure while preserving Gateway ownership, and review found no concrete introduced code defect.

Priority: P0
Reviewed head: 3d47836fef44031497042eea53cb4bf699b0827c

Before merge

  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

None.

Tests

  • Missing end-to-end proof: Show baseline setup after upgrading an existing v2026.10.7 installation, with existing settings and data preserved.
Agent review details

How this fits together

Baseline setup consumes CLI options and existing config, selects the state owner, and produces config updates and setup results; the running Gateway retains config and database write ownership.

flowchart TD
  A[Baseline setup options] --> B[State owner selection]
  B --> C[Offline setup]
  B --> D[Gateway routed setup]
  C --> E[Shared config plan]
  D --> E
  E --> F[Existing config writers]
  F --> G[Config and setup result]
Loading

Technical review

Best possible solution:

Restore automatic companion-app setup through the existing Gateway config writer while retaining the shared offline plan and documented ownership limits.

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

Current main unconditionally refuses baseline setup when a foreign Gateway owns state, matching the reported command and error; no target code was executed during this review.

Is this the best way to solve the issue?

Sharing setup intent and reusing the existing config.patch writer is a focused repair that preserves single-writer ownership without adding a protocol, config option, or competing state owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Baseline setup ownership refusal changes intended behavior with a stated reason (2bf99df: Prevent CLI setup from writing ancillary state outside the running Gateway; this PR retains that invariant by routing config writes and deferring database-backed workspace preparation.)
  • Config owner binding keeps the original intent (5f62201: Restore live config mutations through the existing Gateway with target identity, revision protection, and stable-compatible requests; extraction preserves those decisions.)
  • Setup config and bootstrap intent keeps the original intent (275d0d4: Persist explicit skip-bootstrap intent, preserve omitted preferences and include ownership, and reject unsupported writes before side effects; the shared plan retains those rules.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Dallin Romney: Raw commit 5f62201 adds src/cli/config-cli.ts:148 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5f622010788d; files: src/cli/config-cli.ts)
  • Peter Steinberger: Raw commit 2bf99df adds src/commands/setup.ts:27 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2bf99df55c7e; files: src/commands/setup.ts)

PR surface

Source +141, Tests +59, Docs +5. Total +205 across 8 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 4 302 161 +141
Tests 3 75 16 +59
Docs 1 8 3 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 385 180 +205

Review metrics

Metric Value Why it matters
Production versus tests Production +302/-161; tests +75/-16 Production growth adds Gateway routing while extracting existing setup planning and config binding; tests extend the existing process fixture and preserve patch-contract coverage.

Labels

Label changes:

  • add P0: The reported companion-app setup path fails while its managed Gateway runs, blocking first-time users without an in-product recovery path.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Label justifications:

  • P0: The reported companion-app setup path fails while its managed Gateway runs, blocking first-time users without an in-product recovery path.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.

Rank-up moves

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

  • Provide the stable-upgrade scenario identified in the proof assessment.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 26, 2026, 6:36 PM ET / 22:36 UTC.

@RomneyDa
RomneyDa merged commit 23be3e1 into main Oct 26, 2026
178 of 181 checks passed
@RomneyDa
RomneyDa deleted the fix/setup-running-gateway branch October 26, 2026 23:02
RomneyDa added a commit that referenced this pull request Oct 26, 2026
Release adaptation: config set keeps its in-commit owner checks via bindConfigOwner;
no database-engine selection, proactive job, or daemon pin migration on this branch;
the owner-route fixture already seeds skipBootstrap.

(cherry picked from commit 23be3e1)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes commands Command implementations docs Improvements or additions to documentation P0 Emergency: data loss, security bypass, crash loop, or unusable core runtime. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant