Skip to content

fix(lockfile): hash framing hardening with lockfile version 4 - #4026

Merged
Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-miniature-happiness
Nov 20, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 10 commits into
mainfrom
danielmeppiel-miniature-happiness

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

TL;DR. Hash framing hardening for package content_hash. The package tree digest now uses the same framed encoding the native plugin pin already uses (relative path, NUL, per-file SHA-256), and the change is versioned at the lockfile level as lockfile_version: "4". Lockfiles at versions 1–3 keep verifying unchanged; a writable apm install promotes once, re-hashing every package row from verified bytes. --frozen, apm audit and read-only paths never promote or rewrite.

Important

Upgrade note: APM 0.36.x and earlier refuse a version "4" lockfile through the existing UnsupportedLockfileVersionError (fail closed). Update CI to APM 0.37 before committing a lockfile written by 0.37.

Problem (WHY)

  • The package hash and the native plugin pin used two different tree encodings, so APM had two hashing schemes for one decision. The repo rule is explicit: “Every durable decision, vocabulary, outcome, write, or contract has exactly ONE canonical owner.”
  • Changing what a recorded value means without a version signal would silently invalidate committed lockfiles. APM already versions such changes at the lockfile level ("2" for registry evidence, "3" for replacement state), and old readers fail closed on an unknown version.
  • Frozen installs and audits are read-only contracts; a hash scheme change must never rewrite a lockfile on those paths.

Approach (WHAT)

Concern Decision
Hash scheme One framing primitive (_frame_entry) in utils/content_hash.py serves package and native plugin fingerprints. Values keep the plain sha256:<hex> label; no new prefix.
Versioning lockfile_version: "4" names the framed stream; "1"–"3" name the legacy stream. Each lock row learns its stream from its lockfile (content_hash_framed, not serialized).
Verification Every lock-row verifier passes the row's stream; verify_package_hash requires framed=. The legacy stream exists only to verify 1–3 lockfiles. Bare-hex reader tolerance (req-lk-016) holds in every version.
Promotion Writable install only, all-or-nothing: rows recorded this run carry a framed digest from the same read; carried-over rows are re-hashed from apm_modules only after cheap checks pass for all of them and their legacy hash verifies. Otherwise the lockfile stays as written and --verbose names the package to reinstall. A successful promotion prints one [i] line after the write.
Guard New architecture rule install-deployment-package-content-hash closes the world: no second tree hasher, every src hash call names its stream, one stream rule, one recorder, one promoter.

Implementation (HOW)

Area Change
utils/content_hash.py _frame_entry (shared framing), PackageDigests + compute_package_digests (one read, both streams), compute_package_hash(framed=), verify_package_hash(framed=). Native pin values are byte-identical.
deps/lockfile.py "4" in SUPPORTED_LOCKFILE_VERSIONS, FRAMED_CONTENT_HASH_VERSION, records_framed_content_hashes (the one recording-stream rule), framed_content_hashes derived from the read version, set_content_hash_stream; version derivation emits "4" when a framed lock records any content_hash; replacement evidence accepts "3" or "4".
install/source_helpers.py package_digests (legacy stream only while the existing lock uses it) and record_package_digests, the sole writer of ctx.package_hashes / ctx.package_framed_hashes.
install/phases/content_hash_stream.py (new) promote_content_hashes: frozen/dry run never promote; framed row flags trusted only from a v4 lock; cheap-blocker pre-pass; diagnostics. install/phases/lockfile.py flags built rows with the recording stream, calls it, and prints the promotion line after the write.
deps/carried_license.py verify_locked_package(framed=) and verified_framed_digest (re-hash only bytes whose legacy hash and licence copies verify).
Verifiers _redownload, integrate, native_plugin_admission, security/trust, legacy_plugin_compat, local_content and the frozen local preflight in install/service.py pass the row's stream.
Spec OpenAPM 0.1.68 (proposed): req-lk-016 revised in place (stream named by version, promotion and never-rewrite rules), Section 5.4 names "4", new lockfile-v0.1.68.schema.json (adds "4"), manifest notes, CONFORMANCE regenerated. Count unchanged at 148.
Docs Lockfile reference (version table, promotion), registries page, troubleshooting (install-failures.md, v4 refusal), apm-usage dependencies.md, CHANGELOG upgrade note.
flowchart LR
    A["Existing lock v1-3"] --> B{"Writable install?"}
    B -->|"no: --frozen, audit, read-only"| C["Verify with legacy stream, never rewrite"]
    B -->|yes| D{"Every row has a framed digest of verified bytes?"}
    D -->|yes| E["Write v4 with framed hashes"]
    D -->|no| F["Keep lock as written"]
