Skip to content

fix(backup): verify and restore select the wrong archive after symlink/.. - #197688

Merged
obviyus merged 4 commits into
openclaw:mainfrom
Malpin07:fix/backup-archive-parent-resolution
Nov 12, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
Malpin07:fix/backup-archive-parent-resolution

Conversation

@Malpin07

Copy link
Copy Markdown
Contributor

Closes #197685

What Problem This Solves

Fixes backup verify and backup restore selecting a different archive when a POSIX input path contains a directory symlink followed by ...

User Impact

Both commands read the archive selected by the filesystem, and missing parent directories are rejected instead of silently selecting a same-named archive. For affected inputs, the reported absolute archivePath retains the parent components.

Why This Change Was Made

Preserve those POSIX components at the existing shared archive input boundary, so verification and extraction use the same path. Other input spelling and Windows resolution retain their current behavior. The repair is confined to existing archive input handling; archive contents and restore-target checks keep their existing owners.

Evidence

Real source-built CLI runs on WSL2 Ubuntu 26.04 / Node 26.12.1, with two valid archives generated by backup create --only-config. Their configurations contain different messages.responsePrefix markers. The linked issue includes the fixture and pre-fix output.

Input Base 4eb318d5 Final f7f6fd6de
Absolute alias/../archive.tar.gz Verifies WRONG; restores WRONG bytes Verifies RIGHT; restores RIGHT bytes
Relative alias/../archive.tar.gz Verifies WRONG; restores WRONG bytes Verifies RIGHT; restores RIGHT bytes
missing/../archive.tar.gz Both commands incorrectly succeed Both exit 1; restore target not created
Direct RIGHT / WRONG archive paths Select corresponding archive Select corresponding archive

Final run: 10 successful CLI calls and 2 expected rejections. Archive manifests, archive hashes, and restored configuration bytes were checked; all child processes exited and temporary state was removed.

Final CLI output excerpts (temporary prefix abbreviated)

backup verify "$fixture/alias/../archive.tar.gz" --json:

{
  "ok": true,
  "archivePath": "<temporary>/fixture/alias/../archive.tar.gz",
  "archiveRoot": "2026-11-12T18-17-37.269+08-00-openclaw-backup",
  "createdAt": "2026-11-12T10:17:37.269Z",
  "runtimeVersion": "2026.11.3",
  "assetCount": 1,
  "entryCount": 2,
  "symlinkCount": 0,
  "sqliteInventoryVerified": true
}

Actual restored configuration:

{"messages":{"responsePrefix":"RIGHT"}}

backup restore "$fixture/missing/../archive.tar.gz" --target "$staging" --json exits 1:

{
  "ok": false,
  "error": {
    "type": "cli_error",
    "message": "Backup archive verification failed: <temporary>/fixture/missing/../archive.tar.gz. Archive does not exist. Check the path and run `openclaw backup verify <archive>` again."
  }
}
  • 8 focused backup test files: 135 passed, 1 Windows-only case skipped. The changed restore suite passed with pnpm test src/commands/backup-restore.test.ts --maxWorkers=1: 20 tests, 20.6 s wall time (16.53 s Vitest). CI seconds are pending the first hosted run.
  • Core and commands-test typechecks, focused typed lint, formatting, test/file line checks, changed-lane selection, and git diff --check passed.
  • Complete pnpm build passed on both base (546.3 s) and final commit (417.9 s), with matching build metadata and clean source trees.
  • Fresh independent review, including the final test placement, found no actionable issues. The final regression checks both verification and restored bytes, missing-input refusal without creating a target, and ordinary alias spelling. The earlier verification-suite regression failed on the original wrong-file selection; it was subsequently moved to the restore suite to stay within the existing file-size limit.

Native Windows/macOS execution, the full repository test suite, and the local ClawSweeper/shared autoreview CLI were not run. Production net change: +8 lines; tests: +47, reusing the existing fixture and adding no new helper module or dependency.

