Skip to content

fix(state): symlinked state roots fail after Gateway restart - #168361

Merged
obviyus merged 2 commits into
mainfrom
fix/state-dir-symlink-restart
Oct 10, 2026
Merged

obviyus merged 2 commits into
mainfrom
fix/state-dir-symlink-restart

Conversation

@obviyus

@obviyus obviyus commented Oct 10, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes session turns failing after a clean Gateway restart when OPENCLAW_STATE_DIR traverses 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

  • Built main 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.
  • Built final candidate in secretless Linux isolation: 21/21 turns completed across symlink, resolved-symlink, and ordinary-directory roots, with two SIGTERM restarts per root. Old/new sessions used mock OpenAI; the symlink root also exercised the fake Claude CLI before and after both restarts.
  • Same-state upgrade: the built baseline created two sessions and three turns under a symlink. The candidate then used the identical state directory and environment: both old sessions and a new one completed, with old history retained. The database file inventory and every database inode stayed identical. Sampled persisted path-bearing rows retained the same path strings, including config health, workspace aliases, cron store keys, session snapshots, and transcript events; no added or removed path spelling was observed.
  • Regression fails on baseline: alias-spelled readers cannot capture the existing physical database proof (expected undefined to be defined). Conflict-integrated candidate 992274c74408e6d6595ec25beed4cb29ae2eb049 passes 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.
  • Targeted Oxfmt and pnpm build:docker pass. 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.
  • Exact integrated head 992274c74408e6d6595ec25beed4cb29ae2eb049: real OpenAI gpt-5-mini returned SYMLINK_OK before 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:

Session history worker prewarm failed: Error: Session reader validation is no longer current
old: SessionWorkStartInvalidatedError: Session "agent:main:old" could not verify its diff baseline before starting work. Retry.
new: Error: Session reader validation is no longer current

After two restarts:

symlink old: final — MOCK-OPENAI reply; saw 3 user and 2 assistant messages
symlink new: final — MOCK-OPENAI reply; saw 1 user and 0 assistant messages
symlink Claude CLI: final — FAKE-OK turn 1
realpath old: final — MOCK-OPENAI reply; saw 3 user and 2 assistant messages
ordinary path old: final — MOCK-OPENAI reply; saw 3 user and 2 assistant messages
upgrade old: final — MOCK-OPENAI reply; saw 3 user and 2 assistant messages

Exact-head CI and openclaw/ci-gate pass, 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.

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: S labels Oct 10, 2026
@obviyus
obviyus marked this pull request as ready for review October 10, 2026 09:14
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Existing and new session turns can fail with “Session reader validation is no longer current.”
  • After: History readers and writer admission reuse the same database validation, allowing turns to continue.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-level repair with production-entry-point restart evidence, existing-state preservation, meaningful regression coverage, and no identified introduced defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): Supplied built-Gateway terminal output exercises old and new sessions across symlinked-root restarts, ordinary-root controls, and same-state reuse on the integrated candidate; candidate execution is Linux, baseline reproduction is macOS, and real-provider proof belongs to the prior head.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Session turns fail after a clean Gateway restart when the configured state directory traverses a symlink.
Reason: The focused repair restores a demonstrated core workflow without adding configuration, public APIs, or persisted formats.

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
Reviewed head: 992274c74408e6d6595ec25beed4cb29ae2eb049

Before merge

None.

Findings

None.

Agent review details

How this fits together

Session 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]
Loading

Technical review

Best 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

  • Validation cache retention and revocation keeps the original intent (72f7155: Retain validation across ordinary reopens and revoke it after registry lifecycle changes so replacement databases initialize correctly.)
  • Worker validation transfer keeps the original intent (ba2fc97: Reuse revocable host integrity proof across worker opens while preserving receiver identity validation and durable verification gates.)
  • Canonical filesystem identity keeps the original intent (31f4a7d: Publish one canonical database path to session identity consumers while retaining native-filename and physical-file guards.)
  • Reader cleanup retention keeps the original intent (cb01feb: Preserve selected readers and aliases during temporary discovery cleanup instead of retiring another owner's retained reader.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit bc28af4 adds src/state/openclaw-agent-db-validation-cache.ts:34 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: bc28af41e101; files: src/state/openclaw-agent-db-validation-cache.ts)
  • Chris Eckert: Raw commit 72f7155 adds src/state/openclaw-agent-db-validation-cache.ts:7 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 72f71553f4a5; files: src/state/openclaw-agent-db-validation-cache.ts)

PR surface

Source +20, Tests +24. Total +44 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 52 32 +20
Tests 1 24 0 +24
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 76 32 +44

Labels

Label changes:

  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: The demonstrated restart failure blocks both existing and new session turns when the state root traverses a symlink.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only; repair and merge need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-10T09:18:02.952Z sha 274f94f3d3e9e38b8f1ffe1a080c3ffba492cfc1 :: needs changes before merge. :: [P2] Canonicalize both sides of default-root identity comparisons | [P2] Update the runtime-pinning test for canonical macOS paths
  • reviewed 2026-10-10T09:56:22.473Z sha fd9d5a5 :: needs changes before merge. :: none
  • reviewed 2026-10-10T10:19:00.714Z sha fd9d5a5 :: needs changes before merge. :: none

Reviewed October 10, 2026, 6:32 AM ET / 10:32 UTC (Revision 4).

@obviyus
obviyus force-pushed the fix/state-dir-symlink-restart branch from 274f94f to fd9d5a5 Compare October 10, 2026 09:52
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot removed the docs Improvements or additions to documentation label Oct 10, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Oct 10, 2026
…-restart

# Conflicts:
#	src/state/openclaw-agent-db-validation-cache.test.ts
#	src/state/openclaw-agent-db-validation-cache.ts
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Oct 10, 2026
@obviyus
obviyus merged commit efd0653 into main Oct 10, 2026
143 of 144 checks passed
@obviyus
obviyus deleted the fix/state-dir-symlink-restart branch October 10, 2026 10:43
@obviyus

obviyus commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in efd0653. Symlinked state directories keep working across Gateway restarts; before/after and upgrade evidence is in the PR body.

steipete added a commit that referenced this pull request Oct 10, 2026
#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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 11, 2026
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.
RomneyDa pushed a commit that referenced this pull request Oct 13, 2026
… (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]>
RomneyDa added a commit that referenced this pull request Oct 13, 2026
 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.
RomneyDa added a commit that referenced this pull request Oct 13, 2026
RomneyDa added a commit that referenced this pull request Oct 13, 2026
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
…ventory after the openclaw#168361 backport

(cherry picked from commit ed74399)
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant