Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
29cf274
perf(install): opt-in no-op fast path that replays a verified no-op i…
danielmeppiel Nov 22, 2026
1e5e6cd
test(install): J12 drift recovery with the fast path on; unflagged in…
danielmeppiel Nov 22, 2026
95e951d
perf(install): address H8 pre-review: cache root chmod only on change…
danielmeppiel Nov 22, 2026
e7277ad
refactor(install): split the no-op recorder into install/noop_recorde…
danielmeppiel Nov 22, 2026
84c9464
perf(install): default-off costs nothing: the fast path loads only wh…
danielmeppiel Nov 22, 2026
357f9e2
test(install): approve after the first install; keep journey bodies i…
danielmeppiel Nov 22, 2026
35e61c7
perf(install): a directory's entry-derived metadata is not an input u…
danielmeppiel Nov 22, 2026
d6b4f61
test(install): differential cells compare like for like
danielmeppiel Nov 22, 2026
73273e6
test(install): TEMPORARY red-first mutation, keep only the invocation…
danielmeppiel Nov 22, 2026
b6abe0a
Revert the temporary red-first mutation (W4 H8 proof complete)
danielmeppiel Nov 22, 2026
04cad0e
perf(install): close the latest review findings on the opt-in recorder
danielmeppiel Nov 22, 2026
ea89168
fix(install): the recorder never re-enters itself or fails the install
danielmeppiel Nov 22, 2026
e8f8af2
fix(install): fold review threads on the no-op fast path
danielmeppiel Nov 22, 2026
89ade08
feat(install): the no-op fast path is on by default
danielmeppiel Nov 22, 2026
6856d2c
test(lifecycle): memo fixed point and stamp negative rows (QL ruling)
danielmeppiel Nov 22, 2026
f7cb3ae
fix(install): fold the 9 review threads on the default-on fast path
danielmeppiel Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .apm/architecture/owners/install-deployment.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,16 @@
"selectors": ["src/apm_cli/models/dependency/selection.py"],
"guards": ["install-deployment-uninstall-selection"]
},
{
"id": "noop-install-replay",
"decision": "Whether a plain apm install / --frozen may replay a recorded no-op instead of running the pipeline: recorded inputs byte-identical, live org policy re-discovered, deployed files verified by lockfile content hash",
"owner": "install/noop_fast_path.py (run_with_fast_path, engaged only by commands/install.py install); install/noop_recorder.py observes the recorded run",
"selectors": [
"src/apm_cli/install/noop_fast_path.py",
"src/apm_cli/install/noop_recorder.py"
],
"guards": ["install-deployment-noop-replay-owner"]
},
{
"id": "explicit-policy-source",
"decision": "Explicit install/update --policy source: per-invocation binding, tighten-only composition with discovered org policy, and per-source fetch_failure_default routing of a source that cannot be loaded",
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4775.changed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `apm install` and `apm install --frozen` on an unchanged project replay the verified previous no-op instead of re-running the pipeline; org policy and deployed-file content hashes are re-checked on every run, and `APM_INSTALL_FAST_PATH=0` turns it off (#4775)
1 change: 1 addition & 0 deletions docs/src/content/docs/reference/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ The additive setting does not derive trust settings for `apm run` children or co
| `APM_NO_CACHE` | `1`/`true`/`yes` disables read and write of the cache for the current invocation. | unset | Equivalent to `--no-cache` on commands that support it. |
| `APM_TEMP_DIR` | Override the temp directory used by clone and download operations. | system default | Useful on Windows when endpoint security blocks `%TEMP%`. Resolution: env var > `temp_dir` in `~/.apm/config.json` > system default. |
| `APM_HOME` | Override the root for APM-owned user metadata and configuration. | `~/.apm` | Must be writable. Does not redirect files deployed to agent targets. |
| `APM_INSTALL_FAST_PATH` | `0`/`false`/`no`/`off` turns off the no-op install fast path. When on, a plain `apm install` (or `--frozen`) replays the previous no-op only when every file, directory and setting it read is unchanged, the org policy (re-checked each run) is the same, and deployed files still match their lockfile content hashes; otherwise the full install runs. `trace` also prints each decision to stderr. | on | Stamps live under the cache root (`noop_v1/`); a replay never writes the project. Not used on Windows. |
| `APM_NO_REFLINK` | Any non-empty value disables copy-on-write (reflink) optimisation; APM falls back to plain copies. | unset | Diagnostic / portability escape hatch. |
| `APM_COPILOT_COWORK_SKILLS_DIR` | Override the destination directory for Copilot cowork skills. | platform auto-detect | Resolution: env var > config > auto-detect. |
| `APM_COPILOT_APP_DB` | Override the path to the GitHub Copilot desktop App SQLite database used by the `copilot-app` target. | platform auto-detect | Useful for tests or non-standard Copilot installs. Resolution: env var > auto-detect. |
Expand Down
6 changes: 6 additions & 0 deletions packages/apm-guide/.apm/skills/apm-usage/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ replay without ref discovery; new names may require a lookup.
Align manifest refs and regenerate the lockfile with a normal install to repair
a collapsed graph; `--force` does not bypass this check.

A plain `apm install` (or `--frozen`) on an unchanged project replays the
previous no-op and writes nothing, but only when every file it read is
byte-identical, org policy (re-checked each run) is unchanged and deployed
files match their lockfile content hashes; otherwise the full install runs.
`APM_INSTALL_FAST_PATH=0` turns this off; `=trace` prints each decision.

`apm deps list` recognizes declared or locked aliases at their canonical
install paths and displays logical dependency identities, including in user
scope. It reads only the selected store; it does not substitute another store.
Expand Down
112 changes: 112 additions & 0 deletions scripts/architecture_linter/checks/install_noop_replay.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
"""No-op install replay ownership guard (#4770).

``install/noop_fast_path.py`` owns the decision to replay a recorded no-op
install. Its proof must keep the live checks it adds on top of the
recorded inputs: org policy re-discovery routed by the outcome owner
(``discover_trust_policy`` + ``classify_project_policy``) and
the lockfile content-hash verifier (``verify_deployed_file_hashes``). Only the
``apm install`` command (commands/install.py) may engage it, and no other
module than its recorder (``install/noop_recorder.py``) installs process-wide
audit hooks.
"""

from __future__ import annotations

import re

from scripts.architecture_linter.checks.install_policy_shared import (
_banned,
_configured,
_count_re,
_report,
_tree_python_paths,
)
from scripts.architecture_linter.facts import FactsProvider
from scripts.architecture_linter.models import Violation

RULE_NOOP_REPLAY = "install-deployment-noop-replay-owner"

_OWNER = "src/apm_cli/install/noop_fast_path.py"
_RECORDER = "src/apm_cli/install/noop_recorder.py"
# Imports the owner when apm install runs (on unless APM_INSTALL_FAST_PATH=0).
_GATE = "src/apm_cli/install/pipeline_entry.py"
_ENGAGER = "src/apm_cli/commands/install.py"
_SOURCE_TREE = "src/apm_cli/"
_LIVE_CHECKS = (
(re.compile(r"\bdiscover_trust_policy\(project_root\)"), "live org policy discovery"),
(
re.compile(r"\bclassify_project_policy\(project_root, fetch_result=result\)"),
"the canonical policy outcome route",
),
(
re.compile(r"\bverify_deployed_file_hashes\(project_root, lock\)"),
"the lockfile deployed-file content-hash verifier",
),
(re.compile(r"\bdeployed_hashes_intact\(project_root\)"), "the deployed-hash check on replay"),
)
_ENGAGE = re.compile(r"\bnoop_fast_path\b")
# The decorator must sit directly on the install click callback.
_DECORATED_INSTALL = re.compile(r"^@pipeline_entry\.noop_fast_path$")
_INSTALL_DEF = re.compile(r"^def install\(")
_AUDIT_HOOK = re.compile(r"\bsys\.addaudithook\(")


def _decorates_install(lines) -> bool:
"""``@noop_fast_path`` is the decorator line right above ``def install(``."""
texts = [text.strip() for _, text in lines]
return (
any(
_INSTALL_DEF.match(texts[i]) and i > 0 and _DECORATED_INSTALL.match(texts[i - 1])
for i in range(len(texts))
)
and _count_re(lines, _DECORATED_INSTALL) == 1
)


def check_noop_replay_owner(provider: FactsProvider) -> tuple[Violation, ...]:
"""A no-op install replays only through install/noop_fast_path.py, live checks kept."""
rule_id = RULE_NOOP_REPLAY
owner, owner_fail = _configured(provider, _OWNER, rule_id)
engager, engager_fail = _configured(provider, _ENGAGER, rule_id)
findings: list[Violation] = [*owner_fail, *engager_fail]
if owner_fail or engager_fail:
return tuple(findings)
for pattern, what in _LIVE_CHECKS:
if _count_re(owner, pattern) != 1:
findings.append(
_report(rule_id, _OWNER, f"a replayed no-op must re-run {what} exactly once")
)
if not _decorates_install(engager):
findings.append(
_report(
rule_id,
_ENGAGER,
"apm install's callback must be decorated with @pipeline_entry.noop_fast_path",
)
)
others = _tree_python_paths(
provider, _SOURCE_TREE, excluded=(_OWNER, _ENGAGER, _RECORDER, _GATE)
)
findings.extend(
_banned(
provider,
rule_id=rule_id,
paths=others,
pattern=_ENGAGE,
message="Only apm install (commands/install.py) engages the no-op replay",
configured=False,
respect_exempt=False,
)
)
findings.extend(
_banned(
provider,
rule_id=rule_id,
paths=_tree_python_paths(provider, _SOURCE_TREE, excluded=(_RECORDER,)),
pattern=_AUDIT_HOOK,
message="Only install/noop_recorder.py installs a process-wide audit hook",
configured=False,
respect_exempt=False,
)
)
return tuple(findings)
14 changes: 14 additions & 0 deletions scripts/architecture_linter/checks/install_policy_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

from __future__ import annotations

from scripts.architecture_linter.checks.install_noop_replay import (
RULE_NOOP_REPLAY,
check_noop_replay_owner,
)
from scripts.architecture_linter.checks.install_policy_deployment_and_ref import (
RULE_DEPLOYMENT_FRAME,
RULE_LOCAL_ANCHOR,
Expand Down Expand Up @@ -154,6 +158,16 @@
),
check=check_policy_disable_switch_owner,
),
Rule(
id=RULE_NOOP_REPLAY,
group=GROUP,
guard_ids=(RULE_NOOP_REPLAY,),
description=(
"A no-op install replays only through install/noop_fast_path.py, which keeps "
"live policy discovery and the deployed-file hash verifier."
),
check=check_noop_replay_owner,
),
Rule(
id=RULE_EXPLICIT_POLICY_SOURCE,
group=GROUP,
Expand Down
7 changes: 5 additions & 2 deletions src/apm_cli/cache/paths.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import contextlib
import logging
import os
import stat
import sys
import tempfile
from pathlib import Path
Expand Down Expand Up @@ -136,9 +137,11 @@ def _ensure_dir(path: Path) -> None:
"""Create directory with mode 0o700 if it does not exist."""
try:
path.mkdir(parents=True, exist_ok=True)
# Set permissions (best-effort on Windows where modes are no-ops)
# Set permissions (best-effort on Windows where modes are no-ops). An
# existing 0o700 directory is left untouched: a converged command writes nothing.
with contextlib.suppress(OSError):
os.chmod(str(path), 0o700)
if stat.S_IMODE(path.stat().st_mode) != 0o700:
os.chmod(str(path), 0o700)
except OSError as exc:
_log.warning("[!] Failed to create cache directory %s: %s", path, exc)
raise
Expand Down
2 changes: 2 additions & 0 deletions src/apm_cli/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
)
from apm_cli.deps.lockfile_write_authority import LockfileWriter, lockfile_writer
from apm_cli.deps.registry.feature_gate import UserRegistryConfigDisabledError
from apm_cli.install import pipeline_entry
from apm_cli.install.argv import (
_get_invocation_argv,
_split_argv_at_double_dash,
Expand Down Expand Up @@ -1116,6 +1117,7 @@ def _handle_mcp_install( # noqa: PLR0913
)
@click.pass_context
@serialized_lifecycle_unless_fresh_preview("dry_run")
@pipeline_entry.noop_fast_path
def install( # noqa: PLR0913
ctx,
packages,
Expand Down
Loading
Loading