Format cache: uvm-utils-indent joins the key (§59, topo 34) — Entry carries the option, the store line has it as a fourth field, a 0.49.0 store is rebuilt not trusted; CLI regression both toggle directions
ci / checks (push) Successful in 1m15s
ci / corpus (push) Successful in 34s

This commit is contained in:
lucio committed 2026-09-07 04:31:26 -05:00
1 parent d8d1791c1c
commit c37b13de31
9 files changed
+512 -63

No files matched your search

+327 -21
View File
@@ -23,12 +23,17 @@ what they would have been anyway (modulo one extra summary segment).
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.
- **`line-length` and `indent` are the whole config surface.** They are
the only two things `lucisv_core::config::FileConfig` can put into
`vlog_formatter::Config`. 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.
- **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")`
@@ -56,8 +61,8 @@ what they would have been anyway (modulo one extra summary segment).
### The key
Per file: **(content hash, line-length, indent, lucisv version)**, keyed on
the file path.
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
@@ -111,7 +116,7 @@ the hash of **the bytes that were written** goes in.
| Situation | Cache read | Cache write | Reported as |
|---|---|---|---|
| Hit (hash + line-length + indent + version all match) | skip all work | entry kept | `left unchanged`, plus `N files from cache` |
| 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 |
@@ -140,7 +145,7 @@ 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<version>\t<path>
<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
@@ -153,7 +158,7 @@ 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 five fields. Five fields on a line need no schema; CLAUDE.md's
encode six fields. Six fields on a line need no schema; CLAUDE.md's
"standard library first" says so.
Loading, corruption and staleness:
@@ -168,6 +173,15 @@ Loading, corruption and staleness:
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 `rename`d over `cache`. A reader therefore sees the old file or
the new one, never a half-written one.
@@ -256,12 +270,19 @@ the only writer of an entry is the code path that just observed
- **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`) 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 its two fields.
Nothing in `vlog_parser` / `vlog_formatter` / `vlog_linter` was
touched.
(`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
@@ -269,8 +290,9 @@ the only writer of an entry is the code path that just observed
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, `u64`s and two
`usize`s and has no opinion about arguments or reporting.
Nothing in the module is CLI-specific — it takes paths and the bare
scalars of the key (a `u64`, two `usize`s 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
@@ -289,7 +311,10 @@ the only writer of an entry is the code path that just observed
(`load` / `disabled` / `is_clean` / `record` / `store`).
- [x] Hand-rolled tab-separated store, sorted by path, atomic
temp+rename write, self-ignoring `.gitignore` in the cache dir.
- [x] Corrupt / unreadable / wrong-version entries ignored, never fatal.
- [x] Corrupt / unreadable / wrong-version entries ignored, never fatal;
so is a line in the pre-`uvm-utils-indent` five-field shape.
- [x] `[format] uvm-utils-indent` in `Entry`, in `entry_for` and as the
store's fourth field (TODO §59).
- [x] `--no-cache` and `--cache-dir <PATH>` in `args.rs` and `--help`,
accepted (and inert) for `lucisv check`.
- [x] Lookup at the top of `process_file`; entries collected through the
@@ -303,7 +328,8 @@ the only writer of an entry is the code path that just observed
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).
cache dir is cwd-relative and self-ignoring, `uvm-utils-indent`
invalidates in both directions, an older store is rebuilt).
- [x] Root `.gitignore` entry, `README.md` Cache section, `TODO.md` §3
box.
- [x] `cargo fmt`, `cargo clippy --all-targets`, `cargo test`.
@@ -438,6 +464,75 @@ their work lands.
- 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
@@ -595,8 +690,219 @@ 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.**