Skip to content

fix(infra): report actual backup tar attempt count in failure message - #119197

Merged
steipete merged 2 commits into
openclaw:mainfrom
wanyongstar:fix/backup-tar-retry-attempt-count
Aug 8, 2026
Merged

steipete merged 2 commits into
openclaw:mainfrom
wanyongstar:fix/backup-tar-retry-attempt-count

Conversation

@wanyongstar

@wanyongstar wanyongstar commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

fix(infra): report the real attempt count in the backup tar failure message instead of the hardcoded max

What Problem This Solves

writeTarArchiveWithRetry in src/infra/backup-tar-retry.ts wraps the backup tar writer with a bounded retry loop: it only retries node-tar live-write EOF race errors (TAR_BAD_ARCHIVE / "did not encounter expected EOF"), up to BACKUP_TAR_MAX_ATTEMPTS = 3. Any other failure — permission denied, disk full, ENOENT, etc. — is not retryable, so the loop breaks on the very first attempt. Even an EOF failure followed by a non-EOF failure stops after 2 attempts.

The problem is the error thrown at the end: the message hardcodes BACKUP_TAR_MAX_ATTEMPTS into the suffix, so it always claims after 3 attempts, no matter how many times runTar was actually invoked. An operator debugging a backup failure sees (after 3 attempts) for an error that was never retried at all — the message lies about what the system did, which misleads diagnosis (did it really retry? is the retry loop working?) and makes log-based alerting on attempt counts meaningless.

This hits every backup-archive failure that is not an EOF race, plus EOF races capped by a subsequent non-EOF failure — i.e. the common case, not an edge case. Genuine 3-attempt EOF exhaustion is the only scenario where the old message happened to be accurate.

Code evidence: on main, at src/infra/backup-tar-retry.ts:58-59, the suffix is built from the constant rather than the loop state:

const suffix = offendingPath
  ? ` (last offending path: ${offendingPath}, after ${BACKUP_TAR_MAX_ATTEMPTS} attempts)`
  : ` (after ${BACKUP_TAR_MAX_ATTEMPTS} attempts)`;

while the loop above it (src/infra/backup-tar-retry.ts:34-44) can break out after attempt 1 or 2. Minimal reproduction: call writeTarArchiveWithRetry with a runTar that throws new Error("permission denied") — it is called exactly once, yet the thrown error says after 3 attempts. See Real Behavior Proof below.

