Skip to content

Shared-layer lifecycle: accounting, eviction, recovery, materialization - #458

Open
chruffins wants to merge 1 commit into
hypeship/rootfs-compositionfrom
hypeship/storage-lifecycle
Open

Shared-layer lifecycle: accounting, eviction, recovery, materialization#458
chruffins wants to merge 1 commit into
hypeship/rootfs-compositionfrom
hypeship/storage-lifecycle

Conversation

@chruffins

@chruffins chruffins commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

summary

Capstone stage of the image-storage project — finishes migration, eviction, accounting, recovery, and observability on the shared-layer path.

  • Materialization in builds: after a pull, each manifest layer is materialized into images/layers/<digest>/ (best effort; the composed rootfs still comes from blobs, so an artifact failure is logged and only degrades sharing).
  • Platform fallback: native per-layer artifacts are enabled only on Linux when running as root. Rootless Linux and macOS skip background layer materialization and continue using the merged rootfs composition path with userspace whiteout handling. Image contents remain unchanged; unsupported hosts only lose per-layer sharing.
  • Reference-protected eviction: image deletion evicts only layer artifacts unreferenced by any remaining manifest model; a 10-minute grace period keeps fresh artifacts safe from racing in-flight builds. Startup also evicts orphans left by an unclean shutdown.
  • Interrupted-build recovery: stale .unpack-* / .install-* / .tag-stage-* temp directories are swept at startup (age-gated so live builds are untouched).
  • Layer-aware accounting: with materialization wired into the pull path, layer artifact bytes now actually land in the TotalOCICacheBytes bucket alongside OCI blobs, so CurrentImageStorageBytes (ready rootfs + cache/layers) counts them exactly once and capacity admission sees the real footprint.
  • Observability: hypeman_images_layer_artifacts_evicted_total counter plus slog eviction summaries and per-layer materialization warnings.
  • Legacy flattened images remain readable and bootable; they carry no manifest model and no layer references, and are retired only through the existing delete/promotion paths.

validation

  • End-to-end lifecycle test: two images sharing a base layer materialize the base once; deleting one image keeps the shared layer; deleting the last reference evicts everything.
  • Accounting, grace-period, reference-protection, stale-temp-dir, and unsupported-platform fallback tests.
  • Targeted layer and lifecycle tests pass on a rootless host. The full image package suite is blocked only by Docker Hub anonymous pull rate limits (TOOMANYREQUESTS).
  • Earlier broader validation passed except Docker Hub pulls (anonymous rate limit) and VM lifecycle tests, which require network-bridge privileges; both failures were also present on unmodified main.
  • CI is unavailable during this work; all validation is local.

rebase and follow-up hardening

Rebased onto the current composition and layer-artifact stack. The lifecycle caller now uses the manager's probed native-artifact capability, so Linux-root hosts whose layer-store filesystem lacks mknod or trusted overlay xattrs take the merged-rootfs fallback instead of repeatedly attempting native materialization.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using default effort and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 33c8ca3. Configure here.

Comment thread lib/images/layer_gc.go
info, statErr := os.Stat(dirPath)
if statErr != nil || info.ModTime().After(cutoff) {
continue
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Eviction can wipe in-flight layers

Medium Severity

Layer eviction decides freshness from the digest directory ModTime, and it runs concurrently with materialization. Unpack and mkfs.erofs write inside child temp dirs, so the parent mtime goes stale; DeleteImage can then RemoveAll that tree while a build is still using it, especially during the later unlocked ExportRootfs window before the manifest is written.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 33c8ca3. Configure here.

Comment thread lib/images/manager.go Outdated
if result.CacheHit {
cacheStatus = "hit"
}
m.recordImageBuildPhase(ctx, ref.Digest(), "layer_materialization", time.Since(materializeStart), "success", cacheStatus)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Layer bytes skipped after failed builds

Medium Severity

Materialized layer artifacts are written to the layer store before conversion, but refreshDiskUsageTotals only runs on successful finalize, delete, or startup. After a failed conversion the artifacts remain on disk while TotalImageBytes keeps the stale cached total, so capacity admission undercounts the real footprint.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 33c8ca3. Configure here.

@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 41f4080 to 35de95e Compare August 26, 2026 18:22
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 35de95e to f9a5fcc Compare August 26, 2026 18:46
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from d9caa0e to b0a27b4 Compare August 26, 2026 18:51
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from b0a27b4 to 37b8128 Compare August 26, 2026 18:52
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 37b8128 to 13adf76 Compare August 26, 2026 18:53
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 13adf76 to c0e6c32 Compare August 26, 2026 18:54
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from c0e6c32 to aac8b57 Compare August 26, 2026 18:55
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from aac8b57 to 7464627 Compare August 26, 2026 18:56
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 4467fe9 to 588fff8 Compare August 26, 2026 18:58
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from ac3de8e to 165e42f Compare August 26, 2026 19:30
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 165e42f to 3cac19c Compare August 26, 2026 19:38
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 8ca57c1 to 419c294 Compare August 26, 2026 19:41
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch 2 times, most recently from c238f03 to 5051c46 Compare August 26, 2026 19:49
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 3cf0501 to 10f5e38 Compare August 31, 2026 21:56
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 10f5e38 to 9cbf5fb Compare August 31, 2026 21:59
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch 3 times, most recently from 466f089 to 0fa6aa6 Compare August 31, 2026 22:35
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch 2 times, most recently from 78e404c to 0e1b801 Compare August 31, 2026 23:12
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 0e1b801 to 888f303 Compare August 31, 2026 23:36
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 888f303 to 197ed4c Compare September 1, 2026 16:06
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 197ed4c to 72814fb Compare September 1, 2026 18:56
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from e6597bd to fe533bb Compare September 3, 2026 12:50
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from fe533bb to 962f4d2 Compare September 3, 2026 13:54
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 962f4d2 to 2250812 Compare September 3, 2026 14:02
@chruffins
chruffins force-pushed the hypeship/storage-lifecycle branch from 2250812 to 3787792 Compare September 3, 2026 14:06
Materializes each manifest layer after a pull so sharing degrades instead
of failing the build. Artifacts unreferenced by any manifest model are
evicted, protected by a grace period and by in-flight references held
until the referencing model is durable. Startup sweeps stale staging
directories and orphans left by an unclean shutdown. Evictions are counted
as hypeman_images_layer_artifacts_evicted_total.
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.

1 participant