fix(bundle): self-heal a stale bundle-cache hit after installation relocation - #163
Merged
Conversation
…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.
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.
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.