Files
lucisv/docs/features/format-cache/README.md
T

51 KiB
Raw Blame History

format-cache

Goal

Make a repeat lucisv run over an unchanged tree do (almost) no work. TODO.md §3's content-hash cache item: remember, per file, that this exact content, under these settings, on this lucisv version was already formatted, and skip the whole read-parse-format-verify pipeline on the next run. Monorepo RTL trees are the case that matters — lucisv's per-file cost is dominated by parse + format + the two runtime safety checks (equivalence and convergence), all of which are pure functions of (content, config), so a cache hit is exactly as trustworthy as the run that produced it. The cache is an optimization only: it can lose entries, be deleted, or be corrupted, and the run's stdout/stderr/exit code stay what they would have been anyway (modulo one extra summary segment).

Assumptions

  • Only the "clean" verdict is cacheable. An entry means format(x) == x for that content and config. Nothing else is stored — not errors, not "would reformat", not diff text. See "Semantics" for why.
  • Formatting is a pure function of (source, config), the same assumption parallel-files already relies on. If that ever stops being true (a formatter that reads the file's name, or another file), this cache silently goes wrong and the assumption must be revisited here.
  • The key covers every FileConfig field that reaches the formatter. Today that is line-length, indent and [format] uvm-utils-indent — everything lucisv_core::config::FileConfig can put into vlog_formatter::Config (see lucisv/src/args.rs::config_with). Any future setting that changes formatted output must join Entry and the store line in the same change; a setting left out is a stale clean verdict, which is exactly the bug TODO §59 fixed. The key stores the resolved values, not the config file's path or mtime — so moving a lucisv.toml around, or switching from a file to an equivalent --line-length flag, correctly does not invalidate anything, while a real value change does. exclude is not part of the key: it changes which files are visited, never how one is formatted.
  • The version string is the workspace version (env!("CARGO_PKG_VERSION") read inside lucisv_core, whose version.workspace = true makes it the same string for every crate here). This is a coarse proxy for "the formatter's behavior": two builds of the same version with different code — a cargo build in the middle of development — share a version and therefore share cache entries. Developers of lucisv itself should use --no-cache (the test suite does); released binaries are fine.
  • Paths are keys, byte-for-byte as processed. No canonicalization, no symlink resolution (config discovery is lexical for the same reason). lucisv . and lucisv /abs/path/to/tree therefore do not share entries; they just each build their own. A path that is not valid UTF-8, or that contains a tab or a newline, is never cached (it cannot be written to the line-based store) — those files are simply always re-formatted.
  • The cache is not a lock. Two lucisv processes may write it concurrently; see "Concurrency".
  • lucisv check (the linter) is not cached. --no-cache / --cache-dir are accepted there and do nothing, so a wrapper script can pass them unconditionally. Lint results depend on the rule selection, the waiver comments and the fix mode; caching them is a separate feature with a separate key.

Behavior

The key

Per file: (content hash, line-length, indent, uvm-utils-indent, lucisv version), keyed on the file path.

  • Content hash: hand-rolled FNV-1a, 64-bit, over the file's bytes (cache::content_hash). Two reasons it is not std::collections::hash_map::DefaultHasher: std explicitly does not guarantee that hasher's output is stable across Rust releases (or even across builds), which is fatal for a value persisted to disk — a toolchain bump would silently invalidate every entry, or worse, collide differently; and RandomState is seeded per process, so it is not even stable within one version. FNV-1a is ~15 lines, has no dependency, and is byte-exactly specified. It is not cryptographic and does not need to be (see collision posture).
  • Hashing costs one pass over bytes lucisv has already read into memory; it is noise next to parsing.

Collision posture (stated honestly)

A 64-bit content hash means a collision could make lucisv skip a file that actually changed — a wrong "clean" verdict, the only way this feature can produce a wrong result. Two things bound it:

  1. The map is keyed on the file path, and a lookup never crosses files. A collision between two different files is harmless: they have different keys and never consult each other's entry. To be skipped wrongly, one file must be edited into a different content whose FNV-1a hash equals the previous content's — a collision between two versions of the same path.
  2. That is the standard accepted risk of every content-addressed build cache (ruff, black, ccache, cargo's fingerprints all take it). For accidental (non-adversarial) edits the probability is ~2⁻⁶⁴ per edit.

It is not collision-resistant against an adversary who can choose the file contents: FNV-1a is trivially invertible, so someone able to write files in your tree can craft two files with the same hash and make lucisv skip the second. That threat model (an attacker with write access to your source tree, trying to get past a formatter) is not one lucisv defends against; --no-cache removes the cache from the picture entirely if it ever matters. This is documented rather than fixed because the fix (a cryptographic hash) is a dependency or ~200 lines of SHA-256 for a threat that does not exist here.

What a collision cannot do is corrupt a file: an entry only ever causes work to be skipped, never output to be produced. The hard invariant "never corrupt code" is untouched by this feature — the cache never writes to a .sv file and never changes what the formatter emits.

Semantics

An entry is written only for content that was verified clean by this run: either the file was already a fixed point, or it was rewritten and the hash of the bytes that were written goes in.

Situation Cache read Cache write Reported as
Hit (hash + line-length + indent + uvm-utils-indent + version all match) skip all work entry kept left unchanged, plus N files from cache
Miss, file is already formatted — record hash(src) left unchanged
Miss, file rewritten in place (write succeeded) — record hash(output) reformatted
Miss, --check/--diff says it would reformat — nothing would be reformatted, exit 1
Miss, in-place write failed (I/O) — nothing error, exit 2
Parse error / failed safety check / contained panic — nothing error, exit 2
--stdout cache off for the run nothing printed
stdin (lucisv -) never never as before

Why "would reformat" and errors are never cached: the fix for both is external to lucisv. A dirty file gets fixed by an editor or by lucisv without --check; a parse error gets fixed by editing the source or by teaching the parser new syntax. If either verdict were cached, a CI lucisv --check would keep reporting a stale complaint (or, worse, stop reporting a real one) until someone thought to clear the cache. Caching only the fixed-point verdict also means the cache can never invent work or suppress a diagnostic: the worst a stale, wrong or missing entry can do is cause a file to be re-formatted, which is the un-cached behavior.

--check and --diff exit codes are therefore preserved exactly: a hit means "this content is a fixed point", which is precisely the condition under which those modes stay silent and contribute 0 to the exit code.

Storage

One text file, <cache-dir>/cache, one line per path, tab-separated, hand-rolled in the style of the corpus TSV:

<content-hash, 16 hex digits>\t<line-length>\t<indent>\t<uvm-utils-indent, `true`/`false`>\t<version>\t<path>

The path is last because it is the only field that can contain interesting characters. Lines are sorted by path, so the file is stable and diffable and two runs over the same tree produce byte-identical cache files.

No serde, no TOML, no JSON. lucisv and lucisv_core have exactly one third-party dependency between them (rayon, in lucisv). serde exists in the workspace only because lucisv_server needs it for LSP wire messages — lucisv/lucisv_core do not depend on it, and taking it here would put a proc-macro build step into the CLI's dependency graph to encode six fields. Six fields on a line need no schema; CLAUDE.md's "standard library first" says so.

Loading, corruption and staleness:

  • The file is read once at startup, before any file is processed.
  • Unreadable (missing, no permission, a directory, not UTF-8) → an empty cache. Never an error, never a warning.
  • Any malformed line → the whole file is discarded and the cache starts empty. A file we cannot fully parse is not a file we can prove we wrote; partial trust is not worth the branch.
  • A well-formed line whose version is not this binary's is dropped silently (that is not corruption, just another lucisv's entry). It is not carried forward on write, so alternating between two lucisv versions rebuilds the cache each time.
  • A well-formed line in an older field layout is dropped the same way. A five-field line is the shape lucisv wrote before uvm-utils-indent joined the key: it says nothing about the option, so it is skipped individually rather than trusted or treated as corruption. (The version field alone already makes a 0.49.0 store miss at 0.50.0; the tolerance is what keeps the codec self-describing when the two ever come apart — a hand-written store, a downgrade.) A five-field line that is not well formed in that older shape is corruption like any other, and discards the file.
  • Writing is atomic: the new text goes to <cache-dir>/cache.<pid>.tmp and is renamed over cache. A reader therefore sees the old file or the new one, never a half-written one.
  • Entries whose path no longer exists are dropped at write time, so the file does not grow forever as files are deleted or renamed.
  • Entries for files not visited by this run are preserved: formatting a subdirectory must not throw away the rest of the tree's entries.
  • A failure to write the cache is silent and harmless. The run's exit code and output do not change; the next run just does the work again. (Deliberate: a warning on every run in a read-only checkout would be noise, and it would make stderr depend on the filesystem's state, which the parallel-files determinism contract does not want.)

