OpenClawHomeAssistant icon indicating copy to clipboard operation
OpenClawHomeAssistant copied to clipboard

bug: interrupted upgrade-state backups leave unbounded .tar.gz.tmp files included in Home Assistant backups

Open slawa19 opened this issue 1 month ago • 0 comments

Pre-flight checks

  • [x] I updated to the latest add-on version and restarted it.
  • [x] I checked the docs/troubleshooting section first.

What happened?

If the add-on is stopped or killed while backup_state_before_upgrade() is creating a pre-upgrade archive, the current openclaw-state-*.tar.gz.tmp file can remain in /config/.openclaw/upgrade-backups.

On the next start, the script generates a new timestamped filename, so rm -f "$temporary" only targets the new path and does not remove older temporary files. The retention function only matches completed *.tar.gz archives, not *.tar.gz.tmp files.

In the affected installation this accumulated 172 temporary archives using about 104 GiB. Home Assistant Supervisor then included them in an add-on backup because backup_exclude has no matching rule for these temporary files.

The internal pre-upgrade archive itself excludes ./upgrade-backups, so this is not recursive self-inclusion; it is unbounded accumulation of separate interrupted archives, followed by inclusion in Home Assistant backups.

What did you expect to happen?

  • An interrupted pre-upgrade archive should be removed during shutdown or the next add-on start.
  • Stale openclaw-state-*.tar.gz.tmp files should not accumulate.
  • In-progress temporary archives should be excluded from Home Assistant backups.
  • Completed *.tar.gz rollback archives and started-* markers should remain untouched.

Steps to reproduce

  1. Run add-on version 0.5.94 with existing OpenClaw state and no started-<new-version> marker.
  2. Start the add-on so the log reaches Creating pre-upgrade state backup....
  3. Stop or kill the add-on/container before tar completes, so PID 1 cannot execute its normal failure cleanup.
  4. Confirm that /config/.openclaw/upgrade-backups/openclaw-state-*-before-<version>.tar.gz.tmp remains.
  5. Restart later. A new timestamped .tmp file is created; the stale file is not removed.
  6. Repeat to accumulate more temporary files.
  7. Create a Home Assistant backup containing this add-on and observe that the stale .tmp files are included.

Add-on version

0.5.94

OpenClaw version (if known)

2026.9.9 (bcfc888)

Access mode

lan_https

Relevant add-on configuration (redacted)

access_mode: lan_https
timezone: Europe/Kyiv

Add-on logs

The original interrupted-run logs are no longer available after local cleanup. The relevant startup line before an interrupted archive is:

INFO: Creating pre-upgrade state backup for OpenClaw 2026.9.9...

Observed before cleanup:

$ find /config/.openclaw/upgrade-backups -maxdepth 1 -type f -name 'openclaw-state-*.tar.gz.tmp' | wc -l
172

$ du -sh /config/.openclaw/upgrade-backups
approximately 104 GiB

After deleting only the stale *.tar.gz.tmp files, three completed rollback archives and all started-* markers remained; the directory size dropped to about 1.1 GiB.

Additional context

Verified against current main at commit d3b414dc852e572a22def7ba990480c9ccccf829:

  • run.sh: the temporary filename includes a fresh timestamp; startup only removes that newly calculated path.
  • Cleanup after tar failure cannot run when the container/PID 1 is terminated.
  • prune_upgrade_backups() matches only openclaw-state-*.tar.gz.
  • config.yaml backup_exclude has no rule for .openclaw/upgrade-backups/*.tar.gz.tmp.

Suggested minimal root-cause fix:

  1. After acquiring the existing startup lock, remove stale files matching only openclaw-state-*.tar.gz.tmp from the upgrade-backup directory before checking/creating the next archive.
  2. Add a narrowly scoped backup_exclude pattern for .openclaw/upgrade-backups/*.tar.gz.tmp so a Home Assistant backup cannot capture the currently written archive.
  3. Preserve completed *.tar.gz archives and started-* markers.

Environment: Home Assistant add-on container on Debian 12, aarch64.

slawa19 avatar Oct 15 '26 06:10 slawa19