Skip to content

feat(copy): bind copyRootFileSync to an expected source identity - #841

Merged
steipete merged 2 commits into
mainfrom
feat/sync-copy-source-identity
Oct 6, 2026
Merged

steipete merged 2 commits into
mainfrom
feat/sync-copy-source-identity

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

OpenClaw synchronous plugin captures pin a source before copying and record its identity in a receipt. If that pathname is replaced before copyRootFileSync reopens it, the previous API could copy a different inode. This additive refinement to #839 lets callers bind fs-safe's own admission to their existing pin.

expectedSourceIdentity is snapshotted before filesystem observations and checked by the existing bigint identity inspector before destination creation. A mismatch throws path-mismatch. Every successful copy returns a frozen sourceIdentity, verified by the existing source checks through completion. Omission preserves the existing admission behavior. fs-safe still owns its source descriptor; copy policies, byte bounds, modes, cleanup, and destination ownership are unchanged.

Final API additions

// @openclaw/fs-safe/advanced
// CopyRootFileSyncOptions
expectedSourceIdentity?: { dev: bigint; ino: bigint };

// CopiedRootFileSync
readonly sourceIdentity: Readonly<{ dev: bigint; ino: bigint }>;

The existing identity remains the destination identity, and fd remains its owned readable/writable descriptor.

OpenClaw migration sketch

For openclaw/openclaw#161739, keep the successful openRootFileSync source pin and existing source fingerprint/content checks. Derive the expectation from that descriptor with bigint inspection, never from the numeric stat receipt or a new pathname stat. Keep the caller's descriptor open until the copy returns:

const pinned = fs.fstatSync(opened.fd, { bigint: true });
const expectedSourceIdentity = { dev: pinned.dev, ino: pinned.ino };
using copied = copyRootFileSync({
  source: { rootPath: boundary, absolutePath: source },
  destination: { rootPath: options.captureRoot, absolutePath: target },
  expectedSourceIdentity,
  clone: "auto",
  maxBytes: options.expectedSize,
  sourceHardlinks: "allow",
  mode: options.mode,
  preserveSourceMode: true,
});
const content = options.hashCopiedContent
  ? hashPluginSourceDescriptor(copied.fd)
  : undefined;
// Propagate these facts to the existing capture/receipt owner:
return { content, sourceIdentity: copied.sourceIdentity };

Use the returned source identity to bind the copy's source facts to the already-pinned receipt record. Keep hashing actual destination bytes through copied.fd, with bounded reads. Preserve the too-large translation, ordinary mode 0o600 | (source.mode & 0o100), native materialization branch, source hardlink acceptance, later destination verification, and receipt framing. The owner must prove destination freshness before adopting the existing create-only helper.

For captured aliases, pin the retained capture inside the capture directory, pass that descriptor's bigint identity as expectedSourceIdentity, and verify the returned sourceIdentity against that snapshot. Continue recording the original plugin source identity in the ordered receipt; the alias copy's source identity refers to the retained capture inode. Preserve its bytes and mode even if the installed original changed. This library change does not itself modify the OpenClaw call sites.

Validation

Final head: 6707c9f840628c8cf8ec61a4e50e46190a4956c2.

  • Focused portable run: 34 passed; native APFS run: 49 passed, with only the Linux-specific copy-range test skipped locally. CI exercises that real tmpfs copy-range route and Windows admission.
  • pnpm check passed: 694 test files and 17,220 tests passed, plus lint, build, WASM allocator tests, documentation examples, and installed-package/declaration checks. Used the repository's serial test setting.
  • Separate pnpm pack:check passed. pnpm public-api:update regenerated the export-name/error-code snapshot without a diff, as expected for new type members; installed-package declaration assertions cover both new members.
  • Final isolated Codex autoreview with the full copy implementation and shared bigint inspector: scoped-clean at P0–P2.
  • Coverage, CodeQL, and benchmarks passed on this exact head. CodeQL needed no rerun.
  • All-OS CI: 27 jobs initially passed; the Windows Node 24 package-consumer job hit a 30-second PowerShell timeout in the unchanged private-directory ACL probe. One targeted same-head retry passed; the final CI attempt is green across all 28 active jobs. No admin override was used.

The initial local package build selected Homebrew Rust, whose sysroot lacked the WASM target. Using the documented rustup toolchain resolved this without repository changes. No release.

@clawsweeper

clawsweeper Bot commented Oct 6, 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.

@steipete
steipete marked this pull request as ready for review October 6, 2026 09:03
@steipete
steipete requested a review from a team as a code owner October 6, 2026 09:03
@clawsweeper clawsweeper Bot added P2 Normal priority bug or improvement with limited blast radius. 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 Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 5:06 AM ET / 09:06 UTC.

ClawSweeper review

What this changes

Adds an optional expected source identity to synchronous guarded file copies and returns the verified source identity alongside the destination identity.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main lacks caller-pinned source identity binding, and the additive implementation preserves existing copy safeguards. No actionable introduced defect was found.