Root Cause

  • Bug introduced by commit d1684f48a3 (2026-07-13, refactor: delete dead infra and config exports (#106019)), which created src/infra/backup-tar-retry.ts; the hardcoded after ${BACKUP_TAR_MAX_ATTEMPTS} attempts suffix has been there since the file's first version (verified via the GitHub contents API at that ref).
  • Violated invariant: the failure message assumes the loop always runs to exhaustion — that "attempts made" equals BACKUP_TAR_MAX_ATTEMPTS. That assumption only holds when every failure is a retryable EOF race; the loop's own early-break for non-retryable errors breaks it.
  • Trigger condition: any runTar failure that is not an EOF race (e.g. EACCES/EPERM, ENOSPC, a tar usage error) on any attempt — including after one or two successful EOF retries — produces a message reporting 3 attempts when only 1 or 2 were made.

Why This Fix

  • Option A: leave the message generic (drop the count entirely, e.g. just backup archive write failed) — rejected: the attempt count is genuinely useful operational signal when it is accurate; deleting information to avoid a lie is a worse outcome than fixing the count.
  • Option B: make the retry policy match the message (retry non-EOF errors too, so the count is always 3) — rejected: retrying EACCES/ENOSPC class errors is pointless latency (10s + 20s of backoff) for failures that cannot self-heal; the narrow EOF-race retry policy is deliberate (see the comment on isTarEofRaceError).
  • Option C (chosen): track the real attempt count in the loop (attempts = attempt) and format the suffix from it, with correct singular/plural (after 1 attempt / after 2 attempts). Two added lines plus the suffix change; zero behavioral change to the retry policy itself; the message now always reflects what actually happened.

User Impact

  • Affected operations: any failed openclaw backup archive write whose final failure is not an EOF live-write race — the failure surfaces in CLI output and logs via the thrown error's message.
  • Before: Backup archive write failed: permission denied (after 3 attempts) — even though the writer was invoked exactly once and no retry ever happened.
  • After: Backup archive write failed: permission denied (after 1 attempt); an EOF race followed by a real failure reports after 2 attempts. Genuine 3-attempt exhaustion still reports after 3 attempts.
  • Behavior change: only the text of the failure message changes (count now truthful, singular form for 1). The retry policy, backoff timing, temp-path scheme, and thrown error shape are all unchanged. The new text is strictly more accurate for anyone reading logs or support bundles.

Evidence

Setup: the real src/infra/backup-tar-retry.ts module is imported and executed directly (node --import tsx proof.mjs); runTar is injected through the function's own parameter and sleepMs is stubbed to skip the real 10s/20s backoffs. Nothing in the module under test is mocked. The script counts actual runTar invocations, prints the thrown message, and checks whether the reported count equals the real count.

Before (on main)

$ node --import tsx proof.mjs  # HEAD~1
[non-EOF, 1st attempt fails] runTar called 1 time(s)
[non-EOF, 1st attempt fails] error message: Backup archive write failed: permission denied (after 3 attempts)
[non-EOF, 1st attempt fails] reported=3 actual=1 -> FAIL (message lies about attempt count)

[EOF then non-EOF, 2 attempts] runTar called 2 time(s)
[EOF then non-EOF, 2 attempts] error message: Backup archive write failed: disk full (after 3 attempts)
[EOF then non-EOF, 2 attempts] reported=3 actual=2 -> FAIL (message lies about attempt count)

After (with fix)

$ node --import tsx proof.mjs  # HEAD
[non-EOF, 1st attempt fails] runTar called 1 time(s)
[non-EOF, 1st attempt fails] error message: Backup archive write failed: permission denied (after 1 attempt)
[non-EOF, 1st attempt fails] reported=1 actual=1 -> OK (truthful)

[EOF then non-EOF, 2 attempts] runTar called 2 time(s)
[EOF then non-EOF, 2 attempts] error message: Backup archive write failed: disk full (after 2 attempts)
[EOF then non-EOF, 2 attempts] reported=2 actual=2 -> OK (truthful)

Tests and Validation

  • node node_modules/vitest/vitest.mjs run src/infra/backup-create.test.ts -t attempt — 4 passed, 66 skipped (attempt-related cases only; the full file was not run because this Windows workstation has pre-existing environment-specific failures in the broader suite).
  • Manual verification (the proof above): on main, both a 1-attempt non-EOF failure and a 2-attempt EOF-then-non-EOF failure report after 3 attempts; with the fix they report after 1 attempt and after 2 attempts respectively, matching the counted runTar invocations.

@clawsweeper clawsweeper Bot added 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. P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 9:47 PM ET / August 7, 2026, 01:47 UTC.

ClawSweeper review

What this changes

The PR records the actual number of backup tar-write attempts and uses it in the terminal failure message, with regression tests for one- and two-attempt failures.

Regression provenance

Possible regression — probable (reproduction; reviewed change). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep open: current main still misreports early backup-tar failures as three attempts, while this exact head repairs the retry helper’s own diagnostic state without changing retry behavior. No blocking findings; wait for the remaining exact-head lint check before merge.

Priority: P3
Reviewed head: 692675c309bc63110bca00c5b1978b55f31f15ea

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused owner-boundary correction with direct before/after terminal evidence and regression coverage.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body provides before/after terminal output from the real retry module with controlled fault sequences, showing observed invocation counts and corrected messages.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body provides before/after terminal output from the real retry module with controlled fault sequences, showing observed invocation counts and corrected messages.
Evidence reviewed 6 items Current-main defect: A non-EOF tar error breaks the loop immediately, but the terminal suffix always formats the maximum of three attempts.
Owner-boundary repair: The proposed helper records the entered loop attempt and uses that value, including correct singular formatting, in both terminal suffix forms.
Operator-visible caller: Archive creation supplies the real tar writer to the retry helper, so the corrected message reaches backup and migration operators rather than only tests.
Findings None None.
Security None None.

How this fits together

The backup command and migration pre-backup flow create a tar archive through a bounded retry helper. That helper classifies tar errors and returns its terminal message to CLI operators and logs.

flowchart LR
  A[Backup command] --> B[Archive creation]
  C[Migration pre-backup] --> A
  B --> D[Tar retry helper]
  D --> E{Retryable tar error?}
  E -->|yes| D
  E -->|no or exhausted| F[Accurate failure message]
  F --> G[CLI and logs]
Loading

Before merge

  • Complete next step (P2) - No repair job is needed: the submitted branch already contains the narrow owner-boundary fix, with ordinary exact-head check completion remaining.
Agent review details

Security

None.

PR surface

Source +3, Tests +31. Total +34 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 5 2 +3
Tests 1 31 0 +31
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 36 2 +34

Review metrics

Metric Value Why it matters
Production vs test LOC production +3 net; tests +31 The small production increase is justified by carrying the retry loop’s authoritative attempt count into operator-visible failure text; tests cover the previously unasserted early-exit cases.

Technical review

Best possible solution:

Merge this loop-owner correction after exact-head required checks are green, retaining the existing narrow EOF-only retry policy.

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

Yes. A non-EOF injected tar writer follows the current-main early-break path after one invocation while the current helper formats three attempts; the PR body also supplies matching before/after terminal output.

Is this the best way to solve the issue?

Yes. The retry helper owns the loop state, so recording its entered attempt is narrower and safer than changing retry eligibility or asking callers to infer attempts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P3: This corrects low-blast-radius backup diagnostic text without changing archive creation or retry policy.
  • 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. Sufficient (terminal): The PR body provides before/after terminal output from the real retry module with controlled fault sequences, showing observed invocation counts and corrected messages.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before/after terminal output from the real retry module with controlled fault sequences, showing observed invocation counts and corrected messages.

Evidence

What I checked:

Likely related people:

  • vincentkoc: Current-main blame attributes the retry helper’s relevant lines to this contributor’s August 2026 change. (role: recent area contributor; confidence: high; commits: a91468246759; files: src/infra/backup-tar-retry.ts, src/infra/backup-create.test.ts)
  • steipete: The linked merged infra refactor and backup history connect this contributor to the earlier ownership path, though not the current blamed line. (role: earlier backup and infra contributor; confidence: medium; commits: d1684f48a31c; files: src/infra/backup-tar-retry.ts, src/infra/backup-create.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.

History

Review history (6 earlier review cycles)
  • reviewed 2026-08-04T11:33:36.890Z sha 8e12b62 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-04T11:40:33.786Z sha 8e12b62 :: needs real behavior proof before merge. :: none
  • reviewed 2026-08-05T04:04:28.550Z sha 8e12b62 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-06T03:36:12.361Z sha 8e12b62 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-06T05:52:53.124Z sha 8e12b62 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-07T01:40:13.833Z sha 692675c :: needs maintainer review before merge. :: none

@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 5, 2026
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed 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. labels Aug 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-pr-context Candidate: external PR body lacks required problem context or evidence. label Aug 6, 2026
@vincentkoc vincentkoc self-assigned this Aug 6, 2026
@vincentkoc
vincentkoc force-pushed the fix/backup-tar-retry-attempt-count branch from 8e12b62 to cdbe552 Compare August 7, 2026 00:46
@vincentkoc

Copy link
Copy Markdown
Member

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@vincentkoc
vincentkoc force-pushed the fix/backup-tar-retry-attempt-count branch from cdbe552 to 692675c Compare August 7, 2026 01:33
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 7, 2026
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

@clawsweeper re-review

@steipete
steipete merged commit 2bc3144 into openclaw:main Aug 8, 2026
120 of 121 checks passed
@steipete

steipete commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

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

Punchcard-Session: quiet-orchard-orchard-9t

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

3 participants