Skip to content

refactor(fs): reuse prefix resolution and bounded reads - #150414

Merged
steipete merged 3 commits into
mainfrom
codex/fs-safe-paths-reads-20260916
Sep 17, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/fs-safe-paths-reads-20260916

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Related: #147473

What Problem This Solves

OpenClaw maintains filesystem path resolution and borrowed-file read loops already supplied by its pinned fs-safe dependency.

User Impact

No intended user-visible change. Registered database paths retain their existing owner, including repeated separators in stored locators and raw dangling-symlink targets. Plugin reads retain their byte limits, short-read handling, truncation errors, UTF-8 preview boundaries, and caller-owned descriptor lifetime. Schemas and on-disk formats are unchanged; no migration is needed.

Why This Change Was Made

Use resolvePathPrefixSync for the registry's missing-path fallback, and shared bounded/positional readers for iMessage attachments, Memory Wiki Notes recovery, QA evidence previews, and Anthropic transcript paging. The existing private filesystem SDK facade supplies the plugin helpers. This removes 86 production lines and 50 lines overall, using the fs-safe 0.13.1 version already adopted in #150263.

The registry retains its existing-file fast path, per-operation identity cache, Unicode/suffix probing, and ambiguity policy. Its input adapter collapses locator separator runs while preserving physical .. traversal and raw expanded symlink-target suffixes.

Validation also exposed an inherited updater-test race: the parent could see its ready marker before the scratch path had been written. The fixture now writes a sibling file and renames it into place, preserving its waits, budget assertions, and subprocess cleanup.

Evidence

  • 191 registry/session-target tests and 56 plugin-reader tests passed on fs-safe 0.13.1; four platform-specific cases skipped locally. Coverage includes stored-locator ownership, pinned attachment growth, Notes retention, short reads, mid-window EOF, and the QA evidence HTTP endpoint's UTF-8 boundary.
  • All nine updater budget tests passed. A forced open/write gap reproduced the empty-path failure before the marker repair and passed afterward.
  • Full pnpm build, explicit changed-file checks, and the marker's focused formatting/lint checks passed. Independent Codex P0–P2 reviews found no actionable findings. Retained filesystem production and ownership-test bytes match the built/live-tested revision d25f550abc46913fd813021942da0681245b0593.
  • The supported CLI, pnpm openclaw sessions --all-agents --json, passed with isolated synthetic config/state. An existing future//shared.sqlite registry row resolved to its registered ops owner while the missing directory stayed absent. Registry/config bytes were unchanged; V8 coverage confirmed six executions of both the shared resolver call and fs-safe's missing-prefix return.
  • Exact-head CI passed, including the required CI gate. Native preparation retained the reviewed head 00d98d99d7dcf7e062929ed98ec2701ec0723341.

@clawsweeper

clawsweeper Bot commented Sep 17, 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.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: imessage Channel integration: imessage extensions: anthropic extensions: qa-lab extensions: memory-wiki size: M maintainer Maintainer-authored PR labels Sep 17, 2026
@steipete
steipete marked this pull request as ready for review September 17, 2026 00:43
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 16, 2026, 11:03 PM ET / September 17, 2026, 03:03 UTC (Revision 6).

ClawSweeper review

What this changes

Reuses shared filesystem helpers for database-path matching and four plugin readers, extends ownership coverage, and stabilizes two test fixtures without intended user-visible changes.

Merge readiness

✅ Ready for maintainer review

This maintainer-requested consolidation remains useful and is not implemented on current main. No actionable defects were found, and the previous UI prerequisite no longer blocks this branch.

Priority: P3
Reviewed head: 2a0e85ceb54f92a702be7db9142dbc1f9e7f2b71

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused consolidation with relevant runtime evidence, preserved behavioral coverage, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The maintainer-reported real sessions CLI run exercised existing database registration through the changed resolver and preserved ownership and stored bytes; all changed production blobs match that tested revision. Reader boundary tests supplement this evidence, and no additional external-contributor proof gate applies.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The maintainer-reported real sessions CLI run exercised existing database registration through the changed resolver and preserved ownership and stored bytes; all changed production blobs match that tested revision. Reader boundary tests supplement this evidence, and no additional external-contributor proof gate applies.
Evidence reviewed 8 items Current main still contains the duplicated resolver: The fetched main revision retains resolveDanglingSymlinkTargetPath and its local filesystem traversal. The proposed consolidation therefore remains distinct from the already-merged dependency adoption.
Dependency contract applies directly: The changed facade imports resolvePathPrefixSync and readFileHandleBounded from @openclaw/fs-safe/advanced; file-read.ts already re-exports its positional reader. package.json pins fs-safe 0.13.1. This establishes the dependency boundary; no changed behavior depends on the Codex runtime.
Pinned prefix-resolution implementation: Verified repository ownership through the GitHub repository endpoint and resolved v0.13.1 to this commit. The implementation resolves physical symlink traversal, preserves the unresolved raw suffix, canonicalizes the existing prefix, and bounds symlink traversal.
Findings None None.
Security None None.