The cache directory gets a self-ignoring .gitignore containing * written into it when it is created, the same trick cargo uses for target/; /.lucisv_cache is also listed in this repo's root .gitignore.

Flags

Flag Meaning
--no-cache do not read and do not write the cache. Nothing is created on disk
--cache-dir <PATH> use this directory instead of .lucisv_cache

Where the default lives: the current directory. .lucisv_cache is resolved relative to the cwd, not to the input paths and not to the config file's directory. This is wrong for the multi-project invocation (lucisv ~/a/rtl ~/b/rtl from a third directory writes one cache in that third directory, and running the same command from elsewhere starts a new one), and it is what ruff did for years before growing a per-project resolution. The honest v1 rule is "one cwd, one cache", which is exactly right for the overwhelmingly common cd repo && lucisv --check . in CI and in a pre-commit hook, and --cache-dir covers everything else. Making the default follow the config-file root is the natural next step and is deliberately not guessed at here.

Reporting

The summary line gains a segment when anything was skipped:

2 files left unchanged, 2 files from cache

Cached files are counted in left unchanged as well — they are unchanged, and no CI script's grep should change meaning because a cache appeared. The N files from cache segment is the observable the tests assert on, and the only user-visible difference between a cold and a warm run.

Concurrency

Entries are produced inside the existing par_iter and travel back through the Outcome collection mechanism (a per-file FileResult { outcome, clean: Option<u64> }, collected by an indexed par_iter().map(...).collect() — so input order is preserved exactly as before). The cache map itself is only read during the parallel pass and is only mutated in the serial loop afterwards; the file is written once, single-threaded, at the end of the run. There is no lock and no shared mutable state.

Two lucisv processes running at once: last writer wins the rename, so one process's entries can be lost. That is self-healing and safe:

  • An entry only ever asserts content that this process verified, so a surviving entry from either writer is true.
  • A lost entry costs one file's worth of re-work on the next run.
  • A rename is atomic, so no reader sees a mixture.

The one thing that would be unsafe — an entry asserting "clean" about content nobody verified — cannot be constructed by this design, because the only writer of an entry is the code path that just observed format(x) == x.

