Skip to content

[0.38] fix(install): install -g records user-root primitives in the user lockfile (#3772) - #4684

Merged
Daniel Meppiel (danielmeppiel) merged 23 commits into
mainfrom
danielmeppiel-p2-3772-user-root-lockfile
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 23 commits into
mainfrom
danielmeppiel-p2-3772-user-root-lockfile

Conversation

@danielmeppiel

Copy link
Copy Markdown
Collaborator

Description

apm install -g with only user-root primitives (for example ~/.apm/agents/*.agent.md, no dependencies) wrote no ~/.apm/apm.lock.yaml. With no record of APM owning its deployed files, a later install -g after a source edit skipped APM's own file as user content and printed "No changes".

  • Fix: the post-deps local phase (install/phases/post_deps_local.py) now persists self-entry claims at user scope as it does at project scope, so a later install -g updates APM-owned files. Files APM did not deploy are still skipped.
  • 0.37 migration: a 0.37 install left a deployment receipt but no lock. On the first upgraded install, DeploymentMaterializationSession.adopt_lockless_root_receipts accepts that receipt for the self-entry claim. It does so only at user scope, only for the root owner ., only for a path the lock does not claim, and only while the file still holds the receipted bytes. A hand-edited file never qualifies.
  • Line cap: to keep deployment_ledger.py under the 2100-line cap, the pure row validator validate_rows moved to deployment_state.validate_deployment_rows. DeploymentLedgerCodec.validate_rows still works under the same name.

Issue and approved scope

Issue: Fixes #3772

Human scope-approval comment: the apm-scope:v1 approval comment on #3772 from Daniel Meppiel (@danielmeppiel) (Decision: approve; Area: project; Review contact: Daniel Meppiel (@danielmeppiel)).

Does this PR complete the issue, or what remains? It completes it. All five "Done when" cases have installed-CLI lifecycle tests. Out of scope per the record: receipt trust without a lock claim, dependency and MCP flows, -g policy, #4562, and new lockfile fields.

Type of change

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

Testing

  • Tested locally
  • All existing tests pass
  • Added tests for new functionality (if applicable)

New: tests/integration/test_user_root_primitives_lockfile_lifecycle.py (installed CLI, isolated HOME and APM_HOME, policy on). It covers the scope record's cases:

  1. install -g with only ~/.apm/agents writes the user lockfile claiming the agent.
  2. After a source edit, install -g deploys the new bytes and does not print "No changes". A repeat install changes no bytes.
  3. From a reconstructed 0.37 state (receipt bound to no claim, no lock), the first upgraded install deploys a source edit. A second variant adopts the unchanged file first and then deploys the edit.
  4. A hand-edited deployed file is kept, and one line names it.
  5. An unreceipted pre-existing file is still skipped and not claimed.

Evidence:

  • Failing before (main 69c01b43): .venv/bin/python -m pytest tests/integration/test_user_root_primitives_lockfile_lifecycle.py -p no:xdist -> 3 failed, 1 passed. Cases 1-4 failed; case 5 is the protected control and passed both before and after.
  • Negative control: with only the migration call disabled, both case 3 variants fail.
  • Passing after (merged with main 11f8f585): the lifecycle file, tests/unit/install/test_pipeline_ownership_snapshot.py and tests/quality/test_lifecycle_bug_ledger.py -> 25 passed.
  • Neighbours: tests/unit/core/, tests/unit/deps/, the global/scope e2e tests, the receipt and global-adoption lifecycles, and the pipeline orchestration tests -> 4386 passed. The only earlier failure was in test_pipeline_ownership_snapshot.py, which asserted the old behavior (local_deployed_files == [] at user scope); it now expects root-local claims at both scopes.
  • tests/integration/test_architecture_owner_rule_mutations.py and tests/unit/scripts/test_architecture_runner.py -> 1327 passed.
  • Lint contract, all clean: uvx [email protected] check and format --check (src, tests, architecture scripts), pylint R0801, scripts/lint-auth-signals.sh, scripts/check_complexity_ratchet.py --base-ref origin/main, tests.quality.taxonomy --changed, scripts/check_test_assertions.py, scripts/lint_architecture_boundaries.py --root ., and the file-length guard.

Lifecycle evidence row:

promise: ownership.preserve_unowned, idempotency.byte_stable -- install -g records user-root deployments so a later install updates APM-owned files and still skips files APM did not deploy (source: #3772 scope record)
cell: OP=install SRC=root-local PRIM=agent SCOPE=user LOCK=absent|present   owner: install/phases/post_deps_local.py, core/deployment_ledger.py (DeploymentMaterializationSession)
instrument: today test -> tests/integration/test_user_root_primitives_lockfile_lifecycle.py (new: no user-scope root-primitive lock coverage existed)
oracles: [I1, I2, I7]  ledger: 3772

Changelog

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

Spec conformance (OpenAPM v0.1)

  • Spec edit
  • Manifest edit
  • Test edit
  • CONFORMANCE.{md,json} regenerated
  • N/A -- this PR does not change OpenAPM-observable behaviour.

…kfile (#3772)

User scope now persists self-entry claims for files deployed from
user-root primitives, as project scope does, so a later install -g
updates APM-owned files when the source changes. A pre-0.38 receipt
bound to no lock claim is adopted on the first upgraded install while
the file still holds the receipted bytes.

Co-authored-by: Copilot App <[email protected]>
…er row, docs

Move the lockless user-root receipt adoption into
DeploymentMaterializationSession and the pure deployment row validator into
deployment_state.py to stay within the module length cap. Record the
bug-ledger row, document the user-scope claims and align the ownership
snapshot test with root-local claims at user scope.

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

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

Receipt migration can restore overwrite authority for files whose lock claims were deliberately removed, bypassing the guarded-write requirement for ownership changes.

3 open issues
What changed in this PR

This PR addresses #3772 by recording user-root primitive deployments in the user lockfile, allowing later apm install -g runs to apply source edits while preserving unowned files.

Changes:

  • Persist root-local deployment claims at user scope and add migration for legacy lockless receipts.
  • Extract deployment-row validation while preserving the existing codec API.
  • Add lifecycle coverage, update ownership expectations, and document the behavior.
File Description
tests/​unit/​install/​test_pipeline_ownership_snapshot.py Expect root-local claims at both install scopes.
tests/​integration/​test_user_root_primitives_lockfile_lifecycle.py Cover lock creation, updates, migration, idempotency, and file protection.
tests/​fixtures/​lifecycle_bug_ledger/​bugs/​3772.json Link the reported bug to regression coverage.
src/​apm_cli/​install/​pipeline.py Adopt legacy receipts before integration.
src/​apm_cli/​install/​phases/​post_deps_local.py Enable user-scope local deployment persistence.
src/​apm_cli/​core/​deployment_state.py House the extracted deployment-row validator.
src/​apm_cli/​core/​deployment_ledger.py Implement receipt adoption and preserve the validator API.
docs/​src/​content/​docs/​reference/​cli/​install.md Describe user-root lock tracking and source updates.
CHANGELOG.md Add a release note for the global-install fix.

Review effort: Balanced

Comment thread src/apm_cli/core/deployment_ledger.py Resolved
Comment thread src/apm_cli/core/deployment_ledger.py Resolved
Comment thread src/apm_cli/core/deployment_ledger.py Resolved
… rule citation (#3772)

The lockless receipt migration now merges the prior root-local claims
itself and skips frozen replays, so the pipeline calls it in one line.
The generator rule citing class DeploymentLedgerCodec follows its new line.

Co-authored-by: Copilot App <[email protected]>
@danielmeppiel Daniel Meppiel (danielmeppiel) added this to the 0.38.0 milestone Nov 21, 2026
…gacy receipts (#3772)

- Audit replays the user-scope self package from $HOME, where install
  reads root primitives, so recorded user-root files are not orphaned.
- At user scope a file a dependency of the same install claims stays
  that dependency's ($HOME also holds dependency sources), so the root
  adds no second claim; the ownership snapshot test returns to main.
- Migration adopts only the legacy unbound root receipt, keys the claim
  by the compatibility path (relocated roots such as CLAUDE_CONFIG_DIR),
  and rebinds migrated receipts to the committed lock claims.
- Hash validators move to deployment_state.py for the module length cap.

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

pipeline.py was at its 1005-line budget on main, and the user-root receipt
migration adds a line. The --dry-run preview stop (preview_install) moves
to pipeline_entry.py, which already owns PipelinePreview and the preview
entry; the pipeline keeps its pinned call. The release note moves to
changelog.d/4684.fixed.md.

Co-authored-by: Copilot App <[email protected]>
apm-spec-waiver: user-scope root-local claims reuse the existing self-entry lockfile fields; no new OpenAPM-observable schema or behavior

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.

🟡 Changes recommended

Active migration and replay issues can leave upgraded skills with stale content and incorrectly report user-root scripted hook configurations as modified after installation.

2 open issues
3 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/core/deployment_ledger.py Resolved
Comment thread src/apm_cli/install/drift.py Resolved
#3772)

A 0.37 receipt migrates per file, so the skill directory gate now treats
a directory with a verified managed member as managed (each unclaimed
member stays protected). Audit replay at user scope renders hooks with
user-scope semantics anchored on the live user root while writing into
scratch, so install -g then audit --ci reports no drift.

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.

🟡 Changes recommended

Active issues cause false audit drift reports after clean installs using an external CLAUDE_CONFIG_DIR and O(S × M) inventory checks during skill integration.

2 open issues
2 resolved since last review

Review effort: Balanced

Comment thread src/apm_cli/install/drift.py Resolved
…ion (#3772)

The skill directory gate builds the ancestor-directory index of the
managed inventory at most once per promotion call, and only on a
collision, so membership is O(1) instead of an O(S*M) prefix scan.

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

Human assessment is needed because lockfile replay can omit inline-only user-root hooks, causing audit --ci to falsely report freshly installed Claude settings as modified.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

…3772)

Reverts the skill-gate member scan: another owner's managed file (a
local bundle) must not open an authored skill's directory. The
migration owner instead adopts the skill directory entry beside a
migrated member, as a normal lock records it (user scope only).

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.

🟡 Changes recommended

The predicate change leaves the replay-root-predicate mutation test matching zero occurrences, so its fragment and replacement must be updated to let the test reach the architecture guard.

2 open issues

Review effort: Balanced

Comment thread src/apm_cli/install/drift.py Resolved
…tion cells (#3772)

Replay now synthesizes the root self-entry from the user source root, so the
drift cell pins that root (with and without .apm/) and the replay-root-predicate
mutation targets the self_source_root predicate.

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

User-root agent context links are rendered relative to the scratch directory during replay, causing audit --ci to falsely report freshly installed agents as modified.

2 open issues

Review effort: Balanced

…e user hooks to #4837 (#3772)

Synthesizing the replay self-entry from the user source root made
test_global_update_then_audit_passes_for_released_user_lockfiles report
drift. Restore the project-scope-only self-entry, its guard, drift cell and
mutation case, and track the user-root inline hook case in #4837.

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

Human assessment is needed to evaluate the loss of Windows-compatible test coverage for the existing LF-only receipt serialization regression.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 22, 2026
…yment frame (#4832)

UnifiedLinkResolver._resolve_context_link computed context and memory
links from the replay's scratch target directory, so after a clean
apm install -g a user-root agent linking ../context/notes.context.md
drifted under audit --ci. Context links now map the target through the
deployment frame, as asset links already did; init_link_resolver sets
the frame for every package (the $HOME user root included), and a lock
self-entry (claimed root files) replays with the frame and its live
source root. No self-entry is synthesized. Writes stay in scratch.

Stacked on #4684 (a668d29).

apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract changes

Co-authored-by: Copilot App <[email protected]>
Main (#4730) moved is_canonical_bundle_hash into core/receipt_history; this
branch had moved it into core/deployment_state. Keep receipt_history as the
single owner (deployment_state imports it) and drop the duplicate ledger
helper.

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.

🟢 Approval recommended

No active review issues are reported for the user-root lockfile tracking change.

No open issues 🎉

Review effort: Balanced

…ain merge (#3772)

Inline the user-scope hook predicate at both call sites; behaviour unchanged.

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

Human assessment is needed because lockless 0.37 upgrades can omit verified migrated paths from reconciliation, leaving removed skill assets deployed without a lock claim.

No open issues 🎉

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit 3fa1b87 into main Nov 23, 2026
74 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-p2-3772-user-root-lockfile branch November 23, 2026 00:23
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
…yment frame (#4832)

UnifiedLinkResolver._resolve_context_link computed context and memory
links from the replay's scratch target directory, so after a clean
apm install -g a user-root agent linking ../context/notes.context.md
drifted under audit --ci. Context links now map the target through the
deployment frame, as asset links already did; init_link_resolver sets
the frame for every package (the $HOME user root included), and a lock
self-entry (claimed root files) replays with the frame and its live
source root. No self-entry is synthesized. Writes stay in scratch.

Stacked on #4684 (a668d29).

apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract changes

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

UnifiedLinkResolver._resolve_context_link computed context and memory
links from the replay's scratch target directory, so after a clean
apm install -g a user-root agent linking ../context/notes.context.md
drifted under audit --ci. Context links now map the target through the
deployment frame, as asset links already did; init_link_resolver sets
the frame for every package (the $HOME user root included), and a lock
self-entry (claimed root files) replays with the frame and its live
source root. No self-entry is synthesized. Writes stay in scratch.

Stacked on #4684 (a668d29).

apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract changes

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

UnifiedLinkResolver._resolve_context_link computed context and memory
links from the replay's scratch target directory, so after a clean
apm install -g a user-root agent linking ../context/notes.context.md
drifted under audit --ci. Context links now map the target through the
deployment frame, as asset links already did; init_link_resolver sets
the frame for every package (the $HOME user root included), and a lock
self-entry (claimed root files) replays with the frame and its live
source root. No self-entry is synthesized. Writes stay in scratch.

Stacked on #4684 (a668d29).

apm-spec-waiver: audit replay link text only; no manifest, lockfile or resolver contract 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 -g with only user-root agents writes no user lockfile, so edited agents are skipped instead of updated

2 participants