How this fits together

Database-path matching determines which agent owns a session database. Shared file readers supply bounded attachment, transcript, Memory Wiki, and QA preview content while callers retain their existing access checks and handle cleanup.

flowchart TD
  A[Stored database paths] --> B[Shared path resolution]
  B --> C[Existing ownership rules]
  C --> D[Agent session database]
  E[Opened plugin files] --> F[Shared bounded readers]
  F --> G[Attachments and text content]
  F --> H[Caller cleanup]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -86, Tests +38, Docs 0, Other 0. Total -48 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 7 42 128 -86
Tests 3 60 22 +38
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 1 1 0
Total 12 104 152 -48

Review metrics

Metric Value Why it matters
Production versus test delta Production −86 lines; tests +38 lines The maintainer-requested consolidation removes duplicate implementations while extending stored-locator coverage and repairing fixture timing.

Stored data model

Persistent data-model change detected: vector/embedding metadata: extensions/memory-wiki/src/source-sync-state.ts. Migration or upgrade compatibility proof is recorded; maintainers should verify it before merge.

Technical review

Best possible solution:

Keep filesystem traversal and bounded reads owned by fs-safe, with OpenClaw retaining its caller-specific ownership, limits, errors, and cleanup contracts.

Do we have a high-confidence way to reproduce the issue?

Not applicable to the central refactor: duplicated implementations are directly visible in current main. The PR separately records reproductions for its two fixture repairs.

Is this the best way to solve the issue?

Yes. Reusing the pinned dependency through the existing private filesystem facade removes competing implementations while preserving caller-specific behavior.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 9ca2d1dfcd16.

Labels

Label justifications:

  • P3: This is internal consolidation with no intended user-visible behavior change or urgent runtime defect.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The maintainer-reported real sessions CLI run exercised existing database registration through the changed resolver and preserved ownership and stored bytes; all changed production blobs match that tested revision. Reader boundary tests supplement this evidence, and no additional external-contributor proof gate applies.
  • proof: sufficient: Contributor real behavior proof is sufficient. The maintainer-reported real sessions CLI run exercised existing database registration through the changed resolver and preserved ownership and stored bytes; all changed production blobs match that tested revision. Reader boundary tests supplement this evidence, and no additional external-contributor proof gate applies.

Evidence

