Skip to content

fix(artifacts): accept APFS image disks ejected with their container - #921

Merged
kaoru0822-kitauji merged 2 commits into
mainfrom
fix/dmg-apfs-detach
Oct 7, 2026
Merged

kaoru0822-kitauji merged 2 commits into
mainfrom
fix/dmg-apfs-detach

Conversation

@kaoru0822-kitauji

Copy link
Copy Markdown
Collaborator

Summary

inspect_artifact failed on every APFS disk image with DMG detach or mount-root cleanup failed (artifact_operation_failed, reason unavailable). APFS is what hdiutil create produces by default on current macOS, so this affects most freshly made DMGs.

Problem and expected behavior

hdiutil attach reports an APFS image as two whole disks: the image disk and a synthesized APFS container.

/dev/disk4    GUID_partition_scheme
/dev/disk4s1  Apple_APFS
/dev/disk5s1  (mounted volume)
/dev/disk5    (synthesized container)

NativeDmgArtifactReader.close() detaches observed whole disks in reverse order. Detaching disk5 also ejects disk4, so the next hdiutil detach /dev/disk4 fails with No such file or directory. The inventory was fine, but the detach failure turned the whole operation into an error.

Reproduction on macOS 26.6.2 (arm64), with an APFS DMG from hdiutil create -srcfolder dir -format UDZO:

  • main: rea inspect-artifact image.dmg --json returns "detail": "DMG detach or mount-root cleanup failed".
  • This branch: a complete inventory, and hdiutil info lists nothing left attached.

Change and scope

When a detach fails, close() asks hdiutil info -plist whether that device is still attached.

  • A device that is no longer listed has already been detached with its image.
  • A device that is still listed, or whose state cannot be read, remains a cleanup failure, as before.

The query goes through the existing NativeDmgHost seam, and the info command is recorded in provenance with a read effect. Detach order and the whole-disk filtering are unchanged.

Contract and boundary impact

  • CLI and MCP/tool-catalog contract: none.
  • Process execution and cleanup: one extra read-only hdiutil info -plist, run only after a failed detach. Cleanup failures are still reported when a device remains attached.
  • Generated metadata: none.

Evidence and regression coverage

tests/boundary/providers/native/nativeDmgArtifactReader.test.ts has two new cases. Both model the real APFS attach output:

  • Detaching the container ejects the image disk. close() succeeds and records info. This fails on main.
  • The device that rejected detach is still attached. close() still fails.

The existing attach-cleanup failure test now answers info with the device still attached.

Validation performed

  • npm run test:focused -- tests/boundary/providers/native/nativeDmgArtifactReader.test.ts: 5 passed.
  • Real APFS DMG through the built CLI (rea inspect-artifact): complete inventory, no image left attached.
  • npm run check:changed: passed.

Compatibility, safety, and release

  • Breaking changes: none.
  • Real Hopper/Ghidra coverage: not applicable.
  • Real OS coverage: macOS 26.6.2 arm64.

🤖 Generated with Claude Code

An APFS disk image attaches as an image disk plus a synthesized APFS
container, and hdiutil reports both as whole disks. Detaching the
container also ejects the image disk, so the reverse-order detach then
failed with "No such file or directory" and every APFS DMG inventory
ended in "DMG detach or mount-root cleanup failed". APFS is the default
format of `hdiutil create` on current macOS.

When a detach fails, ask `hdiutil info -plist` whether the device is
still attached. A device that is gone counts as detached; one that is
still listed, or whose state cannot be read, remains a cleanup failure.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chatgpt-codex-connector

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

Copy link
Copy Markdown

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-07T10:10:31.749168Z b72c079 PR opened
ℹ️ 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.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: b72c079a9a

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

timeoutMs: DETACH_TIMEOUT_MS,
});
const parsed = infoOutputSchema.parse(parse(info.stdout));
this.#provenance.push(command(["info", "-plist"], ["read"]));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Record the fallback query before snapshotting provenance

When the APFS fallback succeeds, this provenance entry is added during close(), but scanCanonicalArtifactInventory() clones reader.provenance() into the snapshot before its finally block invokes close(). Consequently, successful CLI/MCP inventory results never report the new hdiutil info -plist observation—the unit test only sees it because it reads provenance after manually closing the reader. Finalize cleanup before capturing the result provenance, or otherwise propagate cleanup provenance into the returned snapshot.

AGENTS.md reference: AGENTS.md:L54-L54

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Confirmed: scanCanonicalArtifactInventory builds the snapshot, including reader.provenance(), before the finally that calls close(). That timing already applies to the existing detach entries, so neither cleanup command reaches CLI or MCP results.

62634e4 stops recording the info -plist query rather than implying it is observable. The unit test no longer expects it.

Returning cleanup provenance in results would mean closing the reader before the snapshot is built. That changes inventory results for every DMG, so I've left it for a separate change.

The inventory snapshot captures reader provenance before close() runs,
so a `hdiutil info -plist` entry recorded during cleanup never reached
CLI or MCP results. Detach entries already share that timing. Record
neither instead of implying the query is observable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@kaoru0822-kitauji
kaoru0822-kitauji merged commit d93ebec into main Oct 7, 2026
24 checks passed
@kaoru0822-kitauji
kaoru0822-kitauji deleted the fix/dmg-apfs-detach branch October 7, 2026 10:59
darsrc pushed a commit to darsrc/rea that referenced this pull request Oct 10, 2026
fix(artifacts): accept APFS image disks ejected with their container
@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.

2 participants