Skip to content

atelet: sweep crash-leftover temp files at startup - #685

Draft
Lorenzo Gironi (lorenzo85) wants to merge 3 commits into
agent-substrate:mainfrom
lorenzo85:fix/startup-sweep-615
Draft

atelet: sweep crash-leftover temp files at startup#685
Lorenzo Gironi (lorenzo85) wants to merge 3 commits into
agent-substrate:mainfrom
lorenzo85:fix/startup-sweep-615

Conversation

@lorenzo85

@lorenzo85 Lorenzo Gironi (lorenzo85) commented Aug 1, 2026

Copy link
Copy Markdown

Fixes #615

What

Introduces internal/startupsweep, a small registry for startup cleanup tasks. Packages register a (label, dir, glob, removeFn) tuple; main.go runs a single sweeper.Sweep(ctx) before the gRPC server starts.

Two sources of crash-leftover files are wired up:

  • ategcs: substrate-upload-compress-* staging files in /tmp, created by sendBufferedZstd for S3/rustfs uploads and never removed if atelet is killed mid-upload.
  • imagecache: .tmp-* unpack dirs, .rm-* retired layer dirs, and dot-prefixed manifest temp files left behind by a crash mid-operation.

Testing

Unit tests added for startupsweep:

  • Files matching the registered glob are removed; non-matching files are kept.
  • Directories matching the registered glob are removed; non-matching dirs are kept.
  • No-op when there are no matching files.
  • Registration via Add removes matching files correctly.
  • Registering on a nil Sweeper does not panic.
  • Sweeping a non-existent directory does not panic.

Existing imagecache tests updated to use the new sweep interface.

Validated on a local kind cluster by planting crash-leftover files and confirming the sweep removes them at atelet startup:

  • /tmp/substrate-upload-compress-crash-test — GCS upload staging file
  • layers/sha256/.tmp-crash-test — interrupted layer unpack
  • layers/sha256/.rm-deadbeef-crash-test — retired layer not yet removed
  • manifests/sha256/.deadbeef.json.tmp-crash-test — interrupted manifest write

@google-cla

google-cla Bot commented Aug 1, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Introduce internal/startupsweep, a generic registry for cleanup tasks
that run once at atelet startup before the gRPC server accepts traffic.
Any package can register a (label, dir, glob, removeFn) tuple; a single
Sweeper.Sweep(ctx) call in main.go removes all matches.

Wire up two sources of crash-leftover files:
- ategcs: substrate-upload-compress-* staging files in os.TempDir(),
  created by sendBufferedZstd for S3/rustfs uploads and never deleted
  if atelet is killed mid-upload.
- imagecache: .tmp-* unpack dirs and .rm-* retired layer dirs under
  layers/sha256/, and dot-prefixed manifest temp files, all orphaned
  by a crash mid-operation.

Fixes agent-substrate#615
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[P3] Compress temp files in os.TempDir() not cleaned on atelet crash — /tmp fills up

1 participant