Skip to content

fix(backup): keep whitespace-suffixed git backup repository roots adoptable - #197974

Closed
wangmiao0668000666 wants to merge 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/backup-git-root
Closed

wangmiao0668000666 wants to merge 1 commit into
openclaw:mainfrom
wangmiao0668000666:fix/backup-git-root

Conversation

@wangmiao0668000666

Copy link
Copy Markdown
Contributor

What Problem This Solves

openclaw backup git init --repository <path> verifies an adopted backup repository by comparing git rev-parse --show-toplevel against the requested path. The shared requireGitCommand helper trims the output, so a backup repository whose directory legitimately ends in whitespace (for example /mnt/backups/openclaw ) had its meaningful trailing space stripped; the subsequent fs.realpath then failed with ENOENT (or compared against a different directory) and initialization refused a valid operator-owned repository. The same root-cause shape was approved for the update path in #196654 and already shipped in src/projects/project-checkout.ts.

Precedent: #196654 (same root cause at the update-check call site; this PR covers the git-backup adoption check)

Why This Change Was Made

assertGitRepository in src/snapshot/git-backup.ts now reads the top level through the existing executeGitCommand + requireGitCommandOutput owners and removes only Git's final LF record terminator (replace(/\n$/, "")), preserving filesystem characters in the repository path. The shared requireGitCommand helper is intentionally untouched (many callers rely on its trimmed output for non-path values); only this path-typed call site changes. The probe a few lines below already used the untrimmed runGit result, so the two checks are now consistent.

Production LOC is +5/-1 in one file.

Classification: behavior-completing

User Impact

Adopting a Git backup repository under a whitespace-suffixed directory now verifies and initializes correctly, including the follow-up remote add and first commit. Ordinary repository paths are byte-for-byte unaffected. Creation of a not-yet-existing whitespace-suffixed directory remains owned by @openclaw/fs-safe and is out of scope for this in-repo fix (the regression test pre-creates the private root, which is also the supported adoption flow for existing directories).

Evidence

Exact-head proof receipt

  • Product head SHA: 51820d5e6db4
  • Current-main RED baseline: 76024435027d4ac4e51a58468bb1b5c4842d9fb0
  • Production entry: initializeGitBackupRepository → assertGitRepository in src/snapshot/git-backup.ts (CLI surface: backup git init --repository <path>)
  • Canonical owner exercised: assertGitRepository at src/snapshot/git-backup.ts:162-171
  • Decision surface: whether the adopted repository verifies as the Git worktree root (gates init/remote/commit)
  • Recorder/readback boundary: real filesystem + real git subprocess end-to-end in the existing src/snapshot/git-backup-ownership.test.ts harness (the test initializes, configures identity, commits a file, and reads it back)
  • Acceptance RED: on current main, a pre-created private root named repository fails with ENOENT: no such file or directory, realpath '<tmp>/repository' (the trimmed path) thrown from assertGitRepository
  • Acceptance GREEN: on exact head, the same flow initializes, commits note.txt, and reads back its contents — 10/10 tests pass
  • Legal control: the nine pre-existing ownership/restore/prune tests (missing/corrupt payloads, symlink escape, legacy refs, staging hygiene) all pass unchanged
  • Cleanup: isolated vitest temp dirs only; no production Gateway, session, token, config, or real backup repository was touched

Inspectable RED -> GREEN terminal trace

Vitest shard on the real runner (Node 24.22.1, docker lexiflow-all):

# BASE (76024435027d) + new test, via node scripts/run-vitest.mjs run src/snapshot/git-backup-ownership.test.ts --maxWorkers=1
FAIL src/snapshot/git-backup-ownership.test.ts > initializes and commits in a repository path that ends in whitespace
Error: ENOENT: no such file or directory, realpath '/tmp/.../git-backup-trailing-space-*/repository'
 ❯ assertGitRepository src/snapshot/git-backup.ts:164
Tests  1 failed | 9 passed (10)
# HEAD (51820d5e6db4), same command
Tests  10 passed (10)   Duration ~146s
# Legal control on HEAD: pre-existing ownership, restore, prune, and symlink-escape cases
Tests  10 passed (10)

Verification

  • node scripts/run-vitest.mjs run src/snapshot/git-backup-ownership.test.ts --maxWorkers=1 — 10/10 passed on exact head; RED reproduced on current main with only the new test
  • Not tested: openclaw backup git init end-to-end via the packaged CLI against a live Gateway was not run on the proof host (kernel 3.10 blocks the Gateway runtime); the verified boundary is the real initializeGitBackupRepository path with real git and real filesystem, matching the proof style of the sibling snapshot/backup tests.

Scope and risk

  • Production LOC: +5/-1 (src/snapshot/git-backup.ts)
  • Test LOC: +13 (src/snapshot/git-backup-ownership.test.ts)
  • Existing-solutions preflight: reuses the existing executeGitCommand/requireGitCommandOutput owners and the approved replace(/\n$/, "") predicate from fix(update): preserve Git identity for whitespace-suffixed checkout paths #196654; the shared requireGitCommand signature is unchanged
  • Config/default, protocol/schema, authorization, storage, migration, upgrade impact: none (adoption-time read-only verification)
Maintainer edits
  • Maintainer edits allowed: yes — address review comments directly on this branch.
Maintainer options

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

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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 real behavior proof before merge.

What this changes

Preserve meaningful trailing whitespace when validating a Git backup repository's root path.

Example: Initialize a pre-created private repository at "/mnt/backups/openclaw " through initializeGitBackupRepository.

  • Before: Git's pathname is trimmed to "/mnt/backups/openclaw", causing realpath failure or comparison against another directory.
  • After: Only Git's final LF is removed, allowing the exact repository path to pass validation.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The local correction is small and appears correct, but the stated CLI repair is partial and the required shipped-entry-point proof is absent.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: An operator's whitespace-suffixed backup repository cannot be selected reliably through the advertised CLI flow.
