Repository navigation
fix(gateway): reclaim a dead owner lease with the same liveness evidence as the state lock - #164546
Conversation
Use the state lock's boot/PID-namespace evidence and 90-second heartbeat policy for SQLite Gateway ownership. Renew every 15 seconds, preserve live owners, bound startup recovery, and explain fresh-lease refusals in Doctor. Keep the existing schema and payload compatibility. Cover stale container leases and repair worker-exit, platform, and shutdown fixture assumptions. Fixes #155644.
|
🦞👀 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: needs maintainer review before merge. Reviewed October 3, 2026, 5:24 PM ET / 21:24 UTC. ClawSweeper reviewWhat this changesThe branch makes Gateway SQLite owner leases use the state lock’s namespace and heartbeat evidence for crash recovery, with bounded startup waiting and clearer Doctor guidance. Merge readiness✅ Ready for maintainer review This PR remains useful: current main still has the hostname-only SQLite lease guard. No concrete introduced defect was found, and the author’s repository-admin status independently confirms maintainer handling. Priority: P1 Review scores
Verification
How this fits togetherGateway ownership coordinates processes sharing an OpenClaw state directory. Physical locks and a SQLite owner lease admit startup or Doctor maintenance while excluding competing writers. flowchart TD
A[Gateway startup or Doctor] --> B[Acquire physical state custody]
B --> C[Read SQLite owner lease]
C --> D[Check namespace and heartbeat]
D --> E[Preserve live or fresh unknown owner]
D --> F[Reclaim stopped owner in transaction]
F --> G[Publish and renew replacement lease]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +101, Tests +313, Docs +8. Total +422 across 15 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Technical reviewBest possible solution: Keep one namespace-qualified recovery policy for physical custody and SQLite leases, preserving live owners and automatic recovery of legacy container state. Do we have a high-confidence way to reproduce the issue? Yes, from source: a recreated container’s changed hostname leaves an unexpired predecessor lease unknown and held on current main. The linked report supplies repeated Docker failures; this review did not run Docker. Is this the best way to solve the issue? Yes. Reusing the established namespace classifier while retaining physical custody and transaction-local owner fencing is a focused repair of the existing startup contract. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 3f1239520835. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
…lease liveness policy (#164697) After #164546 made the owner lease share the state lock's liveness policy, Doctor's maintenance entry inherited runtime schema admission and strict snapshot-cleanup requirements from the acquisition path and refused with GatewayLockError / DoctorSqliteMaintenanceLockUnavailableError on state it exists to repair (doctor-health.dangling-workshop-index and doctor-session-sqlite.retirement-disposal went red on main). Maintenance lease inspection is now separate from runtime schema admission while keeping the lease check and the native-reader closure requirement; foreign-owner refusal is unchanged. Bisected: passes at 5421a78, fails from 06da0de.
…lease liveness policy (#164697) After #164546 made the owner lease share the state lock's liveness policy, Doctor's maintenance entry inherited runtime schema admission and strict snapshot-cleanup requirements from the acquisition path and refused with GatewayLockError / DoctorSqliteMaintenanceLockUnavailableError on state it exists to repair (doctor-health.dangling-workshop-index and doctor-session-sqlite.retirement-disposal went red on main). Maintenance lease inspection is now separate from runtime schema admission while keeping the lease check and the native-reader closure requirement; foreign-owner refusal is unchanged. Bisected: passes at 5421a78, fails from 06da0de. (cherry picked from commit 9aee9ad)
…nce as the state lock (openclaw#164546) A Gateway could not start, and Doctor could not enter maintenance, on its own state after a crash loop or a container recreate: the SQLite owner lease's recovery was hostname-only, so a changed hostname made the dead owner 'unknown' and a lease without expiry blocked startup indefinitely ('Another Gateway owner lease is still active for this state directory'). Lease liveness now uses the state lock's shared boot/PID-namespace classifier and the 90 s heartbeat policy from openclaw#164236: a proven-dead owner (dead PID in the same namespace, or a changed boot on the same host) or an unverifiable namespace whose heartbeat is older than 90 s is reclaimed; fresh unverifiable owners and qualified live owners still refuse; renewal every 15 s; Gateway startup waits out a fresh unverifiable lease; Doctor names the wait. Acquisition rechecks ownership transactionally. No schema change. Closes openclaw#155644. Reported again today on Discord (main crash loop; Docker 2026.9.8 container).
…lease liveness policy (openclaw#164697) After openclaw#164546 made the owner lease share the state lock's liveness policy, Doctor's maintenance entry inherited runtime schema admission and strict snapshot-cleanup requirements from the acquisition path and refused with GatewayLockError / DoctorSqliteMaintenanceLockUnavailableError on state it exists to repair (doctor-health.dangling-workshop-index and doctor-session-sqlite.retirement-disposal went red on main). Maintenance lease inspection is now separate from runtime schema admission while keeping the lease check and the native-reader closure requirement; foreign-owner refusal is unchanged. Bisected: passes at 9cee184, fails from 24dbf43.
Closes #155644
What Problem This Solves
Fixes Gateway startup and Doctor maintenance getting stuck behind a crashed predecessor's SQLite owner lease after container recreation changes its hostname, including leases without an expiry.
User Impact
A provably dead local owner is reclaimed immediately. A replacement Gateway waits up to 95 seconds for an unverifiable predecessor's heartbeat to become older than 90 seconds; Doctor refuses fresh ownership and explains the wait. A verified live owner still blocks takeover, even after its lease deadline.
No configuration, flags, dependencies, database columns, or schema migration change. Existing lease payloads remain readable, and image updates need no manual lease deletion.
Why This Change Was Made
The lease's hostname-only liveness gate could not recognize a dead owner in a recreated container. File locks and SQLite leases now share the existing boot/PID-namespace classifier and 90-second heartbeat policy. The lease records namespace identity in its existing JSON payload and renews every 15 seconds. Physical state custody remains authoritative; acquisition rechecks the observed lease inside the write transaction. Doctor retains its existing old-schema admission path.
Predicate before: dead-owner reclamation required a matching hostname plus a dead PID or mismatched known process-start identities. Generic acquisition could also delete a non-null elapsed expiry. A foreign hostname remained unknown, and a null expiry could not clear through that path.
Predicate after: comparable platform/boot/PID-namespace identity admits PID evidence; a changed boot on the same host proves death. Foreign or unverifiable identity becomes dead only when its heartbeat is strictly older than 90 seconds. Fresh unverifiable ownership refuses regardless of expiry. Qualified live owners refuse even when expired; qualified owners whose PID identity remains unknown use the expiry fallback (
expiresAt === null || expiresAt <= now). Legacy local records preserve local PID classification. Deletion is fenced to the observed owner token.Evidence
node scripts/check-changed.mjs --base 3f4e6a1689c3f38fb7b238bdf46b2cf63f8907dc: passed to completion, including production types, all 27 test graphs, lint, unused exports, runtime import cycles, and repository guards.eager-import-closure,pr-wrapper-source-closure,pr-worktree-provision,check-export-name-collisions.mts, andupdate-restart-swap-fixture.mjs.git diff --check: passed.Representative one-worker measurements use
node scripts/run-vitest.mjs <file> --maxWorkers=1, the repository-supported route that avoids reconciling the shared installation:gateway-owner-lease.test.tsgateway-lock.namespace.test.tsopenclaw-state-lease-acquisition.test.tslifecycle.restart-intent.test.tsdoctor-maintenance.finish-revalidation.test.tsdoctor-maintenance.foreground-update.test.tsThe Doctor suites retain full storage/admission/service-restoration proof; the acquisition suite retains native SQLite contention and worker-generation settlement. The first local importer batch also prepared the E2E runtime: its compiler phase took 15m 28.3s, separate from test time. CI timing is pending when opened.
The stale-container regression originally failed with
Another Gateway owner lease is still active for this state directory. Coverage includes legacy and qualified container identities, dead/recycled local PIDs, null expiry, live expired owners, renewal, the 90-second boundary, bounded Gateway startup, and Doctor's wait hint. Startup tests use the existing injected clock and wait hooks.Importer validation exposed and fixed three fixture assumptions without relaxing liveness or custody checks:
Direct-route Codex P1 review: clean on the final tree. No Docker two-container probe was run. The release-only sustained-contention test and native Windows Scheduled Task lifecycle were skipped by their existing gates; the Windows integration file's four platform-independent assertions passed.
Slow pre-existing suites (waived)
The campaign lead explicitly waived pre-existing slow suites; no performance fixture changes were made. Measured test time, excluding compiler/setup work:
src/flows/doctor-health.test.tssrc/infra/state-migrations.test.tssrc/cli/local-state-owner.process.test.tstest/scripts/pr-worktree-provision.test.tsgateAuto-merge is off.