Repository navigation
perf(install): per-run memos for discovery, registry config and lockfile reads (#5838 slice 3) - #5841
Draft
Daniel Meppiel (danielmeppiel) wants to merge 106 commits into
Draft
Daniel Meppiel (danielmeppiel) wants to merge 106 commits into
Daniel Meppiel (danielmeppiel) wants to merge 106 commits into
Conversation
…t collected fails A required cell in tests/quality/harness_conformance.json must earn a passing receipt. Until now ReceiptWitnessPlugin only checked witnesses that passed, so a skipped witness left its required cell unproven without failing anything. - ReceiptWitnessPlugin fails a skipped or xfailed witness of a required cell (setup or call phase), naming every cell and the skip reason. A cell that no longer applies leaves through the contract (applies()), not a run-time skip. Skips of nodes that witness no required cell stay skips. - harness_ratchet.uncollected_witnesses(): every required witness node must be collected (pytest --collect-only over the witness modules), so a renamed or unparametrized witness is refused. - Mutation tests: a required witness that skips fails the gate (pytester), a skip outside required cells stays a skip, and a dropped node is named as not collected. Refs #5796 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…easured; plain skips and untracked xfails fail Refs #5796 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…quired cells A required cell's witness passes with a receipt, or is a strict KnownFailure listed in required_known_failing whose tracking equals the ledger issue, whose issue is open (closed-issue gate), and whose failure matches. Any other xfail, a skip in any phase, an uncollected node or a strict XPASS fails. The ledger only shrinks against the merge-base; a base without the section compares against the frozen 8-cell #5797 set. Refs #5796 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adds src/apm_cli/lens/: model.py, the stdlib-only interface contract of the apm list inventory (frozen dataclasses Source, Evidence, HarnessRef, Location, Item, CoverageCell, NotVisible, Inventory), and verdict.py, the only evidence -> state judgment (state, folder_content, item_state). Registers the lens-observation owner with guard registry-delegation-lens-observation: model.py imports only the standard library, only verdict.py writes an APM health state, and no lens module writes, deletes, spawns or opens a socket. One mutation case proves it. Refs #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
J13 step 1 now runs 'apm run --list' against an O1 golden captured from today's 'apm list' (the 0.39 scripts table), and asserts it runs nothing. Step 4's diagnose advice moves to 'apm run --list'. Refs #5756 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
'apm run --list' prints the 'apm list' scripts table or the No scripts found panel byte-for-byte, exits 0 and runs nothing, so bare 'apm list' can switch to the agent-config inventory. The script-not-found hint and the docs now point to 'apm run --list'. Refs #5756 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs #5756 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adds the test-only R0 layer of the apm list test plan: structured oracles, pending-witness promises, laws, schema, mutations and static guards. No committed cells: every HC-LIST promise stays pending-witness, so the harness ratchet is untouched. - oracles.Evidence gains json_equal and rows_equal (parsed path plus expected value), checked inside check_obligation; a mismatch or an unparseable output fails with no receipt. - tests/lifecycle/list_oracle.py is the one parser of apm list output (schema-validated JSON views; text rows by header column spans; summary and footer by exact clause and line). - HC-LIST-01..15 and HC-LIST-03.targets appended to harness_contract.py as pending-witness; HC-LIST-07 carries scopes=(user,) with a citation. - P-LAW-list.* laws in the property catalog as forward laws citing #5745; the ledger guard accepts a law only when bug-referenced or forward with a cited issue. - JSON Schema plus 4 outcome fixtures; S137 AST guard; C6 clone proof; tests/lifecycle/mutations/list.yaml. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lens/apm_layers.py reads one scope's lockfile once and turns its deployment ledger rows into logical items: kind and name come from the target layout, rows for one physical path are deduped (targets kept apart), and projections of one package item collapse into one item with several locations. Each unique physical file is classified once through deps/file_provenance.classify_file (made public at its owner). Folder items get a bounded recursive name walk without link following: a file outside the record makes the folder modified, a partial walk leaves it unverifiable. Recorded values that escape their root are rejected lexically, before any filesystem call. 'orphaned' is not produced in 0.40 (declared is 'yes' for every locked owner). Refs #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
'apm run --list' no longer imports from list_cmd, whose scripts body goes away when bare 'apm list' switches to the inventory. The renderer lives in run.py (a new module would need an architecture owner); output stays byte-identical. The list_cmd unit cases are ported to test_run_list.py. Refs #5756 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
lens/inventory.build(ctx) reads each requested scope's APM layer once, asks the reader package for native observations (an empty scan until the readers land) and joins them: a native observation at or inside a path an APM item lists is dropped, so one physical path is one location; a scope whose lockfile is unreadable turns its native items into not-checked. APM locations take HARNESSES from the reader records and keep ledger targets apart. --target and NAME selection run before states are summarised, and under exactly one --target same-name copies get the documented ORDER (higher/lower with order_rank, coexist, or unknown; a missing copy is never ranked). The context carries the keys the renderer needs. Refs #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…es detection The build input key for the --target selection is 'harnesses' (the target vocabulary guard rejects a raw targets read in src). build() resolves the detected harnesses (signal folders at the project and home roots, apm.yml targets and ledger targets, kept to harness reader records) and passes the selection and the detected set to the readers' scan. ORDER under one target now uses the readers' tier_of and the record's ranked/coexist/unknown rule: copies in one tier tie, and a copy whose tier cannot be read is unknown. Refs #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
MCP ledger rows (uri locators under target mcp, one per runtime) become MCP claims instead of file items. The inventory joins each claim to the readers' observation of that server name for that runtime at that scope: the location takes the observed config path and entry pointer, the observation is claimed (not listed again as unrecorded), and the entry is compared with the recorded fingerprint through the ownership owner's mcp_native_hash, imported only when an entry is compared. Entry values are read only for that comparison and never returned; the item carries the readers' keys-only shape. An entry not observed is unverifiable. Refs #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mark test_run_list.py as component (it writes apm.yml and drives Click), and keep the docs truthful while bare 'apm list' still lists scripts. Refs #5756 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Run tests/quality/test_list_{conformance_guards,oracle}.py in the
ratchet contracts job (ci.yml and merge-train.yml, kept identical).
- P-LAW-list.* forward laws are phase 0: no spine transition covers them
until the list observation invariant lands.
- list_oracle: the command kind and Commands section; an empty inventory
summary has no clause; rows() refuses -v detail lines, and details()
attaches them to the row above.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
User-scope APM items now say they are declared in the $APM_HOME manifest, shown as ~/.apm/apm.yml when it sits under the home root; project items keep apm.yml. Refs #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refs #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The oracle unit test credited a pending-witness cell id; use a neutral cell id so the pending-witness leak guard stays clean. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Under -g the project scope has no root, so context.roots values may be null. Reader order rules name the item kind (skill), unlike sources (skills); HC-LIST-10 now applies where a skill rule is recorded. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…paths
- Item names drop any extension the registry gives the primitive, so one
instruction deployed as name.instructions.md and name.md is one item.
- ORDER ranks each copy by the tier of its best location the target reads;
only copies sharing a best tier tie.
- Recorded paths that map to no primitive layout, and paths not confined to
their root, are coverage cells, never a made-up 'file' item; 'canvas'
joins the kind vocabulary.
- User-scope rows under $HOME are matched under the target root install
resolves (root variables such as CLAUDE_CONFIG_DIR honoured).
- Path dedupe and the ancestor manifest hint are separator-agnostic
('../apm.yml' on every OS).
- The folder walk cap is a read_layer parameter, so tests pass it instead
of patching the owner.
Refs #5754
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Link ownership through path_security.user_owned_link, native activation keys from native_plugins.settings, no target-vocabulary reads, records.py counted as registry data by the harness-literal guard, and a vendor file name is not the removed plugin-lifecycle symbol. Refs #5746, #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…olders by descriptor Folds AUD F1-F3: the managed-settings ownership gate is re-checked on fstat, subfolders below a root are opened O_NOFOLLOW and listed by descriptor, and the tombstone exemption applies only to the quoted installed_plugins.json name. Refs #5746, #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… evidence not_visible[].os and record OS rows use linux, macos and windows (sys.platform mapped once). A plugin activation entry in a settings file now sets configured and evidence_source on the install record with the same plugin id (narrowest scope, then the file read last); an entry with no install record is one plugin item with present no. Install records carry plugin@marketplace ids. Tests are Windows-safe (bytes for frontmatter, absolute tmp system paths). Refs #5746, #5754 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ine bypass Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve copies a local legacy plugin into apm_modules and validation normalizes that image in place. The integrate phase deleted it, copied the source again and normalized a second time (install/sources.py:219 via validate_apm_package). Resolve now hashes the raw image of a plain legacy plugin when it copies it (install/local_plugin_image.py), and integrate reuses the image it validated: same bytes, hashed once, normalized once. Native Agent Plugins, Codex compatibility manifests, catalog manifests and any image this run did not produce still take the copy-and-validate path. Fresh 14 plugins: normalize 28 -> 14, top-level copytree 18 -> 7. Re-passing 23: normalize 46 -> 23. apm-spec-waiver: install-internal reuse of an already validated local package image; no OpenAPM requirement changes. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…-local-plugin-install-perf
…owner (#5838) The unit ctx stub carries resolved_local_plugins as InstallContext does. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… it and it still hashes the same (#5838) Resolve records a plain legacy plugin's raw files and digests when it copies it; the record is kept only when the resolved graph holds a validated package rooted at that image (keep_validated_local_plugins). Integrate reuses the image only while it still holds every recorded raw file with the same digest and adds nothing but the synthesized manifest and .apm/; any other change re-copies and re-validates. Unit cells cover an edited, added and linked file and an unvalidated record; an integration cell installs a plugin whose plugin.json is broken: it fails and deploys nothing. The count-budget harness gains the plugins14 journeys (install-g-14-plugins, install-g-23-plugins-repass) with the calls table flattened into calls.* rows; fs rows follow from the Linux CI measure. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Slice 3, step 1 of #5838: - discover_primitives collects one inventory snapshot per root and shares it across the three primitive types (three walks became one per root; the finalize hint's apm_modules discovery too); - _load_yaml_registries reuses its parse while the file's (mtime_ns, size, inode, device) is unchanged, so a rewrite is read again; each caller gets its own dict; - the install -g global compile hint returns before walking apm_modules when no active target can print it, or there is no logger. Results are unchanged: the same snapshot serves every type, and the registry memo is keyed by the file's stat signature. cost: one os.stat per registry lookup instead of a read and YAML parse; on the 14-plugin world scandir 4,912 -> 2,918, open_r 2,858 -> 2,724, lstat 62,733 -> 60,529, discovery walks 45 -> 15. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Slice 3, step 2 of #5838. LockFile.read keeps one immutable snapshot (the pickled, adopted lockfile) per document version and returns an independent copy per read, so mutating one result never reaches another. A version is the writer's staged entry (by identity: every stage is new), else the file's (mtime_ns, size, inode, device): an APM write, a stage or an external rewrite is always read again. Symlinks, missing files and removed stages are never memoized; _note_rows still runs on every read. install/run_memos.py is the one reset of every run memo (perf counters, discovery, lockfile reads, registry parses) at pipeline start. The lockfile contract rules now check LockFile._read_document, which kept the staged, warn_if_newer and read_lockfile_text routes. cost: one lstat per read; on the 14-plugin world 19 reads build 5 LockFile objects (one per version the run writes) instead of 19, and apm.lock.yaml disk opens drop 19 -> 13 (the rest are raw-text readers). Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
- Reuse requires resolve's graph to hold the package at exactly the recorded destination, and integrate to read that same path (cost 0). - Move the record call to one line so install/phases/resolve.py stays at its 1001-line budget. - Add fs budget rows for the plugins14 journeys, measured on Linux PR CI. - Give the LocalDependencySource ctx stubs a resolved_local_plugins map. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Security folds on #5841: - both memo signatures (lockfile reads, registry YAML) add st_ctime_ns, so a same-size in-place rewrite that restores the mtime is read again; no API sets the ctime, and it costs no extra syscall; - the write authority's commit, remove and restore paths, and an unscoped LockFile.write, forget the remembered read for that path, so APM's own writes invalidate regardless of timestamp granularity or inode reuse. cost: 0 (same lstat; one dict pop per write). Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
fs.lockfile_reads for the local plugin world, red on #5839's head: - install-g-14-plugins: 19 -> 13 (budget 14); - install-g-23-plugins-repass: 24 -> 9 (budget 10). LockFile.read now builds each document version once per run. Counted on the same hermetic world (base 19 / 25, head 13 / 9); lstat moves by about 4% here, inside the 5% slack, so its rows stay. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Mutate a recalled copy, not only the object the build returned, and assert the next recall and a fresh read still hold every row. A recall that shared one object per snapshot now fails. Test-only; src is unchanged. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
6 of 14 tasks
…istic Resolve copies local packages on parallel workers. The calls table kept one shared nesting depth and an unlocked increment, so concurrent copies were counted or dropped at random (9 and 13 on Linux CI for the same build). Depth is now per thread and increments are locked. Copytree is exactly one per local plugin: 14 and 23, against 28 and 46 on main. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…memo test_n_shared_configs_with_deep_paths_read_the_other_lock_once pins that the command (invocation) memo reads the other scope's lockfile once across N configs, with a no-memo control reading it N times. The run's LockFile.read memo (#5838) now also dedupes those opens, which made the control read once. Clear that memo before each call in both arms, so the one-versus-N contrast stays the command memo's alone. Test-only. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Dec 3, 2026
6 of 14 tasks
Windows CI showed stat signatures cannot tell a same-size in-place rewrite apart: NTFS mtime ticks are 100 ns and os.stat's st_ctime is the creation time there; Linux's coarse kernel clock leaves the same gap within a tick. Per AUD (K1-K4): - LockFile._read_document reads the text through read_lockfile_text on every read (its link and regular-file refusals included) and recalls only when the full text is identical; only parse, validation, build and adoption are memoized; - the key also carries adoption's other inputs: whether the path is the user scope root, and the home directory; - the registry YAML memo reads the file each call and reparses only when its text changed; - staged-entry identity, the forget on commit/remove/restore, pickled independent copies and the clear at pipeline start are kept. The plugin journeys' fs.lockfile_reads rows return to #5839's values: every read now reads the file, and the saving is the build (19 reads build 5 LockFile objects on the 14-plugin world, 19 on #5839). cost: one raw read per LockFile.read, as before #5838; no stat calls. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve normalizes a local plugin in a staging directory with an opaque name. Normalization names a root-declared skill, and a manifest without a name, after the directory it runs in, so reusing that image deployed the root skill a second time under the staging name. Reuse now refuses an image whose synthesized paths or metadata carry the staging name; integrate normalizes it at its destination as before. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Resolve normalizes a local plugin in an opaque staging slot. A root-declared skill installed at user and project scope deploys once, under the plugin's name, and is normalized again at its destination. Red at bcd7a45 (the slot name deployed as a second skill). Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The staging-name check read only apm.yml and the top-level .apm metadata. It now reads every file normalization added, by path and by content; a file that cannot be read as text still refuses reuse. Refs #5838 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
6 of 10 tasks
Daniel Meppiel (danielmeppiel)
added a commit
that referenced
this pull request
Dec 3, 2026
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
0e8957e61e655adfdcf00222b67930b67b98d059↑ The 14-plugin world installs with the same deployed tree,
apm.ymland lock (analyst A/B on step 1); 11,739 neighbour unit tests and the architecture suites pass.↑ Content-keyed freshness (AUD K1-K4): every mutant is killed by its own cell (recall before read; length-only compare in either memo; no adoption key; no commit forget; shared recall).
↓ PR CI and tier2 are not observed at this head.
Description
Slice 3 of #5838 (per-run memos), stacked on #5839: review
8fa3cfc8,79ba24da, fragmentbce6a930, security folds186cce94, the recall-aliasing cell384c6e29, the shared-hook read-count control isolationd1541003, the owner-pin fix7e714161and the content-keyed memos60b9ca6b(which supersede the stat signatures and the rows in7c9fff7a);61b8441a,382dc329and60f4ded2merge #5839 c9e5703, bcd7a45 and cb64839, and0e8957e6merges signed #5834 5b83983 for train 5 (catalog sorted union only). The rest of the diff is #5839.CompileInventorywalk per root, shared by the three primitive types_DISCOVERY_CACHEalready memoized per root_load_yaml_registries)LockFile.read: one build per document versionread_lockfile_text(refusals included); recall only when the full text is identical (or the same staged entry), with the user-scope flag and home directory in the key; APM commits, removals and restores forget the path; an independent copy per readapm_moduleswithout a root-context-only targetinstall/run_memos.pyis the one reset of every run memo at pipeline start (perf counters, discovery, lockfile reads, registry parses), so a long-lived process never sees an earlier run.lockfile-generator-gate,lockfile-regular-read,lockfile-write-authority) now checkLockFile._read_document, which keeps the staged,warn_if_newerandread_lockfile_textroutes.readonly adds the memo and_note_rows.apm install -gis ~17x slower than file copy (double normalization, repeated copytree, per-char ContentScanner) #5838 candidate, not a slice.cost: no extra syscalls: the lockfile and registry YAML are read as before, and only the parse, validation, build and adoption are saved per content version. Timestamps are never trusted (NTFS ticks, coarse kernel clocks). On the 14-plugin world (macOS, tracer): scandir 4,912 -> 2,918; lstat 62,733 -> 54,888; LockFile builds 19 -> 5 at the same 19 reads; finalize 182 -> 125 ms; services 230 -> 67 ms. Analyst A/B against #5839 on a clean host, best of 3: 1,952 -> 1,805 ms; deployed tree,
apm.ymland lock identical. Budget rows: unchanged from #5839 (every read still reads the file; the saving is the build).Issue and approved scope
Issue: Refs #5838
Human scope-approval comment: #5838 (comment)
Does this PR complete the issue, or what remains? No. This is slice 3 of the floor plan; slices 2, 4-10 remain.
Type of change
Testing
Red-first (
tests/unit/test_install_run_memos.py, new promiseP-PERF-install-run-memos), via local-test.sh:4 failed, 2 passed(before the folds) (discovery walks3 == 1, registry parses3 == 1, lockfile builds5 == 1, hint walk called); the two freshness guards pass on main by design.11 passed(plus a symlink variant skipped on Windows). The two fold cells (an mtime-restoring same-size rewrite; a commit that forgets the replaced read) each fail under their mutant (ctime dropped from either signature; the commit-path forget removed).Neighbours:
tests/unit/deps tests/unit/install tests/unit/primitives tests/unit/compilation tests/unit/registry tests/unit/test_apm_yml_registries.py-> 9,093 passed. The one failure,test_no_install_module_exceeds_loc_budget(phases/resolve.py1004 > 1001), is inherited from #5839's head and is not touched here. Architecture: owner-rule mutations and lockfile write-authority suites -> 1,775 passed.Lint mirror: ruff 0.15.12 check and format, pylint R0801, auth-signals, complexity ratchet, tm006 and the architecture linter are all clean.
Changelog
changelog.d/<pr>.<section>.md.Spec conformance (OpenAPM v0.1)
Co-authored-by: Copilot App 223556219+Copilot@users.noreply.github.com