Skip to content

fix(openshell): preserve nested host symlinks during mirror sync - #131122

Merged
steipete merged 2 commits into
mainfrom
codex/openshell-preserve-nested-host-symlinks
Aug 27, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/openshell-preserve-nested-host-symlinks

Conversation

@steipete

@steipete steipete commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #131111

What Problem This Solves

Fixes an issue where OpenShell mirror users lose existing host symlinks inside subdirectories after an ordinary sandbox command, even when that command changes nothing. The previous download replacement preserved immediate symlink children but recursively deleted their parent directories.

Why This Change Was Made

Upload staging and download publication now share one recursive reconciliation flow. Existing host symlinks and the directories needed to retain them take precedence over conflicting remote entries; ordinary remote edits, deletions, and file/directory changes still apply. Sandbox symlinks and special files remain excluded. Regular destinations are unlinked before copying, preserving the existing protection against writing through a host hardlink into an outside inode.

The traversal also drains all started filesystem operations before reporting an error, so the workspace lease cannot be released while a sibling copy is still mutating the host. No new dependency, configuration, storage, or protocol surface is introduced. The old whole-directory deletion and duplicate copy loops are removed.

Production LOC: +81/-67 (net +14). This growth implements recursive preservation of host links and their ancestors, plus error settlement at the same owner boundary. Tests: +168/-16; docs: +6/-0.

User Impact

Host symlinks survive mirror round-trips at any depth, including dangling links and links whose remote parent was deleted or replaced. A remote replacement that conflicts with such a preserved host path is ignored, matching the existing rule that host links win. The OpenShell guide documents this boundary.

Evidence

  • Before the production change, the focused regression suite had 4 failures and 7 passes. Every new ancestor case failed because a nested host link was deleted or replaced (ENOENT, EINVAL, or ENOTDIR).
  • After the repair, node scripts/run-vitest.mjs extensions/openshell passed 101 tests across 6 files. Coverage includes nested and dangling links, remote ancestor conflicts, normal deletions/type changes, outside hardlink canaries, and draining delayed copies after a sibling failure.
  • pnpm docs:list, targeted formatting, and git diff --check passed.
  • Structured Codex review: no accepted/actionable findings.
  • The changed-file gate passed production and test typechecks, lint, database-first and media guards, runtime sidecar validation, and runtime import-cycle checks.
  • Exact-head CI passed on b2e35d4.
  • Real OpenShell E2E passed 5/5 tests in 96.82s, including mirror and remote stress. Environment: isolated Ubuntu24.04 arm64 container, Node24.19.0, pnpm11.22.0, OpenShell0.0.109, nested Linux Docker29.1.3 with vfs storage, authenticated mTLS. Protected whoami and sandbox list passed before running pnpm test:e2e:openshell. Source hashes matched the PR head. The existing fixture host-IP override used the actual task-owned Docker bridge gateway. The suite verified host links after real upload/SSH/download, ancestor conflicts, remote-link exclusion, outside hardlink canaries and ordinary writes.
  • The hosted live attempt stopped before tests because of the independent bootstrap defect recorded in [Bug]: OpenShell E2E fallback conflicts with managed gateway and TLS bundle #131134. An initial isolated-container attempt lacked the SSH client; installing the required executable allowed the unchanged full E2E suite to pass. No authentication, assertions, timeouts, or CI thresholds were weakened.
  • The first CI attempt found two callback lint violations, corrected in the current head. Its artifact job also exceeded the existing plugins-list startup RSS limit; the current run passed that unchanged gate. The first live run was canceled before tests to replace it with proof of the corrected head.

The affected deletion logic is already present in stable v2026.7.1. The retained local history carries it through e357203; that shallow-history boundary does not establish who originally introduced the defect. Upstream OpenShell v0.0.109 upload/download behavior was checked directly in crates/openshell-cli/src/run.rs and ssh.rs at pinned commit 8d67250a5d17348eb96c4fa46226b06d8041f2ba.

AI-assisted; the implementation, boundary behavior, and regression evidence were reviewed.

Reconcile mirror entries recursively so trusted host symlinks and their ancestors survive remote edits and deletions. Preserve unlink-before-copy hardlink safety and drain pending filesystem work before returning an error. Cover the repair with unit regressions and the real OpenShell E2E flow.

Fixes #131111
@steipete steipete self-assigned this Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime extensions: openshell size: M maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete
steipete marked this pull request as ready for review August 27, 2026 18:42
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. 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 Aug 27, 2026
@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 3:09 PM ET / 19:09 UTC.

ClawSweeper review

What this changes

The PR replaces OpenShell’s directory-copy logic with recursive reconciliation so nested trusted host symlinks survive mirror synchronization while ordinary remote files, directories, and deletions still synchronize.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open for normal maintainer landing: the focused mirror repair appears correct, but its exact-head OpenShell E2E is still in progress and the PR carries the protected maintainer label.

