Repository navigation
fix(macos): packaging leaks an attached Peekaboo snapshot image when attach fails on a busy host - #172903
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
Codex review: needs maintainer review before merge. What this changesThis 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete 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 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceTests +223, Docs +4, Other +63. Total +290 across 3 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment 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.
838d81d to
ad96d1c
Compare
|
Merged via squash.
|
…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.
…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]>
…#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)
What Problem This Solves
Fixes:
pnpm mac:packageleaks an attached Peekaboo snapshot disk image (until a manualhdiutil detach /dev/diskN) whenhdiutil attachfails after creating the image's devices but before mounting them, which happens withResource temporarily unavailableon 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 unavailableattach 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 exacthdiutil detachcommand 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/diskNbut never mounted it, that detach failed, the live-mount check found nothing mounted, and cleanup deleted the image while its devices stayed attached. The standalonecleanupoperation thatscripts/build-mac-swift.mtsruns 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(matchingimage-pathafter 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 neverrm -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 extrahdiutilcall runs there.Evidence
Real
hdiutil, macOS 27 (Apple Silicon). A real APFS UDRO image was attached with-nomountto recreate the incident state (/dev/disk8,/dev/disk8s1, the synthesized container/dev/disk11,/dev/disk11s1, nothing mounted). The script's real standalonecleanupentry point then ran against it:origin/main/dev/disk8 /dev/disk8s1 /dev/disk11 /dev/disk11s1still attached (leak reproduced)The same probe established the facts the fix relies on:
image-pathis 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 viaPATH):cleanupoperation with an attached, unmounted image whoseimage-pathuses a symlinked spelling: it detaches/dev/disk8and removes the files. If the device detach fails, it exits non-zero, keeps the snapshot, image and mount directory, and prints thehdiutil detach /dev/disk8command. It never passes-force. Both cases fail againstorigin/main's script.Permission denied) attaching exactly once, with stderr and exit codes unchanged.pnpm test test/scripts/package-mac-app.test.ts --maxWorkers=1,pnpm format:checkon the touched files,oxlinton the test,/bin/bash -n(Bash 3.2) andgit diff --checkall pass.Docs:
docs/platforms/mac/dev-setup.mdtroubleshooting 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.