Skip to content

fix(claws): refuse local writes while a Gateway owns the state - #168586

Merged
steipete merged 1 commit into
mainfrom
dbasync/clawsimple
Oct 10, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/clawsimple

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes local Claw commands writing configuration, provenance, and indexes while a Gateway owns the same state. The regression reproduced a live-owner add creating a workspace and committing configuration before a later database write failed.

User Impact

claws add, update, remove, migrate, status, and export now refuse while a Gateway owns the state and explain how to stop it and retry. The guard includes previews because planning and status reconciliation can write. Offline commands retain exclusive ownership through the existing local-state owner and run the existing domain code unchanged. Package-only authoring and inspection remain available online.

Full removal of a Claw-created agent still requires Gateway monitor drainage and is unavailable through this offline CLI path; removal of adopted ownership works offline and preserves the existing agent and workspace. No new RPC, receipt, worker refactor, schema, or persistence contract is introduced.

Why This Change Was Made

This is the requested small replacement for the 13-PR Claw chain #168421–#168433 (dbasync/ow2 branches). One adapter uses the existing runWithLocalStateOwner refusal/offline paths before any command body can access state. The lander can retire that chain after landing this replacement.

Lane: clawsimple. Status: pending lander.

Evidence

The regression covers all six commands and their previews against a real held Gateway lock, compares the complete fixture tree byte-for-byte including a populated SQLite database, and verifies no Gateway RPC is attempted. Offline integration coverage exercises add, update, status, export, migration, and adopted-ownership removal. The test uses the existing host-broker lane because the real SQLite broker requires the application host thread.

Independent Codex autoreview: no actionable P0–P2 findings.

  • pnpm test src/cli/claws-cli.state-owner.test.ts --maxWorkers=1: 3 passed; 223.34 s wall time including 131.33 s cold worker preparation, about 32.3 s in test bodies. This exercises real configuration/provenance writes and offline ownership across six commands; mocks would not prove the broker/custody boundary.
  • Focused existing CLI suites (main CLI, legacy resume, update output, inspect, project authoring, migration): 43 passed; 118.51 s wall time.
  • pnpm build: passed, 14m 29.2s. The untouched UI bundle report prints a non-fatal startup gzip overage (366.2 KiB versus 366.1 KiB); build exits 0.
  • pnpm tsgo:core and the owning CLI test typecheck passed. Staged formatting and structural guards passed. Script lint and the remaining schema, database, import-cycle, sidecar, media, webhook, and pairing guards passed.
  • pnpm check:changed --staged stops at an inherited UI test graph budget failure: 722 roots against a 720-root limit. All 722 roots exist at the branch baseline, and this patch changes neither that shard nor its budget. The global test typecheck uses that same blocked graph; the owning CLI test shard passed directly.
  • The unused-export audit reports existing exports in untouched files: tools/solid-lint/index.mjs: default, and resolveSessionConversationStub / resolveSessionTargetStub in src/agents/tools/sessions-channel-fixture.test-support.ts. Their sources, consumers, and Knip configuration are unchanged; the production export scan passed.
  • pnpm lint:core reports only inherited max-lines errors in 19 untouched files; none of the seven files in this patch has a lint finding.
  • CI: pending after push; CI seconds are not yet available.

The initial regression failed on the original code after a live-owner add wrote configuration and workspace state. During verification, an unhosted test-worker run was moved to the existing host-broker lane, and a test/build overlap was rerun after serializing those commands. These were harness failures, not passing product proof.

@clawsweeper

clawsweeper Bot commented Oct 10, 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: S labels Oct 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR requires exclusive offline state ownership for six Claw CLI commands and their previews.

Example: Run claws add ./claw.json while a Gateway owns the same state directory.

  • Before: The command could create a workspace and commit configuration before a database ownership failure.
  • After: The command refuses before entering the Claw operation and explains how to stop the Gateway and retry.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Meaningful ownership integration coverage supports the small repair, but a predictable partial-installation regression remains.