Priority: P1
Reviewed head: b2e35d40d09983b0b4f9e4cb5a05862406fb2be7

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The owner-boundary repair and focused coverage are solid; merge readiness awaits the terminal exact-head E2E result.
Proof confidence 🌊 off-meta tidepool Not applicable: Not applicable: Repository State identifies the author as a MEMBER; the PR-body test evidence is supplementary, while the exact-head real OpenShell E2E is still in progress.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: Not applicable: Repository State identifies the author as a MEMBER; the PR-body test evidence is supplementary, while the exact-head real OpenShell E2E is still in progress.
Evidence reviewed 6 items Current-main defect: Current main still deletes every non-symlink top-level entry before recursively copying the remote tree; a nested host link is therefore deleted with its ordinary parent directory.
Repair owner and caller: The new reconciler preserves target links and reports preserved descendants to their ancestors; the backend calls it after OpenShell download and uses the same flow to stage uploads.
Regression coverage: The focused tests cover deleted, file, directory, and symlink remote ancestors, dangling links, ordinary replacements, hardlink safety, and waiting for started copies before an error returns.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs extensions/openshell/src/mirror.test.ts --reporter=verbose

Result: PASS (completed)

[test] starting test/vitest/vitest.extension-misc.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-131122-Eizohg/target

 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › copies source entries to target 95ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › applies remote deletions and file-directory replacements without protec
ted links 8ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › waits for in-flight copies before reporting a mirror failure 5ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › excludes specified directories from sync 4ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › excludeDirs matching is case-insensitive 3ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › preserves default excluded directories and repository metadata 5ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › skips symbolic links when copying into the host workspace 4ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › preserves trusted host symlinks when their remote ancestor is directory
 9ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › preserves trusted host symlinks when their remote ancestor is absent 7m
s
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › preserves trusted host symlinks when their remote ancestor is file 8ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › replaceDirectoryContents › preserves trusted host symlinks when their remote ancestor is symlink 7
ms
 ✓  extension-misc  extensions/openshell/src/mirror.test.ts › stageDirectoryContents › stages upload content without symbolic links 4ms

 Test Files  1 passed (1)
      Tests  12 passed (12)
   Start at  19:10:30
   Duration  1.96s (transform 1.42s, setup 1.03s, import 393ms, tests 163ms, environment 0ms)

[test] passed 1 Vitest shard in 8.89s

Assertions:

  • PASS expect_output: preserves trusted host symlinks when their remote ancestor is

How this fits together

OpenShell mirrors a trusted Gateway-host workspace into and back from a sandbox used for command execution. The mirror layer filters unsafe filesystem entries and publishes safe sandbox changes back to the host workspace.

flowchart LR
  A[Host workspace] --> B[Upload staging]
  B --> C[Sandbox workspace]
  C --> D[Remote command]
  D --> E[Download reconciliation]
  E --> F[Updated host files]
  E --> G[Preserved host symlinks]
Loading

Before merge

  • Resolve merge risk (P1) - The provided check state still has the exact-head real OpenShell E2E in progress, so the actual upload/SSH/download round trip has not yet reached a terminal result.
  • Resolve merge risk (P1) - Production code grows by 14 lines; the extra state is bounded to the canonical reconciler and is needed to carry preserved-link ancestry and await all started filesystem work.
  • Complete next step (P2) - No repair job is warranted: no actionable defect was found in the proposed diff, and the remaining action is normal exact-head E2E completion for a protected maintainer PR.
Agent review details

Security

None.

PR surface

Source +14, Tests +152, Docs +6. Total +172 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 1 81 67 +14
Tests 2 168 16 +152
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 255 83 +172

Review metrics

Metric Value Why it matters
Production versus test delta production +14 (81 added, 67 removed); tests +152 (168 added, 16 removed); docs +6 The bounded production growth consolidates upload and download traversal into one reconciliation owner while the larger test delta exercises the filesystem and backend boundaries.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #131111
Summary: This PR is the explicitly linked candidate fix for the nested host-symlink deletion report.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain one recursive reconciler, then land only after the exact-head OpenShell E2E confirms host-link preservation and ordinary mirror updates through the real sandbox boundary.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain one recursive reconciler, then land only after the exact-head OpenShell E2E confirms host-link preservation and ordinary mirror updates through the real sandbox boundary.

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

Yes, source reproducible: current main’s top-level deletion loop removes an ordinary ancestor of a nested link, and the focused regression cases encode the resulting failure. I did not execute the suite because even pnpm docs:list could not initialize Corepack in this read-only environment (EROFS).

Is this the best way to solve the issue?

Yes. A shared recursive reconciler repairs the owning traversal while retaining source-link exclusion and unlink-before-copy hardlink protection, rather than adding a downstream exception.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against a9f163ff25ba.

Labels

Label changes:

  • add P1: The PR repairs a stable mirror-mode workflow that can delete host symlinks during ordinary sandbox use.
  • 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: Not applicable: Repository State identifies the author as a MEMBER; the PR-body test evidence is supplementary, while the exact-head real OpenShell E2E is still in progress.

