Repository navigation
fix: agent database opens skip the integrity check for a replaced file while the Gateway holds it - #183052
Conversation
A process reusing a live peer's admission (#182984) matched the peer by path, completed admission and PID start time only. If a different file was renamed over the path while the peer stayed alive, a fresh process could borrow the peer's admission and skip integrity_check for a file nobody verified. Borrowing now also requires the peer's lease provenance (boot, PID namespace, build, file inode) to equal the claimant's, and the opener re-reads provenance after the native open so a file swapped between claim and open still gets the full check. Provenance exists only on Linux, so other platforms fall back to the full check.
|
🦞👀 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: bedd2ee72f
ℹ️ 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".
| held.provenance !== null && | ||
| held.provenance === owner.provenance && |
There was a problem hiding this comment.
Record file provenance after admitting a newly created database
On Linux, when the Gateway creates an agent database, its lease is claimed before the native SQLite open creates the file, so readAgentDatabaseLeaseProvenance() records null. recordOpenClawAgentDatabaseAdmission() subsequently updates only opened_at, leaving that live lease permanently unable to satisfy this new condition. Separate CLI processes therefore resume full integrity scans until the creating handle closes, even though the Gateway admitted the same file. This also affects the existing reuses a live peer process admission instead of rescanning the file test, whose child creates the database from an empty state directory. Publish the admitted file's provenance when completing admission, while retaining the replacement-file checks.
Useful? React with 👍 / 👎.
|
Codex review: needs changes before merge. What this changesBind borrowed agent-database admission to matching physical-file provenance and recheck it after SQLite opens. Example: An index-corrupted replacement is renamed over agent.sqlite while the Gateway holds the original file.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness⛔ Needs changes before merge - 1 item remains Keep open: this PR repairs a real integrity-admission defect, but introduces a fresh-database performance regression confirmed by current-head CI. Priority: P2 Before merge
Findings
Tests
Agent review detailsHow this fits togetherGateway and CLI database opens claim shared-state leases, consult reusable admission facts, and pass through schema and integrity validation before exposing a database connection. flowchart TD
A[Gateway or CLI] --> B[Agent database opener]
B --> C[Shared lease owner]
C --> D[File provenance comparison]
D --> E[Schema and integrity gate]
E --> F[Admitted database connection]
F --> G[Close and seal owner]
Technical reviewBest possible solution: Publish the admitted physical file’s provenance through the existing admission-completion owner while preserving claim-time and post-open replacement checks. Do we have a high-confidence way to reproduce the issue? Source establishes the replacement-file bypass on fetched main; the supplied corrupted-replacement regression exercises that boundary, and current-head CI independently confirms the newly introduced fresh-file borrowing failure. Is this the best way to solve the issue? Reusing existing provenance and admission owners is the smallest appropriate repair, but provenance must also be published when a previously missing database finishes admission. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 9289367925e6. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +12, Tests +87, Docs +3. Total +102 across 5 files. Added test files: 0. View PR surface stats
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 24, 2026, 8:38 PM ET / October 25, 2026, 00:38 UTC. |
|
Merged via explicitly authorized admin squash with attributed pre-existing CI failures.
|
…e while the Gateway holds it (openclaw#183052) * fix(state): bind borrowed agent database admission to the peer's file A process reusing a live peer's admission (openclaw#182984) matched the peer by path, completed admission and PID start time only. If a different file was renamed over the path while the peer stayed alive, a fresh process could borrow the peer's admission and skip integrity_check for a file nobody verified. Borrowing now also requires the peer's lease provenance (boot, PID namespace, build, file inode) to equal the claimant's, and the opener re-reads provenance after the native open so a file swapped between claim and open still gets the full check. Provenance exists only on Linux, so other platforms fall back to the full check. * test(state): let a separate process create the borrowed database * test(state): prove borrowing without the creator's clean-close seal
Related: #182984
What Problem This Solves
Fixes: since #182984, a process opening an agent database while the Gateway holds it could skip the integrity check for a different file that was renamed over the same path.
User Impact
Agent database opens again verify any file the live Gateway did not itself admit, while CLI runs against the Gateway's own file keep skipping the redundant multi-minute scan on Linux.
Why This Change Was Made
ClawSweeper's review of #182984 found that the borrow rule matched the peer by path, completed admission, and PID start time, but not by physical file. A file renamed over the path while the peer is alive could therefore borrow the peer's admission.
Borrowing now also requires the peer's recorded lease provenance to equal the claimant's. Provenance is an existing lease field that hashes boot, PID namespace, build, and file device:inode. The claim hands that value to the opener, which re-reads it after the native SQLite open and borrows only if it still matches, so a swap between claim and open also gets the full check (raised by an independent Codex review of this fix). Lease provenance is Linux-only, so other platforms fall back to the full check as before #182984; the Team Gateway, where the scans were measured, runs Linux.
Accepted residual:
node:sqliteexposes no file descriptor, so identity is a path re-stat after open; a file renamed back to the original inode between the two reads is not detected.Evidence
does not lend a live peer admission to a file replaced at the same path: a live child holds the admitted database, an index-corrupted copy is renamed over the path, and a fresh open must reject it. Fails on current main (opens without a check), passes with this change.borrows a live peer admission only for the file opened after the claim: provenance stubbed so the claim matches and the post-open read sees a swapped file. The swapped case fails when the post-open re-check is disabled and passes with it. The unswapped case borrows and fails when borrowing is disabled. A borrower closing last publishes no clean-close seal; a process that ran the full check does.openclaw-agent-db.integrity-lease,openclaw-agent-db-lease,integrity-cache,open-timing,server-close.agent-databases, andsqlite-integritysuites pass;tsgo:coreand the core oxlint shard pass; independent Codex review (P0–P2) scoped-clean after one accepted finding.