Skip to content

fix(gateway): Gateway refuses to start with a misleading 'another Gateway' hint when its state database is not writable - #178107

Merged
steipete merged 2 commits into
mainfrom
codex/stab-readonly-state-start
Oct 20, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/stab-readonly-state-start

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Related: #34710

What Problem This Solves

Fixes Gateway startup failing on a user-owned read-only state database and suggesting that another Gateway is running.

User Impact

Startup restores user-owned database files to mode 0600 through the existing permission owner. Storage failures that remain identify the affected path and explain how to fix permissions, make the volume writable, or free disk space. Existing exit codes and supervisor restart behavior are preserved.

Why This Change Was Made

Gateway ownership acquisition opened SQLite before the normal permission-hardening owner ran. It now uses that owner before opening the database, including its existing tolerance for writable filesystems that reject chmod. Database-operation failures carry their path to startup presentation; filesystem lock failures retain their own diagnostics. Shared ENOSPC classification is preserved, and new filesystem errno handling stays scoped to database startup.

Doctor permission diagnosis is deferred to a separate follow-up. That follow-up must check effective write access before treating foreign ownership as a problem, so writable Docker/fsGroup and NFS volumes remain usable. This PR adds no Doctor permission detector, schema, protocol, or config changes. Acquisition-time hardening is limited to Gateway starts; offline Doctor can refuse a newer schema without changing its source files.

Evidence

Regression proof on Node and Bun: offline Doctor refuses newer-schema databases at modes 0600 and 0444 without changing mode, ctime, or contents. Already-correct private modes cause no chmod call.

Before the fix, a read-only shared-state database produced this misleading startup message:

Gateway failed to start: failed to acquire gateway state ownership | attempt to write a readonly database ...
If the gateway is supervised, stop it with: openclaw gateway stop

The coordinator live-tested the retained acquisition behavior: an owned 0444 database starts successfully and becomes 0600; an immutable (uchg) database produces a storage error. The revised message gives path-specific repair guidance without promising Doctor diagnosis.

Focused regressions cover real SQLite acquisition for owned read-only files and writable filesystems that reject chmod, immutable storage failure presentation without supervisor/port contention handling, projection-lock failure context, and existing ENOSPC/provider/workspace behavior. The focused Gateway, Doctor, permissions, snapshot, and capture-store suites passed, along with the wrapper inventory, affected type graphs, core types, lint, formatting, and import-cycle checks. Production change: +84 net lines. The separate max-lines check reports three unchanged UI files; no new suppression was added.

Main integration validation

Merged current main to resolve the SQLite classifier conflict. Main's nested-error traversal, shared EIO and ENOSPC handling, and Gateway owner-liveness changes are preserved. The provider regression now follows main's EIO behavior while continuing to verify that EACCES, EPERM, and EROFS are not treated as Gateway storage failures.

The integrated candidate passed 198 tests across 11 focused files, including Doctor newer-schema refusal at 0600 and 0444, real owned-read-only and immutable startup cases, physical/projection lock behavior, embedded retained state, and provider/workspace storage consumers. Core types, targeted lint and formatting passed; independent review found no actionable P0-P2 defects. Exact-head ClawSweeper review completed without findings or before-merge items. All selected CI jobs completed; the inherited failure is documented below.

Inherited CI failure

Exact-head CI 39383655434 completed on ba1cc7483af486f6136f64ff9edd9cf8d8c1d4db. Its only failing test job, 118498781510, reports the two foreign Doctor/schema maintenance checkpoint cases in src/state/openclaw-state-db-open.test.ts:370. They receive an ownership-namespace error instead of an undefined checkpoint status.

The same cases and error occur on scheduled main 39382483409 / 118494854815. The failing test and ownership-record source blobs are identical across main and the actual CI merge checkout. The failure table labels it unknown because main uses a different shard name; independent log and source comparison confirms it is inherited. The aggregate CI gate is red solely because of that job. Security, all other selected test/type/lint jobs, and all three PostgreSQL conformance shards passed. The older UI TS2367 failure did not recur. Landing uses the authorized native inherited-failure exception; no CI rerun or branch push was used to chase green.

@clawsweeper

clawsweeper Bot commented Oct 20, 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 gateway Gateway runtime cli CLI command changes scripts Repository scripts commands Command implementations agents Agent runtime and tooling size: L labels Oct 20, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d0ab27b752

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