Loading

Legend: how a version 1–3 lockfile moves (or does not move) to version 4.

Trade-offs

  • Lockfile-level versioning instead of a per-value prefix: one scheme per file, no new envelope grammar, and old clients fail closed with the existing error instead of a confusing hash mismatch. Cost: a one-time lockfile diff on first 0.37 install.
  • All-or-nothing promotion: a partial install whose carried rows cannot be verified keeps the legacy version rather than producing a mixed lock; the next full install promotes.
  • Recording computes both streams in one read during the promotion window (two SHA-256 passes over bytes already in memory) to avoid re-reading trees.
  • Local carried-over rows are not re-hashed during promotion (their hash covers the source snapshot, not apm_modules); they promote on the next install that records them.
  • Old-contract test expectations updated, not weakened: the revision-pin and replacement lifecycles assert lockfile_version: "4" (they asserted the feature-derived "2"/"3"/"1") and still check resolved_tag and replacements; the links lifecycle pins the framed digest a v4 lock records and keeps its cross-platform byte check via the legacy digest of the installed tree; tests that named "4" as the next unsupported version now use "5".
  • Deferred: making framed required on compute_package_hash (≈100 unrelated test call sites; the guard already enforces it in src), an AST-based guard, and the pre-existing double tree read on cached hits.

Benefits

  1. One hashing scheme with one owner, enforced by a closed-world architecture guard.
  2. Committed lockfiles at versions 1–3 keep verifying byte-for-byte; no forced regeneration.
  3. --frozen (cached and fresh) and apm audit never promote or rewrite.
  4. Older clients fail closed with a clear unsupported-version error.

Issue and approved scope

Issue: Fixes #4000

Human scope-approval comment: #4000 (comment) (supersedes the earlier record).