Proof confidence 🦐 gold shrimp (3/6) The ordinary contributor proof gate does not apply to this maintainer-authored PR; supplied evidence exercises real locks, configuration, and SQLite through an in-process CLI harness rather than a shipped CLI process.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Claw CLI operations can mutate configuration and workspace state while another process owns their database, leaving incomplete installations.
Reason: The maintainer-authored direction explicitly chooses a small offline repair and acknowledges the loss of full removal through this path.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep this PR open: the ownership fix is useful, but both prior findings remain unresolved at the unchanged head.

Priority: P2
Reviewed head: ce40e3eea94479c8584e2f18f0f19b44b6150981

Before merge

  • Reject Gateway-dependent cron actions before offline writes (P2) - A valid Claw declaring daily-summary at 0 9 * * * still receives an unblocked add preview. This wrapper then holds exclusive offline custody while the unchanged add implementation commits the agent, workspace, and other resources before installClawCronJobs waits for the Gateway. The same-root Gateway cannot start while that custody is held, so installation predictably ends partial at config_committed; starting the Gateway afterward makes the retry fail at this wrapper. Scheduler-changing updates retain the same unavailable dependency after earlier mutation phases. Add explicit planning blockers for unsupported offline cron actions before admitting writes.
  • Reconcile the existing live-Gateway instructions (P3) - The new offline-only requirement leaves this page's existing instructions contradictory: lines 390–403 describe add/update with a running Gateway, and lines 546–549 require a running Gateway for actual removal. Users following those instructions now encounter the new refusal. Update the affected sections to describe offline plugin installation, unsupported Gateway-dependent actions, and adopted-ownership removal consistently.

Findings

  • [P2] Reject Gateway-dependent cron actions before offline writes — src/cli/claws-cli.runtime.ts:234
  • [P3] Reconcile the existing live-Gateway instructions — docs/cli/claws.md:33-42

Tests

  • Missing end-to-end proof: The new integration coverage omits a cron-bearing add and scheduler-changing update through the offline command boundary.
Agent review details

How this fits together

Claw CLI commands turn package manifests and installed-agent state into plans, configuration changes, workspace files, and provenance; the shared local-state owner now admits these operations before their existing implementations run.

flowchart TD
  A[Claw CLI command] --> B[Offline action adapter]
  B --> C[Local state owner]
  C --> D[Live owner refusal]
  C --> E[Exclusive offline custody]
  E --> F[Existing Claw operations]
  F --> G[Config workspace and provenance]
Loading

Technical review

Best possible solution:

Keep the shared ownership adapter, reject Gateway-dependent cron actions before offline mutation, and make the CLI documentation consistently describe the supported offline operations.

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

Source inspection confirms both the original missing admission boundary and the introduced cron failure path; no target code or tests were executed during this read-only review.

Is this the best way to solve the issue?

Reusing the existing state owner is a proportionate repair, provided planning rejects operations whose required Gateway cannot run while offline custody is held.

