Skip to content

fix(install): projects installed before 0.37 upgrade seamlessly (#4398) - #4522

Merged
Daniel Meppiel (danielmeppiel) merged 18 commits into
train/0.37-final-2from
danielmeppiel-seamless-legacy-upgrade-4398
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 18 commits into
train/0.37-final-2from
danielmeppiel-seamless-legacy-upgrade-4398

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

The first 0.37 install of a project last installed by an APM before 0.37 refused unedited managed files whose render changed (for example the 0.35 Cursor applyTo: "**" rule and the Codex agent with a relative link). It kept them, named them and exited 1, and the user had to move each one aside by hand. Daniel ruled this a 0.37 tag-gating bug: the upgrade must be seamless, as with npm.

Mechanism, owned by core/deployment_ledger.py:

  • legacy_lock_hashes reads the recorded hashes only from a lock stamped before 0.37, or one with no stamp. A claim recorded with conflicting hashes is dropped.
  • DeploymentMaterializationSession.legacy_owned(path, claim) proves APM wrote the file when three things hold: the file holds the recorded bytes, the lock predates 0.37, and git_tracked_clean(path). git_tracked_clean means git ls-files --error-unmatch succeeds and git status --porcelain is empty. Outside a work tree, or on any git error, it fails closed.
  • overwrite_authorized accepts that proof. The file is re-rendered silently once, with receipts and a new lock written, so the next run uses the 0.37 evidence model.
  • A file whose bytes differ from the recorded hash is a proven edit. It is kept byte-identical and named once via kept_edit_message(proven_edit=True) (fix(install): one owner and one message for a kept edited file #4504). It warns with exit 0 when the package renders the recorded bytes, and errors with exit 1 when it renders new bytes.
  • install --frozen verifies and never migrates: legacy-owned files are adopted as they are, and nothing is written.
  • Locks stamped 0.37 or later keep the install overwrites user-edited managed files when no deployment receipt exists #4360 rule: a lock hash is never evidence.

Stacked on #4504 (shared kept template). This PR's own commits start after 5b69e45.

Issue and approved scope

Issue: Fixes #4398

Human scope-approval comment: #4398 (apm-scope:v1 record). Daniel's 21:30 ruling, relayed by the conductor, makes part 2 tag-gating. The steward's acceptance cells C1-C5 were relayed by PM v2, including the "< 0.37" boundary update.

Does this PR complete the issue, or what remains? It completes it. Part 1 (the --frozen locked-render fallback) is fixed by 3de827c. The steward accepted closing it without a new cell: under --frozen the current render is the locked render, and #4519 refuses dropped targets and removed dependencies first. The pins are test_architecture_lockfile_write_authority, C4, and #4519's dropped-target frozen cell.

Type of change

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

Testing

  • Tested locally (apm 0.37.0 editable, -p no:xdist, via the host guard):
    • pytest tests/integration/test_legacy_lock_upgrade_lifecycle.py tests/quality/test_lifecycle_bug_ledger.py tests/integration/test_receiptless_overwrite_lifecycle.py: 27 passed.
    • Fixtures: tests/fixtures/pre036_upgrade/v0.35.1 was generated by the released apm-cli 0.35.1 wheel. v0.36.1 was built from the v0.36.1 tag because PyPI timed out. FIXTURE.json records each version. Cells by 9fd217b2 and 6f50edad.
    • Red on parent b7bd508: C1, C2 x2, C4, C3 stamp035/036-clean, and C5b.
    • Lint: ruff 0.15.12 check and format are clean. The other lint steps were not run locally because of the host emergency; CI validates them.
  • All existing tests pass (CI)
  • Added tests for new functionality (if applicable)

Changelog

Spec conformance (OpenAPM v0.1)

  • N/A: no requirement text changes.

Agent note, not authored by Daniel.

…de (#4398)

Fixture tests/fixtures/pre036_upgrade/v0.35.1 is produced by the released
apm-cli 0.35.1 wheel (generate.py; FIXTURE.json records the version): a
project with a local package whose Cursor applyTo "**" rule and linked Codex
agent render differently in 0.37.

C1: an unedited clone re-renders silently once (exit 0, no Kept line, files
equal the 0.37 render, lock rewritten and matching disk, receipts recorded,
audit --ci, install --frozen and a repeat install change nothing).
C2: one edited file stays byte-identical with exactly one Kept line from the
shared template, the others converge; exit 1 when 0.37 brings new bytes for
the edited file, 0 when it brings the same bytes (#4504).
C4: install --frozen on the untouched clone exits 0 and writes nothing.

All four fail on the parent b7bd508 (Kept refusals, exit 1, frozen writes).

Co-authored-by: Copilot App <[email protected]>
…essly (#4398)

APM 0.35 and earlier recorded no deployment receipts, so their lockfile
hash is the only record of what they deployed. On a lockfile stamped
before 0.36 (or unstamped), a managed file whose bytes equal its recorded
hash and that git tracks unchanged is proven APM-owned: install re-renders
it once and records receipts and a new lock. A file whose bytes differ is
a proven edit: it is kept and named once through kept_edit_message; it
warns (exit 0) when the package renders the recorded bytes and errors
(exit 1) when it renders new ones. install --frozen verifies such a
project and adopts the files as they are, writing nothing. Locks from 0.36
on keep the #4360 rule: a lock hash is never evidence.

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

C3: a lock hash forged to match a local edit of .cursor/rules/everywhere.mdc.
A >=0.36 stamp (v0.36.1 fixture) never overwrites it, dirty or clean. A
<=0.35 stamp overwrites it only when the file is git-tracked and clean
(edit committed, recoverable from git); tracked-dirty, staged and
untracked are kept with one shared Kept line. The overwrite case is red on
the parent b7bd508 (kept, exit 1); the kept cases are red on the Kept
template only.

C5: a project written by a released 0.36.1 (fixture
tests/fixtures/pre036_upgrade/v0.36.1, FIXTURE.json records 0.36.1) keeps
every deployed byte on upgrade, exits 0, prints no Kept line, and audit
--ci, --frozen and a repeat install converge. Green on the parent
(non-regression guard). The 0.36.1 wheel was built from the v0.36.1
release tag because PyPI file downloads time out on this host.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
Per the steward's #4398 update, the lock-hash migration covers any lock
stamped before 0.37. C3 now runs eight cells: 0.35.1 and 0.36.1 stamps
overwrite a forged-hash edit only when it is git-tracked and clean; a lock
written by the binary under test (asserted >= 0.37) never does. C5b: a
0.36-stamped lock whose files differ from the 0.37 render converges with
exit 0, no Kept line, a lock matching disk, and clean audit --ci, frozen
and repeat installs. Released 0.36.1 renders every file primitive like
0.37, so C5b restamps the 0.35.1 renders as 0.36.1. FIXTURE.json for
v0.36.1 records that its wheel was built at the v0.36.1 tag.

Red on parent b7bd508: stamp036-clean (kept, exit 1), stamp037-clean
(Kept template), C5b (exit 1).

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

Per the steward's update, any lock stamped before 0.37 comes from an APM
that did not require receipt evidence, so a git-clean file holding its
recorded bytes migrates once. Docs, CHANGELOG and the ledger row follow;
the ledger cites C3 and C5b.

Co-authored-by: Copilot App <[email protected]>
…nd Kiro (#4398)

C6 upgrades a Copilot + Kiro project produced by the released 0.36.1 binary
(GitHub release asset, sha256 recorded in FIXTURE.json via the new
generate.py --case copilot-kiro-mcp and --provenance options): the
self-defined MCP server moves from .github/mcp.json to the root .mcp.json,
the package's Kiro agent naming '@notes' (refused by 0.36.1) deploys, every
file equals a fresh 0.37 render, the lock matches disk, and audit --ci,
install --frozen and a repeat install change nothing. Green on b7bd508.

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

Steward rule: a forger can only know committed bytes, which stay
recoverable, so a file git tracks unchanged or does not track at all
(untracked, ignored, no repository) migrates; a tracked file with a staged
or unstaged change matching the lock is kept; other git errors fail
closed. C1 gains nogit and gitignored cells; C3 stamp035-untracked now
expects the overwrite.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 0d134c7 into train/0.37-final-2 Nov 20, 2026
6 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-seamless-legacy-upgrade-4398 branch November 20, 2026 22:06
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
… extraction, frozen-flag reader, legacy/strict cells (#4522 follow-ups)

Co-authored-by: Copilot App <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
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.

1 participant