Handshakes

  • Consumes docs/features/parallel-files/README.md's promise that "the per-file unit of work is process_file(...), a cache lookup belongs at the top of it; the Outcome enum is where a 'cached, unchanged' bucket would go." Both taken literally. Outcome gained a Cached variant and process_file now returns a FileResult wrapper that also carries the hash to record. The determinism contract (byte-identical stdout/stderr at any --threads) is unchanged and re-tested with the cache on.
  • Consumes docs/features/config-discovery/README.md's promise that the cache key "must include the resolved per-file settings … not just file content + lucisv version". Done, with the values (Config::max_width, Config::indent_width, Config::uvm_utils_indent) rather than the config file's identity, so two trees governed by different lucisv.toml files that happen to say the same thing share entries correctly.
  • Consumes vlog_formatter::Config read-only, for every field args.rs::config_with can set from a lucisv.toml. The contract this crate owes back (TODO §59, 2026-09-07): a new formatter setting that changes output is a change to cache::Entry, to lucisv/src/main.rs::entry_for and to the store line, in the same commit — otherwise a warm cache serves the old setting's verdict. Config::uvm_utils_indent was added in 0.49.0 without that and is the reason this line exists. Nothing in vlog_parser / vlog_formatter / vlog_linter was touched.
  • Where the module lives: lucisv_core::cache, next to config and walk. lucisv_core is by its own doc comment "the parts of lucisv that decide which files are processed and with what settings", and "this file is already formatted, skip it" is the third member of that family. It also keeps the door open for lucisv_server: a language server that wanted to avoid re-formatting an unedited buffer on save would want the same predicate, and would otherwise have to duplicate the file format. Nothing in the module is CLI-specific — it takes paths and the bare scalars of the key (a u64, two usizes and a bool) and has no opinion about arguments or reporting.
  • Promises to whoever changes the formatter's output (alignment inference, --lines, any style change): bump the workspace version, or every user with a warm cache keeps their old formatting on files that did not otherwise change. This is the same discipline ruff and black need. Within-version development builds must use --no-cache.
  • Promises to crates/lucisv/tests/cli.rs: the shared run helper appends --no-cache, so the pre-existing tests keep running with the cache out of the picture (they share one cwd — the crate root — and would otherwise share one cache directory and pollute the repo with it). Cache tests call run_raw and pass an explicit --cache-dir under their own temp directory, or set the child's cwd.

Status / TODO

  • lucisv_core::cache: FNV-1a content_hash, Entry, Cache (load / disabled / is_clean / record / store).
  • Hand-rolled tab-separated store, sorted by path, atomic temp+rename write, self-ignoring .gitignore in the cache dir.
  • Corrupt / unreadable / wrong-version entries ignored, never fatal; so is a line in the pre-uvm-utils-indent five-field shape.
  • [format] uvm-utils-indent in Entry, in entry_for and as the store's fourth field (TODO §59).
  • --no-cache and --cache-dir <PATH> in args.rs and --help, accepted (and inert) for lucisv check.
  • Lookup at the top of process_file; entries collected through the indexed par_iter results and recorded serially in input order.
  • Only clean verdicts recorded; --check/--diff/errors/--stdout never write; stdin never caches.
  • N files from cache summary segment.
  • Unit tests in cache.rs (hash stability, round-trip, corruption, version filtering, pruning, atomicity of the rename).
  • CLI tests in crates/lucisv/tests/cli.rs (warm run does no work, content change invalidates, indent change invalidates, wrong version ignored, --no-cache, corrupt file tolerated, --check exit codes, --threads determinism with a warm cache, default cache dir is cwd-relative and self-ignoring, uvm-utils-indent invalidates in both directions, an older store is rebuilt).
  • Root .gitignore entry, README.md Cache section, TODO.md §3 box.
  • cargo fmt, cargo clippy --all-targets, cargo test.

Work log

2026-08-19 — dev agent

  • Read CLAUDE.md, TODO.md §3, docs/features/parallel-files/README.md (whose Handshakes section pre-specifies where the lookup goes) and docs/features/config-discovery/README.md (whose Handshakes section pre-specifies the key), then all of crates/lucisv/src and crates/lucisv_core/src.

Module placement. lucisv_core::cache, reasoning in Handshakes. It costs nothing today (lucisv is the only caller) and keeps lucisv_core dependency-free — Entry carries two bare usizes rather than a vlog_formatter::Config, so the crate still has an empty [dependencies].