Full review comments:

  • [P2] Reject Gateway-dependent cron actions before offline writes — src/cli/claws-cli.runtime.ts:234
    A valid Claw declaring daily-summary at 0 9 * * * still receives an unblocked add preview. This wrapper then holds exclusive offline custody while the unchanged add implementation commits the agent, workspace, and other resources before installClawCronJobs waits for the Gateway. The same-root Gateway cannot start while that custody is held, so installation predictably ends partial at config_committed; starting the Gateway afterward makes the retry fail at this wrapper. Scheduler-changing updates retain the same unavailable dependency after earlier mutation phases. Add explicit planning blockers for unsupported offline cron actions before admitting writes.
    Confidence: 0.99
  • [P3] Reconcile the existing live-Gateway instructions — docs/cli/claws.md:33-42
    The new offline-only requirement leaves this page's existing instructions contradictory: lines 390–403 describe add/update with a running Gateway, and lines 546–549 require a running Gateway for actual removal. Users following those instructions now encounter the new refusal. Update the affected sections to describe offline plugin installation, unsupported Gateway-dependent actions, and adopted-ownership removal consistently.
    Confidence: 0.99

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Installed-state command admission changes intended behavior with a stated reason (138d2a5: The original CLI introduced local plan-first Claw composition, later extended with status, removal, and export; this PR explains why those command bodies now need prior exclusive ownership.)
  • Gateway-owned cron operations keeps the original intent (96e3051: Scheduler mutation intentionally stays in the Gateway, with partial installation provenance retained when cron setup fails; the new offline wrapper leaves that dependency intact.)
  • Live-Gateway removal changes intended behavior with a stated reason (fb3773d: The earlier repair enabled removal through the serving Gateway's Cron receipt authority; this PR explicitly accepts making full removal unavailable through the offline CLI.)
  • Existing-agent migration keeps the original intent (98f7c8d: Migration enrolls an existing agent while preserving its files and unrelated state; the wrapper retains that domain implementation and adds exclusive admission.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test src/cli/claws-cli.state-owner.test.ts --maxWorkers=1
  • pnpm test src/cli/claws-cli.runtime.test.ts src/cli/claws-update-cli.runtime.test.ts --maxWorkers=1
  • pnpm tsgo:core
  • git diff --check

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit e93b01b adds src/cli/claws-cli.runtime.ts:79 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e93b01b32de0; files: src/cli/claws-cli.runtime.ts)
  • Gio Della-Libera: Raw commit 138d2a5 adds src/cli/claws-cli.runtime.ts:120 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 138d2a56274c; files: src/cli/claws-cli.runtime.ts)
  • Patrick Erichsen: Raw commit 98f7c8d adds src/cli/claws-migrate-cli.runtime.ts:84 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 98f7c8d8cb70; files: src/cli/claws-migrate-cli.runtime.ts)

PR surface

Source +31, Tests +156, Docs +11. Total +198 across 7 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 4 37 6 +31
Tests 2 156 0 +156
Docs 1 11 0 +11
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 204 6 +198

Review metrics

Metric Value Why it matters
Production versus tests Production +37/-6; tests +155/-0 The production growth is a small shared adapter and caller cutover; the integration tests exercise real custody and persistent-state preservation.

Labels

Label changes:

  • add P2: This fixes a concrete state-ownership failure in experimental administrative CLI commands, with limited blast radius.
  • add merge-risk: 🚨 compatibility: The accepted offline restriction changes existing command availability, including live-Gateway operations; the remaining cron regression is identified in the findings.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: This fixes a concrete state-ownership failure in experimental administrative CLI commands, with limited blast radius.
  • merge-risk: 🚨 compatibility: The accepted offline restriction changes existing command availability, including live-Gateway operations; the remaining cron regression is identified in the findings.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (1 earlier review cycle)
  • reviewed 2026-10-10T18:08:59.828Z sha ce40e3e :: needs changes before merge. :: [P2] Reject Gateway-dependent cron actions before offline writes | [P3] Reconcile the existing live-Gateway instructions

Reviewed October 10, 2026, 2:13 PM ET / 18:13 UTC (Revision 2).

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Lander proof for ce40e3eea94479c8584e2f18f0f19b44b6150981: the published-driver × candidate update cell passed on Blacksmith Testbox tbx_01m4kg4az3tewxsj2g2f9hj8ge. The wrapper verified tree 4e64645e402fdd460f6d6a57b4d955718c185b41 and used identical-tree carrier 7160a18314a4b9ad161e02a32ccb76b4a43a1ee4. Published OpenClaw 2026.9.9 updated to the candidate, reached readyz=200, reported the expected running version, and passed durable/incognito persistence checks. The full packaging + update command took 593.535 seconds and exited 0; the lease is stopped.

The completed ClawSweeper review has no P0/P1 findings. Its P2 cron-bearing offline partial-operation concern and P3 older live-Gateway documentation conflict remain follow-ups under the explicit P0/P1-only mechanical landing order. No source changes or new commits were made by the lander.

@steipete
steipete merged commit b794062 into main Oct 10, 2026
127 of 128 checks passed
@steipete
steipete deleted the dbasync/clawsimple branch October 10, 2026 18:36
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S 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