Label justifications:

  • P1: The PR repairs a stable mirror-mode workflow that can delete host symlinks during ordinary sandbox use.
  • 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: Not applicable: Repository State identifies the author as a MEMBER; the PR-body test evidence is supplementary, while the exact-head real OpenShell E2E is still in progress.

Evidence

What I checked:

  • Current-main defect: Current main still deletes every non-symlink top-level entry before recursively copying the remote tree; a nested host link is therefore deleted with its ordinary parent directory. (extensions/openshell/src/mirror.ts:75, a9f163ff25ba)
  • Repair owner and caller: The new reconciler preserves target links and reports preserved descendants to their ancestors; the backend calls it after OpenShell download and uses the same flow to stage uploads. (extensions/openshell/src/mirror.ts:27, b2e35d40d099)
  • Regression coverage: The focused tests cover deleted, file, directory, and symlink remote ancestors, dangling links, ordinary replacements, hardlink safety, and waiting for started copies before an error returns. (extensions/openshell/src/mirror.test.ts:237, b2e35d40d099)
  • Production-boundary E2E coverage: The added OpenShell E2E creates nested links, deletes/conflicts with their remote ancestors, verifies host preservation and hardlink safety, and confirms sandbox-created links are not copied back. (extensions/openshell/src/backend.e2e.test.ts:669, b2e35d40d099)
  • SDK error contract: The newly used SDK export delegates to the core helper, which returns a string only for object-valued string or numeric error codes; this supports distinguishing ENOENT from other filesystem failures. (src/infra/errors.ts:6, b2e35d40d099)
  • Area history: Available history identifies Jacob Tomlinson’s earlier OpenShell mirror-hardening work and Peter Steinberger’s recent ownership of the mirror/backend path; the shallow boundary prevents a precise original-defect attribution. (extensions/openshell/src/mirror.ts:75, 3b9dab0ece46)

Likely related people:

  • steipete: Recent merged OpenShell backend and mirror work, including concurrent mirror-write preservation, appears throughout current-history results. (role: recent area contributor; confidence: high; commits: dcb20658fca8, 1362490b804e, 5f8a60c03a27; files: extensions/openshell/src/backend.ts, extensions/openshell/src/mirror.ts)
  • jacobtomlinson: The available history records the earlier OpenShell mirror-boundary hardening commit. (role: earlier mirror-boundary contributor; confidence: medium; commits: 3b9dab0ece46; files: extensions/openshell/src/mirror.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Let the exact-head OpenShell E2E complete and confirm its recorded host-link, remote-link exclusion, and hardlink-canary assertions.

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

Copy link
Copy Markdown
Contributor Author

The remaining live-proof request in the latest ClawSweeper review is now satisfied on b2e35d4. The full pnpm test:e2e:openshell suite passed 5/5 in 96.82s, including both mirror and remote stress. This exercised actual upload, SSH execution and download, nested host links and conflicting/deleted ancestors, remote-link exclusion, the outside hardlink canary, ordinary writes, and the existing policy deny/allow checks.

Proof environment: isolated Ubuntu 24.04 arm64 container, Node 24.19.0, pnpm 11.22.0, OpenShell 0.0.109, nested Linux Docker 29.1.3 with vfs storage. Source hashes matched the reviewed head. The isolated gateway used authenticated mTLS; protected whoami and sandbox list passed. The fixture's existing host-IP override was set to the actual task-owned Docker gateway. No assertions, authentication, timeouts, or CI thresholds were weakened. The hosted bootstrap failure is separately recorded in #131134; the initial container setup was completed by installing its missing SSH client.

Exact-head CI is green, the full local OpenShell suite passed 101 tests, and changed-file type/lint/guard checks passed. The net +14 production lines retain one recursive owner rather than adding backup/restore or downstream paths: the required state carries protected-link ancestry and drains started filesystem mutations before the workspace lease is released. Tests are +168/-16; docs +6/-0.

No actionable code findings remain. Proceeding with normal maintainer landing through the repository's native PR workflow.

@steipete
steipete merged commit 23233bc into main Aug 27, 2026
144 checks passed
@steipete
steipete deleted the codex/openshell-preserve-nested-host-symlinks branch August 27, 2026 19:43
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…nclaw#131122)

* fix(openshell): preserve nested host symlinks during mirror sync

Reconcile mirror entries recursively so trusted host symlinks and their ancestors survive remote edits and deletions. Preserve unlink-before-copy hardlink safety and drain pending filesystem work before returning an error. Cover the repair with unit regressions and the real OpenShell E2E flow.

Fixes openclaw#131111

* chore(openshell): satisfy mirror callback lint rules
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation extensions: openshell gateway Gateway runtime maintainer Maintainer-authored PR P1 High-priority user-facing bug, regression, or broken workflow. 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.

[Bug]: OpenShell mirror sync deletes nested host symlinks

1 participant