The store format. Tab-separated, path last, sorted, one line per entry. Rejected alternatives: (a) serde+serde_json — real dependency for five fields, and lucisv/lucisv_core currently have one dependency total; (b) a binary format — unreadable when debugging exactly the kind of "why did it skip that file?" question a cache creates; (c) one file per cached path (ruff's older layout) — thousands of tiny files, and the atomic-write story gets worse, not better. The version is stored per line rather than once in a header so that a mixed-version cache degrades entry-by-entry instead of wholesale, and so the format needs no header at all.

Corruption policy. Any malformed line discards the entire file, not just that line. The alternative (skip bad lines, keep good ones) trusts a file we have already caught lying; the cost of discarding is one cold run.

Pruning. store drops entries whose path no longer exists. This is one exists() per entry on a serial pass at the end of the run — on the 860-file corpus it is unmeasurable — and without it the file grows forever in a tree where files get renamed.

Test isolation. Integration tests run with cwd = the crate directory, so a default-on cache would (a) create crates/lucisv/.lucisv_cache/ in the working tree and (b) make tests interfere: thread_count_changes_nothing_but_speed runs the same tree twice and compares stderr byte-for-byte, which a warm cache would change. The run helper therefore appends --no-cache, and the cache tests use a new run_raw with an explicit --cache-dir (or a set cwd for the default-location test). Recorded as a handshake so nobody removes it.

Measured. Release build, 10 logical cores, lucisv --check over the corpus, best of 10 runs (mean in the work log's raw numbers was within 10 %). The corpus was formatted first, since a tree that is already clean is exactly the case the cache exists for; the "612 files" column additionally drops the 248 corpus files that do not parse, which can never be cached and are re-attempted every run.

run 612 formattable files full 860-file corpus
--no-cache (today's behavior) 105 ms 116 ms
cold, empty cache (builds it) 108 ms 123 ms
warm, every file a hit 46 ms 56 ms
speedup, warm vs --no-cache 2.3× 2.1×

Building the cache costs ~3 ms per 600 files (hashing content already in memory, plus one write + rename), i.e. under 3 % of a cold run.

The honest framing of the 2.3×: parallelism already took the easy win, and what is left for the cache to remove is the parse+format+ verify time that was already spread over 10 cores. On one core the picture is the one a big monorepo actually cares about:

--threads 1, 612 files wall
--no-cache 396 ms
warm 51 ms
speedup 7.7×

The warm floor (46–56 ms) is the serial directory walk, config discovery, the cache load, and one read_to_string + FNV pass per file — all I/O and no compute, which is the intended endpoint. Process startup is 3 ms of it. Making the floor lower means not reading the files at all (an mtime/size pre-filter), which trades the cache's one strong property — it is keyed on content, so a touch, a checkout, or a rebuild that rewrites identical bytes is still a hit — for a correctness risk. Not taken.

Attacked before handing over (release binary, outside the test suite; every one of these degrades quietly, none changes an exit code):

  • Eight lucisv processes at once over the same 612-file tree and the same cache directory: all eight exit 0, no leftover *.tmp, the resulting file has 612 well-formed lines (awk -F'\t' 'NF!=5' finds none), and the next run is 612 files from cache. Last-writer-wins, as designed.
  • --cache-dir pointing at an existing plain file: create_dir_all fails, the run is unaffected, exit 0.
  • A read-only (chmod 500) cache directory: exit 0, nothing written, no warning.
  • The cache path occupied by a directory: the rename fails, the temp file is cleaned up, exit 0.
  • Paths containing spaces round-trip (the store is tab-separated precisely so they can), and a duplicated line for one path is harmless (last wins).
  • Forged entry for a file that does not parse → the run reports it as cached and exits 0, which is the proof that a hit skips the whole pipeline rather than doing the work and agreeing. That is now the CLI test a_hit_skips_the_work_entirely; the same trick with the wrong version stamp is an_entry_from_another_lucisv_version_is_ignored.

Blocked by the workspace, as parallel-files was. A concurrent agent is mid-landing alignment inference in vlog_formatter (align.rs plus doc.rs/format.rs/printer.rs), which does not compile yet. All gates were therefore run in a scratchpad copy of the workspace with only their three crates reverted to HEAD (git checkout -- crates/vlog_{formatter,parser,semantic}); my own files were copied in from the real tree. Nothing outside crates/lucisv, crates/lucisv_core, docs/features/format-cache, README.md, TODO.md and .gitignore was edited, and cargo fmt was run scoped (-p lucisv -p lucisv_core) so no file of theirs was touched. Re-run everything on the merged tree once their work lands.

Gates (scratchpad tree, described above):

  • cargo test -p lucisv -p lucisv_core: 28 unit (lucisv) + 63 CLI (lucisv) + 45 unit (lucisv_core), all green. New: 15 CLI tests, 14 cache.rs unit tests, 1 args.rs test.
  • cargo test --workspace: green, no churn in any other crate's tests — this feature changes no formatter output.
  • cargo clippy --workspace --all-targets: silent.
  • cargo fmt -p lucisv -p lucisv_core -- --check: clean.
  • No Cargo.toml / Cargo.lock change: no new dependency, and lucisv_core still has an empty [dependencies].

2026-09-07 — dev agent (TODO §59: uvm-utils-indent joins the key)

The owner's audit (topo §2.9 row 34, and the "Confirmed cache omission" paragraph of docs/repository-analysis.md) found the key stale against 0.49.0's [format] uvm-utils-indent. args.rs::config_with sets Config::uvm_utils_indent, the formatter indents `uvm_field_* under it, but Entry and entry_for still named only content, line-length and indent — so a clean --check cached with the option off kept exiting 0 after the option was turned on, while --no-cache --check exited 1. Reproduced first, on the fixture from the audit.

The fix, four lines of real change. Entry gains uvm_utils_indent: bool (equality is derived, so the key follows for free); lucisv/src/main.rs::entry_for fills it from the same Config the formatter is handed; render writes it as the store's fourth field, true/false, after indent and before the version.

Why true/false and not 0/1. The parser's style is one .parse() per field; bool: FromStr accepts exactly true/false, so the round trip is {} out and .parse().ok()? back, with no mapping either way and no new failure mode. A numeric encoding would have needed a hand-written "0" => false match for no gain.

The five-field tolerance. parse now matches on the field slice: six fields is the current shape; five fields that are well formed in the old shape (hex content, numeric line-length and indent, non-empty path) is a store written before the option joined the key, and is dropped individually exactly like another version's entry; anything else still discards the whole file, because partial trust in a file caught lying is still not worth the branch. The precision matters — a blanket "wrong field count → skip the line" would have quietly forgiven not-hex\t100\t2\t0.2.0\t/a.sv, which the corruption tests require to be fatal. The version field alone already makes a 0.49.0 store miss at 0.50.0, so this tolerance buys nothing today; it is there so the codec stays self-describing when the two come apart (a hand-written store, a downgrade).

Tests. cache.rs: uvm_utils_indent_alone_is_a_different_entry (equality differs on the option alone; the line round-trips carrying it), a_line_without_the_option_is_dropped_but_not_fatal (an old-shape line next to a current one: the old one is not trusted, the current one survives, and the old one is not carried forward), plus the option's column added to entries_round_trip_through_the_file, the_file_is_sorted_and_carries_the_version, another_versions_entry_is_dropped_but_not_fatal and two new six-field corruption cases (a non-boolean option, an empty path). crates/lucisv/tests/cli.rs: changing_uvm_utils_indent_invalidates_the_entry — the audit's own probe through the real binary, in both directions (clean under false, cached, flip to true → exit 1; format under true, cached, flip back to false → exit 1) — and a_store_written_before_the_option_joined_the_key_is_rebuilt. The CLI regression was checked against the bug: with entry_for pinned to false it fails with "1 file from cache" at exit 0, which is exactly the audit's step 2.

Note for the lead. README.md's key sentence (line ~89, which still lists four fields) and its --no-cache workaround paragraph (lines ~99-103, "In v0.49.0, the new uvm-utils-indent option is missing from this key") are now stale, as is docs/topo.md row 34, and docs/repository-analysis.md's "Confirmed cache omission" paragraph describes a fixed bug. Per the brief this lane did not touch those three files; they are the lead's to strike at merge.

Gates: cargo fmt clean, cargo clippy --all-targets silent, cargo test -p lucisv_core / -p lucisv / --workspace green, all through tools/guard.sh -m 8 -t 1800.

QA log

2026-08-19 — QA agent

Setup. The workspace would not compile at HEAD in the real tree (a concurrent dev agent mid-landing alignment inference in vlog_formatter). Followed the dev's own technique: rsync'd the whole working tree (including uncommitted changes, excluding target/ and corpus/) to a scratchpad copy, git checkout HEAD -- crates/vlog_{formatter,parser,semantic} in the copy, deleted the two untracked alignment-only files that survived the checkout (vlog_formatter/src/align.rs, vlog_formatter/tests/cases/alignment.cases — unreferenced once lib.rs was reverted). All cargo commands below ran in that copy; the real tree was touched only to append this entry. No commit/push.

Gates, reproduced from scratch in the copy:

  • cargo build -p lucisv -p lucisv_core --release — clean.
  • cargo test -p lucisv -p lucisv_core: 28 (lucisv unit) + 63 (cli.rs) + 45 (lucisv_core unit) = 136, all green, matching the claimed counts exactly.
  • cargo test --workspace: every crate green, no churn elsewhere.
  • cargo clippy --workspace --all-targets: silent.
  • cargo fmt -p lucisv -p lucisv_core -- --check: clean.
  • git diff --stat HEAD -- Cargo.toml Cargo.lock crates/*/Cargo.toml: empty — no dependency added, confirmed.

Claim 1 (key/store). Read cache.rs in full. FNV-1a matches the published test vectors; store is tab-separated, sorted, path last; parse() discards the whole file on any malformed line and drops mismatched-version lines individually (both by direct code read and via the corrupt-file/version unit tests, all passing). Confirmed by hand:

  • A hand-written poisoned entry (correct hash/config/version, forged path key dirty.sv) makes --check on a genuinely dirty file exit 0 and report it "from cache" — the run really is skipped, not re-verified. This is the documented, honest collision/tamper posture (see Claim-2 note below), not a bug.
  • --cache-dir pointing at an existing plain file, and a chmod 500 cache directory: both exit 0, run output unaffected, nothing written — matches "silent write failures."
  • 8 parallel lucisv --check processes over a shared 200-file tree and cache dir: all exit 0, zero *.tmp leftovers, exactly 200 well-formed lines afterward (awk -F'\t' 'NF!=5' empty), next run is a clean 200-file hit.
  • Moving a file (orig.sv → moved.sv) between two --check runs: orig.sv's entry is pruned on the write that follows the move (it no longer exists()), and moved.sv is correctly a fresh miss — path-keyed as documented.

Claim 2 (semantics). Confirmed via the CLI suite (all passing) plus independent repro:

  • a_would_reformat_verdict_is_never_cached-style manual check: a dirty file gives would reformat: .../exit 1 on three consecutive --check runs, never "from cache" — the stale-CI-verdict failure mode does not occur.
  • --stdout never creates .lucisv_cache even with a warm entry present for the same file (prints every time, does not read or write the cache) — matches cache_enabled() == !no_cache && !stdout in args.rs.
  • lucisv check <file> --no-cache --cache-dir X: exits normally (lint verdict, unrelated to formatting), creates no cache artifact under either name — accepted-but-inert confirmed.
  • run_stdin in main.rs never references Cache at all — stdin mode literally cannot touch the cache, by construction, not just by test.
  • A hit genuinely skips the whole pipeline: forged entry for a file the parser cannot even handle (UNPARSEABLE case in cli.rs, and my own chmod-000-after-caching repro below) proves the lookup happens before format_contained is ever called.

Claim 3 (flags). --no-cache: no .lucisv_cache appears for either a lucisv <file> or lucisv --stdout <file> run — checked directly with ls. --cache-dir: exercised throughout. Default cwd-relative location and self-ignoring .gitignore: reproduced outside the test suite too (lucisv --check . from a fresh dir leaves exactly .lucisv_cache/{cache, .gitignore}, the latter reading *\n). The README's own "Where the default lives" paragraph states the multi-root limitation honestly.

Claim 4 (concurrency). 8-process stress at the full requested width: clean cache, no .tmp leftovers (details above). --threads 1 vs default with a warm cache over the 612-file formattable corpus subset: diff on stdout and stderr is empty — byte-identical, as promised.

Claim 5 (tests). 28+63+45 = 136, all green, reproduced above. The run/run_raw/with_no_cache handshake in cli.rs is exactly as described: run inserts --no-cache after the subcommand if present; cache tests use run_raw with their own --cache-dir or run_in for the default-location test. No Cargo.toml/Cargo.lock diff.

Claim 6 (timing). Corpus copied to the scratchpad (real corpus/ never written to), formatted once with --no-cache to reach a clean tree: 612 formattable / 248 unparseable — matches the dev's own split exactly. 10 logical cores, same as the dev's environment. Best-of-N, --check over the 820-file scratchpad corpus copy:

run wall (best of 10, default threads)
--no-cache ~127 ms
cold (building the cache) ~134 ms
warm, every formattable file a hit ~68 ms
speedup, warm vs --no-cache ~1.9×
--threads 1, 612 files wall (best of 5)
--no-cache ~456 ms
warm ~113 ms
speedup ~4.0×

Same direction and same order of magnitude as the dev's numbers (2.1–2.3× / 7.7×); the absolute speedup is lower here, plausibly because the scratchpad corpus lives on this Mac's /private/tmp (fast SSD, warm OS page cache) where the --no-cache floor is already cheaper relative to compute than on the dev's machine — not a red flag, cache still strictly warm < cold < --no-cache on every run observed.

Attacks beyond the claims list, all passed (no code fix needed):

  • mtime-only touch, same content: still a hit after touch — content hashed, not mtime-based, exactly as the README's Work Log states ("a touch ... is still a hit").
  • File replaced by different content of the same byte length (wire x; → wire y;, both 30 bytes): correctly not reported "from cache" on the next run — the hash differs despite equal length, so this is a fresh (if coincidentally still-clean) verdict, not a stale hit.
  • File made unreadable (chmod 000) after being cached: --check errors (Permission denied, exit 2) rather than serving the stale cache hit — process_file always calls read_to_string before consulting the cache (the hash needs the bytes), so an unreadable file can never be served from cache; it surfaces as a normal I/O error. Not a silent wrong "clean" verdict.
  • Cache poisoning (forged entry, correct hash/config/version, for a file that is actually dirty): the run trusts it and exits 0. This is exactly the collision/tamper posture the README's "Collision posture" section states outright — "an attacker with write access to your source tree ... is not one lucisv defends against" — so this is documentation matching behavior, not an undisclosed hole.
  • Two directories with differently-formatted-but-equal-valued lucisv.toml (indent = 2 vs indent = 2 # comment), same file path: still a hit — confirms the key is the resolved value, not the config file's text or identity.
  • CRLF file: never reaches a clean fixed point (always "would reformat"), so it is never cached and both --check runs report identically — consistent, not a cache bug (CRLF handling itself is formatter behavior, out of this feature's scope).
  • 0-byte .sv file: also always "would reformat" (pre-existing formatter behavior for empty input), never cached, cache file stays empty across two runs.

Verdict: PASS on all six claims, no BLOCKING findings. No case was found where a cached verdict was served for genuinely changed content (the one thing that would be blocking), and --check never went stale across repeated runs on a dirty file. The one deliberately-accepted risk (hash-collision / on-disk tamper) is disclosed in the README exactly as strongly as the behavior actually is, which was the main thing worth double-checking given CLAUDE.md's "guilty until proven innocent" rule for verify.rs-adjacent forgiveness — this feature does not touch verify.rs or widen its normalizations, so that rule does not directly apply, but the same spirit (attack the exact class of thing that could silently corrupt trust) was applied here to the cache's own trust boundary instead.

2026-09-07 — QA agent (TODO §59: uvm-utils-indent joins the key)

Read CLAUDE.md, TODO §59, this README's amended Handshakes and the 2026-09-07 dev entry above, then git diff for cache.rs, main.rs, cli.rs. The workspace built clean on trunk this time (no concurrent lane mid-landing), so all gates ran directly, no scratchpad rsync needed.

Gates.

  • cargo fmt -- --check: clean.
  • tools/guard.sh -m 8 -t 1800 -- cargo clippy --all-targets: silent. Re-ran scoped with -p lucisv_core -p lucisv --all-targets -- -D warnings after a touch to force recompilation (not just a cached "Finished"): still silent.
  • tools/guard.sh -m 8 -t 1800 -- cargo test -p lucisv_core -p lucisv: 36 (lucisv unit) + 107 (cli.rs) + 102 (lucisv_core unit) = 245, all green. (The dev's log counts pre-date this run; §59 added 2 cache.rs unit tests, 2 cli.rs tests, and touched shared corruption-vector tests in place, so the totals climbed from the 2026-08-19 136 baseline.) Confirmed a_store_written_before_the_option_joined_the_key_is_rebuilt and changing_uvm_utils_indent_invalidates_the_entry both present and passing.
  • cargo build --release -p lucisv: clean, used for every probe below as target/release/lucisv.

Step 2 — the audit's probe, by hand, --cache-dir in a scratch dir (fixture: the UVM class from the brief, [format] uvm-utils-indent = false first).

  • Fixed binary: format under false → --check exits 0, 1 file from cache. Flip to true → --check exits 1, would reformat: c.sv. Correct.
  • 0.49.0 baseline (~/.cache/lucisv-baselines/lucisv-0.49.0): same sequence — format under false, cache hit, flip to true → --check exits 0, 1 file from cache (the bug, reproduced exactly), while --check --no-cache on the same binary correctly says would reformat / exit 1 — confirming the option really does change output and only the cache is stale.
  • Other direction on the fixed binary: format under true (file is reformatted, output differs from the false rendering — confirmed assert_ne!-style by hand), cache hit under true, flip to false → exits 1. Correct.

Step 3 — attacking the key.

  • (a) Entry recorded under true, then run under false with the same content: --check reports would reformat, no from cache — miss, as required.
  • (b) Option set via a lucisv.toml in a parent directory (file under sub/, config in the parent, config discovery finds it): formatted clean under false, cache hit; flipped the parent config to true → --check exits 1, would reformat. The key follows the resolved value regardless of which directory in the chain set it, as the Assumptions section claims.
  • (c) A store written by the real 0.49.0 binary (five fields) read by the fixed binary: not an error, 1 file left unchanged without "from cache" (the old-shape line is dropped individually, not trusted), and the store is six fields after this run. The next --check is then 1 file from cache in the new shape. Matches the five-field-tolerance branch exactly.
  • (d) A store written by the fixed binary (six fields) read by the real 0.49.0 binary: read crates/lucisv_core/src/cache.rs at v0.49.0 (git show v0.49.0:...) — its parser is line.splitn(5, '\t'). Against a six-field line this splits on only the first 4 tabs, so 0.49.0's "version" slot actually receives the uvm field's text ("false"/"true") and its "path" slot receives everything after that, "<real-version>\t<real-path>" (with the join tab folded in raw). Since that captured "version" text is never equal to 0.49.0's own VERSION constant, the if version == VERSION check fails and the line is silently not inserted — the same code path 0.49.0 already uses for "another version's entry," not an error return. No path.is_empty() trip either (path is nonempty). Verified empirically: 0.49.0 read the six-field store, did not crash, reported plain 1 file left unchanged (no "from cache" — a real re-verify, not a false hit, and correct anyway since the file is genuinely clean), and rewrote the store back to its own five-field shape on exit. No false hit, no crash, confirmed both by code reading and by running it.
  • (e) Six-field line with uvm = "1": bool::from_str only accepts the literal strings true/false, so .parse().ok()? fails and parse() returns None → whole store discarded. Verified: seeded a store with one genuine clean entry plus this line, --check on the genuine file no longer says "from cache" (it re-verified). The "yes" case is already the unit test a_corrupt_file_is_ignored_wholesale's "...\tyes\t0.2.0\t/a.sv\n" vector — read it, it exercises the same .parse().ok()? branch as "1" does (both are non-true/false strings; no reason for one to behave differently from the other, and this run confirms "1" directly since the brief calls it out by name). Five-field line with non-hex content ("nothex\t100\t2\t0.49.0\tc.sv"): prefix()'s u64::from_str_radix(content, 16) fails first, ? short-circuits before the shape is even fully validated → None → discarded. Verified by hand: seeded that single bad line, --check did not trust it (no "from cache"), file re-verified clean on its own merits.
  • (f) Two files, one old-shape (five-field, a.sv) and one new-shape (six-field, b.sv) line in the same store: --check a.sv b.sv reports 2 files left unchanged, 1 file from cache — exactly one hit (b.sv), a.sv silently rebuilt, neither line poisoned the other. Matches a_line_without_the_option_is_dropped_but_not_fatal.

Also checked, prompted by the TODO item's own wording ("a store line with four fields"): a genuine four-field line (hash\t100\t2\t0.49.0, no uvm/no path) matches neither the six- nor the five-field pattern in parse's match, falls to _ => return None, and discards the whole store — including a separately-present, otherwise-good six-field entry for another file. Verified: seeded a good entry for realfile.sv plus a bogus four-field line, and the previously-good entry was no longer served ("from cache" absent) on the next --check. This is the fourth malformed-line shape (three, five, seven+ fields all land here too, by the same _ arm) and behaves like every other corruption case — correct, and consistent with "guilty until proven innocent" for a change that could have silently widened forgiveness but provably didn't.

Step 4 — path shapes that could confound the parser. Read parse and splitn(6, '\t'). The path field is always the last slot (index 5) of an at-most-6-way split, so no matter what the path contains, it receives everything left after the fifth tab is consumed — it cannot be mistaken for field 4 (uvm) and cannot cause a true/false field to be mis-identified as a path or vice versa:

  • Path literally "true": line 42b10c60d1dbc11a\t100\t2\tfalse\t0.49.0\ttrue parses to uvm_utils_indent = false, path = "true" — positionally unambiguous. Verified with a real file named true in a scratch dir: formats, caches, hits on the next --check.
  • Path containing an embedded tab: key() (used both to look up and to record) rejects any path containing \t or \n outright, so lucisv itself can never write such a line — this class is only reachable via a hand-forged/corrupted store. Reasoned from splitn(6, '\t'): a forged line deadbeefdeadbeef\t100\t2\ttrue\t0.49.0\ta\tb.sv (6 tabs, one more than the 5 the split consumes) parses with path = "a\tb.sv" intact — the sixth-and-final split field folds the extra tab in, so it round-trips as one field rather than desyncing the columns. Since key() can never produce a tab-containing lookup key for a real file, this forged entry can never be hit by any real run; verified by seeding exactly this line plus a real file, confirming no crash and no false hit, and that the forged line (path does not exist on disk) is silently pruned by render()'s existence check on the next write.

Step 5 — README cross-check. Handshakes' "Consumes vlog_formatter::Config" paragraph states the obligation on the next formatter setting explicitly, naming Entry, entry_for and "the store line" together, in the same commit — matches CLAUDE.md's rule 4 posture (widen the safety-adjacent surface only with the accompanying proof). The Storage section's line grammar (<hash>\t<line-length>\t<indent>\t<uvm-utils-indent>\t<version>\t<path>) matches render()'s writeln! argument order exactly (content, line_length, indent, uvm_utils_indent, VERSION, path).

Step 6 — size. cache.rs: 191 lines before mod tests (118 non-blank/non-comment) — nowhere near the 300–600 target. lucisv/src/main.rs: 568 lines before mod tests — the entry_for change added 4 lines and did not push it toward a threshold. No file touched by this diff is newly over any CLAUDE.md size line.

One non-blocking observation for the lead. Step 3(c)/(d) used today's actual pairing — the release-tagged lucisv-0.49.0 baseline against this uncommitted fix's local build, which also self-reports CARGO_PKG_VERSION = "0.49.0" because the workspace version has not been bumped for this change. That means in exactly the scenario just tested, the shape-based (five- vs six-field) tolerance is what kept the cross-binary read safe — the version field could not have, since both binaries carry the identical string. This slightly sharpens (not contradicts, once you know which pairing was meant) the dev's work-log claim that the five-field tolerance "buys nothing today" — that claim is true only after whatever release actually ships this fix bumps Cargo.toml's version per the existing release-commit pattern (git log shows each Release X.Y.Z commit does this), which is a lead/release-time step, not something this diff needed to do itself. Recorded so the version bump isn't skipped at merge — no code change needed here, the fallback already covers the pre-bump window correctly, as demonstrated above.

Verdict: PASS. No corruption, no crash, no false hit, no mis-parse in any attacked case; both directions of the audit's own probe reproduce the bug on 0.49.0 and are fixed on the new binary; the five-field tolerance is precise (old-shape-well-formed lines drop individually, anything else on five fields is fatal like any other malformed line, confirmed with "nothex" content); a four-field line (the TODO item's own wording) discards the whole store as corruption, confirmed by direct repro; no file crossed a CLAUDE.md size threshold. Ticking the §59 QA line in TODO.md.

Review

2026-09-07 (lead, §59). Accepted. Read the diff (Entry, the store line, parse's two arms, entry_for, the six cache tests, the two CLI regressions) and both logs.

  • The key now covers every FileConfig field that reaches the formatter, and the Handshakes say so as an obligation on whoever adds the next one. That is the actual fix; the codec change is its consequence.
  • The five-field arm is deliberately conditional (well-formed old shape only), so the existing "one malformed line discards the store" posture is unchanged — the corruption tests still bite on a non-hex content, a yes option, an empty path. Right call; a blanket field-count skip would have been a forgiveness with no attack test behind it.
  • QA's cross-version check is the one that matters: a 0.49.0 store is dropped individually and rebuilt; a 0.50.0 store read by 0.49.0 lands the option text in 0.49.0's version slot and is skipped as another version's entry. Neither direction can produce a false hit.
  • QA's note on the version bump is taken: the release chain bumps CARGO_PKG_VERSION to 0.50.0 before the tag, so the version field invalidates a 0.49.0 store on its own and the shape arm is belt and braces.
  • Docs applied at merge: README.md's key sentence and the workaround paragraph replaced by a one-line history note; topo row 34 struck; repository-analysis and coverage_gaps annotated as fixed.

2026-08-19 — lead. Verdict: accepted and committed. Warm runs are 2-4× faster in parallel and up to 7.7× single-threaded, bought without touching a single correctness property.

Points reviewed and accepted:

  1. Caching only the fixed-point verdict is the design decision that makes everything else safe: a hit can only skip work, never produce output, so "never corrupt code" is untouchable by construction, and --check/--diff can't go stale because dirty and error verdicts are recomputed every run — QA verified the staleness property three runs deep and the read-before-consult ordering on an unreadable file.
  2. The collision/tamper posture is disclosed, not hidden — QA's poisoning attack confirmed both the behavior and the honesty of the README's statement of it. Same-file 64-bit collision risk is the standard trade every formatter cache takes; keying the map on path keeps lookups from ever crossing files.
  3. FNV-1a with published test vectors turns "the hash silently changed" into a build failure instead of a fleet-wide cache bust — small touch, right instinct. The whole-file-discard-on-any-malformed- line rule is the right paranoia for a value store.
  4. Value-keyed config (not config-file identity) means two differently-written-but-equal lucisv.tomls share hits — QA probed it. The cwd-relative default cache location is the honest v1 limitation, stated.
  5. Both agents' isolation discipline under the concurrent alignment churn — dev and QA each gated in scratchpad copies with the churning crates reverted to HEAD — is now the house pattern for working alongside an in-flight round.
  6. The run-helper --no-cache insertion in cli.rs is recorded as a handshake: test isolation demanded it, and future CLI tests inherit it silently — worth knowing when a cache test needs the opposite.

Commits with round 17 (jointly with alignment, which owns the other half of the shared README/TODO edits).