Repository navigation
fix(infra): report actual backup tar attempt count in failure message - #119197
Conversation
|
Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 9:47 PM ET / August 7, 2026, 01:47 UTC. ClawSweeper reviewWhat this changesThe 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 provenancePossible regression — probable (reproduction; reviewed change). No predecessor PR is attributed. Merge readinessKeep 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 Review scores
Verification
How this fits togetherThe 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]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +3, Tests +31. Total +34 across 2 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
8e12b62 to
cdbe552
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Punchcard-Session: quiet-orchard-orchard-9t
cdbe552 to
692675c
Compare
|
@clawsweeper re-review |
|
Merged via squash.
|
…openclaw#119197) Punchcard-Session: quiet-orchard-orchard-9t Co-authored-by: Peter Steinberger <[email protected]>
Summary
fix(infra): report the real attempt count in the backup tar failure message instead of the hardcoded maxWhat Problem This Solves
writeTarArchiveWithRetryinsrc/infra/backup-tar-retry.tswraps 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 toBACKUP_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_ATTEMPTSinto the suffix, so it always claimsafter 3 attempts, no matter how many timesrunTarwas 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:while the loop above it (
src/infra/backup-tar-retry.ts:34-44) canbreakout after attempt 1 or 2. Minimal reproduction: callwriteTarArchiveWithRetrywith arunTarthat throwsnew Error("permission denied")— it is called exactly once, yet the thrown error saysafter 3 attempts. See Real Behavior Proof below.Root Cause
d1684f48a3(2026-07-13,refactor: delete dead infra and config exports (#106019)), which createdsrc/infra/backup-tar-retry.ts; the hardcodedafter ${BACKUP_TAR_MAX_ATTEMPTS} attemptssuffix has been there since the file's first version (verified via the GitHub contents API at that ref).BACKUP_TAR_MAX_ATTEMPTS. That assumption only holds when every failure is a retryable EOF race; the loop's own early-breakfor non-retryable errors breaks it.runTarfailure 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
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.EACCES/ENOSPCclass 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 onisTarEofRaceError).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
openclawbackup 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.Backup archive write failed: permission denied (after 3 attempts)— even though the writer was invoked exactly once and no retry ever happened.Backup archive write failed: permission denied (after 1 attempt); an EOF race followed by a real failure reportsafter 2 attempts. Genuine 3-attempt exhaustion still reportsafter 3 attempts.Evidence
Setup: the real
src/infra/backup-tar-retry.tsmodule is imported and executed directly (node --import tsx proof.mjs);runTaris injected through the function's own parameter andsleepMsis stubbed to skip the real 10s/20s backoffs. Nothing in the module under test is mocked. The script counts actualrunTarinvocations, prints the thrown message, and checks whether the reported count equals the real count.Before (on main)
After (with fix)
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).after 3 attempts; with the fix they reportafter 1 attemptandafter 2 attemptsrespectively, matching the countedrunTarinvocations.