Repository navigation
fix(update): recover a handoff store left readable by an interrupted write - #145085
Conversation
…write Creating the lease store is not atomic: open creates the file under the caller's umask, the table is written, and only then does the store chmod it to 0600. A crash anywhere in that window leaves a world-readable file, and with the common umask 022 that is every crash in the window. Every later reader checks the mode before opening, so one interrupted first write refused config mutation and native service operations for every install root on the host until an operator deleted the file by hand. #144715 made the uninitialized table readable, but the mode check runs first and still refused. Repair the mode the store itself maintains instead of refusing it, and set it before the table write so the window is one syscall rather than a disk write. Ownership, type and link count are not ours to repair and still refuse.
|
🦞👀 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 September 11, 2026, 2:46 PM ET / 18:46 UTC (Revision 4). ClawSweeper reviewWhat this changesRestores private permissions on eligible interrupted-update handoff databases so configuration and service operations can resume, and adds recovery and refusal coverage. Merge readiness✅ Ready for maintainer review The repair remains necessary on current main and is supported by real CLI before/after evidence. The earlier fixture finding is resolved, and this review found no blocking defect. Priority: P2 Review scores
Verification
How this fits togetherThe managed-update handoff database records update ownership and retained custody. Configuration writes and Gateway service operations consult it before changing protected resources. flowchart TD
A[Configuration or service operation] --> B[Inspect handoff database]
B --> C{Safe ownership and permissions?}
C -->|Eligible permission drift| D[Restore private permissions]
C -->|Unsafe file| E[Refuse operation]
C -->|Already private| F[Check retained custody]
D --> F
F -->|Resource available| G[Allow operation]
F -->|Resource retained| E
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +33, Tests +134. Total +167 across 3 files. View PR surface stats
Review metricsNone. Technical reviewBest possible solution: Keep permission recovery in the existing database owner while preserving strict refusal of writable, foreign-owned, malformed, or retained-custody state. Do we have a high-confidence way to reproduce the issue? Yes: current-main source rejects an owned 0644 tableless handoff store before configuration or service callbacks run; the supplied CLI transcript demonstrates that failure and recovery. This read-only review did not execute tests or application code. Is this the best way to solve the issue? Yes: restoring the existing permission invariant at the shared database owner repairs both callers without a second recovery implementation or a schema change. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b3ffe8760d73. LabelsLabel justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (3 earlier review cycles)
|
The daemon retained-custody suite asserted that unsafe-mode storage refuses without repairing it, using a group-readable 0640 file. That is exactly the drift this change repairs, so point the refusal case at 0660 instead, where a descriptor another user may already hold keeps the store unrepairable, and assert the repaired mode admits both the config and service lock owners.
install.test.ts crossed the 1000-line cap when #143905 added an authority case, so every pull request merging main now fails lint on a file it never touched. expectFields asserts named fields and touches none of this suite's mocks, so it belongs in the existing sibling helper module rather than here.
|
Also carries an unrelated red-main repair, because it blocks every pull request in the repo.
Fixed by shrinking rather than suppressing: |
…e-fail-safe # Conflicts: # src/cli/daemon-cli/install.test.ts
…write (openclaw#145085) fix(update): recover a handoff store left readable by an interrupted write Creating the lease store is not atomic: open creates the file under the caller's umask, the table is written, and only then does the store chmod it to 0600. A crash anywhere in that window leaves a world-readable file, and with the common umask 022 that is every crash in the window. Every later reader checks the mode before opening, so one interrupted first write refused config mutation and native service operations for every install root on the host until an operator deleted the file by hand. openclaw#144715 made the uninitialized table readable, but the mode check runs first and still refused. Repair the mode the store itself maintains instead of refusing it, and set it before the table write so the window is one syscall rather than a disk write. Excess bits are defense in depth here: assertPath enforces a 0700 owned directory on every read and write, and a single link, so no other user could reach the inode whatever the file's own mode said. Group and other write bits stay unrepairable, because chmod cannot revoke a descriptor another user already holds. Ownership, type and link count are likewise not ours to repair and still refuse. Proven on Linux at umask 0022 through the installed CLI: before the repair a config write exits 1 with "managed handoff lease file is unsafe" and the store stays 0644; after, it exits 0 and the store is restored to 0600.
Problem
Creating the managed-handoff lease store is not atomic:
opencreates the file — under the caller's umask, so 0644 with the commonumask 022chmodit to 0600Every reader checks the file mode before opening the database. So a crash anywhere in steps 1-2 leaves a world-readable file, and from then on
withConfigWriteLockandwithGatewayServiceOperationLockrefuse withmanaged handoff lease file is unsafe— for every install root on the host, not just the interrupted one. The store is machine-global under/tmp/openclawwith no env override, so the only recovery was deleting the file by hand.openclaw doctorcannot help: its repair path writes config and dies on the same throw.This is the other half of #144715. That PR made an uninitialized table readable, but the mode check runs first, so the interrupted-write case it was aimed at still refused. #144715 only helps hosts running
umask 077; on the macOS and Linux default it never reached the new schema probe.Fix
Repair the invariant the store already maintains rather than refusing it.
repairPrivateFileModerestores 0600 on a path we own, then revalidates. Thechmodalso moves ahead of the table write, shrinking the window it exists for from a disk write to one syscall.Excess bits are defense in depth here rather than a live exposure:
assertPathenforces a 0700 owned directory on every read and every write, andnlink === 1, so no other user could traverse to the inode or hold a descriptor on it whatever the file's own mode said. Group/other write bits are still refused rather than repaired —chmodcannot revoke a descriptor, and integrity is the one thing the directory guarantee would not restore. Ownership, type and link count stay unrepairable and still refuse.Evidence
Live before/after on Linux (Docker,
umask 0022), through the real installedopenclawCLI, in one image — the BEFORE arm removes only the repair call from the shipped bundle:Local:
src/infra/update-managed-service-handoff-store-recovery.test.ts— new, and the first coverage these checks have had. Verified it fails on the original defect: with the repair reverted, the recovery case fails with the exact production error while the refusal cases keep passing, so they guard the boundary rather than the fix.src/state/local-onboarding-state.test.ts: 72 passed, 2 skipped and 13 passed.node scripts/check-changed.mjs— passed.repairPrivateFileModeand locked in by a test asserting the directory check still refuses once it stops being private.Known gap, deliberately not closed here
On a host with
umask 002an interrupted write leaves 0664, which this change refuses rather than repairs. Those hosts stay locked out. Refusing is the right call for write bits, but it means the recovery story is still incomplete, and it lands on the two gaps I did not touch:retain diagnostics and run openclaw triage manually, buttriageonly ever touches the lease at its own install root; it cannot inspect or clear the row blocking a different one. The advised recovery does not exist for this failure.@fuller-stack-dev — same area as #140339 / #144715, so flagging rather than quietly changing it. A Doctor-owned inspect/repair for this store looks like the right home for both.