@clawsweeper

clawsweeper Bot commented Nov 12, 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 commands Command implementations size: S labels Nov 12, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 12, 2026
@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves POSIX parent components in input archive paths so verification and restore follow filesystem symlink resolution.

Example: With /backups/alias pointing to physical/child, restore /backups/alias/../archive.tar.gz.

  • Before: Reads /backups/archive.tar.gz and restores its WRONG configuration.
  • After: Reads /backups/physical/archive.tar.gz and restores its RIGHT configuration.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A small, complete repair with shipped-CLI proof and a meaningful regression; required CI remains in progress.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): Source-built CLI evidence on WSL2 and a secretless Node 24 container exercises real archive creation, absolute and relative symlink-parent verification and restore, restored configuration bytes, and rejection controls; the exercised production path is unchanged at the reviewed 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: Verification and restore can silently read a different backup than the pathname selects.
Reason: Correct archive selection is an existing command contract, and the repair is narrow and supported by production CLI evidence.

Merge readiness

✅ Ready for maintainer review

This PR fixes a current wrong-archive selection bug with a focused change and convincing CLI evidence; no actionable findings remain, and exact-head CI is pending.

Priority: P2
Reviewed head: e3554a770dce2d9aac9e7df5518283f1895781e6

Before merge

None.

Findings

None.

Agent review details

How this fits together

The backup CLI passes archive arguments to the shared preparation boundary, which verifies the selected archive and supplies the same pathname to staging extraction.

flowchart TD
  A[Backup CLI] --> B[Prepare archive input]
  B --> C[Filesystem pathname resolution]
  C --> D[Archive verification]
  D --> E[Verification report]
  D --> F[Restore to fresh staging]
Loading

Technical review

Best possible solution:

Land the focused repair at the shared archive input boundary once required CI passes.

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

Current-main source shows lexical parent collapse before filesystem access, and the linked report and collaborator CLI runs demonstrate wrong-archive selection; this review executed no target code.

Is this the best way to solve the issue?

The patch restores filesystem pathname semantics at the existing shared preparation owner without introducing another resolver module or changing archive contents or restore-target policy.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Archive input resolution keeps the original intent (e32d529: Preserve literal whitespace while keeping required-path validation and home expansion.)
  • Restore reporting regression keeps the original intent (b307533: Escape terminal controls in human-readable reports while preserving paths and restored payload bytes.)
  • Existing restore test consolidation keeps the original intent (05c3308: Reduce redundant fixtures and fragmented test families while preserving distinct behavior coverage.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Alix-007: Raw commit b307533 adds src/commands/backup-restore.test.ts:129 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: b307533754a1; files: src/commands/backup-restore.test.ts)
  • Peter Steinberger: Raw commit a1d51ce adds src/commands/backup-verify.ts:464 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: a1d51cede5e0; files: src/commands/backup-verify.ts)
  • Vincent Koc: Raw commit e4758f1 adds src/commands/backup-verify.ts:427 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: e4758f1fc472; files: src/commands/backup-verify.ts)

PR surface

Source +8, Tests 0. Total +8 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 9 1 +8
Tests 1 7 7 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 16 8 +8

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Wrong archive contents can be restored into staging for a specific POSIX symlink-parent input, with explicit activation still required.
  • 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 execution lanes are retired.

History

Review history (1 earlier review cycle)
  • reviewed 2026-11-12T10:36:31.373Z sha f7f6fd6 :: needs maintainer review before merge. :: none

Reviewed November 12, 2026, 6:10 AM ET / 11:10 UTC (Revision 2).

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Proof for head 57ee6d8 (main 4ea8ace merged in, no force-push). Both runs used the built CLI (node openclaw.mjs) in a node:24.22.1 container with no secrets.

