Repository navigation
fix(macos): DMG packaging leaks an attached disk image when hdiutil attach fails on a busy host - #173686
Conversation
…ttach fails on a busy host On a busy host, hdiutil attach can fail with EAGAIN after creating the image devices but before mounting. create-dmg.sh then skipped detach and deleted the RW image while it stayed attached, and the package-mac-dist DMG audit left the retained release DMG attached. Add scripts/lib/mac-disk-image.sh, which finds every attachment of an image in hdiutil info by real path, detaches its whole-disk device without -force, and fails closed if it stays attached. create-dmg.sh checks before deleting its temp root and preserves it when the image is still attached; the DMG audit runs the device cleanup when its attach did not complete.
|
🦞👀 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 cleans up disk-image devices left by failed macOS DMG attachment and preserves backing files when detachment fails. Example: hdiutil creates /dev/disk8 and synthesized /dev/disk11, then exits 35 before mounting image-rw.dmg.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes a concrete packaging leak still present on current main, with no actionable correctness or security finding. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherThe macOS packaging scripts turn app bundles and retained notarization artifacts into distributable DMGs; their exit handlers own temporary mounts, image devices, and backing-file cleanup. flowchart TD
A[App bundle or retained DMG] --> B[Packaging script]
B --> C[hdiutil attach]
C --> D[Failed attachment]
D --> E[Shared image cleanup]
E --> F[Discover and detach whole disk]
F --> G[Verify removal or preserve files]
Technical reviewBest possible solution: Use the shared image-device cleanup in both failed-attachment paths while retaining the existing successful-mount cleanup behavior. Do we have a high-confidence way to reproduce the issue? Current-main source exposes the failed-attach cleanup gap, and the PR records matching native macOS reproduction; this read-only review ran no target code. Is this the best way to solve the issue? The change repairs attachment ownership directly by matching canonical image paths, detaching the owning whole disk, and checking the resulting state before deleting backing files. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 680e6b5e329b. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceTests +126, Other +60. Total +186 across 6 files. Added test files: 0. View PR surface stats
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, 11:14 PM ET / October 16, 2026, 03:14 UTC. |
|
Merged via squash.
|
…ttach fails on a busy host (openclaw#173686) On a busy host, hdiutil attach can fail with EAGAIN after creating the image devices but before mounting. create-dmg.sh then skipped detach and deleted the RW image while it stayed attached, and the package-mac-dist DMG audit left the retained release DMG attached. Add scripts/lib/mac-disk-image.sh, which finds every attachment of an image in hdiutil info by real path, detaches its whole-disk device without -force, and fails closed if it stays attached. create-dmg.sh checks before deleting its temp root and preserves it when the image is still attached; the DMG audit runs the device cleanup when its attach did not complete.
…oo snapshots (#173934) mac-swift-build.sh carried a private copy of the attachment lookup and fail-closed detach that scripts/lib/mac-disk-image.sh already provides (#173686). Source the shared helper next to the worker so both the sourced packager path and the standalone per-architecture worker resolve it, keep the snapshot attach EAGAIN retry loop, and call detach_disk_image between attempts and in cleanup. Release-note context: no packaging behavior change; a snapshot image that stays attached now reports the shared wording "ERROR: disk image <path> is still attached; detach it with: hdiutil detach /dev/diskN".
…oo snapshots (openclaw#173934) mac-swift-build.sh carried a private copy of the attachment lookup and fail-closed detach that scripts/lib/mac-disk-image.sh already provides (openclaw#173686). Source the shared helper next to the worker so both the sourced packager path and the standalone per-architecture worker resolve it, keep the snapshot attach EAGAIN retry loop, and call detach_disk_image between attempts and in cleanup. Release-note context: no packaging behavior change; a snapshot image that stays attached now reports the shared wording "ERROR: disk image <path> is still attached; detach it with: hdiutil detach /dev/diskN".
…ttach fails on a busy host (openclaw#173686) On a busy host, hdiutil attach can fail with EAGAIN after creating the image devices but before mounting. create-dmg.sh then skipped detach and deleted the RW image while it stayed attached, and the package-mac-dist DMG audit left the retained release DMG attached. Add scripts/lib/mac-disk-image.sh, which finds every attachment of an image in hdiutil info by real path, detaches its whole-disk device without -force, and fails closed if it stays attached. create-dmg.sh checks before deleting its temp root and preserves it when the image is still attached; the DMG audit runs the device cleanup when its attach did not complete. (cherry picked from commit 2e6caad) Co-authored-by: RomneyDa <[email protected]>
…ttach fails on a busy host (#173686) On a busy host, hdiutil attach can fail with EAGAIN after creating the image devices but before mounting. create-dmg.sh then skipped detach and deleted the RW image while it stayed attached, and the package-mac-dist DMG audit left the retained release DMG attached. Add scripts/lib/mac-disk-image.sh, which finds every attachment of an image in hdiutil info by real path, detaches its whole-disk device without -force, and fails closed if it stays attached. create-dmg.sh checks before deleting its temp root and preserves it when the image is still attached; the DMG audit runs the device cleanup when its attach did not complete. (cherry picked from commit 2e6caad)
Related: #172903
What Problem This Solves
Fixes: macOS DMG packaging leaves disk images attached on the build host when
hdiutil attachfails on a busy machine, andcreate-dmg.shthen deletes the image file out from under the still-attached devices.User Impact
Release and local DMG packaging no longer accumulate orphaned
/dev/diskNattachments after a transient attach failure. If an image cannot be detached, packaging fails, keeps the files, and prints the exacthdiutil detach /dev/diskNcommand to run.Why This Change Was Made
On a busy host,
hdiutil attach ... -mountpoint M IMAGEcan fail withResource temporarily unavailableafter it has created the image's devices (for example/dev/disk8plus the synthesized APFS container/dev/disk11) but before mounting. Both scripts only detached when the attach had succeeded, so this state was never cleaned up:scripts/create-dmg.shskipped detach and ranrm -rfon the temp root, deleting the RW image while it stayed attached.scripts/package-mac-dist.sh(audit_retained_dmg_async_frames, notarization resume) left the retained release DMG attached.This is the same leak class #172903 fixes for the Peekaboo snapshot image. The new shared
scripts/lib/mac-disk-image.shuses that approach: find every attachment of the image inhdiutil info -plistby real path, detach its whole-disk device withhdiutil detach -quiet(never-force), re-query to confirm, and fail closed if it is still attached.create-dmg.shchecks before deleting its temp root on every exit and preserves it if the image stays attached; the DMG audit runs the device cleanup when its attach did not complete.mac-swift-build.shcan adopt the helper once #172903 lands.Release-note context: macOS packaging (
scripts/create-dmg.sh,scripts/package-mac-dist.sh --resume-notarization) detaches disk images by device after a failed attach instead of leaking them; maintainer/release tooling only, no app behavior change.Evidence
Real
hdiutilon macOS 27 (hdiutilwrapped soattachrunsattach -nomountand then fails with the EAGAIN message, reproducing the leaked state exactly; every other command is the real/usr/bin/hdiutil):create-dmg.shonmain: exit 35, temp root deleted,hdiutil infostill lists the deletedimage-rw.dmgattached as/dev/disk8,/dev/disk8s1,/dev/disk11,/dev/disk11s1.create-dmg.shwith this change: exit 35, temp root deleted, no attachment left.audit_retained_dmg_async_framesonmain: exit 35, release DMG still attached as/dev/disk8+/dev/disk11. With this change: exit 35, nothing attached.main-run images (one whose file was already deleted), so the host was left clean.Focused tests (
pnpm test <file> --maxWorkers=1):test/scripts/create-dmg.test.ts: 16 passed. The new failed-attach cases (detach succeeds / detach fails) fail againstmain's script.test/scripts/package-mac-dist.test.ts: 29 passed. The new failed-audit-attach cases (detach succeeds / detach fails) fail againstmain's script.test/scripts/build-and-run-mac.test.tsmacOS Bash selection: 137 passed (the helper is pinned to/bin/bashand scanned for Bash 3.2 compatibility).node scripts/run-tsgo-core-test-shards.mjs root,oxfmt --checkandoxlinton the touched tests, and/bin/bash -non the touched scripts all pass.Test cost: the two new
create-dmgcases run about 0.6 s each. The two newpackage-mac-distcases run about 4–5 s each, measured on a heavily loaded host (load average around 200), because they go through the real--resume-notarizationentry point with a built checkpoint; the existing checkpoint cases in that file have the same shape.