Repository navigation
fix: preserve Gateway ownership with separate Docker CLI containers - #164236
Conversation
|
🦞👀 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: blocked before merge. Reviewed October 3, 2026, 12:14 PM ET / 16:14 UTC (Revision 5). ClawSweeper reviewWhat this changesThe PR qualifies Gateway ownership by boot and Docker PID namespace, renews ownership locks in a worker, documents safe CLI container use, and repairs affected test fixtures. Merge readiness⛔ Blocked before merge - 3 items remain The fix remains necessary and has meaningful Docker boundary proof, but the previously reported shutdown retry defect remains in the current head. Priority: P1 Review scores
Verification
How this fits togetherGateway ownership coordinates access to shared OpenClaw state across the serving Gateway and maintenance processes. Namespace checks and heartbeat renewal determine whether another process must preserve ownership or may reclaim it. flowchart TD
A[Gateway or CLI process] --> B[Shared ownership locks]
B --> C[Boot and PID namespace check]
C --> D[Preserve fresh owner]
C --> E[Reclaim stopped owner]
F[Gateway heartbeat worker] --> B
D --> G[Refuse competing maintenance]
E --> H[Admit state access]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +484, Tests +1148, Docs +11, Other +4. Total +1647 across 33 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Keep namespace-qualified ownership and descriptor-bound renewal, with retryable shutdown that retains custody until cleanup succeeds. Do we have a high-confidence way to reproduce the issue? Yes, from source: make retained plugin cleanup reject the first public close call, then retry; the cached rejected promise prevents another inner cleanup attempt. No runtime reproduction was executed during this read-only review. Is this the best way to solve the issue? The ownership approach fits the existing coordinator, but the shutdown wrapper must preserve the core server's retry contract before this is a complete repair. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against f1b983fac8fa. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (4 earlier review cycles)
|
|
82a6eaf to
a2ae915
Compare
Qualify PID liveness using the recorded boot and PID namespace before reclaiming shared state. Renew lock mtimes without replacing fs-safe's immutable ownership receipts, and fence expired or replaced local owners. CLI maintenance refuses a fresh foreign owner immediately. Gateway startup waits up to 95 seconds for a crashed container's heartbeat to expire, while same-namespace and same-host reboot recovery retain their fast paths. Closes #163961. Thanks @JakeMalis for reporting the Docker TUI failure.
The executable-graph allowlist in tsdown-runtime-config.test.ts rejected infra/gateway-state-owner-heartbeat.worker. #164236 (99fccf4) added that worker to standaloneRuntimeProcessBuildEntries, and every standalone runtime graph installs the state-schema inline plugin, exactly like the listed state-lease heartbeat worker. #164296 (ba8cb92) landed seven minutes later and edited the same allowlist without the new graph, so main has failed this case since both merged. The config is correct; the expectation was stale. Proof: CI=1 node scripts/run-vitest.mjs run test/scripts/tsdown-runtime-config.test.ts --maxWorkers=1 fails 1/33 on 8db9539 and passes 33/33 with this change (52 s wall).
…penclaw#164236) A CLI run in a sibling Docker container (different PID namespace) saw the Gateway's owner lock, could not observe the owner PID, classified the live owner as stale (src/infra/stale-lock-file.ts) and reclaimed custody of a running Gateway's state. PID evidence is now qualified by the owner's recorded boot/namespace identity (linux: boot id + PID namespace inode; macOS/Windows: boot id); a lifecycle-owned worker thread renews the lock's mtime every 15 s through the verified file descriptor, so a resumed worker can only touch the inode it verified; foreign or unreadable Linux identity decides by heartbeat age (fresh: UNKNOWN, preserve, CLI refuses; older than 90 s: stale, reclaim); a different boot on the same host is stale; legacy locks keep the old rules. The owner fences itself (custody lost) after 60 s without a successful renewal via the existing replacement path; Gateway startup waits up to 95 s for a fresh foreign heartbeat to age out. Docker proof: sibling refusal 1.66 ms, SIGKILL/restart recovery 90.5 s, 93 s synchronous-SQLite overlap keeps the owner. Closes openclaw#163961. Thanks @JakeMalis for the report.
…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).
The executable-graph allowlist in tsdown-runtime-config.test.ts rejected infra/gateway-state-owner-heartbeat.worker. openclaw#164236 (0625edd) added that worker to standaloneRuntimeProcessBuildEntries, and every standalone runtime graph installs the state-schema inline plugin, exactly like the listed state-lease heartbeat worker. openclaw#164296 (a2b2534) landed seven minutes later and edited the same allowlist without the new graph, so main has failed this case since both merged. The config is correct; the expectation was stale. Proof: CI=1 node scripts/run-vitest.mjs run test/scripts/tsdown-runtime-config.test.ts --maxWorkers=1 fails 1/33 on 2be9bee and passes 33/33 with this change (52 s wall).
Portable workers start the state-owner heartbeat during SQLite admission, but the archive omitted its entry. Build and stage the existing worker, register its sealed sibling URL, and resolve that URL through the existing runtime owner. Keep custody and error handling intact. The existing relocated authorization regression now uses a dist/worker path and existing artifact fixtures include the heartbeat. Culprit: 99fccf4 (#164236), exposed by d0554f4 (#170790). Scoped Codex review and changed-file format/lint checks pass; focused hosted execution is pending.
Portable workers start the state-owner heartbeat during SQLite admission, but the archive omitted its entry. Build and stage the existing worker, register its sealed sibling URL, and resolve that URL through the existing runtime owner. Keep custody and error handling intact. The existing relocated authorization regression now uses a dist/worker path and existing artifact fixtures include the heartbeat. Culprit: 0625edd (openclaw#164236), exposed by 1fa2181 (openclaw#170790). Scoped Codex review and changed-file format/lint checks pass; focused hosted execution is pending.
Portable workers start the state-owner heartbeat during SQLite admission, but the archive omitted its entry. Build and stage the existing worker, register its sealed sibling URL, and resolve that URL through the existing runtime owner. Keep custody and error handling intact. The existing relocated authorization regression now uses a dist/worker path and existing artifact fixtures include the heartbeat. Culprit: 99fccf4 (#164236), exposed by d0554f4 (#170790). Scoped Codex review and changed-file format/lint checks pass; focused hosted execution is pending. (cherry picked from commit 9e52f76)
Closes #163961
What Problem This Solves
A separate Compose CLI container could treat the serving Gateway's PID as absent or recycled in its own PID namespace, reclaim shared state ownership, and break later Gateway state access. Thanks @JakeMalis for the report. The original misclassification is
src/infra/stale-lock-file.ts:72–76, reached through the state-owner reclamation predicate.User Impact
Fresh foreign ownership is preserved with an actionable message to run inside the Gateway container or share its PID namespace. A crashed container can recover automatically after about 90 seconds. The Compose operations page documents
pid: "service:openclaw-gateway";tui --localremains embedded-agent execution, not a workaround for sharing state across PID namespaces.No new application configuration, environment variables, CLI flags, dependencies, or SQLite schema. Legacy locks without namespace identity retain their prior PID behavior until the upgraded Gateway rewrites them.
Why This Change Was Made
The existing state owner qualifies PID evidence with boot and PID-namespace identity. One lifecycle-owned worker renews lock-file mtimes every 15 seconds, independent of synchronous work on the main thread. Each lock acquisition is bound to a retained descriptor: inode/device identity and payload are verified through the descriptor, the custody deadline is checked before renewal, and
futimesSynctouches that descriptor. A suspended old worker therefore cannot backdate a successor's new inode. Descriptors close on release or lost identity; fs-safe acquisition tokens distinguish newly retained projections.Renewal errors retry with backoff. After 60 seconds without successful renewal, the owner stops admission through the same custody-loss path used for replacement, then uses existing Gateway restart/close handling. There is no separate worker restart supervisor. Readers retain their
could not be verifiederror, while schema admission retains typed contention and the underlying loss cause.Failed non-Linux boot observations are cached per process/platform. Previously, an unavailable Windows boot probe could repeat a synchronous 5-second PowerShell timeout on every state access. Linux
/procfailures remain retryable and never authorize PID evidence.Only Gateway startup polls, every five seconds with a 95-second bound. An owner that keeps renewing is preserved. A namespace-bearing old owner that cannot renew ages out from its write mtime.
CI red classification
openclaw-state-read-worker.ownership.test.ts,gateway-state-owner.read.test.tsgateway-state-owner.test.ts(adjacent assertion exposed after the read fix)GatewayStateOwnerContentionErrorwith the custody-loss cause.gateway-service-capability.process.test.tsdoctor-maintenance.foreground-update.test.ts/ rowless-releasedserver-startup-post-attach.test.tsstartup-config-preflight.recovery.test.ts/ webhook-repair6e4b44530228a2240142c84dffdcd74d1ff9bc75. This branch takes main’s file verbatim; its duplicate fixture hunk was dropped during the rebase.exec.windows.integration.test.ts/ three 120-second timeoutsRebase and Doctor CI repair
Rebased onto
61f9c3e16dfcc59e378e98908db17feadf3a73fewithout conflicts. The webhook fixture is byte-for-byte main’s version. The rebase is the explicitly authorized reason for the lease-protected force push; auto-merge remains off.The two Doctor failures came from CI run
37132281987, job111229791127, on head8b683d7fa94a1de008cea0f25b2070cb731a0881:doctor-update-schema-guard.test.ts/ different-update claimTest preload bytes changed, with an empty shim, before database or custody admission. Concurrent processes/threads created the same final shim path before writing its contents. Each execution context now publishes its own PID/thread-qualified shim; exact-byte and alias checks remain. A deterministic two-worker regression fails on the original helper with the same empty-byte assertion and passes after the repair.doctor-update-refusal.test.ts/ detached switchingreadDrivingUpdatererrors are caught before returning without refusal, but CI did not retain the swallowed error; historical attribution remains qualified. No assertion or production behavior was weakened.This round changes only the shared test helper and its regression; Gateway/Doctor production changes are unchanged. Fresh direct-route P1 was not rerun under the maintainer’s production-change-only rule; the prior scoped-clean review remains historical evidence.
Evidence
Current validation
4ba582e8976f7415cc27acccdc61dc6af7960e9f. Fourteen owner/CI/helper suites passed 3×: 264 tests per pass, in 147.99 s, 132.18 s, and 132.49 s. Both named Doctor suites also passed the initial two-file run (40 tests, 124.40 s wall).node scripts/check-changed.mjspassed in 1897.26 s, including all selected typecheck/lint/policy gates.git diff --checkpassed.Previous-head evidence
8b683d7fa94a1de008cea0f25b2070cb731a0881. Twelve touched/CI suites passed 3×: 222 tests per pass, in 119.39 s, 100.08 s, and 106.49 s.node scripts/check-changed.mjspassed in 1720.19 s;git diff --checkpassed.oldOwnerCurrent=true,noSuccessor=true. Both payloads and inodes stayed unchanged while mtimes advanced; graceful release removed both locks. All 1,498 inputs were reverified, and all owned containers/volumes removed. This is production ownership-API proof, not a complete authenticated Gateway RPC/TUI session.Inherited evidence and waivers
The pre-repair full build exited 0 with four inherited Control UI
[INEFFECTIVE_DYNAMIC_IMPORT]warnings; all implicated inputs were unchanged from that build's base. The maintainer explicitly waived them. They concernedsession-roster-cache.runtime.ts,session-snapshot-invalidation.ts,chat-send-actions.ts, andcomposer-draft-store.runtime.ts, not the heartbeat worker.The maintainer also waived the remaining 273 importer files after seven passing batches, passing checks/guards, and clean P1 review. They are not claimed as executed. The previous descriptor repair reran the twelve owner/CI suites recorded above; the current round passed fourteen suites three times. Earlier batch 8's live-test auto-routing failure was resolved through the canonical live config with existing opt-in skips; that is collection evidence, not live-provider proof.
The branch was previously rebased onto main
b12b4b98bb39f34ebdd907af49e3ad8fec771cb2with the explicitly authorized rebase-only--force-with-lease, from82a6eafcbc1f5a2ce3c2cb0c35c0b8b1e219dcf3toa2ae915250ae1724b124f434521e35566e90167c. The rebase retained main's provenance move and lifecycle changes. The subsequent descriptor repair used a normal push. The current rebase uses the separately authorized--force-with-lease; auto-merge stays off.Slow pre-existing suites (waived)
gateway-backed-exit.process.test.tspreviously passed twice alone at 186.42 s and 191.03 s under the maintainer classification. This remains historical transport evidence.doctor-session-sqlite.memory.test.ts: earlier batch/public transcript cases 30.786 s / 36.384 s, passed.server.sessions.fixture-lifecycle.test.ts: earlier retained-fixture close-failure case 34.954 s, passed.