Reason: The backend correction has clear value and negligible complexity, but resolveRequiredBackupPath still strips the CLI argument; this delivers one necessary part of the user-visible repair.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep open: this PR contains a focused fix for a current backup repository validation bug, with no introduced correctness or security defect identified.

Priority: P2
Reviewed head: 51820d5e6db461d8f1040e415d088dc0800b1fd1

Before merge

  • Add real behavior proof - The supplied terminal trace proves baseline failure and fixed initialization through a real-Git integration test, but bypasses the shipped CLI argument resolver that still trims the path; provide CLI output with IPs, credentials, phone numbers, and non-public endpoints redacted. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.

Findings

None.

Tests

  • Missing end-to-end proof: Supply redacted output from the shipped backup git init command using a pre-created whitespace-suffixed directory and distinct trimmed-name neighbor, showing which exact directory is adopted.
Agent review details

How this fits together

The backup subsystem receives repository paths, checks filesystem privacy and Git worktree identity, and supplies validated repositories to initialization, backup creation, verification, restore, and log operations.

flowchart LR
  A[Backup CLI] --> B[Required path resolver]
  B --> C[Backup repository initializer]
  C --> D[Private directory admission]
  C --> E[Git root validation]
  E --> F[Canonical filesystem comparison]
  F --> G[Repository operations]
Loading

Technical review

Best possible solution:

Complete the literal-path repair through the existing CLI and snapshot owners in coordination with #195644.

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

Current-main source directly shows pathname loss before realpath, and the supplied regression trace reports the corresponding baseline failure; no target code was executed during this review.

Is this the best way to solve the issue?

Removing only Git's final LF is the smallest complete correction at assertGitRepository, but the stated CLI outcome also requires preserving the argument before it reaches that owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Introduced patch: The production hunk replaces the trimming helper with existing raw-output and failure-checking owners, then removes exactly one final LF; the added regression exercises initialization using real Git. (src/snapshot/git-backup.ts:163, 51820d5e6db4)
  • Current main remains affected: Current main still passes Git's top-level pathname through requireGitCommand, whose trim removes legal filesystem characters before canonical comparison. (src/snapshot/git-backup.ts:163, 20237d956bb5)
  • CLI boundary still trims paths: backupGitInitCommand invokes resolveRequiredBackupPath, which trims the repository argument before calling the patched initializer; the stated CLI adoption problem therefore remains. (src/commands/backup-shared.ts:111, 51820d5e6db4)
  • Broader overlapping repair: fix(backup): preserve literal repository and restore paths #195644 remains open and includes this Git-root correction plus CLI argument preservation and literal-directory creation, with recorded CLI red/green output; its mergeability is unknown, so safe supersession is not established. (038885153418)
  • Supplied proof boundary: The full PR body supplies baseline-failing and head-passing Vitest output through initializeGitBackupRepository with real filesystem and Git subprocesses, and explicitly states that the packaged CLI was not exercised. (src/snapshot/git-backup-ownership.test.ts:301, 51820d5e6db4)
  • Feature history and intent: History traces canonical-root validation to the original Git backup feature and later shared-Git and filesystem refactors; preserving path characters retains those responsibilities. Follow-history reached the documented unavailable creation-parent object, while the creation commit and relevant source were readable. (src/snapshot/git-backup.ts:164, 37b4fc8621d9)

Likely related people:

  • Richard O’Shaughnessy: Raw commit 151cf8d adds src/snapshot/git-backup.ts:21 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 151cf8db96f9; files: src/snapshot/git-backup.ts)

PR surface

Source +4, Tests +13. Total +17 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 5 1 +4
Tests 1 13 0 +13
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 18 1 +17

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.

Review metrics

Metric Value Why it matters
Production versus test growth Production +5/-1; tests +13/-0 The existing Git execution owners support a small parser correction and one distinct real-Git regression without new production machinery.

Labels

Label changes:

  • add P2: A valid but unusual repository pathname fails backup root validation; the affected surface is limited.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P2: A valid but unusual repository pathname fails backup root validation; the affected surface is limited.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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.

Reviewed November 12, 2026, 6:41 PM ET / 23:41 UTC.

@wangmiao0668000666

Copy link
Copy Markdown
Contributor Author

Closing in favor of #195644, which is the strictly broader repair for the same defect family and is already proof: sufficient / ready for maintainer look:

  • fix(backup): preserve literal repository and restore paths #195644 covers this PR's assertGitRepository git-root correction plus the CLI-side argument preservation (resolveRequiredBackupPath) and literal-directory creation — the "Fix scope: Partial" gap flagged in the review here.
  • This PR's backend hunk is a strict subset of that work, so keeping it open would only duplicate review load.

Two things from this PR that are not in #195644 and may be worth porting there or tracking separately:

  1. Real-git regression in the ownership suite (src/snapshot/git-backup-ownership.test.ts): adopts a pre-created whitespace-suffixed private repository through initializeGitBackupRepository with real git init/identity/commit — red on base (ENOENT realpath '…/repository'), green on head. Distinct from fix(backup): preserve literal repository and restore paths #195644's unit coverage.
  2. Adjacent external gap found while proving: for a non-pre-created trailing-space repository directory, @openclaw/[email protected]'s ensurePrivateDirectory lstat-ENoENTs on the literal path before this module's validation ever runs — so full CLI adoption of a trailing-space directory additionally needs an fs-safe-side fix (out of scope for this repo's PR).

Evidence (base-red/head-green vitest output) remains in the PR body and the branch (fix/backup-git-root @ 51820d5e6db4) if any part of it is useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: XS status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant