Repository navigation
fix(gateway): never reclaim locks from unverifiable owners - #178076
Conversation
Keep foreign, missing and unreadable namespace owners unknown regardless of heartbeat age. Only comparable process death or verified boot change permits automatic recovery, including the SQLite Gateway owner lease. Add explicit fingerprint-confirmed gateway recover-lock for crashed owners that cannot be verified locally, preserving fs-safe remove-if-unchanged and exclusive state custody. Refs #174895
|
🦞👀 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 SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1bb4c2c7fa
ℹ️ 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".
|
Codex review: blocked before merge. What this changesThis PR preserves unverifiable Gateway owners indefinitely and adds fingerprint-confirmed recovery for stopped holders. Example: Container A pauses while holding shared Gateway state, leaving a 156-second-old heartbeat.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness⛔ Blocked before merge - 7 items remain Keep this PR open: protecting paused Gateway owners is valuable and maintainer-approved, but the shared classifier change breaks non-Gateway lease recovery and leaves concrete CI failures to repair. Priority: P1 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway startup, Doctor, and shared lease consumers classify recorded process ownership before admitting state access; the recovery CLI replaces confirmed sidecars and removes the matching SQLite Gateway lease under exclusive custody. flowchart TD
A[Gateway startup or Doctor] --> B[Namespace and process classifier]
B --> C[File lock admission]
B --> D[SQLite lease admission]
E[Recovery CLI confirmation] --> C
C --> F[Exclusive state custody]
F --> D
D --> G[Gateway state access]
Technical reviewBest possible solution: Keep the existing Gateway classifier and lock owners, complete the shared-lease producer and existing-record cutover, and repair the affected tests and static checks. Do we have a high-confidence way to reproduce the issue? Current-main source permits expired foreign heartbeats to authorize reclamation, and the supplied exact-head Docker transcript demonstrates the repaired paused-owner scenario; no target code was executed during this review. Is this the best way to solve the issue? The conservative Gateway policy and explicit recovery are coherent, but changing a classifier shared with namespace-less lease producers requires a complete consumer cutover. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 578578cdeca9. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceAcceptance criteria:
What I checked:
PR surfaceSource +301, Tests +209, Docs +69. Total +579 across 20 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 20, 2026, 1:30 AM ET / 05:30 UTC. |
Record process namespaces for startup migrations, worktree reservations and process-bound leases. Update consumer fixtures for conservative ownership, and use the canonical lease release helper for explicit recovery.
Align live Gateway fixtures and update admission expectations with conservative owner classification. Keep host PID and namespace observations real while simulating service platforms. Correct the stale command-inspection comment. Refs #174895
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 922066f4d6
ℹ️ 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".
| if (isStatePostgres()) { | ||
| throw new Error("Gateway lock recovery requires a local SQLite state database."); | ||
| } |
There was a problem hiding this comment.
Provide a recovery path for PostgreSQL-backed state
When a Gateway using PostgreSQL crashes in a foreign PID namespace, the new conservative owner classification preserves its PostgreSQL gateway-owner lease indefinitely, but the only recovery command always rejects that configuration here. The operator therefore cannot clear the lease through the documented workflow, and every subsequent Gateway startup remains blocked unless they manually edit PostgreSQL. Recovery needs to inspect and conditionally remove the matching lease through the configured state engine, or provide an equally safe supported PostgreSQL procedure.
Useful? React with 👍 / 👎.
| commandPath: ["gateway", "recover-lock"], | ||
| exact: true, | ||
| // Recovery must reach the lock before config preflight can request state ownership. | ||
| policy: { configGuard: "skip", loadPlugins: "never", networkProxy: "bypass" }, |
There was a problem hiding this comment.
Bypass early config validation for lock recovery
For gateway recover-lock with a malformed or unreadable config, this policy does not actually let the action reach the lock: run-main.ts calls prepareCliDatabaseEngine before Commander pre-actions, and because gateway recover-lock is absent from OWNED_DATABASE_SELECTION, that function reads and rejects the config first. This leaves the advertised recovery command unusable precisely when config damage accompanies a stale lock; route this command around the early engine-selection preflight or otherwise make that selection recovery-safe.
Useful? React with 👍 / 👎.
|
Merged via squash.
|
…178076) * fix(gateway): never reclaim locks from unverifiable owners Keep foreign, missing and unreadable namespace owners unknown regardless of heartbeat age. Only comparable process death or verified boot change permits automatic recovery, including the SQLite Gateway owner lease. Add explicit fingerprint-confirmed gateway recover-lock for crashed owners that cannot be verified locally, preserving fs-safe remove-if-unchanged and exclusive state custody. Refs openclaw#174895 * fix(gateway): preserve verified lease recovery across consumers Record process namespaces for startup migrations, worktree reservations and process-bound leases. Update consumer fixtures for conservative ownership, and use the canonical lease release helper for explicit recovery. * test(gateway): record namespace in temporary schema fixture * test(gateway): qualify live owner fixtures with namespace identity Align live Gateway fixtures and update admission expectations with conservative owner classification. Keep host PID and namespace observations real while simulating service platforms. Correct the stale command-inspection comment. Refs openclaw#174895
…78229) Record the Windows host namespace without the unused PowerShell boot observation, so CLI and portable-worker state admission can verify their own owners. Keep native process-start checks and conservative foreign-owner refusal. Accept validated timestamps from existing lock records. Regression exposed by openclaw#178076. Verified 156 ownership tests and 23 portable-worker build tests, targeted types, lint, format, and P2 review. Native Windows execution remains pending.
* fix(state): reduce lease heartbeat write contention Renew long-lived state leases at TTL/3 without the obsolete 30-second cap. Keep Gateway SQL renewal aligned with ordinary leases while preserving FULL durability, conditional expiry checks, and closure-bound authority. The SQL heartbeat age is diagnostic after #178076; the separate filesystem owner heartbeat remains unchanged. Native delayed-fsync evidence shows fewer commits and lower cumulative foreground writer wait, with one-commit stalls still possible. * test(state): use explicit worker transfer lists in lease benchmark
* fix(state): reduce lease heartbeat write contention Renew long-lived state leases at TTL/3 without the obsolete 30-second cap. Keep Gateway SQL renewal aligned with ordinary leases while preserving FULL durability, conditional expiry checks, and closure-bound authority. The SQL heartbeat age is diagnostic after openclaw#178076; the separate filesystem owner heartbeat remains unchanged. Native delayed-fsync evidence shows fewer commits and lower cumulative foreground writer wait, with one-commit stalls still possible. * test(state): use explicit worker transfer lists in lease benchmark
What Problem This Solves
A paused Gateway or an owner in an unreadable/foreign PID namespace could lose its state lock after its heartbeat aged past 90 seconds. A missing process observation is not proof that its owner stopped.
Refs #174895.
User Impact
Unverifiable owners retain their locks regardless of heartbeat age. After confirming that a crashed foreign owner has stopped, operators run
openclaw gateway recover-lock, then the exact--confirm <fingerprint>command it prints. Crashed foreign owners now require this explicit recovery; waiting alone no longer authorizes takeover. Records lacking usable namespace identity are also preserved.Same-namespace exited processes, changed process-start identities, and verified comparable host boot changes still recover automatically. Windows boot disagreement continues to use process identity. No schema migration or release is included.
Why This Change Was Made
File-lock admission and SQLite Gateway leases now share the conservative namespace policy; lease expiry and command-line differences cannot independently prove death. Heartbeats remain useful for diagnostics and waiting. Existing inode/record checks allow a paused owner to resume while its physical lock remains intact. Startup-migration, managed-worktree capacity/pending-slot, and process-bound SQLite lease producers now record namespace identity too, preserving verified local crash recovery for every caller of the shared policy.
Explicit recovery fingerprints startup's exact owner/state/current-config records, including file identity, contents and heartbeat, plus the SQLite lease. It uses fs-safe's remove-if-unchanged protocol, retains exclusive state custody while comparing/deleting the matching lease, and refuses a verified live local holder. It preserves profile selection in its printed command. Documentation covers CLI and Docker recovery.
Evidence
pnpm install --frozen-lockfile, fullpnpm build(10m 41s), core typecheck, six relevant test-type graphs (agents, infra, state, CLI, commands, services), targeted lint, formatting, andgit diff --checkpassed. The default pinned runtime and dependency lockfile are unchanged.a8bc87f1c5b134f1fe978bf0db8cb169695d326b: gateway-root 726 > 720 and plugins-platform 727 > 720. The guard/budget was not changed; relevant canonical type graphs passed separately.abe58c1e010c19c77f8a9b0cb24db4b054d9047e), using two containers with separate PID namespaces, one shared state volume, and synthetic configuration. Both containers and the volume were removed afterward. The post-live follow-up changes only test fixtures and one stale source comment; runtime logic is unchanged, so this live proof is retained.Live transcript summary
The image reported
OpenClaw 2026.10.5 (abe58c1). Gateway readiness was checked through/healthz(200,{"ok":true,"status":"live"}). Commands usednode /app/openclaw.mjsas the installed CLI entry point./state.openclaw gateway recover-lock. A retained its lock.docker pause A; wait 150 seconds; start B;docker unpause A.docker kill A; start B; inspect withgateway recover-lock --json; execute the returnedgateway recover-lock --confirm <fingerprint> --json; start B.{"recovered":true,"removed":3}; B then became healthy with a new owner.All four scenarios passed. The unchanged-record regression also verifies that a refreshed or replaced record rejects an earlier confirmation fingerprint.