This PR completes the issue.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass (unit + spec conformance failures match the base branch's environment-only failures exactly)
  • Added tests for new functionality

Scenario evidence

Scenario Test Principle
Framing regression test; framed and legacy streams match their published definitions and base goldens; native pins unchanged tests/unit/test_content_hash.py::TestFramedPackageStream, tests/unit/test_native_bundle_hash.py Secure by default
Version 1–3 lock rows verify with the legacy stream tests/unit/install/test_content_hash_promotion.py::test_legacy_version_rows_verify_with_the_legacy_stream Reproducible installs
Promotion only on a writable install, from verified bytes; unverified carried row blocks it test_writable_install_promotes_every_row_from_verified_bytes, test_unverified_carried_row_blocks_promotion_and_keeps_every_row Secure by default
--frozen cached and fresh, and apm audit, never rewrite (v4 and v1); writable install promotes v1 to v4 tests/spec_conformance/test_lockfile_reqs.py::test_frozen_consumer_accepts_equivalent_local_content_hash_encodings (5 cases, real CLI) Reproducible installs
--frozen never promotes (unit); v3 replay and promotion keep replacements; blocker pre-pass hashes nothing tests/unit/install/test_content_hash_promotion.py Reproducible installs
Real CLI: v1 legacy lock with a git-hosted dependency promotes; partial install promotes carried rows only from verified bytes (edited cache keeps lock bytes) tests/integration/test_required_lifecycle_state_machine.py (legacy_content_hash, partial_install_promotes) Secure by default
Bare-hex content_hash replays in v4 and v1 test_frozen_consumer_accepts_equivalent_local_content_hash_encodings[version4-bare64-cached], test_frozen_local_path_lifecycle.py Reproducible installs
A v0.36.1-equivalent version check fails closed on "4" test_a_release_without_version_4_fails_closed Secure by default
Schema 0.1.68 adds only "4" test_lock_schema_0_1_68_* Spec conformance
Owner guard and framing mutation-break tests/integration/test_architecture_owner_rule_mutations.py (matrix case + test_package_content_hash_guard_rejects_second_streams_and_hashers) Single owner
Validation commands
uv run --extra dev ruff check src/ tests/ scripts/lint_architecture_boundaries.py scripts/architecture_linter/   -> All checks passed!
uv run --extra dev ruff format --check ...                                                                    -> 2477 files already formatted
bash scripts/lint-auth-signals.sh                                                                             -> [+] auth-signal lint clean
bash scripts/lint-architecture-boundaries.sh                                                                  -> clean (exit 0)
python -m pylint --disable=all --enable=R0801 ... src/apm_cli/ scripts/...                                  -> 10.00/10
uv run --extra dev pytest -n 3 tests/unit tests/spec_conformance                                              -> only failures are the base branch's environment-only set
owner-evidence set (23 node IDs incl. e2e lifecycle, APM_E2E_TESTS=1)                                         -> all passed at head
links / revision-pin / replacement / frozen-local-path lifecycles + test_lockfile_reqs                        -> passed
GitHub CI on this stacked PR runs only the CLA check; the release-train tip CI is the integration run.

How to test

  • In a project with a committed version 1–3 apm.lock.yaml, run apm install --frozen and apm audit: the lockfile is byte-identical.
  • Run apm install: lockfile_version becomes "4" and every package content_hash is re-recorded once.
  • Run apm install again: no lockfile change.
  • Read the version 4 lockfile with APM 0.36.1: it refuses with the unsupported-version error.

Changelog

  • One line in one section under ## [Unreleased] in CHANGELOG.md (Breaking changes and upgrade notes).
  • N/A -- internal-only change (CI, tests, refactor).

Spec conformance (OpenAPM v0.1)

  • Spec edit: docs/src/content/docs/specs/openapm-v0.1.md updated (req-lk-016 revised in place; Appendix C row unchanged because keyword, section and class are unchanged).
  • Manifest edit: openapm-v0.1.requirements.yml notes for req-lk-016.
  • Test edit: @pytest.mark.req("req-lk-016") tests added and extended.
  • CONFORMANCE.{md,json} regenerated and committed.

Co-authored-by: Copilot [email protected]

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Hash framing hardening moves package content hashes to the framed stream that native plugin pins already use, under lockfile version 4. A writable install promotes the lockfile once, and older clients fail closed.

panel-mode=full; personas=python-architect,supply-chain-security-expert,test-coverage-expert,performance-expert,doc-writer,devx-ux-expert,apm-ceo

All six panelists say the design holds and none raised a blocking finding. The PR stays inside the accepted scope for #4000. Package content hashes keep the plain sha256: label. utils/content_hash.py is the only module that defines the framing. Versions 1-3 keep verifying with their own stream until a writable install promotes them. --frozen, audit and read-only paths never rewrite the lockfile. Older readers stop at the existing UnsupportedLockfileVersionError. supply-chain-security-expert confirmed that promotion uses only verified or same-run bytes, and every lockfile-row check uses that row's own stream. test-coverage-expert ran a throwaway variant that models a real v1 lock (remote-git source): promotion to '4' and the frozen no-rewrite path both passed (6.79s).

The main correctness follow-up comes from two panelists. python-architect and supply-chain-security-expert each point at the same weak spot: the run-level stream rule (existing is None or existing.framed_content_hashes) is written in two places, and from_installed_packages briefly marks legacy-digest rows as framed until promotion runs, so the result depends on branch order. It is correct today but fragile. Fix it in this PR: give the rule one owner, call set_content_hash_stream right after from_installed_packages, and run the elif dep.content_hash_framed promotion branch only when the existing lockfile is already framed. Then pin the behavior with integration-tier tests. Making framed a required keyword on compute_package_hash and verify_package_hash closes the same class of risk from the API side.

This PR changes what users see on upgrade: lockfiles get a one-time diff, and CI must run the new APM version. doc-writer and devx-ux-expert agree that troubleshooting/migration.md section 3 is where users of the previous release land when an older client refuses a v4 lockfile; it still lists only versions 1 and 2. Users should get one [i] line when promotion succeeds and a verbose-mode diagnostic when promotion is held back. The performance-expert finding that both SHA-256 streams are computed and one is thrown away (+59% on a 75 MB tree) is a cost this PR introduces, so it is in scope.

Dissent. No panelist disagreed on severity; every finding is recommended or nit. The overlap between python-architect (one owner for the stream rule) and supply-chain-security-expert (gate the framed promotion branch) is one finding seen from two angles. I side with folding both into one change instead of choosing between them.

Aligned with: Portable by manifest: the lockfile version is the contract; versions 1-3 replay with their own stream, v4 is declared in the OpenAPM spec (req-lk-016, schema 0.1.68, conformance), and older clients refuse instead of misreading. Secure by default: new lockfiles default to the framed stream; promotion uses only verified or same-run bytes and is all-or-nothing. Governed by policy: --frozen and audit never rewrite or promote, and a new architecture-linter rule keeps one tree hasher and one writer of package_hashes. Pragmatic as npm: upgrading takes no command; the gap is visibility of the one-time diff and a held-back promotion.

Panel summary

Persona B R N Takeaway
Python Architect 0 2 1 Hash framing stays with one owner, content_hash.py, and promotion sits correctly after carry-forward. Main suggestion: make the stream (framed flag) a required argument instead of defaulting it to True.
Supply Chain Security Expert 0 2 1 Hash framing hardening looks sound. Promotion uses only verified or same-run bytes, frozen and audit leave the lockfile unchanged, and every lock-row check uses the row's own stream. Older readers refuse version 4.
Test Coverage Expert 0 2 1 Framing, legacy replay, promotion, frozen no-rewrite, audit and fail-closed tests are present and pass. Remote-dependency promotion is proven only at unit tier, and version 3 replay has no test.
Performance Expert 0 2 1 Steady-state installs read each tree the same number of times as before, but every check now runs SHA-256 twice. A blocked promotion can repeat its re-hash on every partial install.
Doc Writer 0 3 0 The new docs match the code and follow the public text rule. The canonical version table, the promotion fallback and the troubleshooting page still need updates; the CHANGELOG line follows the rules.
Devx Ux Expert 0 3 0 Safe upgrade, and newer clients refuse an older lock with a clear message. The one-time diff and the silent no-promotion path need a line of output, and the migration page needs the version 4 error.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 5 follow-ups

  1. [Python Architect] Give the run-level content-hash stream rule one owner, used by both record_package_digests and _promote_content_hashes. Call set_content_hash_stream right after from_installed_packages. Run the 'elif dep.content_hash_framed' promotion branch only when the existing lockfile is framed (supply-chain-security-expert raised the same point). -- Correctness currently depends on branch order, and legacy-digest rows are briefly marked framed. Two panelists found this independently. It is the highest-signal in-scope fold.
  2. [Test Coverage Expert] Add integration-tier promotion tests. Extend the legacy content-hash test in test_required_lifecycle_state_machine.py to model a real v1 lock (framed=False digest, lockfile_version '1') and assert promotion to '4'. Add promotion through build_and_save with carried remote rows: a partial install and a preserved failed download (supply-chain-security-expert). -- This is a missing test on a secure-by-default surface. Remote promotion is tested only at unit tier today, and the persona's throwaway variant passed, so this is cheap to keep in the suite.
  3. [Python Architect] Make framed a required keyword on compute_package_hash and verify_package_hash. Update the receipt pair (resolve.py:173, integrate.py:241) that relies on the default, and close the guard regex gaps. -- Callers that rely on the default can pick the wrong stream without any error. verify_locked_package and carried_license already require the keyword.
  4. [Doc Writer] Update troubleshooting/migration.md section 3 with version 4, the exact refusal message and the upgrade commands (devx-ux-expert raised the same point). Add a '4' row to the lockfile-spec.md version table and fix its Purpose line. Say that promotion is all-or-nothing and can keep the old version, in the reference page and in apm-usage. -- The migration page is where users of the previous release land when an older client refuses a v4 lockfile. The current text says every writable install promotes, which is not true when a row blocks promotion.
  5. [Devx Ux Expert] Print one [i] line when promotion succeeds that explains the one-time lockfile diff and the minimum CI version, with a CLI test that asserts it. Add a verbose-mode diagnostic that names the package blocking promotion and the next step. Add a remedy to the RuntimeError message. -- Users should never get an unexplained lockfile rewrite, or an unexplained missing one, from a package manager.

Architecture

classDiagram
    direction LR
    class content_hash {
      <<SingleOwner>>
      +compute_package_digests(path, exclude) PackageDigests
      +compute_package_hash(path, exclude, framed) str
      +verify_package_hash(path, expected, exclude, framed) bool
      -_frame_entry(relative, payload, mode) bytes
    }
    class PackageDigests {
      <<ValueObject>>
      +legacy str
      +framed str
      +select(framed) str
    }
    class LockFile {
      <<Aggregate>>
      +framed_content_hashes bool
      +set_content_hash_stream(framed)
      +add_dependency(dep)
    }
    class LockedDependency {
      +content_hash str
      +content_hash_framed bool
    }
    class source_helpers {
      <<Recorder>>
      +record_package_digests(ctx, dep_key, digests) str
    }
    class LockfileBuilder {
      <<PhaseBuilder>>
      -_promote_content_hashes(lockfile)
    }
    class carried_license {
      +verify_locked_package(root, hash, records, framed)
    }
    content_hash ..> PackageDigests : returns
    LockFile *-- LockedDependency : rows
    source_helpers ..> content_hash : digests
    LockfileBuilder ..> LockFile : promotes
    LockfileBuilder ..> content_hash : rehash carried rows
    carried_license ..> content_hash : verify in row stream
    class content_hash:::touched
    class LockFile:::touched
    class LockfileBuilder:::touched
    classDef touched fill:#fff3b0,stroke:#d47600
Loading
flowchart TD
    A["apm install"] --> B["resolve.py _load_lockfile: LockFile._from_validated_data"]
    B --> C{"lockfile_version is 4?"}
    C -->|yes| C1["framed_content_hashes=True; rows framed"]
    C -->|"no, 1-3"| C2["framed_content_hashes=False; rows legacy"]
    C1 --> D
    C2 --> D
    D["sources.py acquire / record_carried_package_hash"] --> E["content_hash.compute_package_digests: one read, legacy + framed"]
    E --> F["record_package_digests: package_hashes in existing stream; package_framed_hashes"]
    D --> V["verifiers use framed=row.content_hash_framed"]
    V -->|mismatch| V1["re-download or frozen failure"]
    F --> G["LockfileBuilder.build_and_save"]
    G --> G2["attach content hashes, merge and carry-forward steps"]
    G2 --> H["_promote_content_hashes"]
    H --> H0{"frozen or dry run?"}
    H0 -->|yes| H1["keep existing stream; no rewrite"]
    H0 -->|no| H2{"every row has a framed digest of verified bytes?"}
    H2 -->|yes| H6["rewrite content_hash; version 4"]
    H2 -->|no| H4["keep version 1-3 and every recorded value"]
    H1 --> I["sync_lockfile_version"]
    H4 --> I
    H6 --> I
    I --> J["_write_if_changed: apm.lock.yaml"]
Loading
sequenceDiagram
    participant U as User
    participant I as apm install
    participant R as record_package_digests
    participant B as LockfileBuilder
    participant L as apm.lock.yaml
    U->>I: apm install (existing lockfile_version 3)
    I->>L: read, rows flagged legacy
    I->>R: digests for each fetched package
    R-->>I: package_hashes legacy, package_framed_hashes framed
    I->>B: build_and_save
    B->>B: _promote_content_hashes, rehash carried remote rows
    B->>L: write lockfile_version 4 with framed hashes
    U->>I: apm install --frozen
    I->>L: verify in the row stream, never promote
Loading

Recommendation

The design is sound and the tests that exist pass. Fold the in-scope follow-ups into this PR before merge, highest-signal first. First comes one owner for the stream rule plus the framed-only promotion gate, backed by integration-tier v1 and carried-row promotion tests. Next come the migration.md v4 entry and the promotion output lines, so the one-time lockfile diff is explained to users. The single-stream hashing fix belongs here because this PR introduced the cost. Move the pre-existing double tree read to its own issue. The CHANGELOG upgrade note should say that CI must run the new APM version once a lockfile is promoted.


Full per-persona findings

Python Architect

  • [recommended] Make framed a required keyword on compute_package_hash / verify_package_hash, as verify_locked_package already does, instead of defaulting to True at src/apm_cli/utils/content_hash.py:271
    A verifier that forgets to pass the row's stream checks a v1-3 row against the framed stream without warning. It fails closed, but legacy users would see a false mismatch. The guard's raw-compare and record-write regexes have gaps; the receipt pair in resolve.py / integrate.py relies on the default.
    Suggested: Require framed on compute_package_hash, verify_package_hash and compute_local_package_hash; pass framed=True explicitly at the receipt pair.
  • [recommended] The run-level stream rule is written out in two modules, and the build lockfile briefly marks legacy rows as framed at src/apm_cli/install/phases/lockfile.py:473
    Promotion is correct only because the recorded-this-run branch runs before the branch that trusts the per-row flag.
    Suggested: One owner for the recording stream; call set_content_hash_stream right after from_installed_packages.
  • [nit] _rehash_verified_row rebuilds the verify_locked_package logic inside the lockfile phase
    A sibling owner in carried_license (for example verified_framed_digest) keeps that verification logic in one place.

Supply Chain Security Expert

  • [recommended] Trust the in-memory content_hash_framed flag during promotion only when the existing lockfile already uses the framed stream at src/apm_cli/install/phases/lockfile.py:485
    Today the flag is safe only because of how rows move between LockFile objects; gating the branch makes the verified-bytes-only rule independent of carry-forward mechanics.
    Suggested: elif recorded_framed and dep.content_hash_framed:
  • [recommended] Test promotion through build_and_save for carried rows, not only on a lockfile parsed from YAML at tests/unit/install/test_content_hash_promotion.py
    The mix of fresh rows and carried legacy rows is where a carried row could be stamped without re-hashing.
    Proof (missing at): tests/unit/install/test_content_hash_promotion.py -- proves: a writable install on a version 1-3 lockfile writes version 4 only after every carried remote row is re-hashed from verified bytes [secure-by-default,portability-by-manifest]
  • [nit] Accept bare-hex content_hash in the frozen local preflight only for lockfile versions 1-3 at src/apm_cli/install/service.py:566
    The 0.1.68 schema requires the envelope in version 4.

Test Coverage Expert

  • [recommended] Remote-dependency promotion is proven only at unit tier, and the existing legacy-hash lifecycle test no longer models a legacy lockfile at tests/integration/test_required_lifecycle_state_machine.py:2190
    The only real-CLI promotion test uses a local dependency. A throwaway remote-git variant passed (v1 promoted to '4'; --frozen left bytes unchanged), so the gap is coverage only.
    Proof (missing at): tests/integration/test_required_lifecycle_state_machine.py::test_required_legacy_content_hash_upgrade_preserves_skills_and_converges -- proves: upgrading APM and running install promotes git-hosted dependencies to version 4 once from verified bytes [portability-by-manifest,secure-by-default]
  • [recommended] No test covers version 3 replay or promoting a version 3 lockfile with replacement evidence at tests/unit/install/test_content_hash_promotion.py
    Version 3 is the one legacy version with extra state, and the reader now accepts that evidence under '3' or '4'.
    Proof (missing at): tests/unit/install/test_content_hash_promotion.py -- proves: a lockfile that records source replacements keeps verifying until promotion and keeps its replacement evidence after [portability-by-manifest,governed-by-policy]
  • [nit] No fixed-value test confirms native plugin pin values are unchanged now that they use the shared framing helper at tests/unit/test_native_bundle_hash.py
    Proof (missing at): tests/unit/test_native_bundle_hash.py -- proves: existing native plugin pins keep verifying [portability-by-manifest,secure-by-default]

Performance Expert

  • [recommended] compute_package_hash / verify_package_hash always compute both streams, so single-stream verify paths pay a second SHA-256 pass at src/apm_cli/utils/content_hash.py:84
    Measured +59% on a 300-file / 75 MB tree; small-file trees are dominated by walk and stat.
    Suggested: Feed only the selected hasher; keep dual-stream only for recording pre-v4 and for promotion.
  • [recommended] A blocked promotion re-hashes carried remote rows before it hits the blocker, and a partial install repeats that waste on every run at src/apm_cli/install/phases/lockfile.py:460
    Suggested: Classify rows and check cheap blockers before hashing any row.
  • [nit] Follow-up (pre-existing): cached hits read the tree twice per install at src/apm_cli/install/sources.py:608
    Track as a separate issue.

Doc Writer

  • [recommended] lockfile-spec.md has no version 4 row in the Version bumping table, and the Purpose section still says two versions at docs/src/content/docs/reference/lockfile-spec.md:416
  • [recommended] The reference page and apm-usage say every writable install promotes to version 4, but promotion is all-or-nothing at packages/apm-guide/.apm/skills/apm-usage/dependencies.md:533
  • [recommended] troubleshooting/migration.md section 3 still says the current versions are 1 and 2 at docs/src/content/docs/troubleshooting/migration.md:60

Devx Ux Expert

  • [recommended] The first writable install rewrites every content_hash row and bumps lockfile_version, but prints only 'Updated apm.lock.yaml.' at src/apm_cli/install/phases/lockfile.py:460
    Proof (missing at): tests/spec_conformance/test_lockfile_reqs.py -- proves: a user who upgrades is told why apm.lock.yaml changed on every package row [devx]
  • [recommended] When a carried row cannot be verified, promotion is skipped with no message at src/apm_cli/install/phases/lockfile.py:491
    Proof (passed): tests/unit/install/test_content_hash_promotion.py::test_unverified_carried_row_blocks_promotion_and_keeps_every_row -- proves: the fallback keeps the legacy lock unchanged [devx]
  • [recommended] APM 0.36 and earlier fail on a version 4 lock with no upgrade hint, and the troubleshooting page still lists only versions 1 and 2 at docs/src/content/docs/troubleshooting/migration.md:60

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.

Package content hashes use the framed stream the native plugin pin
already uses, owned by utils/content_hash.py. Lockfile version 4 names
the stream; versions 1-3 keep verifying with the legacy stream, and a
writable install promotes once from verified bytes. --frozen, audit
and read-only paths never promote. OpenAPM 0.1.68 amends req-lk-016.

Fixes #4000

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
The base gained an include_mode switch on the native hasher; keep the
guard's required fragment on the shared framing call.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
One owner for the recording stream (records_framed_content_hashes);
built rows carry it until promotion, and promotion trusts a framed
row flag only from a version 4 lock. Promotion moves to
install/phases/content_hash_stream.py, checks cheap blockers before
hashing any tree, explains the one-time lockfile change, and names
the package that holds it back. Re-hash of carried rows is owned by
carried_license.verified_framed_digest. verify_package_hash requires
the stream; every src hash call names it (guarded). Single-stream
hashing when only one stream is needed. Bare-hex tolerance stays for
versions 1-3. Docs: version table, all-or-nothing promotion,
troubleshooting migration entry. Tests: v3 replay and promotion,
framed-flag gating, blocker pre-pass, promotion message, native pin
golden values, v1 legacy promotion in the lifecycle suite.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Version 4 is now supported; the embedded-lock gate still fails closed
before any project mutation on an unknown version.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Recording hashes the legacy stream only while the existing lockfile
uses it. The promotion message prints after the lockfile write
succeeds. Tests: legacy-stream definition and golden value, version 4
bare-hex refusal under --frozen, partial-install promotion of carried
rows (intact and edited cache), recording-stream selection, and guard
mutations for unnamed streams, a re-derived stream rule and the
framed-flag gate. Docs: version 4 wording in the lockfile reference
and registries page; the refusal sample no longer pins a version list.

Co-authored-by: copilot-swe-agent[bot] <[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
req-lk-016 requires v0.1 readers to accept a bare 64-hex content_hash.
The frozen local preflight had narrowed that to versions 1-3, which
refused committed lockfiles a 0.37 install had promoted. Restore it,
and drop the matching envelope rule from the 0.1.68 schema so spec,
schema and code agree; writers still emit the envelope.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
A package content_hash now selects lockfile_version 4, so the
revision-pin and replacement lifecycles assert 4 while still checking
resolved_tag and replacements. The links lifecycle pins the framed
digest a version 4 lock records and keeps the cross-platform byte
check through the legacy digest of the installed tree. The owner
mutation matrix keeps one sorted case for the content-hash guard; its
other mutations move to a dedicated parametrized test.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Pins req-lk-016 reader tolerance for promoted lockfiles so the frozen
preflight is not narrowed again.

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026

Copy link
Copy Markdown
Collaborator Author

APM Review Panel: ship_with_followups

Hash framing hardening moves the lockfile to version 4. Every in-scope delta finding is folded, plus one spec-driven reversal; what remains is polish to track after merge.

panel-mode=delta; personas=python-architect,supply-chain-security-expert,test-coverage-expert,performance-expert,doc-writer,devx-ux-expert,apm-ceo

Delta since the last advisory. All six panelists confirm their prior findings are fixed (stream owner, framed-flag gate, single-stream verify, blocker pre-pass, promotion messages, v3 and native-pin tests, docs). Later commits then folded this round's items:

  • Performance: recording hashes the legacy stream only while the existing lock still uses it (regression test asserts legacy=False for new and v4 locks).
  • Logging: the promotion line prints only after the lockfile write succeeds.
  • Legacy stream: a published-definition test pins a golden value taken from the base implementation.
  • Partial-install promotion: e2e test; an intact cache promotes carried rows to framed, an edited cache leaves the lock bytes unchanged.
  • Guard: mutation cases for an unnamed stream, a re-derived stream rule and the framed-flag gate; the owner matrix keeps one sorted case.
  • Docs: stale version lines in the lockfile reference and registries page, and the refusal sample.

One reversal. The v4 bare-hex tightening folded last round is reverted. req-lk-016 requires v0.1 readers to accept bare hex in every lockfile version; the tightening refused committed lockfiles that 0.37 had already promoted, and the lifecycle suite caught it. The 0.1.68 schema drops its v4 envelope rule to match; writers still emit the envelope. A new conformance case now asserts that a version 4 lock with a bare-hex content_hash replays under --frozen (mutation-break confirmed).

Stack integration. Revision-pin and replacement lifecycles now assert lockfile_version: "4" (the old feature-derived "2"/"3"/"1" contract) while still checking resolved_tag and replacements. The links lifecycle pins the framed digest a version 4 lock records and keeps the cross-platform byte check through the legacy digest of the installed tree.

Aligned with: Portable by manifest: version 4 is a declared format step and promoted lockfiles keep replaying. Secure by default: new and promoted rows use the framed stream; the guard requires every hash call to name its stream. Governed by policy: spec, schema and implementation agree on reader tolerance. Pragmatic as npm: no user command needed; an unverifiable cache leaves the lock untouched.

Panel summary

Persona B R N Takeaway
Python Architect 0 1 2 Prior findings fixed; asked for guard mutation tests (folded) and log-after-write (folded).
Supply Chain Security Expert 0 1 1 Trust gaps closed; partial-install carried-row promotion now has an e2e test.
Test Coverage Expert 0 3 0 Prior gaps fixed; legacy-stream golden and carried-row e2e folded; bare-hex trap now asserts acceptance.
Performance Expert 0 1 1 Recording now hashes only the needed stream; blocker pre-pass confirmed.
Doc Writer 0 1 2 Prior findings fixed; remaining stale version lines folded.
Devx Ux Expert 0 1 1 Prior findings fixed; registries page claim folded.

B = blocking-severity findings, R = recommended, N = nits.
Counts are signal strength, not gates. The maintainer ships.

Top 4 follow-ups

  1. [Performance Expert] Track the pre-existing double tree read on cached hits as its own issue. -- Not introduced here, but it is now the dominant hash-path cost on large trees.
  2. [Supply Chain Security Expert] Make framed a required keyword on compute_package_hash in a dedicated test-migration PR. -- Deferred only for the ~100 unrelated test call sites; the guard already requires framed= on every src call and a miss fails closed.
  3. [Python Architect] Replace the regex guard with an AST-based check so aliased imports are covered. -- Polish that closes the guard's one known blind spot.
  4. [Apm Ceo] Keep the CHANGELOG upgrade note for lockfile version 4. -- Already present under Breaking changes and upgrade notes: update CI to APM 0.37 before committing a promoted lockfile.

Recommendation

Merge once the release-train tip CI is green; that run is the integration proof, because stacked PRs run only the CLA check. Every in-scope finding is folded, and the bare-hex reversal keeps spec, schema and code aligned.


Full per-persona findings (delta)

Python Architect

  • [recommended] No mutation test covered the new closed-world rules -- folded (dedicated parametrized test).
  • [nit] Promotion line logged before the write -- folded (logged after _write_if_changed).
  • [nit] Regex guard misses aliased imports -- deferred (polish).

Supply Chain Security Expert

  • [recommended] Partial-install carried-row promotion only unit-tested -- folded (e2e, intact and edited cache).
  • [nit] compute_package_hash framed default -- deferred (test-migration scope).

Test Coverage Expert

  • [recommended] Legacy stream lacked a published-definition test -- folded with a base-implementation golden.
  • [recommended] No v4 bare-hex frozen trap -- resolved as an acceptance trap after the req-lk-016 reversal.
  • [recommended] Carried-row promotion lacked a real-CLI test -- folded.

Performance Expert

  • [recommended] Recording still hashed the legacy stream on v4 locks -- folded.
  • [nit] Blocker pre-pass confirmed fixed.

Doc Writer

  • [recommended] lockfile-spec and registries lines still said "3"/"1" -- folded.
  • [nit] Purpose and field row should say "new or promoted" -- folded.
  • [nit] Refusal sample pinned one version list -- folded.

Devx Ux Expert

  • [recommended] registries.md stale claim -- folded.
  • [nit] First Versioning bullet conflicted -- folded.

This panel is advisory. It does not block merge. Re-apply the
panel-review label after addressing feedback to re-run.


Generated by autopilot-pr-review-worker. This comment is AI-generated and may contain errors.

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
Co-authored-by: Copilot App <[email protected]>

# Conflicts:
#	tests/integration/test_architecture_owner_rule_mutations.py
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
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
The single-file matrix recomputed package content_hash with the legacy
stream in three places. Replace them with one independent oracle for
the lockfile version 4 stream (path, NUL, raw file digest), kept
separate from the code under test.

Co-authored-by: copilot-swe-agent[bot] <[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
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
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
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 20, 2026
Base automatically changed from danielmeppiel-scaling-potato to main November 20, 2026 06:40
@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 7976636 into main Nov 20, 2026
1 check passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-miniature-happiness branch November 20, 2026 06:41
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.37.0 milestone Nov 20, 2026
Takeshi Masukawa (takeaship) pushed a commit to takeaship/apm that referenced this pull request Nov 20, 2026
The 0.35.1/0.36.0 upgrade lifecycles compared the first writable install
against the old lock byte-for-byte outside the fields they meant to
change. Since microsoft#4026 that install also promotes the lock to version 4
(hash framing hardening) and re-hashes every package row. Assert the
promotion explicitly: version 4, and each untouched row's content_hash
equals the framed digest of its installed tree; every other field must
still match.

Refs microsoft#4000

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 21, 2026
Steward ruling for cell (4) of the #4517 manifest_targets fix: lockfile v4
is the intended #4000/#4026 format change, so the previous release must
refuse it. An opt-in cell (APM_E2E_TESTS + APM_RUN_INTEGRATION_TESTS)
downloads the SHA-pinned v0.36.1 artifact, locks a 'target: claude' project
with this build (v4, manifest_targets [claude]), then runs 0.36.1 install,
install --frozen and audit --ci: each exits non-zero naming
"Unsupported lockfile version '4'" and the project tree is byte-identical.

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.

Lockfile v4: frame the package content hash

1 participant