Skip to content

fix(bundle): self-heal a stale bundle-cache hit after installation relocation - #163

Merged
Brian Krabach (bkrabach) merged 1 commit into
mainfrom
lane/next-mind
Sep 2, 2026
Merged

fix(bundle): self-heal a stale bundle-cache hit after installation relocation#163
Brian Krabach (bkrabach) merged 1 commit into
mainfrom
lane/next-mind

Conversation

@bkrabach

Copy link
Copy Markdown
Contributor

The prepared-bundle cache keys on (version, bundle hash) and pickles absolute agent source paths into a machine-global directory. When the installing venv is rebuilt onto a different Python minor version, warm hits return paths that no longer exist — taking every downstream run down with FileNotFoundError until the cache is cleared by hand. Fix: on every warm hit, verify each cached agent's source_path still exists for this process; a miss is treated like the existing corruption case (logged, cleared, cold-path re-resolve). New verification script wired into make verify; make check/verify-codegen/verify-wheel green.

…location

cortex-90ei: the prepared-bundle cache is keyed on (aaa_version, bundle
content hash) only -- never on where the installation actually lives on
disk. `load_and_prepare_bundle` bakes each agent's ABSOLUTE `source_path`
into the pickled PreparedBundle, and `~/.amplifier-agent/cache/` is a
single machine-global directory, so any process with a matching key
warm-hits the same entry even if it is a completely different
installation. A uv tool venv rebuilt onto a different Python minor
version (e.g. amplifier-dot-runner going 3.12 -> 3.13) is exactly such a
case: the cached agent paths still point at
`.../lib/python3.12/site-packages/...`, which no longer exists once the
venv is on 3.13. This produced a `FileNotFoundError` for
`amplifier_agent_lib/bundle/agents/explorer.md` and took down every
scheduled automation for ~2.5 hours until the venv was force-reinstalled
back onto 3.12 -- which "fixed" it only by coincidence (the stale cached
paths happened to match again).

Fix: on every warm-cache hit, verify each agent's cached `source_path`
still exists as seen by *this* process (`_stale_agent_source_paths`). A
miss is treated exactly like the existing corruption case -- logged, the
stale artifact+manifest removed, and control falls through to the cold
path, which re-resolves every path fresh against whatever installation is
actually running right now. No Python version is ever hardcoded or
assumed; staleness is detected dynamically regardless of *why* the
installation moved.

Proof: this repo has no unit-test tier by design (AGENTS.md), so the fix
is proven the same way verify-wheel.py proves packaging -- a standalone
simulation script (scripts/verify-bundle-cache-staleness.py, wired into
`make verify`) that fabricates two fixture installations (a dangling
"python3.12" one and a live "python3.13" one), seeds a warm cache entry
as the 3.12 fixture would have written it, and proves the fix detects
the staleness and rebuilds from the 3.13 fixture -- while a second check
proves a healthy warm entry is still returned without ever invoking the
cold path (no overcorrection / no perf regression).

Gates: make check (ruff + ruff format + pyright) PASS; make verify-codegen
PASS; make verify-wheel PASS; make verify-bundle-cache-staleness PASS.
@bkrabach
Brian Krabach (bkrabach) merged commit 8c2031c into main Sep 2, 2026
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.

2 participants