Skip to content

perf(install): locked install engine -- no-op and locked apply skip the pipeline (2-3x) - #4893

Merged
Daniel Meppiel (danielmeppiel) merged 125 commits into
mainfrom
danielmeppiel-perf-lanec-s2
Nov 23, 2026
Merged

Daniel Meppiel (danielmeppiel) merged 125 commits into
mainfrom
danielmeppiel-perf-lanec-s2

Conversation

@danielmeppiel

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

Copy link
Copy Markdown
Collaborator

Description

Lane C install engine train: a bare apm install or apm install --frozen on a locked project skips the install pipeline when the verified lockfile, caches and live policy prove the full run would produce the same state.

  • No-op (empty diff): prints the full run's output through the full run's own owners and writes nothing.
  • Locked apply (warm cache, deployed files or apm_modules missing, e.g. CI or a fresh clone with a committed lock): copies package copies from the read-only git cache (verified and scanned in a private temp copy, then published inside apm_modules by one rename each), writes deployed bytes from the deploy store (perf(cache): store every deployed file's bytes by lockfile hash (deploy store) #4846) bound to package-bound render records and re-hashed against the committed lockfile (each file appears whole by a link and never replaces one; paths only under the active targets' deploy roots), records receipts, then prints the full run's output.
  • Any doubt = the untouched full pipeline. The engine decides before any write; APPLY never deletes; non-ASCII deployed bytes, edited or unreceipted files, orphans, stale copies, store or record misses, non-git sources, root .apm/, a found org policy issue, and any non-bare argv all run the full pipeline. The writes, receipts and rendered output share one journal: any failure restores the pre-run tree, drops the held output and runs the full pipeline once; a restore that cannot put every path back stops with exit 1 and names the paths, and never falls back. APM_INSTALL_FAST_PATH=decide decides with every cache read-only.
  • APM_INSTALL_FAST_PATH=0 disables it; trace prints one decision line; decide stops after a decline (parity cells).

Cars in this train: S0 no-op (L5), S1 deploy store sync with #4846 (F&C), package-bound records (F&C), APPLY engine + early CLI entry (IFP), fast_output renderer + update_notice import trim (L5), policy-chain memo (F&C).

Fresh installs (no lockfile) are NOT in this train: the resolution-memo design was blocked by W3b/QL (C1-C9) and reverted; it is tracked as research.

Issue and approved scope

Issue: Refs #4897 (locked apply), Refs #4770 (no-op fast path) and Refs #4854 (deploy store, S1).

Human scope-approval comment: #4897 (comment) (locked apply), #4770 (comment) (no-op) and #4854 (comment) (deploy store).

Does this PR complete the issue, or what remains? It delivers the #4770 no-op target by a different mechanism (stateless proof instead of replay) plus locked apply. Fresh-install speedups remain (S4'').

Type of change

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

Testing

  • Tested locally (targeted, through the shared host guard)
  • All existing tests pass (CI)
  • Added tests for new functionality (if applicable)

