Repository navigation
fix(state): symlinked state roots fail after Gateway restart - #168361
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. |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR shares canonical process-local database keys across symlinked paths while preserving configured and persisted path spelling. Example: OPENCLAW_STATE_DIR traverses macOS /tmp → /private/tmp, and the Gateway restarts.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review This PR fixes a demonstrated restart failure that current main still permits; the integrated head resolves the previous conflict, and no introduced defect was found. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherSession history readers and native writer admission exchange revocable database-validation receipts; filesystem paths enter the shared identity owner, and canonical keys select the receipt for the physical SQLite store. flowchart TD
A[Session turn] --> B[History reader]
A --> C[Writer admission]
B --> D[Database path identity]
C --> D
D --> E[Validation receipt cache]
E --> F[Agent SQLite database]
Technical reviewBest possible solution: Use the shared canonical key for process-local validation while retaining physical identity checks, revocation, lexical lifecycle custody, and durable path spelling. Do we have a high-confidence way to reproduce the issue? Current-main lexical validation keys and canonical admission keys explain the supplied baseline restart failure; this read-only review executed no target code. Is this the best way to solve the issue? The repair fixes identity disagreement at the shared owner and avoids broader state-root normalization that could change durable exact-string path keys. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against a14a5d1908eb. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +20, Tests +24. Total +44 across 3 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 HistoryReview history (3 earlier review cycles)
Reviewed October 10, 2026, 6:32 AM ET / 10:32 UTC (Revision 4). |
274f94f to
fd9d5a5
Compare
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…-restart # Conflicts: # src/state/openclaw-agent-db-validation-cache.test.ts # src/state/openclaw-agent-db-validation-cache.ts
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Landed in efd0653. Symlinked state directories keep working across Gateway restarts; before/after and upgrade evidence is in the PR body. |
#168361 made validation-cache cleanup resolve filesystem paths again. An ENOTDIR discovery candidate could then throw during reader teardown and turn unrelated native incognito placement evidence into unknown. Use the existing captured-path matcher for metadata release. Admission and revocation retain their physical identity checks. Extend both exact and sibling-family cleanup cases with an unreadable candidate while preserving their selected, retained, and parent-proof assertions.
…w#168361) With OPENCLAW_STATE_DIR (or a database path) reached through a symlink, every turn failed after a clean Gateway restart ('Session reader validation is no longer current', 'could not verify its diff baseline'): the agent database validation cache keyed entries by path.resolve, so the reader proof and the writer admission registered under different spellings of the same file. Validation and admission now share one in-process key from the existing database identity resolver (realpath, including not-yet-created files). Configured, displayed and persisted paths are unchanged; state created before the fix is reused as is. Found by our claude-cli bug hunt. Co-authored-by: Ayaan Zaidi <[email protected]>
openclaw#168361 made validation-cache cleanup resolve filesystem paths again. An ENOTDIR discovery candidate could then throw during reader teardown and turn unrelated native incognito placement evidence into unknown. Use the existing captured-path matcher for metadata release. Admission and revocation retain their physical identity checks. Extend both exact and sibling-family cleanup cases with an unreadable candidate while preserving their selected, retained, and parent-proof assertions.
… (2026.10.5 backport)
With OPENCLAW_STATE_DIR (or a database path) reached through a symlink, every turn failed after a clean Gateway restart ('Session reader validation is no longer current', 'could not verify its diff baseline'): the agent database validation cache keyed entries by path.resolve, so the reader proof and the writer admission registered under different spellings of the same file. Validation and admission now share one in-process key from the existing database identity resolver (realpath, including not-yet-created files). Configured, displayed and persisted paths are unchanged; state created before the fix is reused as is.
Backport: sqlite-worker-identity.ts applied cleanly. The release branch's
validation cache predates main's physical-admission promotion in
getOpenClawAgentDatabaseValidation, so the conflicting hunks were
re-applied by keying every validatedPaths lookup/write (including clear and
read-release) on resolveDatabasePathKey instead of path.resolve. No
unrelated main refactors were taken. Regression test taken verbatim.
Extracted-from: efd0653
Co-authored-by: Ayaan Zaidi <[email protected]>
backport The #168361 backport (ce10298) keys agent database validation by the realpath-based physical key. Opening the same database through a new lexical alias (a directory symlink) now finds the canonical proof and is treated as a validated reopen, so it skipped registerOpenClawAgentDatabase and the alias spelling never reached the agent registry. Update discovery builds its source spellings from that registry, so database restore no longer drained the alias handle and failed with "Cannot remove OpenClaw state directory while another SQLite connection is active" (update-database-restore.test.ts "restores aliased databases through timestamp drift", FRV job 115088212088; reproduced on macOS, passes on beta.2 467e83d and on main; bisected to ce10298). Main avoids this with hasRegisteredOpenClawAgentDatabasePath from #167739 (bb7d32e), which depends on shared admission infrastructure not on this branch. Instead, each validation receipt now records the lexical spellings it was admitted under (set, adopt, worker transfer), and a validated reopen still registers when its spelling is new. This restores beta.2's registration behavior while keeping #168361's physical keying. Receipt creation moves into the new receipt module with the spelling record to keep the validation cache within its line budget.
…ventory after the #168361 backport
…ventory after the openclaw#168361 backport (cherry picked from commit ed74399) Co-authored-by: RomneyDa <[email protected]>
What Problem This Solves
Fixes session turns failing after a clean Gateway restart when
OPENCLAW_STATE_DIRtraverses a symlink, including macOS/tmp→/private/tmp.User Impact
Existing and new sessions remain usable after restart with a symlinked state directory. Configured, displayed, and persisted paths retain their original spelling. No configuration, schema, transaction, retention, or recovery changes are required.
Why This Change Was Made
History readers keyed validation by the lexical database path, while native writer admission used its filesystem-canonical path. Both referred to the same file but could replace the proof borrowed by a pending reader.
Use one shared in-process database key for validation and native identity capture, which already supplies writer-admission queue keys. Missing database files use the canonical existing parent plus the missing suffix. Validation publication, revocation, root clearing, and retained-reader cleanup agree on that key. Physical identity checks, hardlink receipt alias revocation, and lexical lifecycle custody remain intact.
resolveStateDir,CONFIG_PATH, database locators, and stored keys are unchanged. Broad state-root normalization was rejected because config health entries use a durable exact-string config-path key; this narrower fix never changes it.Evidence
8cedf203e34af009708af0ccfaaa43f2ff7c0987, macOS, isolated state, local OpenAI-compatible provider: old/new turns succeeded before SIGTERM; both failed after a clean restart. The realpath control completed all four turns, including retained history.expected undefined to be defined). Conflict-integrated candidate992274c74408e6d6595ec25beed4cb29ae2eb049passes 65 tests across validation cache, writer admission, and SQLite worker identity suites (71.28s cold wrapper including worker compilation; new regression body 724ms). The suites cover revocation, replacement, transaction settlement, missing-file admission, and removed-file races. The full restart and same-state upgrade proofs above also pass after preserving current main's physical-admission and birthtime checks.pnpm build:dockerpass. Real Claude CLI turns were unavailable; its subprocess protocol used a synthetic CLI. Baseline macOS and candidate Linux platform boundaries are recorded rather than claiming a native macOS candidate run.992274c74408e6d6595ec25beed4cb29ae2eb049: real OpenAIgpt-5-minireturnedSYMLINK_OKbefore and after SIGTERM with the symlinked state root and the same session. The credential-scoped container and temporary credential file were removed after the run.Before:
After two restarts:
Exact-head CI and
openclaw/ci-gatepass, with zero failed or cancelled jobs. ClawSweeper reviewed the same SHA: ready for maintainer review, no actionable findings, no before-merge items.Merge danger: two-way door. Reverting changes only process-local keying, with no data migration. Blast radius is agent database validation/admission and reader cleanup through filesystem aliases; configured and durable paths are not rewritten.