Skip to content
7 changes: 7 additions & 0 deletions .apm/architecture/owners/transport-auth-platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@
"selectors": ["install.ps1"],
"guards": ["transport-platform-windows-stable-path"]
},
{
"id": "deploy-store",
"decision": "Content-addressed store of deployed file bytes: hex-digest keys, verify on every read, no symlink following, atomic owner-only writes",
"owner": "cache/deploy_store.py (DeployStore)",
"selectors": ["src/apm_cli/cache/deploy_store.py"],
"guards": ["transport-platform-deploy-store-verified-reads"]
},
{
"id": "git-cache-key-normalization",
"decision": "Git repository cache-key normalization",
Expand Down
1 change: 1 addition & 0 deletions changelog.d/4846.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Installs now keep a verified copy of each deployed file in the machine cache, keyed by its lockfile hash, for faster future reinstalls (#4846)
11 changes: 9 additions & 2 deletions docs/src/content/docs/reference/cli/cache.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ apm cache prune [--days N]
## Description

`apm cache` groups three subcommands that operate on the local cache
root. The cache holds two independent stores:
root. The cache holds three independent stores:

- **Git cache** -- bare repository databases plus per-SHA worktree
checkouts, keyed by resolved commit.
- **HTTP cache** -- conditional-GET responses for MCP registry
endpoints.
- **Deploy store** -- the exact bytes of every file a successful install
deployed, keyed by the file's `deployed_file_hashes` digest in
`apm.lock.yaml`. Every read re-hashes the entry, and a mismatch counts
as a miss. A refused or failed install stores nothing. Entries above
4 MiB are not stored, and when the store passes 256 MiB the least
recently used entries are evicted down to 80% of that.

A fresh, integrity-verified HTTP cache hit updates only the entry
directory's `mtime`. This recency marker drives LRU eviction; it does
Expand Down Expand Up @@ -76,7 +82,7 @@ Output:

### `apm cache clean`

Remove every entry from both the git and HTTP caches. Prompts for
Remove every entry from the git cache, the HTTP cache and the deploy store. Prompts for
confirmation unless a skip flag is passed.

```bash
Expand Down Expand Up @@ -184,6 +190,7 @@ Inside the cache root:
# 16 hex of
# sha256(paths))
http_v1/ # conditional-GET response cache
deploy_v1/ # deployed file bytes: <hex[:2]>/<hex>
```

The `full/` and `sparse-<variant>/` subdirs let two consumers of the
Expand Down
2 changes: 1 addition & 1 deletion packages/apm-guide/.apm/skills/apm-usage/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ drift check without starting Codex or changing native state.
| Command | Purpose | Key flags |
|---------|---------|-----------|
| `apm cache info` | Show the cache root and counts of Git repositories, Git checkouts, and HTTP entries, plus total size | -- |
| `apm cache clean` | Remove every entry from the git and HTTP caches. If a deletion fails, it still removes every other entry, reports the affected paths, and exits nonzero; successful removals are not rolled back. Close locking processes or fix permissions, then retry. | `--force`/`-f`, `--yes`/`-y` skip the confirmation prompt only -- they do not suppress deletion failures or make the command succeed |
| `apm cache clean` | Remove every entry from the git cache, the HTTP cache and the deploy store. If a deletion fails, it still removes every other entry, reports the affected paths, and exits nonzero; successful removals are not rolled back. Close locking processes or fix permissions, then retry. | `--force`/`-f`, `--yes`/`-y` skip the confirmation prompt only -- they do not suppress deletion failures or make the command succeed |
| `apm cache prune` | Remove Git checkout SHA groups not accessed within `--days`; full and sparse variants share recency and are evicted together, and `0` makes every group eligible. Partial failures exit `1`; fix permissions or release locks and rerun | `--days N` (default `30`; negative values are rejected before the cache is touched) |

## Compilation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@

_RULE_ID = "transport-platform-cache-cleanup-outcome"
_OWNER = "src/apm_cli/cache/cleanup.py"
_CONSUMERS = ("src/apm_cli/cache/git_cache.py", "src/apm_cli/cache/http_cache.py")
_CONSUMERS = (
"src/apm_cli/cache/git_cache.py",
"src/apm_cli/cache/http_cache.py",
"src/apm_cli/cache/deploy_store.py",
)


def _check_cache_cleanup(provider: FactsProvider) -> tuple[Violation, ...]:
Expand Down
64 changes: 64 additions & 0 deletions scripts/architecture_linter/checks/transport_deploy_store.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""Keep the deployed-file byte store behind its verifying owner."""

from __future__ import annotations

import re

from scripts.architecture_linter.checks.transport_platform_shared import (
GROUP,
_forbid_scan,
_require_subs,
_src_python,
)
from scripts.architecture_linter.facts import FactsProvider
from scripts.architecture_linter.models import Rule, Violation

_RULE_ID = "transport-platform-deploy-store-verified-reads"
_OWNER = "src/apm_cli/cache/deploy_store.py"


def _check_deploy_store(provider: FactsProvider) -> tuple[Violation, ...]:
"""Only the owner addresses the bucket; it re-hashes reads and never follows links."""
inventory = frozenset(provider.inventory)
findings: list[Violation] = []
findings.extend(
_forbid_scan(
provider,
inventory,
_RULE_ID,
_src_python(provider, exclude={_OWNER}),
re.compile(r"[\"']deploy_v1[\"']"),
"The deploy store bucket must be addressed only through cache/deploy_store.py",
exempt=False,
)
)
findings.extend(
_require_subs(
provider,
inventory,
_RULE_ID,
_OWNER,
(
"_KEY_RE.fullmatch(key)",
"os.O_RDONLY | _NOFOLLOW",
"if not stat.S_ISREG(info.st_mode)",
"if data is None or canonical_digest(data) != key:",
"tempfile.mkstemp(dir=entry.parent",
"os.replace(temp, entry)",
),
"Deploy store reads must verify the digest and refuse links; writes stay atomic",
)
)
return tuple(findings)


RULES = (
Rule(
id=_RULE_ID,
group=GROUP,
guard_ids=(_RULE_ID,),
description="Deployed-file bytes have one owner that verifies every read.",
check=_check_deploy_store,
),
)
COLLECTORS: tuple[object, ...] = ()
2 changes: 2 additions & 0 deletions scripts/architecture_linter/groups/transport_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from scripts.architecture_linter.checks.transport_credential_value_rendering import (
RULES as _CREDENTIAL_RENDERING_RULES,
)
from scripts.architecture_linter.checks.transport_deploy_store import RULES as _DEPLOY_STORE_RULES
from scripts.architecture_linter.checks.transport_egress_route import (
RULES as _EGRESS_ROUTE_RULES,
)
Expand Down Expand Up @@ -74,6 +75,7 @@
+ _EGRESS_ROUTE_RULES
+ _CACHE_RULES
+ _CLEANUP_RULES
+ _DEPLOY_STORE_RULES
+ _SPARSE_RULES
+ _GITLAB_SPARSE_RULES
+ _REVISION_PIN_RULES
Expand Down
Loading
Loading