Skip to content

fix(install): a converged install leaves an identical .apm-pin marker untouched - #4794

Merged
Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
danielmeppiel-cache-pin-idempotent
Nov 22, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 4 commits into
mainfrom
danielmeppiel-cache-pin-idempotent

Conversation

@danielmeppiel

@danielmeppiel Daniel Meppiel (danielmeppiel) commented Nov 22, 2026 •

Copy link
Copy Markdown
Collaborator

Description

install/cache_pin.py::write_marker rewrote every apm_modules/<pkg>/.apm-pin cache-pin marker on every install, with identical bytes. So no apm install was ever write-free: a tree-10 no-op made 10 marker rewrites. This blocks a strict no-op fast path (#4775), which may replay only a run that wrote nothing, and it adds needless writes to every warm install.

Changes to the marker write (the only writer of .apm-pin):

  • An existing regular-file marker with identical bytes is left untouched; it is read without following links.
  • Otherwise the marker is written atomically as a regular file: a temp file in the same directory, fsync, then os.replace over the old entry. An existing link or other non-regular entry is replaced, never written through. A directory in the way is left alone, the temp file is removed, and install continues as before (silent, surfaced by the drift-replay verify step).
  • The marker format does not change.

Effect: marker rewrites per tree-10 no-op go from 10 to 0. Found by the #4775 recorder (ABAB#3 at 7161255: not recorded ['write:.../apm_modules/perf-org/pkg-000/.apm-pin', ...]).

Issue and approved scope

Issue: Fixes #4790

Human scope-approval comment: #4790 (accepted, 0.38.0 bug; VP ruling 19:41).

Does this PR complete the issue, or what remains? Completes it.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Maintenance / refactor

Testing

  • Tested locally (host test slots saturated; CI validates)
  • All existing tests pass
  • Added tests for new functionality (if applicable)

tests/unit/install/test_cache_pin_idempotent.py:

  • a second write of an identical marker keeps its bytes, mtime and inode;
  • a missing marker is written; a different marker is rewritten;
  • a symlinked marker becomes a regular file and the link target stays unchanged (bytes and mtime), also when the target holds identical bytes (POSIX);
  • a directory in the way is left and no temp file is left behind.

Changelog

  • One fragment per section: changelog.d/4794.fixed.md
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • N/A -- this PR does not change OpenAPM-observable behaviour.

… untouched

write_marker rewrote every apm_modules/<pkg>/.apm-pin on every install, so a
no-op install was never write-free (10 marker rewrites per tree-10 no-op).
An existing regular-file marker with identical bytes is now left as is; a
missing, different or symlinked marker is still (re)written. No marker
format change.

apm-spec-waiver: skips rewriting a byte-identical cache marker; the marker format and every observable outcome are unchanged

Co-authored-by: Copilot App <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 22, 2026 18:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

An unreadable but writable marker triggers PermissionError and skips the best-effort write, regressing self-healing for markers that could previously be repaired.

1 open issue
What changed in this PR

This PR addresses #4790 by avoiding redundant .apm-pin writes during converged installs, removing one obstacle to the write-free no-op fast path proposed in #4775.

Changes:

  • Skip rewriting identical regular-file markers without changing their format.
  • Add regression tests for identical, missing, different and symlinked markers.
  • Document the reduced marker writes in a changelog fragment.
File Description
tests/​unit/​install/​test_cache_pin_idempotent.py Tests marker preservation and rewrite behavior.
src/​apm_cli/​install/​cache_pin.py Compares existing marker bytes before writing.
changelog.d/​4794.fixed.md Records the user-visible install improvement.

Review effort: Balanced

Comment thread src/apm_cli/install/cache_pin.py Resolved
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
…nstall

A full eligible install records every input it observes (files read and
their SHA-256, directories listed, paths probed, realpath answers, env vars
read). When that run was itself a no-op (no writes, no network or subprocess
outside org-policy discovery, no prompt, clean exit 0, one No changes
summary) the inputs are stamped in the cache root. A later run whose
recorded inputs are all identical, whose LIVE org policy routes to the same
fingerprint and whose deployed files match the lockfile content hashes
replays the recorded output and writes nothing; anything else runs the full
pipeline. Off by default: APM_INSTALL_FAST_PATH=1 opts in (#4770 re-scope).

Rebased on #4794 (cache-pin markers no longer rewritten on a no-op).
Squash of the reviewed L5 history (backup ref l5-backup-6b1395d).

apm-spec-waiver: the opt-in no-op replay reproduces the full pipeline's observable install output and state; no OpenAPM requirement changes

Co-authored-by: Copilot App <[email protected]>
The marker is written to a temp file in the same directory and renamed over
the old entry, so an existing link or other non-regular entry is replaced
and never written through; an identical regular-file marker is still left
untouched. Tests: a symlinked marker becomes a regular file and its target
is unchanged; a directory in the way leaves no temp file behind.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
…nstall

A full eligible install records every input it observes (files read and
their SHA-256, directories listed, paths probed, realpath answers, env vars
read). When that run was itself a no-op (no writes, no network or subprocess
outside org-policy discovery, no prompt, clean exit 0, one No changes
summary) the inputs are stamped in the cache root. A later run whose
recorded inputs are all identical, whose LIVE org policy routes to the same
fingerprint and whose deployed files match the lockfile content hashes
replays the recorded output and writes nothing; anything else runs the full
pipeline. Off by default: APM_INSTALL_FAST_PATH=1 opts in (#4770 re-scope).

Rebased on #4794 (cache-pin markers no longer rewritten on a no-op).
Squash of the reviewed L5 history (backup ref l5-backup-6b1395d).

apm-spec-waiver: the opt-in no-op replay reproduces the full pipeline's observable install output and state; no OpenAPM requirement changes

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A marker read failure aborts repair even when atomic replacement is permitted, leaving stale cache markers unrepaired.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Treat marker read failures as cache misses

src/​apm_cli/​install/​cache_pin.py:90

A read failure now prevents the marker from being repaired. For example, a stale write-only marker (mode 0200) makes the comparison raise PermissionError, so the outer handler returns even when the package directory permits atomic replacement. Treat a failed comparison as a cache miss and still attempt _replace_marker.

Review effort: Balanced

A failed comparison (for example a write-only marker) is a miss, so the
best-effort atomic write still runs, as before this change.

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
…nstall

A full eligible install records every input it observes (files read and
their SHA-256, directories listed, paths probed, realpath answers, env vars
read). When that run was itself a no-op (no writes, no network or subprocess
outside org-policy discovery, no prompt, clean exit 0, one No changes
summary) the inputs are stamped in the cache root. A later run whose
recorded inputs are all identical, whose LIVE org policy routes to the same
fingerprint and whose deployed files match the lockfile content hashes
replays the recorded output and writes nothing; anything else runs the full
pipeline. Off by default: APM_INSTALL_FAST_PATH=1 opts in (#4770 re-scope).

Rebased on #4794 (cache-pin markers no longer rewritten on a no-op).
Squash of the reviewed L5 history (backup ref l5-backup-6b1395d).

apm-spec-waiver: the opt-in no-op replay reproduces the full pipeline's observable install output and state; no OpenAPM requirement changes

Co-authored-by: Copilot App <[email protected]>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

The new cache-pin tests perform real filesystem I/O but are marked as unit tests, violating the no-filesystem unit-test definition and placing them in the wrong test selections.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

Medium severity Classify filesystem marker tests as component, not unit

tests/​unit/​install/​test_cache_pin_idempotent.py:19

Please classify this module as component: every test exercises real filesystem I/O through tmp_path and write_marker, including metadata, symlinks and permissions. pyproject.toml:217-218 defines unit as having no filesystem access, and the existing marker tests use component in tests/integration/test_cache_pin.py:37-40. Using unit incorrectly includes these tests in pure-logic selections and excludes them from component selections.

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 82f3d22 into main Nov 22, 2026
69 of 72 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-cache-pin-idempotent branch November 22, 2026 19:55
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
…nstall

A full eligible install records every input it observes (files read and
their SHA-256, directories listed, paths probed, realpath answers, env vars
read). When that run was itself a no-op (no writes, no network or subprocess
outside org-policy discovery, no prompt, clean exit 0, one No changes
summary) the inputs are stamped in the cache root. A later run whose
recorded inputs are all identical, whose LIVE org policy routes to the same
fingerprint and whose deployed files match the lockfile content hashes
replays the recorded output and writes nothing; anything else runs the full
pipeline. Off by default: APM_INSTALL_FAST_PATH=1 opts in (#4770 re-scope).

Rebased on #4794 (cache-pin markers no longer rewritten on a no-op).
Squash of the reviewed L5 history (backup ref l5-backup-6b1395d).

apm-spec-waiver: the opt-in no-op replay reproduces the full pipeline's observable install output and state; no OpenAPM requirement changes

Co-authored-by: Copilot App <[email protected]>
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] install rewrites identical .apm-pin markers on every run (no-op install is not write-free)

2 participants