MCP M6: read-only reuse of the editor's index cache, an own store, the forced-delete ruling, first instructions; the block's closing docs
crates/lucisv_mcp/src/cache.rs: at startup `--index-cache DIR/index-cache` (the language server's store) is read READ-ONLY — header CACHE_FORMAT/FACTS_FORMAT/version must match this build or the store is ignored with one stderr line; each record line's checksum verified, decoded, keyed by (record path, content hash) and used only for a discovered file whose bytes hash to it, through IndexBuilder::add_facts instead of a parse; the server never writes that file. Its own `index-cache-mcp` is written once at exit, atomically, in the same codec (a test pins the restated framing against index_cache.rs's source). opentitan: cold 1.9 s → warm 0.8 s (walk 210 ms + merge 204 ms are the floor). delete_item with force may remove an item holding `define/`undef, warning which macros went (M4's ruling); INSTRUCTIONS names the read tools, the edit tools, dry_run and diagnostics. Closing docs: docs/topo.md gains the lucisv_mcp node and its six edges, the mcp-packaging spawn/packaging rows, the read-only cache row and §2.9 rows 35–42 (MCP-5/6/7/8/10/11/12/13 and the parser leniency the M3.5 verifier exposed); repository-analysis map row and nine-crate count; README architecture row; CLAUDE.md measurement for the new crate. QA (Opus; interrupted by the owner moving the machine, verdict pass so far): swapped/stale/foreign/deleted/off-by-one-header/CRLF stores skipped, the editor's store byte-identical through a session, SIGKILL mid-write harmless, a 231 MB store linear, fingerprint parity over the whole checkout; two low items open — the README threat model reworded, and an orphaned `.tmp` after a kill between write and rename to be swept in the census round. Gates: fmt, clippy clean; lucisv_mcp 318 passed; the dev's workspace run 4 858 passed on the same code. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
d4ec571958
commit
0f4830afa5
20 files changed
+2163
-60
No files matched your search
@@ -0,0 +1,385 @@
|
||||
# mcp-cache-and-census
|
||||
|
||||
Lane **M6** of the MCP block (`TODO-MCP.md`, `docs/mcp/PLAN.md` §6 and §8):
|
||||
the index cache reuse, the startup and per-call timings, the M4 review's
|
||||
rule-6 ruling, the first revision of the `initialize` instructions — and,
|
||||
the lead's half, the token census and the closing release.
|
||||
|
||||
## Goal
|
||||
|
||||
A coding agent's first question to `lucisv-mcp` pays for the index build:
|
||||
1.9 s on opentitan, every session. The language server has already parsed
|
||||
the same files and persisted one `FileFacts` record per file, keyed by the
|
||||
file's content hash (`lucisv_server::index_cache`). This lane lets MCP
|
||||
start from those records — read only, never written — and from a store of
|
||||
its own in the same codec, so a warm start skips the parse of every file
|
||||
whose bytes a record was read from. A record can only ever stand in for the
|
||||
parse of exactly the bytes it was read from, so the cache is a performance
|
||||
input and never a correctness one: a torn, damaged, foreign or stale record
|
||||
costs a parse and nothing else.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **Where.** Only `--index-cache DIR` turns the caches on (the extension
|
||||
passes VS Code's `storagePath`, the directory the language server writes
|
||||
`index-cache` in). No OS-cache-dir fallback: without the flag MCP starts
|
||||
cold, as before. The directory may not exist yet (M5 QA F4: VS Code
|
||||
creates `storagePath` lazily) — that is a silent cold start.
|
||||
- **Read.** At startup `cache::Records::load` reads `DIR/index-cache-mcp`
|
||||
and then `DIR/index-cache` (so a record both hold is credited to the
|
||||
editor). A store is used only when its first line is exactly this build's
|
||||
header `lucisv-index-cache\t2\t<FACTS_FORMAT>\t<version>`; any other first
|
||||
line ignores the store whole with **one stderr line**; a missing or empty
|
||||
file is silent. Each record line is `hash\tfacts\tchecksum`; a line whose
|
||||
hash or checksum is not 16 hex digits, whose checksum is not the FNV-1a of
|
||||
the facts field, or which is not UTF-8 is skipped — that covers a torn
|
||||
last line (a writer killed mid-append) and a record edited after it was
|
||||
written. Records are keyed by `(record_path, content hash)`.
|
||||
- **Use.** For each discovered file, MCP reads and hashes the bytes (it
|
||||
must anyway: the stamp and the freshness sweep need the hash). When
|
||||
`(canonical path, hash)` has a record that `FileFacts::decode`s to the
|
||||
same path, `IndexBuilder::add_facts` takes it instead of `add_file`. A
|
||||
record under another path (the language server's paths are whatever the
|
||||
editor handed it; MCP's are canonical) is a miss, not a translation.
|
||||
- **Write — only our own store.** On EOF (the host closes stdin) the
|
||||
server writes `DIR/index-cache-mcp`: the same header, then one record per
|
||||
indexed file — the facts the index holds, under the hash in the file's
|
||||
stamp (both come from the same read, so they describe the same bytes),
|
||||
in path order. Atomic: a `index-cache-mcp.<pid>.tmp` renamed over the
|
||||
store; a failure removes the temp file and is **one stderr line**
|
||||
(`cannot write the index cache: …`); the session ends either way. The
|
||||
directory is created if missing, and gets a `.gitignore` of `*` when it
|
||||
has none (the language server does the same). **`DIR/index-cache` is
|
||||
never opened for writing**: `cache.rs` has no code path that names it
|
||||
except `fs::read`, and `tests/cache.rs` hashes it before and after whole
|
||||
sessions.
|
||||
- **Not written:** a session that never answered a tool call (no project
|
||||
was built), or a session killed rather than closed. Two MCP servers on one
|
||||
directory each rename their own complete store over the file: last writer
|
||||
wins, both stores are whole.
|
||||
- **The stderr line** is `lucisv-mcp: indexed N files in M ms (E from the
|
||||
editor's cache, O from its own)` when `--index-cache` is given, and the
|
||||
old line without the parenthesis otherwise. `M` now includes the index
|
||||
merge (`IndexBuilder::finish`), which the M1 line left out — the number
|
||||
went up by the merge's ~200 ms on opentitan; the build did not change.
|
||||
- **The codec is restated, not shared.** `index_cache.rs`'s `FILE`,
|
||||
`CACHE_FORMAT`, header and line formats are private to `lucisv_server`
|
||||
(a binary crate MCP must not depend on — PLAN §4.1). `cache.rs` restates
|
||||
them; `cache::tests::the_codec_is_the_language_servers_own` reads
|
||||
`crates/lucisv_server/src/index_cache.rs` at test time and fails if any of
|
||||
the five pinned source lines changes (Handshake MCP-14).
|
||||
- **Rule 6, the M4 ruling.** `delete_item` with `force: true` may remove an
|
||||
item that holds `` `define``/`` `undef`` entries (a module with a
|
||||
`` `define`` in its body, an `always` with one nested): the deletion
|
||||
passes rule 6 and the answer carries the warning `deleted macro
|
||||
definitions: Q, W (undef) — code after the item that used them will
|
||||
change meaning` (each name once, in source order, `(undef)` for an
|
||||
`` `undef``). Without `force` the refusal stands and now ends `, or pass
|
||||
`force: true` to delete it anyway`. `replace_item` and `insert_item` take
|
||||
no `force` and are unchanged. The verifier change is local:
|
||||
`Expect::Nothing { force }`, and `Outcome::dropped_macros`.
|
||||
- **The instructions** (`rpc.rs`, 787 characters, pinned ≤ 900 by a wire
|
||||
test) name the read tools to prefer over reading files, that edits are
|
||||
verified, all-or-nothing, on disk with `dry_run`, the item tools vs the
|
||||
design-wide ones, `diagnostics` to check, and the path/column units. The
|
||||
lead revises them after the census.
|
||||
|
||||
## Handshakes
|
||||
|
||||
Consumed (unchanged, read only): `vlog_semantic::{FileFacts::{encode,
|
||||
decode, path}, record_path, FACTS_FORMAT, IndexBuilder::{add_facts,
|
||||
add_file, finish}, WorkspaceIndex::{facts_for, fingerprint}}`;
|
||||
`lucisv_core::cache::content_hash`; the byte format of
|
||||
`lucisv_server::index_cache` (below).
|
||||
|
||||
Promised: `Project::open_cached(roots, filelist, cache_dir)` (the old
|
||||
`Project::open` is now the tests' uncached shorthand), `Project::save_cache`,
|
||||
`Project::reuse`. `rpc.rs` calls them in `open_project` and on EOF.
|
||||
|
||||
Filed:
|
||||
|
||||
- **MCP-14 → `lucisv_server` (informational + one request).** MCP reads
|
||||
the server's `index-cache` read-only (`fs::read`, never a write handle)
|
||||
and writes `index-cache-mcp` beside it in the same codec. Nothing in the
|
||||
server changes. *Request (not blocking):* the codec constants (`FILE`,
|
||||
`CACHE_FORMAT`, `header()`, `line()`/`parse_entry`) are private to a
|
||||
binary crate, so MCP restates them and pins the restatement against the
|
||||
source text; lifting the codec (not the store) into `vlog_semantic` or
|
||||
`lucisv_core` as a pure move would let both sides share one definition
|
||||
and retire the pin. Until then, **a change to the store's framing must
|
||||
bump `CACHE_FORMAT` and update `crates/lucisv_mcp/src/cache.rs`** — the
|
||||
pin test fails otherwise.
|
||||
- **MCP-7 → `vlog_refactor`: status unchanged (open).** `rename` still
|
||||
hands the engine the whole set: 2.23–2.28 s per dry run on opentitan
|
||||
(below), the cost MCP-7's `KnownFacts` variant (or passing the index's
|
||||
facts to `rename_traced_with`, which already takes `&dyn KnownFacts`)
|
||||
would remove. That is an M3 tools change, not this lane's.
|
||||
- **Out-of-ownership edit, flagged for the lead:** `tests/qa_m4.rs`
|
||||
`qa_recheck_a_define_item_may_be_inserted_but_not_nested_in_an_always`
|
||||
pinned "a forced delete of a module holding a `define is refused" — the
|
||||
exact behaviour the M4 review ruled to change. The loop over
|
||||
`force ∈ {false, true}` became the unforced refusal plus a forced dry run
|
||||
that must succeed and name `LOCAL` (8 lines, comment says why). Without
|
||||
it `cargo test -p lucisv_mcp` is red.
|
||||
- **For the lead (docs outside this lane):** the M1 README's Assumption
|
||||
"`--index-cache DIR` is accepted and stored, and unused until M6" is now
|
||||
stale; `docs/mcp/PLAN.md` §6 matches what was built.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] `cache.rs`: read-only reader of the editor's store (header, per-line
|
||||
checksum, `record_path`, `decode`), keyed by path + content hash
|
||||
- [x] warm start: `add_facts` on a hit, parse on a miss; hit counts on the
|
||||
stderr startup line
|
||||
- [x] own store `index-cache-mcp`: same codec, written atomically on EOF,
|
||||
read on start; a write failure is one stderr line
|
||||
- [x] F4: a missing directory is a silent cold start
|
||||
- [x] unit tests (`src/cache/tests.rs`): the codec pin; warm from the
|
||||
editor's store = cold fingerprint; own store round trip = cold
|
||||
fingerprint; a changed file misses; torn / damaged / foreign records
|
||||
each a parse; a record under another path or hash not taken
|
||||
- [x] wire tests (`tests/cache.rs`): the editor's store byte-identical
|
||||
(hash + mtime) after a session that indexes, answers and edits, with
|
||||
a damaged and a torn record skipped; another version's store ignored
|
||||
with one line; missing directory → cold, own store written, next
|
||||
start warm from it, a changed file re-parsed and answered new; an
|
||||
unwritable directory (0555) → answers, one stderr line, nothing
|
||||
written
|
||||
- [x] opentitan timings (`tests/opentitan.rs`, ignored): cold / warm from
|
||||
own store / warm from the editor's store, exit write, stat sweep,
|
||||
whole-set `rename`
|
||||
- [x] rule-6 ruling: `force` relaxes rule 6 on `delete_item` with the
|
||||
warning; wire test + attack test
|
||||
- [x] `INSTRUCTIONS` first revision (≤ 900 characters, wire-tested)
|
||||
- [x] `docs/perf/README.md` MCP entry
|
||||
- [ ] token census, instruction revision after it, topo, CHANGELOG,
|
||||
release — the lead's
|
||||
|
||||
## Timings
|
||||
|
||||
Release build (`cargo test --release -p lucisv_mcp --test opentitan --
|
||||
--ignored --nocapture opentitan_startup`), macOS arm64, the whole opentitan
|
||||
checkout (3 944 indexed files, 3 over 1 MiB skipped), two runs; the
|
||||
checkout's `git status --porcelain` identical before and after. The stores
|
||||
live in a scratch directory outside the checkout; the "editor's store" is
|
||||
the own store renamed to `index-cache` — the same bytes the language server
|
||||
would write (46.3 MB), which is what the codec pin guarantees.
|
||||
|
||||
| what | wall |
|
||||
|---|---|
|
||||
| cold start, no store (first `project_overview`) | 1 854–1 887 ms (build 1 800–1 880 ms) |
|
||||
| warm from its own store | 837–847 ms (build 821–840 ms, 3 944 hits) |
|
||||
| warm from the editor's store | 821–832 ms (build 814–824 ms, 3 944 hits) |
|
||||
| exit, writing `index-cache-mcp` (46.3 MB) | 251–272 ms |
|
||||
| per-call freshness sweep (`outline` of a cached file, median of 21) | 5.6–6.1 ms |
|
||||
| — the transport floor (`tools/list`, median of 21) | 0.38 ms |
|
||||
| `rename` `op_i` → `cipher_op_i` at `hw/ip/aes/rtl/aes_cipher_core.sv:123`, `dry_run`, whole set | 2 227–2 276 ms (first and second call alike) |
|
||||
|
||||
Where a warm build's ~820 ms goes (one instrumented run, not committed):
|
||||
walk 210 ms, reading the store 87 ms, reading + hashing + decoding 3 944
|
||||
files 318 ms (1 387 ms when each is parsed instead), the index merge
|
||||
204 ms. The walk and the merge are the floor a cache cannot remove.
|
||||
|
||||
## Token census (lead)
|
||||
|
||||
## Work log
|
||||
|
||||
**2026-09-23 (dev, Opus).** Built as briefed, in the owned files plus the
|
||||
two flagged edits (`rpc.rs` wiring beyond `INSTRUCTIONS`; `tests/qa_m4.rs`).
|
||||
|
||||
- `cache.rs` (118 production lines): `Records::load/take`, `write_own`,
|
||||
the restated header/line codec, `store_lines` reading bytes a line at a
|
||||
time exactly as the language server does (a torn multi-byte character
|
||||
costs one line). `Reuse` counts hits by source.
|
||||
- `project/mod.rs`: `open_cached` + a `load` helper (read, stamp, take a
|
||||
record or parse); `save_cache` builds `(stamp.hash, index.facts_for)`
|
||||
per file; `reuse()`. **Deviation:** the build clock now stops after
|
||||
`finish()` — the old code read the clock before the merge ran inside the
|
||||
struct literal, so every "indexed in M ms" since M1 left out ~200 ms on
|
||||
opentitan. `Project::open` became `#[cfg(test)]` (its only callers are
|
||||
tests; clippy's dead-code lint otherwise).
|
||||
- `rpc.rs`: `open_project` calls `open_cached` and prints the counts;
|
||||
`Line::Eof` calls `Server::finish`, which saves (verbose: a line with the
|
||||
record count; failure: one line always). **Deviation:** the brief listed
|
||||
`rpc.rs` for `INSTRUCTIONS` only, but the startup line and the EOF write
|
||||
live there; the change is those two call sites.
|
||||
- `verify.rs`/`item.rs`: the rule-6 ruling (above); `delete_item`'s
|
||||
description and `force` parameter say so.
|
||||
- Unit tests live in `src/cache/tests.rs` (the fingerprint oracle needs
|
||||
`Project`, which a `tests/` file cannot reach in a binary crate).
|
||||
- The own store is rewritten on every exit even when unchanged (~260 ms on
|
||||
opentitan, after the last answer): simple, and a store the host kills us
|
||||
during is still the previous whole store.
|
||||
- Tests: `lucisv_mcp` 290 → 302 passing (+5 unit, +4 `tests/cache.rs`,
|
||||
+3 wire), ignored 2 → 3 (the opentitan timing test); workspace 4 846 →
|
||||
4 858.
|
||||
|
||||
## QA log
|
||||
|
||||
**2026-09-23 (QA, Opus) — QA — interrupted** (the session was cut off before the workspace gate finished; everything below was run and is recorded as measured).
|
||||
|
||||
**The cache half of the M6 QA line. Verdict so far: pass;
|
||||
no wrong record served, the editor's store never written. Two non-blocking
|
||||
findings (one doc, one inherited leak). The census spot-check waits for the
|
||||
census.** Tests in `crates/lucisv_mcp/tests/qa_m6.rs` (16 pass, 1 ignored =
|
||||
finding 2), each spawning the real binary over a scratch copy of the
|
||||
`design` fixture.
|
||||
|
||||
*Wrong-record hunt (blocking class — nothing found).*
|
||||
|
||||
- **Swapped records, checksums recomputed** (`leaf.sv`'s hash carrying
|
||||
`top.sv`'s facts and the reverse): not served. The key is `(record_path
|
||||
of the facts, hash)` and `take` compares the decoded path again, so each
|
||||
lands under (other path, this hash) and matches no file — 5/7 hits, the
|
||||
probe's nine answers equal a cold start's. Also run on a copy of opentitan
|
||||
`hw/ip/{aes,prim}` with a real language-server store (`prim_fifo_sync` ↔
|
||||
`prim_fifo_async`): 391/393 hits, both interfaces right.
|
||||
- **Inherited, documented limit (not a finding against the code):** a
|
||||
record *relabelled* — `prim_fifo_async`'s facts with `prim_fifo_sync.sv`'s
|
||||
path, under `prim_fifo_sync.sv`'s real hash, checksum recomputed — is
|
||||
served (393/393 hits; `unit_interface prim_fifo_sync` answers "not
|
||||
indexed") and is then re-laundered into `index-cache-mcp` with a fresh
|
||||
checksum. The language server does exactly the same: `index_cache.rs`'s
|
||||
module doc states the same-user/same-disk threat model (FNV-1a is not a
|
||||
MAC; whoever can write the store can write the sources). Accidental
|
||||
damage cannot produce this shape. See finding 1 for the doc.
|
||||
- Records for a deleted file and for a file outside every root (it exists
|
||||
beside the root): neither module listed, neither record written back
|
||||
(own store = header + 7). Two records for one path under two hashes
|
||||
(the append log's normal shape): the one whose hash is the bytes on disk is
|
||||
served, older or newer; two for one `(path, hash)`: the later line wins, as
|
||||
in `IndexCache::open` (tested with a checksum-valid wrong record first and
|
||||
the honest one last).
|
||||
- CRLF store: `\r` stripped exactly as the language server strips it, 7/7
|
||||
hits, answers = cold. Header near-misses — version patch + 1,
|
||||
`FACTS_FORMAT` ± 1, `CACHE_FORMAT` 1 and 3, a trailing space, a BOM, a
|
||||
fifth field: each ignored whole with exactly one stderr line, store
|
||||
byte-identical. Empty store, header-only store, a directory named
|
||||
`index-cache`: silent cold starts (stderr = the startup line only).
|
||||
- A 231 MB store (opentitan's 46 MB store + 4 copies under `/ghostN` paths,
|
||||
checksums valid), release build, 3 944 files: build 892 / 937 / 1 026 /
|
||||
1 203 ms at 46 / 92 / 138 / 231 MB — linear (~1.7 ms/MB); peak RSS 407 →
|
||||
750 MB (the store bytes plus every record's string are held until the
|
||||
load ends); the store byte-identical after each run.
|
||||
|
||||
*Read-only promise and the own store's writes.*
|
||||
|
||||
- The editor's store at mode 0444, in a live server's between-compactions
|
||||
shape (reversed path order, a duplicate line, a torn line mid-file, a
|
||||
checksum-failing line), through a session that indexes, answers, runs
|
||||
`format` (writes a file) and ends: bytes, mtime and mode identical, 7/7
|
||||
hits. On the real `aes`+`prim` LSP store: `shasum` identical after a warm
|
||||
session. Code: `cache.rs` names `EDITOR_STORE` only in `Records::load`
|
||||
→ `fs::read`; `write_own` writes only `index-cache-mcp`, its temp file and
|
||||
`.gitignore` (when missing — as the language server does).
|
||||
- Killed sessions (SIGKILL): after an answer and before EOF (fixture, with
|
||||
a changed file that would have changed the store): the previous own store
|
||||
byte-identical, no temp file, the next start re-parses the changed file.
|
||||
On opentitan, killed at 20–350 ms after EOF (11 delays): own store
|
||||
intact, no temp. Killed the instant `index-cache-mcp.<pid>.tmp` appeared:
|
||||
store intact, **a 9.4 MB temp file left behind for good** → finding 2.
|
||||
- `--index-cache` naming a regular file: answers right, one `cannot write
|
||||
the index cache` line, the file untouched. A directory named
|
||||
`index-cache-mcp`: silent read miss, one line at exit, no temp left. Cache
|
||||
directory mode 000 holding an honest store: cold start, the nine probe
|
||||
answers equal cold's, one line at exit, store untouched. (A startup that
|
||||
cannot *read* a store is silent — only the exit's write failure speaks.
|
||||
Acceptable for a performance input; noted, not filed.)
|
||||
|
||||
*Parity.*
|
||||
|
||||
- The nine-answer probe (`list_units`, two `unit_interface`, two `outline`,
|
||||
`search_symbols`, `references`, `hierarchy`, `defines`) is identical cold,
|
||||
warm from the editor's store and warm from the own store.
|
||||
- A **real language-server store** (release `lucisv-server` driven over
|
||||
stdio on a copy of `hw/ip/{aes,prim}`, `index.scope = workspace`,
|
||||
`storagePath` = scratch; 393 records, 2.69 MB): MCP warm start 393/393
|
||||
editor hits, and — the stronger check — a **cold** MCP session's
|
||||
`index-cache-mcp` over the same tree is **byte-identical** to the
|
||||
server's `index-cache`: same header, same facts, same order.
|
||||
- `WorkspaceIndex::fingerprint` (throwaway unit test in a scratch copy of
|
||||
the crate, not committed): warm-from-LSP-store = cold on `aes`+`prim`
|
||||
(393 files); warm-from-own-store = cold on the **whole opentitan
|
||||
checkout** (3 944 files, fingerprint 37.2 MB); the checkout's `git status
|
||||
--porcelain` identical before and after every run.
|
||||
- Same-size edit (`held` → `hold`) since the store: re-parsed, the outline
|
||||
shows `hold`; a new file since the store: indexed; 6/7 hits.
|
||||
|
||||
*Rule 6 (the M4 ruling).* A module holding `` `define LOCAL`` twice and a
|
||||
nested `` `undef GONE``, read by the module after it: without `force`
|
||||
refused (names rule 6 and `force: true`), file byte-identical; forced: the
|
||||
warning reads `deleted macro definitions: LOCAL, GONE (undef) — …` (each
|
||||
name once, source order), every byte before and after the item's lines is
|
||||
the original's. `force` on an item with no macro says nothing about
|
||||
macros. The `tests/qa_m4.rs` diff is exactly the ruling's assertion swap
|
||||
(the `force ∈ {false, true}` refusal loop → unforced refusal + forced dry
|
||||
run naming `LOCAL`), nothing else. The code: `Expect::Nothing { force }`;
|
||||
for a deletion `same_macros` can only fail when the region held a
|
||||
definition, which is exactly what `dropped` lists — `force` cannot excuse
|
||||
anything else.
|
||||
|
||||
*Instructions.* 787 characters (≤ 900). Names `unit_interface`, `outline`,
|
||||
`read_item`, `list_units`, `search_symbols`, `definition`, `references`,
|
||||
`hierarchy`, the three item tools, `rename`, `add_port`, `remove_port`,
|
||||
`format`, `fix_lint`, `diagnostics` — every one in `tools/list`, and no
|
||||
snake_case word that is not a tool (`dry_run` aside); says disk-only,
|
||||
root-relative paths, 1-based byte columns.
|
||||
|
||||
*Sizes.* Production lines: `cache.rs` 118, `project/mod.rs` 289, `rpc.rs`
|
||||
265, `tools/item.rs` 389, `tools/item/verify.rs` 388 — all under 600.
|
||||
|
||||
*Timings (release, whole opentitan, this machine, `tests/opentitan.rs`).*
|
||||
Cold 1 769 ms build (first call 1 776 ms); warm own 833 ms; warm editor's
|
||||
807 ms; exit write 243–260 ms; sweep median 4.9–5.0 ms (floor 0.35 ms);
|
||||
`rename` dry run 2 152–2 172 ms. Consistent with the dev's table.
|
||||
|
||||
*Findings.*
|
||||
|
||||
1. **(low, doc)** `docs/features/mcp-cache-and-census/README.md` Goal:
|
||||
"a torn, damaged, foreign or stale record costs a parse and nothing else"
|
||||
overclaims — a forgery that recomputes the FNV-1a checksum is served
|
||||
(reproduction above; the language server has the same property by
|
||||
design). Fix: say "a torn, damaged, foreign or stale record", and add the
|
||||
threat-model sentence the server's `index_cache.rs` module doc carries
|
||||
(same user, same disk; the checksum catches damage, not intent) to
|
||||
Assumptions → Read. No code change.
|
||||
2. **(minor, inherited)** `crates/lucisv_mcp/src/cache.rs:140-146`
|
||||
(`write_own`): a process killed between `fs::write(tmp)` and the rename
|
||||
leaves `index-cache-mcp.<pid>.tmp` (9.4 MB on opentitan) that no later
|
||||
session removes — one per crash, each up to the store's size. Harmless
|
||||
to correctness (only the exact store names are read). Same leak as the
|
||||
language server's, filed by its QA 2026-08-27
|
||||
(`an_orphaned_compaction_tmp_file_is_never_swept_up`). Pinned by
|
||||
`qa_an_orphaned_temp_file_is_swept_by_the_next_write` (ignored). Fix:
|
||||
before writing, remove `index-cache-mcp.*.tmp` files in `dir` older than
|
||||
a few minutes (a concurrent writer's live temp file is seconds old).
|
||||
|
||||
*Gates* (through `tools/guard.sh`, one at a time): `cargo fmt --all --
|
||||
--check` clean; `cargo clippy --workspace --all-targets` clean (no
|
||||
warnings); `cargo test -p lucisv_mcp` 318 passed, 0 failed, 4 ignored
|
||||
(302 + 16 QA; ignored: 2 opentitan, M3 finding, M6 finding 2); the
|
||||
opentitan tests (release, `--ignored`) 2 passed, checkout unchanged;
|
||||
`cargo test --workspace` **NOT completed** — cut off after ~16 minutes, mid-run (reached `vlog_refactor`, `corpus`, `inline` test binaries; every result line captured before the cut-off was `ok`, no failure seen).
|
||||
|
||||
*Not yet checked:* the full `cargo test --workspace` count (needs ≥ 4 858 + 16 = 4 874 passing); the census transcripts spot-check (the census has not been run — the lead's half); a whole-opentitan store written by the *language server itself* (only `aes`+`prim` was; whole opentitan was checked with MCP's own store). The M6 QA box in `TODO-MCP.md` is left unticked.
|
||||
|
||||
## Review
|
||||
|
||||
**Lead, 2026-09-23 (M6, committed at the owner's move).** The reader keys a
|
||||
record on the file's content hash and the record's own path, never writes
|
||||
the editor's store, and a warm start on opentitan halves the startup (1.9 s
|
||||
→ 0.8 s; the walk and the merge are the floor). QA (interrupted by the move,
|
||||
verdict pass so far): swapped, stale, foreign-path, deleted-file, off-by-one
|
||||
header and CRLF stores all skipped; the editor's store byte-identical through
|
||||
a session; SIGKILL mid-write leaves the previous own store intact; a
|
||||
231 MB store loads linearly; fingerprint parity with a cold build over the
|
||||
whole checkout. Two low items: the README's threat model now says
|
||||
"damaged", not "forged" — a record with a recomputed checksum is used,
|
||||
exactly as the language server uses it, because whoever can write the store
|
||||
can write the sources; and an orphaned `index-cache-mcp.<pid>.tmp` after a
|
||||
kill between write and rename is not swept (QA's ignored test
|
||||
`qa_an_orphaned_temp_file_is_swept_by_the_next_write`) — to be fixed in the
|
||||
first census round. The forced-delete ruling (rule 6) and the first
|
||||
`INSTRUCTIONS` revision landed here; the census revises the instructions
|
||||
again. The full workspace suite was still running when the machine moved;
|
||||
the dev's run on the same code passed 4 858 and QA's crate suite 318.
|
||||
@@ -89,8 +89,10 @@ arrived.
|
||||
tree. The build line (`lucisv-mcp: indexed N files in M ms`) is always
|
||||
written to stderr; `--verbose` adds one timing line per request and the
|
||||
freshness report per call.
|
||||
- **`--index-cache DIR` is accepted and stored, and unused** until M6 reads
|
||||
the LSP's store.
|
||||
- **`--index-cache DIR`** names the directory holding the language server's
|
||||
`index-cache` store, read read-only at startup (M6, 2026-09-23:
|
||||
`docs/features/mcp-cache-and-census`), beside which this server writes its
|
||||
own `index-cache-mcp` once at exit. A missing directory is a cold start.
|
||||
- **Argument validation is a tool error, not a protocol error.** A call whose
|
||||
`arguments` do not fit the tool's schema (unknown argument, wrong type,
|
||||
missing required one) is answered `isError: true` with a sentence naming
|
||||
|
||||
@@ -1423,3 +1423,24 @@ count and within noise in time (`aes` 14 locations / 9 files, `.clk_i`
|
||||
before it is rendered — one slice compare per location, unmeasurable —
|
||||
so a stale index can omit a location but never point at a wrong line
|
||||
(QA findings 1–4). `docs/features/references-hierarchical-surface/README.md`.
|
||||
### 2026-09-23 — MCP: `lucisv-mcp` startup and the per-call sweep (TODO-MCP M6)
|
||||
|
||||
`lucisv-mcp` builds its index at the first tool call and can start it from
|
||||
the language server's `index-cache` (read only) or its own
|
||||
`index-cache-mcp` beside it (`docs/features/mcp-cache-and-census/README.md`).
|
||||
Release build, the whole opentitan checkout (3 944 files), two runs of
|
||||
`tests/opentitan.rs::opentitan_startup_cold_and_warm_and_the_stat_sweep`:
|
||||
|
||||
| what | wall | the language server's nearest row |
|
||||
|---|---|---|
|
||||
| cold start, no store | 1 854–1 887 ms | — |
|
||||
| warm, own store (3 944 hits) | 837–847 ms | warm quiet workspace start 985–997 ms (§61), workspace scope |
|
||||
| warm, the editor's store (3 944 hits) | 821–832 ms | — |
|
||||
| exit, writing the own store (46.3 MB) | 251–272 ms | compaction skipped when unchanged (§P4b) |
|
||||
| freshness sweep per call (median, 21 calls) | 5.6–6.1 ms (floor `tools/list` 0.38 ms) | — |
|
||||
| `rename` dry run, whole set (`op_i` in `aes_cipher_core.sv`) | 2 227–2 276 ms | — (MCP-7) |
|
||||
|
||||
A warm build is walk 210 ms + store read 87 ms + read/hash/decode 318 ms +
|
||||
merge 204 ms; a cold one parses instead (1 387 ms). The rows are not
|
||||
like-for-like with the server's (it scans in stages and answers during the
|
||||
scan); they sit side by side so a regression in either shows.
|
||||
@@ -6,7 +6,7 @@ this review. Loop 2 is closed; no uncommitted feature work is included.
|
||||
|
||||
## Assessment and current status
|
||||
|
||||
lucisv remains an eight-crate toolchain: six reusable Rust libraries, CLI and
|
||||
lucisv is a nine-crate toolchain (2026-09-23: `lucisv_mcp` joined): six reusable Rust libraries, CLI, MCP and
|
||||
LSP binaries, editor integration, corpus/release tools, and a static docs site.
|
||||
The architecture still separates syntax, formatting, semantics, linting,
|
||||
refactoring, and project inputs. The September 4 audit findings are fixed.
|
||||
@@ -47,6 +47,7 @@ two edits have disjoint ownership.
|
||||
| `crates/lucisv_core` | Config, filelists, cycle-aware walks and warning channel, format cache, atomic replacement; no language-engine dependency |
|
||||
| `crates/lucisv` | Argument handling, input discovery/dedup, worker pool, reports and source writes |
|
||||
| `crates/lucisv_server` | Ordered LSP loop and workspace overlays; `server/`, `state.rs`, capability handlers including `imports.rs`, `extract.rs`, `inline_module.rs`; project lint validation/logging in `lint/project.rs` |
|
||||
| `crates/lucisv_mcp` | Model Context Protocol server for coding agents over stdio: `project/` (roots, filelist-or-walk, freshness sweep), `tools/` (26 tools: read, navigation, verified edits, structural edits with their own verifier in `tools/item/`), `apply.rs` (one all-or-nothing write path), `resources.rs`; composes the six libraries, never `lucisv_server` (`docs/mcp/PLAN.md`) |
|
||||
| `editors/` | VS Code client/grammar/settings/hierarchy UI and other editor configuration; `hierarchySections.js` models DUT sections, `extract.js` supplies the module-name prompt |
|
||||
| `tools/`, `scripts/`, `.gitea/workflows/` | Resource guard, corpus evaluation, artifact checks and releases |
|
||||
| `docs/features/` | Implementation contracts, dated measurements, QA and acceptance records |
|
||||
|
||||
@@ -94,6 +94,14 @@ graph TD
|
||||
TOOLS[tools/ release scripts] -.builds/packages.-> CLI
|
||||
TOOLS -.builds/packages.-> SRV
|
||||
TOOLS -.builds/packages.-> VSC
|
||||
MCP[lucisv_mcp] --> C
|
||||
MCP --> P
|
||||
MCP --> S
|
||||
MCP --> R
|
||||
MCP --> F
|
||||
MCP --> L
|
||||
VSC -.spawn contract.-> MCP
|
||||
TOOLS -.builds/packages.-> MCP
|
||||
CI[Gitea Actions] --> TOOLS
|
||||
DOCS[docs/site] -.documents CLI and generated rule reference.-> CLI
|
||||
DOCS -.documents protocol.-> SRV
|
||||
@@ -145,6 +153,7 @@ what a change on the pointed-to side must not silently break.
|
||||
| `lucisv_server ◀──▶ vlog_refactor` | handshake | Request-scope selectors added for the performance wave: `prepare_rename_here` must produce the same answer/refusal text as whole-scope `prepare_rename`; `rename_name_at` must name the target that the rename engine acts on; `port_action_modules` and `enclosing_module` must name every module the corresponding port action/command can edit. The server uses those names to choose an index-derived file set; `extract_site`, `inline_site` and `imported_packages` also name source requirements. **`rename_preflight(semantics, offset, new_name)` (perf5r-preflight, 2026-09-08)** owes whole-scope `rename` the same *refusal* text one-directionally — it may always stand aside with `Ok(())` and never invents a refusal — and deliberately reads no workspace index (unlike `prepare_rename_here`): only refusals that are a pure function of the request buffer's own text (the new-name check, no symbol here, an unresolved or inherited-candidate reference, an unspelled declaration, the same name at a non-file-scope declaration); every index-answered refusal stays on the slow road. The engine remains the authority, and every selector must supply a superset of files needed for edits and refusals (inline gap: §2.9-33). |
|
||||
| `lucisv_server ──▶ vlog_formatter` | depends | `format_source`, `format_range`/`LineRanges` (range, ranges, on-type formatting), `Config`, `fence::protected_regions` (quick-fix filter). |
|
||||
| `lucisv_server ──▶ vlog_linter` | depends | `run`, `lint` + `LintContext::from_parse` (lints from the `Document`'s own parse — one-parse), `default_rules`, `apply_fixes`, `rule_by_name`. Same three promises the CLI relies on. |
|
||||
| `lucisv_mcp ──▶ lucisv_core, vlog_parser, vlog_semantic, vlog_refactor, vlog_formatter, vlog_linter` | depends | The MCP block (2026-09-23, `docs/mcp/PLAN.md`, `TODO-MCP.md`): `lucisv-mcp` composes the six libraries through their public APIs only — `Discovery`/`filelist`/`walk`/`content_hash`/`write_atomic`/`diff::unified` (core); `tokenize`, `parse_tolerant`, `parse_source` (strict, the structural edits' rule 1), `LineIndex`, `defines`, the AST (`Item`/`ItemKind`, `Meta::leading`, `Connections`), `PARSE_STACK_SIZE` (parser); `analyze`, `IndexBuilder::{add_file, add_facts}`, `WorkspaceIndex::{absorb, fingerprint, units, members_of, member_in, instantiations, workspace_symbols, find_define, files_mentioning, …}`, `resolve_external`, `FileFacts::{of, decode}`, `FACTS_FORMAT` (semantic); every refactoring entry point + `find_references` + `instantiation_plan` (refactor); `format_source`/`format_range`/`fence` (formatter); `LintContext::from_parse`, `lint_with`, `select_rules`, `apply_fixes`, `rules_markdown`, `MentionOracle` (linter). **Never `lucisv_server`** (bin-only) and never `lsp-types`. Feature READMEs `docs/features/mcp-*`. |
|
||||
| `lucisv_server ──▶ lsp-server / lsp-types` | depends | The transport (synchronous, no async runtime) and the protocol data model. Both pinned exactly. cancel-request additionally relies on `lsp-server 0.10.0`'s stdio transport being a **rendezvous channel** (its own forwarder queue exists because of it) — a version bump must re-read that crate's `stdio.rs`. |
|
||||
| `editors/vscode ◀──▶ lucisv_server` | handshake | The **spawn contract**: binary named `lucisv-server`, no env, LSP over stdio, `initialize` works with no roots (single-file mode). The extension passes exactly `[]` by default or `['--verbose']` when `lucisv.verbose` is true; the server accepts only that spelling (repeats are idempotent) and refuses any other argument with exit 2. Changing that setting restarts the server because it is a process argument, not an LSP setting. Wire shapes pinned on both sides: the custom `lucisv/scopePairs` result, the other `lucisv.*` settings section (push and pull), `initializationOptions.storagePath`, the markdown fence tag `systemverilog` (server emits it, extension's grammar registers it), the `bin/` layouts of the platform `.vsix` packages. `smoke.js` still drives the default no-argument contract headlessly; `tests/e2e.rs` pins both spawns and `tests/grammar.rs` pins the grammar. |
|
||||
| `editors/vscode ◀──▶ vlog_parser` | handshake | The TextMate grammar's keyword alternation is **hand-maintained and test-locked to `vlog_parser::KEYWORDS`**: `crates/lucisv_server/tests/grammar.rs` fails, naming the missing/extra words, when they diverge (there is no generator script). Adding a keyword to `token.rs`'s `keywords!` macro is therefore also a hand edit to `editors/vscode/syntaxes/systemverilog.tmLanguage.json`. |
|
||||
@@ -650,6 +659,9 @@ engine-lane features are listed above; this table is the server-internal web.
|
||||
| `ci-release ──▶ release-prep / editor-platform-vsix` | depends | Workflow = one-liners over `tools/`; consumes the exact seven `.vsix` names (`prune_release_assets.sh` checks each), the `CHANGELOG.md` heading convention, tag == workspace version. |
|
||||
| `release-prep ──▶ editor-packaging` | depends | `release.sh` runs `smoke.js` as its gate; closed the missing-`LICENSE` item editor-packaging filed. Version lives in exactly four files — a promise to everyone. |
|
||||
| `editor-marketplace-page ──▶ lucisv-server` (docs) | depends | The Details page mirrors the shipped capability table in the server's README; drifts if that table does. |
|
||||
| `editor-packaging ◀──▶ lucisv-mcp` (mcp-packaging) | handshake | The MCP spawn contract (2026-09-23): the binary `lucisv-mcp[.exe]` found by the same three-rung ladder as the server (`lucisv.mcp.path` → `bin/` → `PATH`), spawned by VS Code from `McpStdioServerDefinition(label, command, ["--root", folder, "--index-cache", storage], env, version)` — the constructor is positional — one per workspace folder; `serverInfo.name == "lucisv-mcp"`, ≥ 26 tools (`mcp_smoke.js` `MIN_TOOLS`). Provider id `lucisv.mcp`; settings `lucisv.mcp.enabled`/`.path`; command `lucisv.mcp.copyConfig`. |
|
||||
| `release-prep / editor-platform-vsix ──▶ lucisv-mcp` (mcp-packaging) | depends | `release.sh` builds `-p lucisv_mcp` for every triple and stages it as the THIRD `bin/` entry (fifteen in the `all` package); `expect_vsix_bins` and `audit_artifacts.sh` pin the name; the seven `.vsix` names are unchanged. `mcp_smoke.js` is the gate beside `smoke.js`. |
|
||||
| `lucisv-mcp ──▶ lucisv-server` (index cache, M6) | depends (read-only) | MCP reads the server's `index-cache` store read-only when `--index-cache DIR` names it (header `CACHE_FORMAT`/`FACTS_FORMAT`/version must match, else ignored) and writes its own `index-cache-mcp` beside it; it never writes the server's file. A codec change on the server side costs MCP its warm start, never its correctness. |
|
||||
|
||||
### 2.9 Open handshakes (filed, not yet delivered — claim before working)
|
||||
|
||||
@@ -692,6 +704,14 @@ update the filing README(s) and this file.
|
||||
| 32 | **The refactoring verifier does not catch a same-file relocation of a never-dropped piece written as two well-formed edits** (delete here, insert there): `verify_move` computes `after` by applying the edits, so `positions_match`'s reconstruction cannot diverge from it and equation 3 of the ledger is unreachable through any real caller. No planner produces the shape today. Wanted: an independent `after` (the client's applied text, or a second reconstruction) and a test that isolates equation 3. Found by extract-module's QA re-attack. | extract-inline-module (QA) | vlog_refactor |
|
||||
| ~~33~~ | ~~**`module_sources`' fan-out has no rung for a file that reaches an instance through an intermediate module it does not itself instantiate** (a bench naming `wrap.u_S.x` where `wrap` instantiates `S`): inline-module's hierarchical-reference refusal sees only the handed files, so such a reference is missed. Wanted: a transitive-instantiators rung (§49's hierarchical surface knows the path) in `module_sources` for the refactorings that must see every hierarchical use. Found by §53.2's QA.~~ — **closed 2026-09-07 by perf5-p2 (TODO §60.2): a fifth, opt-in rung** `Workspace::module_sources_reaching(file, modules, Reach { scopes })` in `lucisv_server/src/module_select.rs` — every file whose *token census* (`WorkspaceIndex::files_mentioning`, i.e. `FileFacts::words`) writes the dissolved instance's name down. That is exactly the set `no_hierarchy` can refuse from, so the selected set answers the refusal as the whole workspace does (asserted engine-run-twice on six shapes; QA attacked seven more incl. `$root`, a macro-built `bind` path, an escaped identifier, a generate label). **The transitive-instantiator walk this row asked for was implemented and rejected:** a `bind tb.u_wrapper.u_top.u_sub …` in an SVA file that instantiates nothing in the chain has no instantiation edge for any walk to follow — structurally weaker, confirmed by QA. Only inline-module asks for the rung (extract and ports pass `Reach::none()`, unchanged in answer and cost); worst corpus cost 2 % of files on a command, +1.2 ms at the measured site. | extract-inline-module (QA) | lucisv_server / vlog_refactor |
|
||||
| ~~34~~ | ~~**The format cache omits `Config::uvm_utils_indent`.** CLI `args.rs::config_with` applies the key, but `main.rs::entry_for` and core `cache::Entry` serialize/compare only content, line length and indent (plus the store version). On one UVM class: cache a clean verdict with the option false, change only the option to true, then cached `--check` exits 0 while `--no-cache --check` exits 1. Wanted: key/equality/codec coverage for the option and a regression for both toggle directions. Until fixed, use `--no-cache` or delete the format cache after toggling. See repository-analysis.md for the bounded reproduction.~~ — **fixed 2026-09-07 (TODO §59, 0.50.0):** `Entry` carries `uvm_utils_indent`, `entry_for` fills it, the store line has it as a fourth field; a well-formed five-field (0.49.0) line is dropped individually like another version's entry; the audit's probe is `changing_uvm_utils_indent_invalidates_the_entry` in `lucisv/tests/cli.rs`, both directions. | repository audit, 2026-09-07 | lucisv_core / lucisv |
|
||||
| 35 | **MCP-5 → `vlog_parser`:** lift the server's `expand.rs` (one-step macro expansion) into `vlog_parser::defines` as a pure move so `lucisv-mcp`'s `defines` can offer expansion | mcp-navigation | vlog_parser |
|
||||
| 36 | **MCP-6 → `lucisv_server` (possible bug):** LSP `references` omits three real `aes` instantiations in the `*_pd_main.sv` tops (and their `.clk_i` connections) that `lucisv-mcp`'s whole-set answer lists; stable after a 30 s settle, not investigated | mcp-navigation | lucisv_server |
|
||||
| 37 | **MCP-7 → `vlog_refactor`:** a `find_references` variant taking `&dyn KnownFacts` (like `rename_traced_with`) so whole-set callers feed cached records instead of re-parsing 3 944 files (≈2 s per opentitan call today) | mcp-navigation | vlog_refactor |
|
||||
| 38 | **MCP-8 → `vlog_refactor`:** false `remove_port` refusal when the only "use" of the port is a named connection from another module in the same file (`ports/remove.rs::body_uses_in`) | mcp-edit-tools | vlog_refactor |
|
||||
| 39 | **MCP-10 → `vlog_refactor`:** `extract_module` writes LF into a CRLF file (`extract/render.rs`) | mcp-edit-tools | vlog_refactor |
|
||||
| 40 | **MCP-11/12 → `vlog_refactor`/`vlog_semantic`:** a batched `find_references` for several declarations; `find_references` misses a hierarchical use into a generate loop (`gen_l[0].z`) | mcp-structural-edits | vlog_refactor, vlog_semantic |
|
||||
| 41 | **MCP-13 → `vlog_linter`:** a forced deletion of a non-ANSI body port leaves a header port with no direction and no lint reports it | mcp-structural-edits | vlog_linter |
|
||||
| 42 | **Parser leniency → `vlog_parser`:** a trailing `,` in a named connection list, an empty concatenation element `{d,, d}`, and `type(x)'(y)` in a connection parse without a diagnostic (the rename verifier's position rule covers the rename; every other splice contract is exposed) | refactor-rename (M3.5) | vlog_parser |
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in new issue
Block a user