Setup: two real archives made with openclaw backup create --only-config. Config A is at dirA/archive.tar.gz, config B at dirB/archive.tar.gz, and dirA/link -> ../dirB/sub. In the shell, cat dirA/link/../archive.tar.gz gives the same bytes as B. Restores went to fresh staging folders, and the live config stayed LIVE in both runs.

case main this PR
dirA/link/../archive.tar.gz (absolute), verify / restore marker A / A (wrong) B / B
link/../archive.tar.gz (relative), verify / restore marker A / A (wrong) B / B
plain absolute dirA/archive.tar.gz A / A A / A
relative archive.tar.gz, no .. A / A A / A
x/../archive.tar.gz, no symlink A / A A / A
missing archive same "Archive does not exist…" error, nothing staged same
restore into a non-empty target refused ("must be empty"), file kept same

Tests: the regression is folded into the existing POSIX restore case, and a redundant multi-line call was collapsed, so net test lines are 0. That case fails on main and passes here. backup-restore and backup-verify tests: 59 passed, 1 skipped.

@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 12, 2026
@obviyus
obviyus merged commit c4bf368 into openclaw:main Nov 12, 2026
117 checks passed
@obviyus

obviyus commented Nov 12, 2026

Copy link
Copy Markdown
Collaborator

Landed in c4bf368. Thanks @Malpin07.