Evidence:

  • S3 engine-parity suite (test(lifecycle): engine parity suite for the install fast paths #4849, 43 cells: fast vs full byte-compared stdout, stderr, exit code, project tree, lockfile, receipts): 42 passed, 1 xfail (fresh hit, gated on S4) at this head, locally via host_guard with -n 2.
  • tests/unit/install/test_diff_apply.py (15, incl. a static no-delete guard), tests/unit/cache/test_deploy_store.py, tests/integration/test_deploy_store_lifecycle.py, tests/integration/test_policy_absent_memo.py: pass.
  • Lint mirror: ruff check/format, pylint R0801, complexity ratchet, architecture boundaries, auth signals, taxonomy (tm006), assertion ratchet: clean.

CI perf bench at head a8e519d (code-identical to the final head) (CPU user+sys incl. children, paired new/base vs 8710b95, rtt 30 ms, 3 runners x 3 interleaved pairs; wall not used):

OS no-op locked-warm frozen run
Linux tree-10 2.46x 2.03x 2.26x 45114368129
Linux tree-50 3.78x 2.61x 2.91x 45114368129
macOS tree-10 2.72x 2.13x 2.42x 45114380519
Windows tree-10 2.42x 1.90x 2.18x 45114381459

Spawns 29 -> 3 on frozen, 0 network requests, 0 errors in every cell.

Changelog

  • One fragment per section, changelog.d/<pr>.<section>.md, holding
    one line: user-visible effect first, 25 words or fewer, ending with
    (#PR); breaking changes only under upgrade notes; no Highlights; no
    new lines under ## [Unreleased]. See changelog.d/README.md and
    .github/instructions/changelog.instructions.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 (install outcome, lockfile and deployed bytes are byte-identical to the full pipeline; apm-spec-waiver in the merge commit).

A plain 'apm install' (or --frozen) on an unchanged project now decides
'No changes' from state alone: the lockfile written by this APM version,
every locked package copy proving its locked content, the apm audit --ci
baseline owner passing (manifest/lock identity, ledger owners, deployed
files present and hashed, MCP config consistency, hook approval pins, the
executables gate against the live policy) and, when a policy is in force,
its dependency checks. Org policy is discovered and routed live on every
run. Anything else, or any doubt, runs the full pipeline. No memo, no
recorder. APM_INSTALL_FAST_PATH=0 turns it off.

apm-spec-waiver: prototype for the lane C no-op bench; output is the no-op summary

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

Every full install now records each deployed file's exact bytes in
<cache>/deploy_v1/<hex[:2]>/<hex>, keyed by the canonical sha256 the
lockfile records as its deployed_file_hashes value. This is the lane C
deploy-store unit (S1): later commands can rebuild a deployed file from the
lockfile hash alone.

- Keys are exactly 64 lowercase hex characters (fullmatch), so no path.
- Every read re-hashes the entry; a mismatch is evicted and returned as a
  miss. Linked buckets and entries are never followed; only regular files.
- Writes go to an owner-only exclusive temp file, then os.replace; a warm
  install costs one lstat per file (same-size entries are left alone).
- The lockfile phase reads each deployed file once to hash and store it.
- Owner record deploy-store + guard transport-platform-deploy-store-verified-reads
  (frozen inventory + mutation case).

apm-spec-waiver: machine-cache side store only; lockfile, deployed files and every OpenAPM-observable output are unchanged

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

W3b hardening at 42d3658: Windows junctions/reparse points are refused
like symlinks; get(raw_sha256=...) lets a byte-exact restorer reject the
other line-ending image sharing a normalized key; APM_NO_CACHE parses like
get_cache_root.

Co-authored-by: Copilot App <[email protected]>
Co-authored-by: Copilot App <[email protected]>
…entity, no-delete apply (S2 car 1)

Co-authored-by: Copilot App <[email protected]>
…ordered plan to the renderer (S2)

Co-authored-by: Copilot App <[email protected]>
…e's owners

install/fast_output.render prints the header, target provenance, one cached
header plus '(files unchanged)' (or the engine's per-package body) per
locked package in install order, runs the pre-deploy merged MCP policy
check and the MCP/LSP service reconciliation itself, then the post-install
summary. The engine's empty diff now prints exactly the full no-op's
output (validated on tree-10 and the lifecycle differential cells on
danielmeppiel-perf-noop-diff @973dca8a).

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

The install's own policy gate announces the org policy outcome with the
same logger (and records the banner, so the executables trust reader does
not repeat it neutrally), then runs the dependency policy checks on the
locked set; its fetch feeds the trust map, so discovery runs once.

Co-authored-by: Copilot App <[email protected]>
… bound; cache clean

QL red at c29777a: a refused `install --frozen` stored the changed local
snapshot's bytes, because hashing wrote the store. Hashing now only stages
{path: digest} per command run; InstallService.run commits the staged files
after the install committed (and discards them before the pipeline), each
re-read and re-verified, so a refused or failed install stores nothing.

#4854 conditions: entries above 4 MiB are never stored; a command that
added entries evicts least recently used ones above 256 MiB down to 80%
(a verified read refreshes recency); `apm cache clean` empties the store
through the canonical cleanup owner (cleanup guard consumer); DeployStore
takes the cache root. Cells: size bound, entry bound, clean, staging
contract, bytes changed after hashing, and an e2e that an empty or deleted
store changes nothing. The frozen-local lifecycle oracle after the
SUCCESSFUL accepted install now allows only self-verifying deploy-store
entries holding the accepted deployment; every refused row is unchanged.

Refs #4854

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

- The engine's own policy/audit verification runs under fast_output.quiet():
  its trust readers would report a policy miss neutrally before the header;
  render's policy gate announces it in the full run's place and wording.
- noop_diff.sources_scan_clean: any pre-deploy scan finding in a package
  copy declines to the full pipeline, which prints those warnings.

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

QL's S2 binding rule, owned in the deploy store: the lockfile authorizes
nothing by itself. After an install commits, each dependency whose content
hash was verified this run, and whose every recorded file the integrators
produced or claimed and this run hashed, gets one render record keyed by
sha256(version, repo_url, resolved_commit, content_hash, sorted targets,
scope): {rel: [canonical digest, raw sha256 of the exact bytes]}, ascii_only
and the package's output body (fresh deploys only). A record is written only
when every blob it names is stored.

- DeployStore.package_record(...) validates the shape and refuses linked,
  non-regular, oversized or malformed records (None = full run).
- record_matches(record, lock_hashes): exact equality with the lock's
  deployed_file_hashes, so a hand-edited row pointing a path at another
  cached blob is refused.
- get(digest, raw_sha256=...) refuses the other line-ending image.

Red-first rows: lock edit to another cached blob refused; CRLF image refused
by the recorded raw digest; another setup never reads the record; malformed
and linked records read as None; no record when a blob is not stored; e2e:
every installed package gets a record binding its lockfile hashes.

Co-authored-by: Copilot App <[email protected]>
A no-op install asks for the org policy several times (preflight, gate,
exec trust, MCP); each ran discovery again, re-reading the git remote and
re-fetching. discover_policy_with_chain is now memoized per command run
(core/invocation_memo, keyed on every argument), reusing each answer except
outcomes a retry in the same command may change (cached_stale,
cache_miss_fetch_fail, incomplete_chain). Lifecycle scripts still drop the
memo; a new command run discovers again. No .git/config parsing.

Red-first: one command run discovers a found chain once and reads the git
remote once (both fail without the memo); a transient failure is retried in
the same run; the next run discovers again.

apm-spec-waiver: policy discovery call count only; the resolved policy and every outcome are unchanged

Co-authored-by: Copilot App <[email protected]>
- render(frozen=True) runs the services phase with the frozen disposition
  and prints frozen_verified_line (the same owner as commands/install.py)
  after the summary.
- The engine's empty diff traces 'no-op (desired state already deployed)',
  the S3 contract line.

Co-authored-by: Copilot App <[email protected]>
…ng; harvest-only decorator (S2)

Co-authored-by: Copilot App <[email protected]>
Apply output renders through the full run's owners with per-package bodies;
frozen is a FrozenDisposition end to end.

Co-authored-by: Copilot App <[email protected]>
…e; cache info

Copilot threads on 9283d91:
- Reads open with O_NONBLOCK (a FIFO is a miss, not a hang), reject
  oversized descriptors and read at most the bound + 1 (an entry grown out
  of band is a miss and is evicted).
- put() verifies the incoming digest first; a same-size existing entry is
  kept only if it still hashes to its key, otherwise it is atomically
  replaced (so the next full install heals same-length damage).
- Eviction scans only key-named entries in their own real shard (Windows
  junctions and linked shards refused; .tmp-*.part and strays untouched);
  the same scan feeds `apm cache info` (deployed entries and size).
- The empty-store e2e ignores .apm-local/installation (a per-run id), and
  an e2e covers install -> cache info -> cache clean --force.

Co-authored-by: Copilot App <[email protected]>
Cold: a refused install leaves deploy_v1 empty. Warm: after a successful
install, a refused install leaves the whole cache byte-identical.

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

The fresh-install memo needs live re-derivation of every trust field and
git-object verification; it moves to a dated follow-up, not this train.

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 a critical fast-path target-selection mismatch can report success after switching to Claude without deploying Claude files.

2 open issues

Review effort: Balanced

…ecide skips the update notice

The engine's present-copy check uses cache_pin.marker_is_current, the cache-pin
owner's own predicate, instead of probing the marker itself (copy validity
stays with drift.locked_copy_proof). APM_INSTALL_FAST_PATH=decide skips the
update notice, which may create its cache or fetch. The one umask read that
must swap uses the most private temporary mask, and a guard keeps every other
module off os.umask.

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 fast installs can bypass carried-licence validation and publish altered executable permissions despite package-content hash checks.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

… observes a real write's mode

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 a critical publication race can cause rollback to mistake another writer’s directory for its own and recursively delete that writer’s files.

No open issues 🎉

Review effort: Balanced

@danielmeppiel

Copy link
Copy Markdown
Collaborator Author

Merge-only update: main 9959a49 merged into the train (head 5767591). The train's src patch is unchanged across the merge: the md5 of the filtered +/- lines of git diff <main base> <head> -- src is a870ed7c both before (04676a3 against main 7f94fb4) and after (5767591 against main 9959a49). The parity kit and CI durations are byte-identical to #4916 at 920527c.

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

A critical race can cause rollback to delete another writer’s files because the destination’s identity is captured after publication rather than from the staged directory before the atomic rename.

1 open issue

Review effort: Balanced

… before the rename

The rename keeps the directory's identity, so taking it from the staged copy
means a destination substituted between the rename and the record is never
taken for this install's output; rollback leaves it in place and reports it.

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

With APM_NO_CACHE=1, the temporary-cache path still creates and chmods a directory during read-only scopes, violating the no-write contract for decision-only runs.

No open issues 🎉

1 resolved since last review

Review effort: Balanced

@danielmeppiel
Daniel Meppiel (danielmeppiel) merged commit fc1866b into main Nov 23, 2026
79 checks passed
@danielmeppiel
Daniel Meppiel (danielmeppiel) deleted the danielmeppiel-perf-lanec-s2 branch November 23, 2026 14:38
Daniel Meppiel (danielmeppiel) added a commit that referenced this pull request Nov 23, 2026
Rebased onto main after #4893 (squashed). LockFile.write records the
document it dumped as the parse of the text it wrote, so later reads in
the same command skip the YAML parse; top_level_scalar_values memoizes
its pure scan.

QL rebase conditions:
- The seed goes through lockfile_container.parse_key(text), the machine
  loader's key, so a read uses exactly the parse a fresh read would.
- One admission gate, yaml_io.machine_yaml_admits, is shared by
  load_machine_yaml_str and the seed: an over-budget text is never
  seeded and a read refuses it exactly like a fresh read (cell).
- A dumped document loads back exactly equal, in key order, through the
  machine loader for adversarial scalars (cell).

Refs #4939

apm-spec-waiver: in-process parse reuse of APM-written lockfile text; no spec surface 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

performance Legacy classification name; prefer type/performance. Retained for history.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants