Revision: 1 Last modified: 2026-12-04T19:00:00Z
verdict_cache.py is the fastcycle content-addressed verdict cache. It stores a gate's verdict
keyed by everything that could change that verdict, so an identical run can be answered from disk
instead of re-executed — and an almost identical run cannot.
That "almost" is the whole design. A cache that keys on too little is worse than no cache: it returns
PASS for a tree that was never tested, and every downstream gate inherits the lie. The DEC-07 key is
therefore seven components, and a change to any one of them is a miss by construction.
Contract: specs/004-fast-dev-cycles/contracts/affected-set-and-verdict-cache.md VC-001..VC-005,
data-model.md Section 5, research.md DEC-07. The binding wire format is T051's RED test, not
this guide and not the docstring — if they ever disagree, the RED test wins.
python3(stdlibsqlite3included).- A writable cache directory (
--cache-dir); a separate DB file lives inside it, so caches for different trees never collide. - An
--inputs <trace.json>envelope — the same observed-I/O documentio_trace.shproduces, wrapped with gate identity.
No environment variables are read.
# record a verdict (only PASS and FAIL are cacheable)
python3 scripts/fastcycle/gates/verdict_cache.py put \
--cache-dir .cache/fastcycle/vc --gate my_gate \
--inputs trace.json --verdict PASS --evidence evidence/my_gate.log
# ask for a previous verdict
python3 scripts/fastcycle/gates/verdict_cache.py get \
--cache-dir .cache/fastcycle/vc --gate my_gate --inputs trace.json
# HIT key=<hex64> verdict=PASS evidence=evidence/my_gate.log → exit 0
# MISS key=<hex64> → exit 1
# drop this gate's entries
python3 scripts/fastcycle/gates/verdict_cache.py purge \
--cache-dir .cache/fastcycle/vc --gate my_gate
# PURGED gate=my_gate count=<n> → exit 0A MISS exit of 1 is the branch you must actually handle: it means run the gate, not "error".
| Subcommand | Code | Meaning |
|---|---|---|
put |
0 |
Stored. stdout: PUT key=<hex64> verdict=<v> |
put |
3 |
REFUSED — the verdict is not cacheable (see below). stdout records the refusal. |
get |
0 |
HIT key=<hex64> verdict=<v> evidence=<path> on the first stdout line. |
get |
1 |
MISS key=<hex64> (or key=UNKNOWN when the key cannot be computed). |
purge |
0 |
PURGED gate=<gate_id> count=<n> where n is rows removed. |
put and get also exit 2 on usage/config errors.
Only PASS and FAIL are cacheable. SKIP, a partial verdict, and BLIND are never cached. A
BLIND gate cached as a reusable answer would silently convert "we could not decide" into a stable
result — exactly the failure the C-001 table exists to prevent. The refusal is a distinct code so a
caller cannot mistake it for success.
The DEC-07 seven-component key, in the terms the envelope exposes:
- the
gate_id; - the gate script's content (resolved relative to the envelope file's own directory);
- each
observed_inputsentry'spathandsha256; - the remaining DEC-07 components defined by the contract and
research.md.
recorded_mtime appears in the envelope but is not a semantic key component — an mtime inside a key
would invalidate the cache on every touch.
- An observed input deleted. Its
sha256cannot be computed, so the key cannot be computed;getreportskey=UNKNOWNand misses rather than matching a stale row. - A gate script edited. New script content → new key → miss. This is the self-change case the fast lane must never cache away.
- A
putofBLIND/SKIP/ partial. Refused, exit3, nothing written. - Two different
--cache-dirs. Independent databases. Sharing one directory across divergent trees is a caller error the per-directory DB file is designed to make harmless. - A corrupt or missing DB file. Usage/config error path (
2) rather than a silent empty cache. - Concurrent writers. The store uses
INSERT OR REPLACEon put and a pointSELECTon get, so a concurrent put is last-writer-wins for the same key; no cross-key corruption.
- Parses the subcommand and flags.
- Reads the
--inputsenvelope and computes the DEC-07 key. put: validates the verdict isPASSorFAIL(else exit3), thenINSERT OR REPLACEskey → (verdict, evidence_path, stored_at).get: point-SELECTs the key; printsHITand exits0, or printsMISSand exits1.purge: deletes every row for the gate and reports the count.
The SQLite persistence layer is a fresh implementation of the same storage pattern as the ATM-659
WS10 verdict-cache POC (docs/research/tokens/ws10_testing_strategy/POC/) — not an import of it. It
differs in two deliberate ways: the real seven-component DEC-07 key instead of the POC's simplified
four-component stand-in, and a per---cache-dir DB file instead of one fixed path.
Called by scripts/fastcycle/gates/lib/gate_runner_order.py,
scripts/fastcycle/gates/lib/backstop_run.py, scripts/fastcycle/gates/backstop.sh (via the runner),
scripts/fastcycle/gates/mutation_reuse.py and scripts/fastcycle/gates/flake_ledger.py.
Guarded by scripts/fastcycle/tests/test_verdict_cache_red.sh (T051), fixtures under
scripts/fastcycle/tests/fixtures/verdict_cache/.
Its key definition is one of the listed triggers that must force a full backstop.sh run.
See also docs/scripts/io_trace.sh.md (produces the --inputs envelope),
docs/scripts/gate_runner.sh.md and docs/scripts/backstop.sh.md.
2026-12-04 — python3 -c "import ast;ast.parse(open('scripts/fastcycle/gates/verdict_cache.py').read())"
→ exit 0. python3 scripts/fastcycle/gates/verdict_cache.py with no subcommand exits 2 with a usage
message.