What I checked:

  • Current main still contains the duplicated resolver: The fetched main revision retains resolveDanglingSymlinkTargetPath and its local filesystem traversal. The proposed consolidation therefore remains distinct from the already-merged dependency adoption. (src/state/openclaw-agent-db-registry.ts:432, 9ca2d1dfcd16)
  • Dependency contract applies directly: The changed facade imports resolvePathPrefixSync and readFileHandleBounded from @openclaw/fs-safe/advanced; file-read.ts already re-exports its positional reader. package.json pins fs-safe 0.13.1. This establishes the dependency boundary; no changed behavior depends on the Codex runtime. (src/infra/fs-safe-advanced.ts:11, 2a0e85ceb54f)
  • Pinned prefix-resolution implementation: Verified repository ownership through the GitHub repository endpoint and resolved v0.13.1 to this commit. The implementation resolves physical symlink traversal, preserves the unresolved raw suffix, canonicalizes the existing prefix, and bounds symlink traversal. (src/path-prefix.ts:31, 7022a0a10c53)
  • Borrowed-handle read contracts: Inspected bounded-read.ts and positional-read.ts at v0.13.1. Bounded reads enforce maxBytes with a sentinel byte and retain caller ownership; positional reads continue through short reads and return the filled length at EOF without closing the handle. (src/positional-read.ts:20, 7022a0a10c53)
  • Existing ownership and reader safeguards remain: The registry keeps its existing-path fast path, operation-local cache, ambiguity handling, and ownership selection. Added cases distinguish repeated separators in stored locators from raw dangling-symlink targets. Anthropic and Memory Wiki retain premature-EOF errors; iMessage retains its byte-limit error and final handle closure; QA retains its UTF-8 sentinel handling. No schema, stored-field, permission, dependency-pin, or public subpath change is introduced. (src/config/sessions/session-sqlite-target.test.ts:94, 2a0e85ceb54f)
  • Runtime evidence and source continuity: The captured PR body reports a supported sessions CLI run against isolated synthetic state: an existing future//shared.sqlite registration retained its ops owner without creating the missing directory or rewriting stored state. It reports six executions of the shared resolver and dependency missing-prefix branch. GitHub blob identities for all seven changed production files match the cited live-tested revision d25f550abc46913fd813021942da0681245b0593 and the reviewed head. The reported 191 registry/session cases and 56 reader cases are supplemental; this review did not execute tests. (src/state/openclaw-agent-db-registry.ts:467, 2a0e85ceb54f)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (5 earlier review cycles)
  • reviewed 2026-09-17T00:49:39.780Z sha d25f550abc46913fd813021942da0681245b0593 :: blocked before merge. :: none
  • reviewed 2026-09-17T01:20:33.318Z sha bcc45691d0b42f5b8a81ea94ceeb89a08489ab50 :: blocked before merge. :: none
  • reviewed 2026-09-17T01:42:28.065Z sha 268f1984213dbeae127afad225a700eacbe4bfec :: blocked before merge. :: none
  • reviewed 2026-09-17T02:16:38.796Z sha 1c76fc6bf9d040e7e058e1fb919e67cc2a167dbc :: blocked before merge. :: none
  • reviewed 2026-09-17T02:38:29.795Z sha d17d704dd7827de9512034248a26cdbec7ab981f :: blocked before merge. :: none

@steipete

Copy link
Copy Markdown
Contributor Author

CI follow-up: the registry assertion count is now reduced from 7 to 5, matching the deleted implementation. No baseline was raised.

The plugin skill bounded-read fixture also failed on unchanged base 6dbf1873f98a1154b06d1a3c39efc26b41dbcce9: 23 tests passed and one observed zero bytes. fs-safe 0.13 deliberately stopped invoking afterOpenedPathIdentityCheck on Root.read, so the fixture never installed its spies or grew the files. Commit 74813e0ef0ed59c5503d7bd127254d1709fb4d8e installs observation through afterOpen and grows the file immediately before its first real read. All original assertions remain, and all 24 tests pass on both the unchanged base and this candidate. The isolated fixture commit is reusable by other PRs blocked by the same failure.

The UI budget failure is inherited: paired builds of exact CI merge 869740efc7eb71c6dad2867e3966980e4c1ce609 and parent 74345aa20c30b8e9d681de0d9589a300fb53954c, with identical toolchain and fixed comparison metadata, produced byte-identical complete Control UI outputs (1,981 files). Both measured 362,625 B startup gzip against the unchanged 362,588 B limit. This refactor adds zero UI bytes. Existing startup repairs #150420 and #150424 cover the underlying issue; this PR keeps UI source and budgets unchanged.

@steipete
steipete force-pushed the codex/fs-safe-paths-reads-20260916 branch 3 times, most recently from d17d704 to 2a0e85c Compare September 17, 2026 02:54
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 17, 2026
Write the scratch path to a sibling file before exposing the readiness marker. Preserve the existing budget and cache assertions while preventing the parent from observing an empty path during the child write.
@steipete
steipete force-pushed the codex/fs-safe-paths-reads-20260916 branch from 2a0e85c to 00d98d9 Compare September 17, 2026 03:28
@steipete
steipete merged commit cdd318c into main Sep 17, 2026
225 checks passed
@steipete
steipete deleted the codex/fs-safe-paths-reads-20260916 branch September 17, 2026 03:56
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 17, 2026
)

* refactor(fs): reuse prefix resolution and bounded reads

* chore(fs): shrink registry assertion baseline

* test(update): publish budget fixture readiness atomically

Write the scratch path to a sibling file before exposing the readiness marker. Preserve the existing budget and cache assertions while preventing the parent from observing an empty path during the child write.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: imessage Channel integration: imessage docs Improvements or additions to documentation extensions: anthropic extensions: memory-wiki extensions: qa-lab maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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