github-actions Bot pushed a commit to u12ebauer/openclaw that referenced this pull request Nov 12, 2026
…k/.. (#197688)

fix(backup): resolve archive paths through symlinks before parent segments

On Linux and macOS, openclaw backup verify and backup restore collapsed a path like link/../archive.tar.gz as text before the system followed the symlink, so they read a different archive than the shell would, and restore staged the wrong backup's config. Outside Windows the parent segments are now kept, so the system resolves them after following the symlink. Windows is unchanged, and no backup format, storage, retention or restore policy changes. No text changes.

Evidence: the real CLI in a secretless node:24.22.1 container with two config-only backups holding different markers and a directory symlink that makes link/../archive.tar.gz resolve to the second archive. On main, verify and restore through that path (absolute and relative) picked the first archive; with this change they pick the same archive the shell reads. A plain absolute path, a relative path without parent segments, a parent segment without a symlink, a missing archive and a non-empty restore target behave the same on both, and live config stays untouched. The folded POSIX restore test fails on main, at net 0 test lines. Details: openclaw/openclaw#197688.

Closes #197685. Thanks @Malpin07.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 13, 2026
…k/.. (openclaw#197688)

fix(backup): resolve archive paths through symlinks before parent segments

On Linux and macOS, openclaw backup verify and backup restore collapsed a path like link/../archive.tar.gz as text before the system followed the symlink, so they read a different archive than the shell would, and restore staged the wrong backup's config. Outside Windows the parent segments are now kept, so the system resolves them after following the symlink. Windows is unchanged, and no backup format, storage, retention or restore policy changes. No text changes.

Evidence: the real CLI in a secretless node:24.22.1 container with two config-only backups holding different markers and a directory symlink that makes link/../archive.tar.gz resolve to the second archive. On main, verify and restore through that path (absolute and relative) picked the first archive; with this change they pick the same archive the shell reads. A plain absolute path, a relative path without parent segments, a parent segment without a symlink, a missing archive and a non-empty restore target behave the same on both, and live config stays untouched. The folded POSIX restore test fails on main, at net 0 test lines. Details: openclaw#197688.

Closes openclaw#197685. Thanks @Malpin07.

Co-authored-by: Ayaan Zaidi <[email protected]>
daniel-lxs added a commit to daniel-lxs/openclaw that referenced this pull request Nov 16, 2026
…nked folder and `..`

`backup create --output` and `backup restore --target` resolved their path
with `path.resolve`, so with `selected -> ../physical/nested`,
`selected/../backup.tar.gz` was written to `./backup.tar.gz` and
`--target selected/../restored` extracted into `./restored`.

Route `resolveBackupArchivePath` (`--output`, `--target`, `<archive>`)
through the shared resolver and drop the archive-only copy of this fix in
backup-verify (openclaw#197688). An untraversable path fails as
`Could not resolve <label>: <OS error>`. `backup verify`/`restore` report
the archive path the filesystem opened.

`plugins install` names the typed path and the OS error when a folder
before `..` is missing, instead of `Plugin path not found: undefined`.
hannesrudolph pushed a commit that referenced this pull request Nov 16, 2026
…der is followed by `..` (#200031)

* fix: local path commands pick a neighbor through a symlinked folder and `..`

`path.resolve` folds `folder/..` as text, but the OS applies `..` to the
folder's real location. With `selected -> ../physical/nested`,
`selected/../plugin-b` installed, read or wrote `./plugin-b` instead of
`physical/plugin-b`, and the command reported success.

Add one resolver in src/infra/home-dir.ts for paths a command is about to
open or write (`resolveFilesystemPath`, and `resolveUserFilesystemPath` with
trimming and `~`). Only a symlink directly before `..` is followed; every
other segment keeps its spelling, so `plugins install --link` still records a
final symlink as typed. Paths without `..`, and Windows, resolve as before. A
missing, unreadable or non-folder segment before `..` leaves the path
unfolded so the I/O reports the OS error.

Route plugin install (local path, archive, npm-pack, local git, marketplace
path), diagnostics export, agents set-identity, infer file inputs and outputs
(replacing the per-command fix from #192718) and the templates project
commands through it. Config-stored paths keep resolveUserPath.

Closes #199950

* fix: reject untraversable paths instead of returning them unfolded

When a segment before `..` was missing, unreadable or a file, the resolver
returned the unfolded path and relied on the I/O to fail. Later steps fold
it again: the media attachment cache calls path.resolve, so
`infer audio transcribe --file missing/../memo.wav` transcribed the lexical
neighbor `./memo.wav`. The loop also dropped a trailing `/` or `/.`, so
`link/../memo.wav/` read a regular file. The audio/video resolver this
replaced rejected all three.

Throw the OS error (ENOENT, ENOTDIR, EACCES) at the resolver, and require a
trailing `/` or `/.` to name a directory when it exists. Plugin install and
`--marketplace` treat an untraversable spec as not a local path and keep
classifying it; template source reading keeps reporting a diagnostic, and
template validation labels discovery failures with the lexical spelling.

Make the `--link` install row assert the linked validate-in-place call, the
path recorded in plugins.load.paths, instead of repeating the copy row.

Move the audio/video `--file` path tests into
capability-cli.media-paths.test-support.ts so capability-cli.test.ts does not
grow past its line cap.

* fix: backup output and restore target pick a neighbor through a symlinked folder and `..`

`backup create --output` and `backup restore --target` resolved their path
with `path.resolve`, so with `selected -> ../physical/nested`,
`selected/../backup.tar.gz` was written to `./backup.tar.gz` and
`--target selected/../restored` extracted into `./restored`.

Route `resolveBackupArchivePath` (`--output`, `--target`, `<archive>`)
through the shared resolver and drop the archive-only copy of this fix in
backup-verify (#197688). An untraversable path fails as
`Could not resolve <label>: <OS error>`. `backup verify`/`restore` report
the archive path the filesystem opened.

`plugins install` names the typed path and the OS error when a folder
before `..` is missing, instead of `Plugin path not found: undefined`.

* chore: restart CI after PostgreSQL conformance runner timeout
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…der is followed by `..` (openclaw#200031)

* fix: local path commands pick a neighbor through a symlinked folder and `..`

`path.resolve` folds `folder/..` as text, but the OS applies `..` to the
folder's real location. With `selected -> ../physical/nested`,
`selected/../plugin-b` installed, read or wrote `./plugin-b` instead of
`physical/plugin-b`, and the command reported success.

Add one resolver in src/infra/home-dir.ts for paths a command is about to
open or write (`resolveFilesystemPath`, and `resolveUserFilesystemPath` with
trimming and `~`). Only a symlink directly before `..` is followed; every
other segment keeps its spelling, so `plugins install --link` still records a
final symlink as typed. Paths without `..`, and Windows, resolve as before. A
missing, unreadable or non-folder segment before `..` leaves the path
unfolded so the I/O reports the OS error.

Route plugin install (local path, archive, npm-pack, local git, marketplace
path), diagnostics export, agents set-identity, infer file inputs and outputs
(replacing the per-command fix from openclaw#192718) and the templates project
commands through it. Config-stored paths keep resolveUserPath.

Closes openclaw#199950

* fix: reject untraversable paths instead of returning them unfolded

When a segment before `..` was missing, unreadable or a file, the resolver
returned the unfolded path and relied on the I/O to fail. Later steps fold
it again: the media attachment cache calls path.resolve, so
`infer audio transcribe --file missing/../memo.wav` transcribed the lexical
neighbor `./memo.wav`. The loop also dropped a trailing `/` or `/.`, so
`link/../memo.wav/` read a regular file. The audio/video resolver this
replaced rejected all three.

Throw the OS error (ENOENT, ENOTDIR, EACCES) at the resolver, and require a
trailing `/` or `/.` to name a directory when it exists. Plugin install and
`--marketplace` treat an untraversable spec as not a local path and keep
classifying it; template source reading keeps reporting a diagnostic, and
template validation labels discovery failures with the lexical spelling.

Make the `--link` install row assert the linked validate-in-place call, the
path recorded in plugins.load.paths, instead of repeating the copy row.

Move the audio/video `--file` path tests into
capability-cli.media-paths.test-support.ts so capability-cli.test.ts does not
grow past its line cap.

* fix: backup output and restore target pick a neighbor through a symlinked folder and `..`

`backup create --output` and `backup restore --target` resolved their path
with `path.resolve`, so with `selected -> ../physical/nested`,
`selected/../backup.tar.gz` was written to `./backup.tar.gz` and
`--target selected/../restored` extracted into `./restored`.

Route `resolveBackupArchivePath` (`--output`, `--target`, `<archive>`)
through the shared resolver and drop the archive-only copy of this fix in
backup-verify (openclaw#197688). An untraversable path fails as
`Could not resolve <label>: <OS error>`. `backup verify`/`restore` report
the archive path the filesystem opened.

`plugins install` names the typed path and the OS error when a folder
before `..` is missing, instead of `Plugin path not found: undefined`.

* chore: restart CI after PostgreSQL conformance runner timeout
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…k/.. (openclaw#197688)

fix(backup): resolve archive paths through symlinks before parent segments

On Linux and macOS, openclaw backup verify and backup restore collapsed a path like link/../archive.tar.gz as text before the system followed the symlink, so they read a different archive than the shell would, and restore staged the wrong backup's config. Outside Windows the parent segments are now kept, so the system resolves them after following the symlink. Windows is unchanged, and no backup format, storage, retention or restore policy changes. No text changes.

Evidence: the real CLI in a secretless node:24.22.1 container with two config-only backups holding different markers and a directory symlink that makes link/../archive.tar.gz resolve to the second archive. On main, verify and restore through that path (absolute and relative) picked the first archive; with this change they pick the same archive the shell reads. A plain absolute path, a relative path without parent segments, a parent segment without a symlink, a missing archive and a non-empty restore target behave the same on both, and live config stays untouched. The folded POSIX restore test fails on main, at net 0 test lines. Details: openclaw#197688.

Closes openclaw#197685. Thanks @Malpin07.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit c4bf368)
Source-x: c4bf368
Backport scope: In backup-verify.ts prepareBackupArchive preserve POSIX filesystem parent semantics with home expansion; leave Windows and archive validation unchanged.
Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit e9c33692959acaa09114e8aaa190a180e594d817)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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]: backup verify and restore select the wrong archive through a symlink parent

2 participants