Priority: P2
Reviewed head: 6707c9f840628c8cf8ec61a4e50e46190a4956c2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused additive implementation with aligned documentation and regression coverage; no blocking correctness or security finding emerged.
Proof confidence 🌊 off-meta tidepool Not applicable: Verified repository-administrator authorship exempts this PR from external-contributor runtime proof; inspected tests exercise the changed copier's matching-pin and pre-creation rejection paths as supplemental coverage. No persisted data-model contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Verified repository-administrator authorship exempts this PR from external-contributor runtime proof; inspected tests exercise the changed copier's matching-pin and pre-creation rejection paths as supplemental coverage. No persisted data-model contract changes.
Evidence reviewed 8 items Introduced patch and merge result: Read all six introduced files. The verified test-merge comparison preserves the same additive production changes; no current-main behavior is removed.
Rejection precedes destination creation: The snapshotted expectation is checked against the owned source descriptor at line 132, before native transfer at line 158 or portable creation at line 164. Existing source checks remain before transfer and after copying and mode finalization; the returned source identity is frozen.
Exact identity comparison: The shared inspector rejects non-bigint expectations, definite device/inode mismatches, and unknown Windows expected identities. The native engine duplicates the admitted source descriptor rather than reopening the source pathname.
Findings None None.
Security None None.

How this fits together

fs-safe's synchronous copier accepts source and destination paths within filesystem roots and creates an exclusive destination. Callers receive an owned destination descriptor and identity facts for subsequent reads and receipts.

flowchart TD
 A[Source and destination paths] --> B[Guarded path admission]
 C[Optional pinned source identity] --> D[Exact source identity check]
 B --> D
 D --> E[Exclusive native or byte copy]
 E --> F[Source and destination verification]
 F --> G[Owned destination and identity facts]
Loading

Before merge

None.

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Production and test changes production +6/-1 lines; tests +64/-1 lines The small production increase implements the stated identity-binding contract, with focused regression coverage.

Technical review

Best possible solution:

Keep the optional identity constraint in the existing guarded copier, with exact bigint checks and unchanged descriptor ownership and omission behavior.

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

Not applicable as a new API capability; source inspection establishes that current main cannot bind copy admission to a caller's existing pin. No runtime reproduction was executed.

Is this the best way to solve the issue?

Yes: reusing the existing exact identity inspector before both destination-creation paths is a narrow solution that retains the established copy and cleanup owners.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P2: This is a bounded additive filesystem-safety improvement without an identified urgent regression.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository-administrator authorship exempts this PR from external-contributor runtime proof; inspected tests exercise the changed copier's matching-pin and pre-creation rejection paths as supplemental coverage. No persisted data-model contract changes.

Label justifications:

  • P2: This is a bounded additive filesystem-safety improvement without an identified urgent regression.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: Verified repository-administrator authorship exempts this PR from external-contributor runtime proof; inspected tests exercise the changed copier's matching-pin and pre-creation rejection paths as supplemental coverage. No persisted data-model contract changes.

Evidence

What I checked:

  • Introduced patch and merge result: Read all six introduced files. The verified test-merge comparison preserves the same additive production changes; no current-main behavior is removed. (src/copy-root-file-sync.ts:25, 6707c9f84062)
  • Rejection precedes destination creation: The snapshotted expectation is checked against the owned source descriptor at line 132, before native transfer at line 158 or portable creation at line 164. Existing source checks remain before transfer and after copying and mode finalization; the returned source identity is frozen. (src/copy-root-file-sync.ts:132, 6707c9f84062)
  • Exact identity comparison: The shared inspector rejects non-bigint expectations, definite device/inode mismatches, and unknown Windows expected identities. The native engine duplicates the admitted source descriptor rather than reopening the source pathname. (src/strict-file-identity.ts:59, 6707c9f84062)
  • Focused regression coverage: Added cases cover matching caller pins, retained caller ownership and cursor position, replacement rejection without destination creation, and independent device/inode mismatches for portable and native configurations. Additional assertions cover returned source identity across copy methods. These tests were inspected, not executed. (test/copy-root-file-sync.test.ts:45, 6707c9f84062)
  • Current main and tag do not supersede the refinement: Both fetched main and the locally available v0.24.0 tag contain the original copier without expectedSourceIdentity or returned sourceIdentity. The merged predecessor feat(copy): add a synchronous guarded clone-capable file copy #839 supplies the underlying copier, not this refinement; no shipped-release claim is made for this PR. (src/copy-root-file-sync.ts:22, ec6206308912)
  • Merged feature-history routing: Main-line blame and log connect the synchronous copier to merged commit 3bdcb00. Its raw recorded parent lacks this file, establishing concrete prior merged involvement rather than relying on authorship of the proposed branch. (src/copy-root-file-sync.ts:149, 3bdcb003d6a1)

Likely related people:

  • Peter Steinberger: Raw commit 3bdcb00 adds src/copy-root-file-sync.ts:145 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3bdcb003d6a1; files: src/copy-root-file-sync.ts)

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.

@steipete
steipete merged commit 6ef2b90 into main Oct 6, 2026
79 of 81 checks passed
@steipete
steipete deleted the feat/sync-copy-source-identity branch October 6, 2026 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant