Skip to content

fix(artifacts): recheck failed DMG detaches before reporting cleanup failure - #1155

Merged
N0zoM1z0 merged 2 commits into
mainfrom
fix/dmg-cleanup-recheck
Oct 9, 2026
Merged

N0zoM1z0 merged 2 commits into
mainfrom
fix/dmg-cleanup-recheck

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Problem

NativeDmgArtifactReader.close() detaches each device once. When a detach fails, it asks hdiutil info once whether the device is still attached, and counts it as a cleanup failure if so. That single check is racy:

  • On APFS images, detaching the synthesized container also ejects the image disk. hdiutil info can still list the ejected device for a moment.
  • A volume that was just read can briefly report busy.

In both cases the cleanup actually succeeds or would succeed, but close() throws DMG detach or mount-root cleanup failed and keeps the mount root. Inventory and extraction callers then report the false failure.

This is the intermittent "Real Apple artifact CLI/MCP E2E" failure in verify:macos-bundle (for example on #1070, #1097 and fix/hopper-block-endpoints). Since #1103 added the cause to the message, the job log shows the mechanism:

DMG detach or mount-root cleanup failed for ".../MacFixture.dmg": hdiutil detach failed: {"arguments":["detach","/dev/disk23"],"exitCode":1,"stderr":"hdiutil: detach failed - No such file or directory\n"}

The device was already gone, but it was still counted as attached. The #1103 review raised the same missing recheck ("Recheck failed devices after completing the detach loop"), and it was still unaddressed on main.

Change

  • After the first detach pass, recheck the remaining devices up to three times, after 250, 500 and 1000 ms:
    • drop any device hdiutil info no longer lists;
    • retry the detach of any device still listed;
    • fail only for devices that stay attached through every recheck.
  • A successful pass skips the waits entirely. A truly stuck device still fails, with its latest hdiutil diagnostic and the mount root kept, as before.
  • NativeDmgHost gains an optional delay, so tests exercise the recheck without real waits. The attach-failure cleanup path goes through close() and gets the same behavior.

Verification

  • npm run test:focused -- tests/boundary/providers/native/nativeDmgArtifactReader.test.ts. Two new cases: a device listed once more after its container's detach ejected it, which matches the CI log; and a device that is busy on its first detach, then detaches within the same close. Both fail on main. The existing APFS, retained-attachment and attach-cleanup cases still pass.
  • The real-hdiutil test "classifies a real hdiutil verify refusal…" fails on this Mac identically on unmodified main. It's environmental and passes on CI runners.
  • Real macOS 26.7 check with this branch: 3 HFS+ and 5 APFS hdiutil create images through rea inspect-artifact. All succeeded, and hdiutil info showed no leftover devices.
  • npm run check:fast

No real Hopper or Ghidra verification was run, because this change does not touch those providers.

🤖 Generated with Claude Code

…failure

NativeDmgArtifactReader.close() detached each device once and, when a
detach failed, asked `hdiutil info` once whether the device was still
attached. On APFS images, detaching the synthesized container ejects the
image disk too. `hdiutil info` can still list that ejected device
briefly, and a just-read volume can report busy. Either way a real
cleanup succeeded but close() reported "DMG detach or mount-root cleanup
failed" and kept the mount root.

macOS CI hit this intermittently in verify:macos-bundle: `hdiutil
detach /dev/disk23` failed with "No such file or directory" (already
ejected) and the device was still counted as attached. The #1103
review also raised the missing recheck.

After the first pass, recheck the remaining devices up to three times
with 250/500/1000 ms settle delays. Drop any that hdiutil no longer
lists, retry the detach of any still listed, and fail only for devices
that stay attached. The host seam gains an optional delay so tests run
without real waits.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Repo admins can enable using credits for code reviews in their settings.

…ion gate

The new busy-device and recheck cases copied the fake hdiutil host and
the APFS close sequence from neighbouring tests, which pushed jscpd to
its 2.5% threshold in Static checks. Share one single-device host
between the busy and retained-attachment cases and one APFS close
helper between the ejected-device cases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@N0zoM1z0 N0zoM1z0 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed detach/recheck ordering, retained-attachment recovery, and attach-failure cleanup. The delayed rechecks keep persistent failures actionable and avoid treating an already-ejected APFS device as a cleanup failure. Independent Linux validation: build, static checks, 11 tests passed (3 macOS-only tests skipped). The exact-head real Apple artifact CLI/MCP CI also passed.

@N0zoM1z0
N0zoM1z0 merged commit 58a91f0 into main Oct 9, 2026
22 checks passed
@N0zoM1z0
N0zoM1z0 deleted the fix/dmg-cleanup-recheck branch October 9, 2026 02:01
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
…failure (morluto#1155)

* fix(artifacts): recheck failed DMG detaches before reporting cleanup failure

NativeDmgArtifactReader.close() detached each device once and, when a
detach failed, asked `hdiutil info` once whether the device was still
attached. On APFS images, detaching the synthesized container ejects the
image disk too. `hdiutil info` can still list that ejected device
briefly, and a just-read volume can report busy. Either way a real
cleanup succeeded but close() reported "DMG detach or mount-root cleanup
failed" and kept the mount root.

macOS CI hit this intermittently in verify:macos-bundle: `hdiutil
detach /dev/disk23` failed with "No such file or directory" (already
ejected) and the device was still counted as attached. The morluto#1103
review also raised the missing recheck.

After the first pass, recheck the remaining devices up to three times
with 250/500/1000 ms settle delays. Drop any that hdiutil no longer
lists, retry the detach of any still listed, and fail only for devices
that stay attached. The host seam gains an optional delay so tests run
without real waits.


* test(artifacts): share DMG detach fixtures to stay under the duplication gate

The new busy-device and recheck cases copied the fake hdiutil host and
the APFS close sequence from neighbouring tests, which pushed jscpd to
its 2.5% threshold in Static checks. Share one single-device host
between the busy and retained-attachment cases and one APFS close
helper between the ejected-device cases.


---------
@morluto morluto added bug Something isn't working area: evidence Evidence, artifacts, and reconstruction labels Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: evidence Evidence, artifacts, and reconstruction bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants