Skip to content

fix(patch): keep the update marker on a no-op commit so a retry finalizes#9567

Merged
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/patch-commit-marker-survival
Jun 18, 2026
Merged

fix(patch): keep the update marker on a no-op commit so a retry finalizes#9567
owlstronaut merged 1 commit into
npm:latestfrom
manzoorwanijk:fix/patch-commit-marker-survival

Conversation

@manzoorwanijk

Copy link
Copy Markdown
Contributor

A conflicted npm patch update leaves an edit dir and a .npm-patch-update.json marker that the finalizing npm patch commit reads to finish the update — a metadata-only finalize that drops the renamed-from selector and tolerates the new version not being installed yet.

commit() deleted that marker before checking whether the edit dir produced a diff. So a first commit that did no net work — the conflict resolved to the new version verbatim, giving "nothing to commit" — consumed the marker. A corrected retry then found none, ran a full reify, and failed EPATCHUNUSED (the rebased-to version isn't installed), leaving both the old and new selector in the manifest. The same loss happened on any non-finalizing path (e.g. the EPATCHUNSAFE throw).

Fix

The marker was deleted eagerly only to keep it out of the generated patch. Instead, keep it and teach diffDirs to skip it:

  • diffDirs(originalDir, editedDir, ignore = new Set()) skips a set of root-relative filenames, like it already skips the root package.json.
  • commit() no longer deletes the marker — it reads/parses it (still throwing EPATCHBADMARKER on bad JSON before any diff), and passes new Set([UPDATE_MARKER]) to diffDirs.

The marker now survives any non-finalizing path, so a corrected retry still finalizes. A successful commit removes the whole edit dir (unless --keep-edit-dir), so nothing lingers.

References

Fixes #9566
Follow-up to #9439 (native dependency patching).

@manzoorwanijk manzoorwanijk requested review from a team as code owners June 18, 2026 16:44
@manzoorwanijk manzoorwanijk marked this pull request as draft June 18, 2026 16:44
@manzoorwanijk manzoorwanijk marked this pull request as ready for review June 18, 2026 16:45
@manzoorwanijk manzoorwanijk changed the title fix(patch): keep the update marker on a no-op commit so a corrected retry finalizes fix(patch): keep the update marker on a no-op commit so a retry finalizes Jun 18, 2026
@owlstronaut owlstronaut merged commit 5ddf6cc into npm:latest Jun 18, 2026
26 of 27 checks passed
@manzoorwanijk manzoorwanijk deleted the fix/patch-commit-marker-survival branch June 18, 2026 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] npm patch commit: a no-op resolving commit discards the update marker, so a corrected retry fails EPATCHUNUSED

2 participants