const storageFailure = collectNestedErrorCandidates(err)
.map((cause) => {
// Generic errno is storage evidence only within state-database acquisition.
if (err.databasePath) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Scope errno classification to database operations

When gateway ownership fails because the owner/legacy lock file itself is inaccessible—for example, the existing acquireGatewayLock path can receive EACCES from the lock file openSync—the wrapper still attaches databasePath, so this condition reclassifies that unrelated failure as SQLITE_READONLY. Startup then reports openclaw.sqlite as the failing path and skips the lock diagnostics, while openclaw doctor cannot repair the actual lock path; only errors originating from the database permission/open operation should carry this storage context.

AGENTS.md reference: AGENTS.md:L75-L75

Useful? React with 👍 / 👎.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T07:06:25.473279Z ba1cc74 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR hardens state permissions before Gateway database acquisition and gives path-specific guidance for storage failures.

Example: Start the Gateway with a user-owned openclaw.sqlite file at mode 0444.

  • Before: Startup can fail with a readonly-database error and suggest stopping another Gateway.
  • After: Startup applies mode 0600 through the existing permission owner and continues.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused repair has no actionable correctness finding; proof confidence rests on the reported live scenario and production-path regressions rather than an attached shipped-entry-point artifact.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor-proof gate; its body reports live owned-0444 and immutable-file acquisition checks plus integrated real-SQLite regressions, without attaching a final CLI capture.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An owned read-only state database can stop Gateway startup and produce an incorrect suggestion to stop another Gateway.
Reason: The maintainer-authored direction restores startup using existing permission policy and gives actionable diagnostics for failures that remain.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still opens state before permission hardening and can give misleading contention guidance. The integrated head addresses the earlier findings without introducing a new actionable defect.

Priority: P2
Reviewed head: ba1cc7483af486f6136f64ff9edd9cf8d8c1d4db

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The supplied live-testing narrative has no attached shipped-CLI transcript showing the final revised diagnostic.
Agent review details

How this fits together

The Gateway CLI acquires physical state custody, checks database ownership, and starts its listener; acquisition failures become CLI diagnostics and supervisor exit codes.

flowchart TD
  A[Gateway CLI] --> B[Acquire physical custody]
  B --> C[Existing permission owner]
  C --> D[Inspect database ownership]
  D --> E[Start Gateway]
  D --> F[Classify acquisition failure]
  F --> G[Path-specific CLI guidance]
Loading

Technical review

Best possible solution:

Retain the existing permission owner and scoped storage diagnostics, with Doctor diagnosis handled by its separate follow-up.

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

Current main performs lease inspection before this permission repair and presents GatewayLockError failures with contention guidance; the supplied regressions exercise real read-only SQLite acquisition.

Is this the best way to solve the issue?

The patch repairs ordering through the existing permission owner, scopes filesystem errno handling to database operations, and preserves shared classification and offline-maintenance behavior.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Gateway physical custody and lease inspection keeps the original intent (60cff23: The prior port-recovery work checks interrupted-port admission under fresh physical custody before inspecting database leases.)
  • Shared-state ownership lifecycle keeps the original intent (8b16e53: Startup and offline maintenance retain bounded process ownership while ordinary exclusion belongs to the actual SQLite database.)
  • Permission hardening on chmod-incompatible volumes keeps the original intent (fix(state): tolerate chmod failures when opening the state database #91934: Writable Azure Files, NFS, and Docker volumes must remain usable when chmod is unsupported, without swallowing ordinary permission failures.)
  • Already-private filesystem metadata changes intended behavior with a stated reason (d264306: The shared-helper refactor preserved permission policy; this PR explains skipping redundant chmod to avoid changing ctime during refusal inspection.)
  • Startup failure exit behavior keeps the original intent (be36d55: Storage read failures remain retryable with exit code 1, while configuration and maintenance refusals retain their distinct handling.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 60cff23 adds src/infra/gateway-lock.ts:529 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 60cff23203dd; files: src/infra/gateway-lock.ts)
  • Vincent Koc: Raw commit aeb5b79 adds src/infra/private-mode.ts:61 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: aeb5b794c91a; files: src/infra/private-mode.ts)

PR surface

Source +84, Tests +271, Docs +1, Other -1. Total +355 across 16 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 5 118 34 +84
Tests 9 331 60 +271
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 16 450 95 +355

Review metrics

Metric Value Why it matters
Production versus test changes Production +118/-34; tests and support +331/-60 Production growth carries database-error context and replaces inline CLI presentation; tests cover acquisition, storage diagnostics, permission tolerance, and offline refusal.

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A focused startup repair restores owned read-only databases and improves diagnostics for storage failures without changing supervisor exit policy.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-20T05:50:22.028Z sha d0ab27b :: blocked before merge. :: [P2] Attach database context only to database-operation failures | [P2] Preserve shared ENOSPC disk-full handling | [P1] Allow Doctor to inspect writable foreign-owned databases | [P3] Update the embedded-lock consumer for directory preparation
  • reviewed 2026-10-20T06:29:59.894Z sha 39d708e8a9d3fd2e129dcf42ce8abfdaa9b69e15 :: needs changes before merge. :: [P2] Reconcile Doctor’s refusal snapshot with permission hardening
  • reviewed 2026-10-20T06:48:38.063Z sha 259db97 :: needs changes before merge. :: none

Reviewed October 20, 2026, 3:05 AM ET / 07:05 UTC (Revision 4).

@steipete
steipete force-pushed the codex/stab-readonly-state-start branch from 5f336af to 39d708e Compare October 20, 2026 06:15
@openclaw-barnacle openclaw-barnacle Bot added size: M and removed scripts Repository scripts size: L labels Oct 20, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Please review current head 39d708e8a9d3fd2e129dcf42ce8abfdaa9b69e15. This narrowed startup fix removes the Doctor changes, preserves shared ENOSPC classification and the existing writable-volume permission policy, attaches database context only to database-operation failures, and updates the retained-state assertion. The earlier findings have been addressed; the PR body records the focused proof and deferred Doctor follow-up.

@clawsweeper

clawsweeper Bot commented Oct 20, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
… storage

Use the existing permission owner before Gateway database acquisition, and report path-specific storage failures without contention hints. Preserve shared ENOSPC classification and chmod-incompatible writable volumes.

Skip redundant chmod calls and keep startup hardening out of offline maintenance so newer-schema refusals preserve source contents and metadata.
@steipete
steipete force-pushed the codex/stab-readonly-state-start branch from 39d708e to 259db97 Compare October 20, 2026 06:41
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Please review exact head 259db979c454b05a5e5925e9685538f1ade360e1. The existing permission owner now skips same-mode chmod, and acquisition-time hardening is limited to Gateway starts. Offline Doctor newer-schema refusal preserves mode, ctime, and contents at both 0600 and 0444. Shared ENOSPC classification, writable chmod-rejecting volume tolerance, and non-database lock diagnostics are preserved. The PR body records the focused Node/Bun regressions and deferred Doctor permission-diagnosis follow-up.

@clawsweeper

clawsweeper Bot commented Oct 20, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
Preserve current main nested storage classification and Gateway owner-liveness handling. Resolve the classifier overlap by retaining shared EIO and ENOSPC semantics alongside SQLite CANTOPEN normalization, and align the provider regression with current main behavior.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Please review exact integrated head ba1cc7483af486f6136f64ff9edd9cf8d8c1d4db. The conflict is resolved by preserving main's nested storage classification, shared EIO/ENOSPC handling, and Gateway owner-liveness changes alongside the SQLite CANTOPEN addition. The provider regression now follows main's EIO behavior. The integrated candidate passed 198 tests across 11 focused files, core types, targeted lint/formatting, and independent review with no actionable P0-P2 findings. The prior completed round on 259db979c454 found no code defects and requested this integration.

@clawsweeper

clawsweeper Bot commented Oct 20, 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. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@steipete
steipete merged commit 2a8b77f into main Oct 20, 2026
178 of 181 checks passed
@steipete
steipete deleted the codex/stab-readonly-state-start branch October 20, 2026 07:26
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via explicitly authorized admin squash with attributed pre-existing CI failures.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 21, 2026
… storage (openclaw#178107)

Use the existing permission owner before Gateway database acquisition, and report path-specific storage failures without contention hints. Preserve shared ENOSPC classification and chmod-incompatible writable volumes.

Skip redundant chmod calls and keep startup hardening out of offline maintenance so newer-schema refusals preserve source contents and metadata.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant