Skip to content

fix(macos): packaging leaks an attached Peekaboo snapshot image when attach fails on a busy host - #172903

Merged
steipete merged 1 commit into
mainfrom
steipete/mac-snapshot-image-detach
Oct 16, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/mac-snapshot-image-detach

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: pnpm mac:package leaks an attached Peekaboo snapshot disk image (until a manual hdiutil detach /dev/diskN) when hdiutil attach fails after creating the image's devices but before mounting them, which happens with Resource temporarily unavailable on a heavily loaded Mac.

User Impact

User impact: a transient attach failure no longer leaves a disk image attached to the Mac with its backing file deleted. A transient Resource temporarily unavailable attach is retried (up to three attempts in total), and if cleanup ever cannot detach the image it now fails, keeps the files, and prints the exact hdiutil detach command instead of silently leaking. Successful packaging runs behave exactly as before.

Why This Change Was Made

Snapshot cleanup only detached by mountpoint. When the attach had created /dev/diskN but never mounted it, that detach failed, the live-mount check found nothing mounted, and cleanup deleted the image while its devices stayed attached. The standalone cleanup operation that scripts/build-mac-swift.mts runs in a separate process also never knew the image path.

Now, when the mountpoint detach fails, cleanup looks up attachments of the snapshot image in hdiutil info -plist (matching image-path after resolving symlinks on both sides) and detaches the image's whole-disk device. It never uses -force. It then re-checks, and files are only removed once nothing is mounted or attached, so the existing rule that a live mount is never rm -rf'd still holds. The attach retries only on EAGAIN, detaching any devices the failed attempt left behind before trying again. The success path is unchanged: a mountpoint detach already releases the whole image, so no extra hdiutil call runs there.

Evidence

Real hdiutil, macOS 27 (Apple Silicon). A real APFS UDRO image was attached with -nomount to recreate the incident state (/dev/disk8, /dev/disk8s1, the synthesized container /dev/disk11, /dev/disk11s1, nothing mounted). The script's real standalone cleanup entry point then ran against it:

Script Cleanup exit Devices after cleanup Files
origin/main 0 /dev/disk8 /dev/disk8s1 /dev/disk11 /dev/disk11s1 still attached (leak reproduced) deleted
this branch 0 none deleted after detach
this branch, normal mounted path 0 none deleted

The same probe established the facts the fix relies on: image-path is reported exactly as given to attach (not canonicalized); the image's own whole disk is listed first, and detaching it also releases the synthesized APFS container; and detaching an already-gone device exits 1, so the fix verifies by querying again instead of trusting exit codes.

Regression tests (test/scripts/package-mac-app.test.ts, hdiutil/mount stubbed via PATH):

  • The standalone cleanup operation with an attached, unmounted image whose image-path uses a symlinked spelling: it detaches /dev/disk8 and removes the files. If the device detach fails, it exits non-zero, keeps the snapshot, image and mount directory, and prints the hdiutil detach /dev/disk8 command. It never passes -force. Both cases fail against origin/main's script.
  • An EAGAIN attach is retried after its leftover devices are detached, and only the original diagnostic line reaches stderr.
  • The existing diagnostics test still shows non-EAGAIN failures (Permission denied) attaching exactly once, with stderr and exit codes unchanged.

pnpm test test/scripts/package-mac-app.test.ts --maxWorkers=1, pnpm format:check on the touched files, oxlint on the test, /bin/bash -n (Bash 3.2) and git diff --check all pass.

Docs: docs/platforms/mac/dev-setup.md troubleshooting now describes the retry and the retained-cleanup recovery. Release-note context: macOS packaging no longer leaks the Peekaboo snapshot disk image when attach fails transiently on a busy host.

@clawsweeper

clawsweeper Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 15, 2026 07:35
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-16T03:41:46.469011Z ad96d1c New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: macos App: macos scripts Repository scripts size: M labels Oct 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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. labels Oct 15, 2026
@clawsweeper

clawsweeper Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR detaches unmounted Peekaboo snapshot images after failed attachment and retries transient attachment failures.

Example: A failed snapshot attachment leaves /dev/disk8 and its APFS container attached without a mounted volume.

  • Before: Cleanup reports success and deletes Peekaboo.dmg while its devices remain attached.
  • After: Cleanup detaches the image's whole disk before deleting files, or retains them and prints a recovery command.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, useful repair with native cleanup results and meaningful boundary regressions; required CI remains red without an established diff-caused defect.
Proof confidence 🐚 platinum hermit (4/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its body records the real standalone cleanup entry point on macOS 27 releasing an unmounted APFS image and preserving normal mounted cleanup, while retry behavior is covered with stubbed hdiutil.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A transient packaging failure leaves snapshot devices attached after deleting their backing image.
Reason: This maintainer-authored repair addresses an observed resource leak without adding configuration, changing packaged app behavior, or bypassing source verification.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it repairs a concrete packaging cleanup defect still present on main, and no introduced correctness or security defect was found.

Priority: P2
Reviewed head: 838d81d3fea0fef3d59580509fa026f0fcbba902

Before merge

None.

Findings

None.

Agent review details

How this fits together

The macOS packager delegates architecture builds and cleanup to a shell worker, which creates authenticated read-only Peekaboo snapshots and releases their disk images before retiring temporary build files.

flowchart TD
  A[mac package command] --> B[Swift build controller]
  B --> C[Architecture shell worker]
  C --> D[Read only snapshot attachment]
  D --> E[Swift compilation]
  B --> F[Snapshot cleanup]
  F --> G[Detach devices and retire files]
Loading

Technical review

Best possible solution:

Keep snapshot cleanup in the existing architecture worker and detach image-owned devices before removing their backing files.

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

Current-main source exposes the unmounted-attachment leak, and the PR records a native before/after reproduction using a real APFS UDRO image; no target code was executed during this review.

Is this the best way to solve the issue?

The patch repairs the existing cleanup owner, preserves read-only source verification and native diagnostics, and limits retries to the reported transient failure.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 66e67a0758ed.

Provenance checked

  • Architecture-local snapshot cleanup keeps the original intent (00baa02: Concurrent architecture builds require isolated snapshots, settled workers, and retained files and locks when cleanup cannot be verified.)
  • Snapshot attachment diagnostics and retry changes intended behavior with a stated reason (e6efad2: Preserve native hdiutil failure diagnostics and status while keeping successful output quiet; the PR explains why the newly observed EAGAIN failure warrants bounded retries and device cleanup.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

  • Verified PR scope: The pinned introduction diff changes snapshot attachment, device cleanup, standalone cleanup initialization, regression coverage, and troubleshooting documentation. (scripts/lib/mac-swift-build.sh:328, 838d81d3fea0)
  • Current main retains the defect: Main detaches only by mountpoint and permits file removal when no mounted volume is found; standalone cleanup also lacks the snapshot image path. (scripts/lib/mac-swift-build.sh:465, 66e67a0758ed)
  • Cleanup ownership: The controller joins architecture workers before invoking standalone cleanup and retains work and architecture locks when cleanup fails. (scripts/build-mac-swift.mts:118, 838d81d3fea0)
  • Native cleanup evidence: The PR body records real macOS 27 hdiutil results: main leaked the unmounted image's devices, whereas the branch's standalone cleanup released them; normal mounted cleanup also succeeded. (838d81d3fea0)
  • Prior design preserved: improve: build macOS release architectures concurrently #135753 established architecture-local snapshot ownership and retention after uncertain cleanup; this patch extends that owner rather than adding a competing cleanup path. (scripts/lib/mac-swift-build.sh:523, 00baa02687d7)
  • CI remains blocked: The failing shard reports a Windows partition assertion in test/scripts/test-projects.test.ts:85, and the required CI gate fails consequently. These annotations establish no packaging regression; attribution remains unresolved. Downloading full job logs was blocked by the artifact host allowlist. (test/scripts/test-projects.test.ts:85, 838d81d3fea0)

Likely related people:

  • Peter Steinberger: Raw commit 00baa02 adds scripts/lib/mac-swift-build.sh:384 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 00baa02687d7; files: scripts/lib/mac-swift-build.sh)

PR surface

Tests +223, Docs +4, Other +63. Total +290 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 224 1 +223
Docs 1 4 0 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 1 66 3 +63
Total 3 294 4 +290

Review metrics

Metric Value Why it matters
Production versus test growth Production +66/-3; tests +224/-1 Production growth supplies attachment discovery, verified detachment, and bounded retry; tests exercise retry ordering, symlinked image identity, and file retention through the standalone cleanup boundary.

Labels

Label changes:

  • add P2: A busy macOS packaging host can retain attached snapshot devices and require manual recovery; the blast radius is limited to the developer packaging workflow.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: A busy macOS packaging host can retain attached snapshot devices and require manual recovery; the blast radius is limited to the developer packaging workflow.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 15, 2026, 3:51 AM ET / 07:51 UTC.

On a busy host, hdiutil attach can fail with EAGAIN after creating the
snapshot image's devices but before mounting them. Cleanup only detached
by mountpoint, found nothing mounted, and deleted the image while its
devices stayed attached. The standalone cleanup operation also never set
the image path.

When the mountpoint detach fails, cleanup now detaches any attachment of
the snapshot image by its whole-disk device (matched in hdiutil info by
resolved image path, never -force) and fails closed, retaining files and
printing the hdiutil detach command, if it stays attached. Attach retries
EAGAIN up to three attempts, detaching leftovers between attempts.

Release note: macOS packaging no longer leaks the Peekaboo snapshot disk
image when attach fails transiently on a busy host.
@steipete
steipete force-pushed the steipete/mac-snapshot-image-detach branch from 838d81d to ad96d1c Compare October 16, 2026 03:38
@steipete
steipete merged commit e3eefe1 into main Oct 16, 2026
96 checks passed
@steipete
steipete deleted the steipete/mac-snapshot-image-detach branch October 16, 2026 05:35
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 17, 2026
…openclaw#172903)

On a busy host, hdiutil attach can fail with EAGAIN after creating the
snapshot image's devices but before mounting them. Cleanup only detached
by mountpoint, found nothing mounted, and deleted the image while its
devices stayed attached. The standalone cleanup operation also never set
the image path.

When the mountpoint detach fails, cleanup now detaches any attachment of
the snapshot image by its whole-disk device (matched in hdiutil info by
resolved image path, never -force) and fails closed, retaining files and
printing the hdiutil detach command, if it stays attached. Attach retries
EAGAIN up to three attempts, detaching leftovers between attempts.

Release note: macOS packaging no longer leaks the Peekaboo snapshot disk
image when attach fails transiently on a busy host.
hilsbos pushed a commit to hilsbos/openclaw that referenced this pull request Oct 22, 2026
…openclaw#172903)

On a busy host, hdiutil attach can fail with EAGAIN after creating the
snapshot image's devices but before mounting them. Cleanup only detached
by mountpoint, found nothing mounted, and deleted the image while its
devices stayed attached. The standalone cleanup operation also never set
the image path.

When the mountpoint detach fails, cleanup now detaches any attachment of
the snapshot image by its whole-disk device (matched in hdiutil info by
resolved image path, never -force) and fails closed, retaining files and
printing the hdiutil detach command, if it stays attached. Attach retries
EAGAIN up to three attempts, detaching leftovers between attempts.

Release note: macOS packaging no longer leaks the Peekaboo snapshot disk
image when attach fails transiently on a busy host.

(cherry picked from commit e3eefe1)
Co-authored-by: RomneyDa <[email protected]>
RomneyDa pushed a commit that referenced this pull request Oct 27, 2026
…#172903)

On a busy host, hdiutil attach can fail with EAGAIN after creating the
snapshot image's devices but before mounting them. Cleanup only detached
by mountpoint, found nothing mounted, and deleted the image while its
devices stayed attached. The standalone cleanup operation also never set
the image path.

When the mountpoint detach fails, cleanup now detaches any attachment of
the snapshot image by its whole-disk device (matched in hdiutil info by
resolved image path, never -force) and fails closed, retaining files and
printing the hdiutil detach command, if it stays attached. Attach retries
EAGAIN up to three attempts, detaching leftovers between attempts.

Release note: macOS packaging no longer leaks the Peekaboo snapshot disk
image when attach fails transiently on a busy host.

(cherry picked from commit e3eefe1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: macos App: macos docs Improvements or additions to documentation P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: M 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.

1 participant