Every F12 jump into a new folder didOpen-widened the scope and re-ran a full rescan of all folders accumulated so far, growing with browsing (opentitan, warm: 120-169 ms per jump, ~90 ms of it re-opening and decoding the whole persistent store). widen_of chooses: pure folder adds take a widen scan over only the new files (absorbed into the live index/candidates/includes, open buffers refreshed from held analyses, store handle kept, no compaction); anything else still takes the whole rescan; mid-scan defers to one whole follow-up. Jumps now cost the new folder alone (12-44 ms flat), first definition of a session 99.7 -> 0.9 ms. IncludeGraph stores edges as the filesystem answered them and re-spells on relearn so a newly scoped file lends its spelling to earlier edges. Watcher-coverage narrowing documented: watcher-less clients lose the widen's incidental disk re-read, same staleness class as the save path since 2026-08-27. QA was stopped by the owner mid-gates after its adversarial phases; lead gates run twice, green. Co-Authored-By: Claude Fable 5 <[email protected]>
607 lines
36 KiB
Markdown
607 lines
36 KiB
Markdown
# scan-interleave
|
||
|
||
## Goal
|
||
|
||
`Server::new` ran the whole startup scan before `run()`'s message loop took its
|
||
first message, so everything a client sent the instant the handshake was done
|
||
sat in the OS pipe until the scan was over: **780 ms cold store / 287 ms warm**
|
||
over a 200-file workspace, against 26–64 µs for the same hover once the scan
|
||
had finished (filed as "suspect 2" in
|
||
`docs/features/hover-line-index/README.md`, and the larger half of the owner's
|
||
"hover is really slow on first try"). This round takes the scan apart into
|
||
per-file steps and drains the message queue between them, so a scan long enough
|
||
for a person to notice answers questions while it runs. The first hover of a
|
||
session now comes back in **15.5 ms cold / 12.8 ms warm** on the same fixture —
|
||
a 50× and 22× improvement — and the scan's own total is unchanged inside
|
||
run-to-run noise.
|
||
|
||
## Assumptions
|
||
|
||
- **An answer given mid-scan reads the index as of that moment.** It is
|
||
scope-relative in *time* exactly the way every answer is already
|
||
scope-relative in *space* (`crates/lucisv_server/README.md`): a declaration in
|
||
a file the scan has not reached yet is a declaration this server does not know
|
||
about yet, and it says so by answering nothing rather than by making the
|
||
client wait. Which files that means depends on how far the scan got, so a
|
||
mid-scan answer is genuinely **not reproducible** — which is why the rule
|
||
below narrows the cases it can happen in to the one where it is worth it.
|
||
- **Only a scan nobody asked for answers mid-way.** The message loop has always
|
||
promised that everything queued *ahead* of a request is applied before that
|
||
request is answered. A `didOpen` that widened the scope, a `didSave`, a
|
||
changed setting or an added workspace folder ask for a rescan, and "applied"
|
||
for those means the rescan has **run** — one message at a time, the server
|
||
would have finished it before ever taking the request. So requests that arrive
|
||
during a rescan wait for it, and only the *startup* scan — which nothing was
|
||
queued ahead of — answers from a half-built index. See `Server::must_wait`.
|
||
- **And only a scan long enough to be worth it.** A scan of at most
|
||
`INTERLEAVE_ABOVE` (64) files is over in a few milliseconds and runs exactly as
|
||
it always did, one shot, no drains: trading a complete answer for those
|
||
milliseconds would be a bad bargain. A count rather than a clock, because a
|
||
rule about elapsed time makes what a server answers depend on how loaded the
|
||
machine is — which is a property neither a test suite nor a bug report can
|
||
work with.
|
||
- **The scan indexes the text each file had when its work list was taken.** A
|
||
`didOpen` or a `didChange` answered mid-scan changes the *buffer* and not the
|
||
index — exactly as it does when it lands a millisecond after the scan
|
||
finished, because neither notification touches the index (a save is what
|
||
does). So a message answered in the middle of a scan cannot move that scan's
|
||
result.
|
||
- **A record written through is a record kept.** A scan a `shutdown` interrupts
|
||
leaves every file it had already parsed in the persistent store, because the
|
||
store is appended to per file (`docs/features/index-persistence/README.md`).
|
||
That was already true of a scan a `kill` interrupted; it is now reachable
|
||
through the protocol as well.
|
||
|
||
## Handshakes
|
||
|
||
### `vlog_semantic` — `WorkspaceIndex::absorb`
|
||
|
||
```rust
|
||
/// [`WorkspaceIndex::update_facts`] and [`WorkspaceIndex::remove_file`] for
|
||
/// many files at once — and for **one** merge rather than one each.
|
||
pub fn absorb(&mut self, records: Vec<FileFacts>, gone: &[PathBuf]);
|
||
|
||
// generic in what rides beside the path, so an owning caller gets the same order
|
||
pub fn index_order<T>(files: impl IntoIterator<Item = (PathBuf, T)>) -> Vec<(PathBuf, T)>;
|
||
```
|
||
|
||
`absorb` keeps the same promise `update_facts` does — what comes out is the
|
||
index a full `build` over the records it now holds would have produced — and for
|
||
the same structural reason: the records stay path-sorted and one file to a path,
|
||
and `merge` is then the loop `IndexBuilder::finish` runs over the same list. It
|
||
exists because **a merge is a pass over every record the index holds**, which is
|
||
measured below and is the difference between a linear scan and a quadratic one.
|
||
|
||
`index_order`'s lifetime parameter became a type parameter. Every existing
|
||
caller passes `&str` and is unchanged; the scan passes `String`, because it owns
|
||
its work list.
|
||
|
||
### `lucisv_server::state` — the scan as a value
|
||
|
||
**Amended (index-scope, 2026-08-28): a scan now has two shapes and one
|
||
ending.** `Scan` carries a private kind, `Workspace::begin_widen` is a second
|
||
constructor for it — the files a scope widen brought in, rather than every
|
||
in-scope file — and `finish_scan` branches on that kind so a widen cannot be
|
||
landed as a whole scan. **`begin_scan`, `scan_step` and `publish_scan` are
|
||
unchanged and are the same code for both shapes**, which is what keeps the
|
||
cache behaviour, the open-buffer reuse and the event stream identical without a
|
||
second implementation to keep in step. A widen deliberately does *not*
|
||
interleave: it is a rescan, so `must_wait` holds requests queued behind it
|
||
either way, and the point of that round is that there is no longer a wait worth
|
||
breaking up. A widen asked for **mid-scan** sets `rescan_wanted` like every
|
||
other mid-scan trigger, so it is one more *whole* scan behind this one and never
|
||
a scan inside a scan. See `docs/features/index-scope/README.md`.
|
||
|
||
```rust
|
||
pub struct Scan { /* work list, how far through it, what is staged */ }
|
||
|
||
impl Scan {
|
||
pub fn skipped(&self) -> usize;
|
||
pub fn cached(&self) -> usize;
|
||
pub fn total(&self) -> usize;
|
||
pub fn index_next(&mut self, path: &Path) -> bool;
|
||
}
|
||
|
||
impl Workspace {
|
||
pub fn adopt_roots(&mut self, roots: Vec<PathBuf>);
|
||
pub fn begin_scan(&mut self, watch: &mut dyn FnMut(IndexEvent)) -> Scan;
|
||
pub fn scan_step(&mut self, scan: &mut Scan, watch: &mut dyn FnMut(IndexEvent)) -> bool;
|
||
pub fn publish_scan(&mut self, scan: &mut Scan);
|
||
pub fn finish_scan(&mut self, scan: Scan) -> Vec<String>;
|
||
}
|
||
```
|
||
|
||
**A value rather than a loop, because a callback cannot be handed the workspace
|
||
it is called from.** `rebuild_index_with` held `&mut self` for the whole scan,
|
||
so its watcher callback could reach the connection (a disjoint field) but never
|
||
the workspace — and answering a message needs exactly that. Splitting the loop
|
||
puts the scan's state somewhere the server can own it, and `rebuild_index_with`
|
||
is now literally
|
||
|
||
```rust
|
||
let mut scan = self.begin_scan(watch);
|
||
while self.scan_step(&mut scan, watch) {}
|
||
self.finish_scan(scan)
|
||
```
|
||
|
||
so "one shot" and "interleaved" are not two scans that have to be kept in step:
|
||
they are this loop with and without a drain in it. That is what makes the
|
||
fingerprint equivalence structural rather than tested-and-hoped.
|
||
|
||
`skipped`/`cached` moved from `IndexWatch` to `Scan`: they are facts about the
|
||
scan, and `IndexWatch` is now purely the thing that speaks protocol.
|
||
`open_roots_with` and `rebuild_index_with` are `#[cfg(test)]` now — the server
|
||
drives the three calls itself, and every test that just wants an index still
|
||
calls the one-shot form.
|
||
|
||
### `lucisv_server::candidates`, `::includes` — the batch forms
|
||
|
||
```rust
|
||
impl Candidates {
|
||
pub fn absorb(&mut self, index: &WorkspaceIndex, batch: Vec<(PathBuf, Vec<String>)>);
|
||
}
|
||
impl IncludeGraph {
|
||
pub fn absorb(&mut self, incdirs: &[PathBuf], known: &[PathBuf], batch: &[(&Path, &str)]);
|
||
}
|
||
```
|
||
|
||
Both are the batch form of the incremental update each already had
|
||
(`update_words`, `update_file`), doing the whole-table half once for the batch
|
||
instead of once per file. **All three tables are published together, never one
|
||
of them**: an index that had seen a scanned file while a completion or an
|
||
include link could not would make "the workspace as far as it has been scanned"
|
||
three different things at once.
|
||
|
||
`candidates::words_in` became `pub(crate)`, because a scan lexes each file's
|
||
completion words as it reaches it rather than in one pass at the end. That moves
|
||
work rather than adding it — `Candidates::build` at the end of the scan now
|
||
finds every file's words already in hand and lexes nothing — and it is what
|
||
keeps the *tail* of a scan from being an unbroken block longer than one file.
|
||
|
||
### `docs/features/hover-line-index` — suspect 2, **DELIVERED**
|
||
|
||
That round measured the wait, filed it as a request to "whoever owns the message
|
||
loop next" and named the probe. This is that round; the probe is flipped and
|
||
renamed (`e2e::a_hover_issued_during_the_initial_scan_is_answered_during_it`)
|
||
and its before-numbers are the ones in the table below.
|
||
|
||
## Measured
|
||
|
||
Machine and method are `docs/perf/README.md`'s: Apple M1 Max, macOS 27.0,
|
||
`--release`, `#[ignore]`d probes, `--test-threads=1`. Taken 2026-08-28, before
|
||
and after, in the same session.
|
||
|
||
### The merge cost, measured before the design was chosen
|
||
|
||
`perf::publishing_a_half_built_index_mid_scan`, files of 1 000 lines:
|
||
|
||
| workspace | one file's parse | one whole merge | one `update_facts` | per-file feeding would cost | against parsing |
|
||
|---|---:|---:|---:|---:|---:|
|
||
| 50 files | 2.35 ms | 0.73 ms | 0.66 ms | 32.8 ms | 117.6 ms |
|
||
| 200 files | 2.32 ms | 3.35 ms | 3.15 ms | **630.7 ms** | 464.4 ms |
|
||
| 800 files | 2.23 ms | 15.90 ms | 14.66 ms | **11.73 s** | 1.78 s |
|
||
|
||
**So: not per file.** A merge is linear in the whole workspace, so feeding the
|
||
live index one file at a time is quadratic — at 200 files it would have *more
|
||
than doubled* the scan, and at 800 files multiplied it by seven. The decision
|
||
the numbers make is **deferred**: records are staged as they are taken and
|
||
folded in with one `absorb` per *drain*, and a drain only happens when the queue
|
||
is not empty. A scan nobody is waiting on therefore pays nothing beyond one
|
||
`try_recv` per file, and a scan somebody is waiting on pays 3.35 ms per burst at
|
||
200 files — one and a half files' worth of parse.
|
||
|
||
### The latency the round is about
|
||
|
||
`e2e::a_hover_issued_during_the_initial_scan_is_answered_during_it`, 200 files
|
||
of 1 000 lines with a filelist, over the wire against the real binary:
|
||
|
||
| the first hover of a session | before | after |
|
||
|---|---:|---:|
|
||
| issued the moment `initialized` was sent, cold store | 780 ms | **15.5 ms** |
|
||
| — warm store | 287 ms | **12.8 ms** |
|
||
| the same hover once the scan is done | 64 / 61 µs | 191 / 151 µs |
|
||
|
||
Two honest caveats on that table. The "after" figures move with how busy the
|
||
machine is — a second run minutes later, with the corpus suite running beside
|
||
it, reported 19.8 ms and 14.0 ms — so read them as *tens of milliseconds
|
||
against hundreds*, which is the claim, and not as three significant figures.
|
||
And the last row is the same answer either way, measured differently now: the
|
||
"after" run waits for the progress bar to come down before asking, which is
|
||
what makes it a *post*-scan measurement rather than a race with the scan. Both
|
||
are microseconds and neither is what the round moved.
|
||
|
||
### What the scan's total cost
|
||
|
||
`state::tests::qa_perf_cold_warm_and_half_warm_scans`, the 860-file corpus,
|
||
before and after on the same machine minutes apart:
|
||
|
||
| | before | after |
|
||
|---|---:|---:|
|
||
| no cache | 321.5 ms | 322.0 ms |
|
||
| cold, filling the store | 351.3 ms | 353.4 ms |
|
||
| warm, every file from the store | 187.0 ms | 188.6 ms |
|
||
| the store | 2 380 790 B | 2 380 790 B |
|
||
|
||
**+0.2 % / +0.6 % / +0.9 %**, which is well under the "a few percent" this
|
||
round was allowed — and inside the run-to-run band, which is worth stating with
|
||
a number of its own: the same "after" measurement taken again on a busier
|
||
machine reported 357 / 375 / 201 ms, so the pair above is only meaningful
|
||
*because* it was taken minutes apart in one session on one tree. Nothing was added to the
|
||
per-file path; the completion word lex moved into it from the tail, and the
|
||
index is folded in with the same number of merges a one-shot scan always did
|
||
(one) when nothing is waiting.
|
||
|
||
### The floor under a mid-scan answer
|
||
|
||
`perf::what_a_scan_does_before_its_first_file`, 200 files of 1 000 lines:
|
||
|
||
| | quiet machine | busy machine |
|
||
|---|---:|---:|
|
||
| before the first file (resolve the scope, read every file, open the store) | 6.9 ms | 9.8 ms |
|
||
| one file | 4.0 ms | 5.7 ms |
|
||
| the other 199 | 682 ms | 723 ms |
|
||
| finishing (last merge, completion tables, include graph, overlays) | 10.7 ms | 10.9 ms |
|
||
|
||
So the 15.5 ms above is the first two rows plus the handshake and the message's
|
||
own travel, and it is **not** the "single digit ms" the brief hoped for. The
|
||
first row is one block no drain can break up, and reading the files lazily is
|
||
what would break it up — filed as a deliberate not-done below with this number
|
||
attached.
|
||
|
||
## Status / TODO
|
||
|
||
- [x] Measure the merge cost before choosing a rhythm; per-file feeding
|
||
rejected on the numbers above, deferred-and-batched chosen.
|
||
- [x] `WorkspaceIndex::absorb`, with the fresh-build equivalence tested three
|
||
ways (a batch of every shape, one batch against the same records in
|
||
pieces, and an empty batch).
|
||
- [x] `Scan` + `begin_scan`/`scan_step`/`publish_scan`/`finish_scan`, with
|
||
`rebuild_index_with` rewritten as the loop over them.
|
||
- [x] The server drives the scan and drains the queue between files; the
|
||
queue moved onto `Server` so a scan and `run` share it.
|
||
- [x] Order preserved: `Server::must_wait` holds a request (and everything
|
||
behind it) that is queued behind a rescan, and `run` answers what was
|
||
held before it takes anything newer — keeping its place among messages
|
||
the rescan itself held, and carrying its `$/cancelRequest` with it.
|
||
- [x] Coalescing: a rescan asked for mid-scan is a flag, and
|
||
`scan_until_settled` is a loop — never a scan inside a scan.
|
||
- [x] Shutdown mid-scan stops the scan where it stands and `run` returns
|
||
without taking another message.
|
||
- [x] The completion tables and the include graph are published with the
|
||
index, so a mid-scan answer is one generation and not three.
|
||
- [x] A file opened mid-scan is indexed next (`Scan::index_next`).
|
||
- [x] The startup scan republishes and refreshes lenses when a buffer was
|
||
opened during it — a debt that did not exist before this round.
|
||
- [x] The e2e probe flipped and renamed; the before-numbers kept above.
|
||
- [x] `cargo fmt` / `cargo clippy --all-targets --workspace` / `cargo test
|
||
--workspace` / `node editors/vscode/smoke.js`.
|
||
- [ ] **Not done, deliberately: the files are still read eagerly.** The 6.9 ms
|
||
before the first file is mostly 200 `read_to_string`s. Reading each file
|
||
in `scan_step` instead would take the mid-scan floor to single digits,
|
||
and it costs a work list of `Option<String>` and a decision about what a
|
||
file that turns out to be unreadable does to the progress bar's `total`
|
||
(today such a file never joins the work list at all, because the read
|
||
that fails happens before the list is taken). Worth doing; not worth
|
||
guessing at inside a round that is already changing when answers happen.
|
||
- [ ] **Not done, deliberately: a scan of a few very large files still
|
||
blocks.** `INTERLEAVE_ABOVE` counts files, and 20 netlist-shaped files
|
||
can take a second. A second rule on elapsed time would catch it and would
|
||
make what the server answers depend on machine load; the honest fix is a
|
||
cost estimate from the sizes the cap already reads (`oversize` does a
|
||
`metadata` call per walked file), which is a design, not a patch.
|
||
- [ ] **Not done, deliberately: a rescan still makes requests wait.** The
|
||
brief named later rescans as blocking the loop the same way, and they
|
||
still block *requests* — notifications, cancels and responses are
|
||
processed throughout. Answering a request from a half-updated index would
|
||
break the order contract the loop has always kept, and no measurement
|
||
says a rescan is where the pain is: the owner's report is about the first
|
||
request of a session.
|
||
|
||
## Work log
|
||
|
||
### 2026-08-28 — dev
|
||
|
||
**Measured the merge first, and the number chose the design.** The brief left
|
||
per-file / chunked / deferred open and asked for numbers. `update_facts` on an
|
||
already-held file is 3.15 ms at 200 files and 14.7 ms at 800, because
|
||
`merge_references` re-resolves every reference in the workspace; one per file is
|
||
630 ms and 11.7 s of pure merging. The rhythm that survives is **stage per
|
||
file, fold in per drain, and drain only when something is waiting** — which
|
||
makes the cost of interleaving zero for a scan nobody is waiting on and one
|
||
merge per burst for a scan somebody is. There is no chunk size to tune, which
|
||
is the nicest property of it: the client's own traffic sets the rhythm.
|
||
|
||
**The scan had to become a value before it could be interrupted.** The
|
||
blocker was borrowing, not design: `rebuild_index_with(&mut self)` holds the
|
||
workspace for the whole scan, and a message answered from inside it needs that
|
||
same workspace. `Scan` owns the work list and the staged records, so
|
||
`scan_step(&mut self, scan: &mut Scan)` borrows two separate things and the
|
||
server can put whatever it likes between two calls. `rebuild_index_with` is now
|
||
three lines over the same three methods, which is what makes "the interleaved
|
||
scan is the one-shot scan with a drain in it" a fact about the code rather than
|
||
a claim in a document.
|
||
|
||
**The hard part was not latency, it was the order contract.** The first
|
||
working version answered requests mid-scan unconditionally, and sixteen e2e
|
||
tests began failing *intermittently* — which is the real finding, not the
|
||
failures. Those sessions pipeline a whole conversation into the pipe
|
||
(`initialize`, `initialized`, a `didOpen` that widens the scope, three
|
||
requests, `shutdown`), so whether a request saw a finished index depended on
|
||
whether the forwarder thread got scheduled before the scan ended. Three
|
||
decisions came out of that:
|
||
|
||
1. **`must_wait`.** A request queued behind a message that asked for a rescan
|
||
waits for that rescan, because that is what one message at a time would have
|
||
done, and once one request is waiting every later one waits too. Held
|
||
messages keep their arrival order and are answered by `run` before it takes
|
||
anything newer. `shutdown` waits with them: a request sent before a shutdown
|
||
is a request the client is still owed an answer to.
|
||
2. **Only the startup scan answers mid-way.** A scan a *message* asked for has
|
||
that message queued ahead of everything else, so nothing arriving during it
|
||
may be answered from a half-updated index. The startup scan has nothing
|
||
queued ahead of it, and it is the one the owner's report is about.
|
||
3. **`INTERLEAVE_ABOVE`.** Even the startup scan should not trade a complete
|
||
answer for milliseconds. Sixty-four files is the line: below it the scan runs
|
||
exactly as it always did, which is also why the whole existing suite passes
|
||
unmodified — every fixture in it is a handful of files. A count and not a
|
||
clock, so that what the server answers never depends on how busy the machine
|
||
was.
|
||
|
||
**All three tables, or none.** After `must_wait` there were still failures
|
||
where a macro hover and an include link came back empty mid-scan: the index was
|
||
being published but `Candidates` and `IncludeGraph` were still built whole at
|
||
the end. Publishing one of three tables makes "as far as the scan has got" mean
|
||
three different things at once, so both grew a batch `absorb` and all three are
|
||
folded in together. The include graph's known-file table is relearned from the
|
||
scan's **whole work list** rather than the files it has reached, because which
|
||
files *exist* is settled the moment the scope is resolved and only the edges are
|
||
discovered file by file.
|
||
|
||
**Coalescing: finish, then rescan again — not abort and restart.** A message
|
||
answered mid-scan sets `rescan_wanted`; `scan_until_settled` is a loop that
|
||
scans again while the flag is set, and `reindex`/`reindex_one` set the flag
|
||
instead of running when `scanning`. Finishing was chosen over aborting because
|
||
it needs no way to unwind a half-published index and cannot loop forever: the
|
||
follow-up scan reads the persistent store for every file the abandoned one had
|
||
already parsed. Each scan keeps its own progress token, which is what a client
|
||
showing a bar expects of two scans. `reindex_one` returns `true` when it defers,
|
||
because its caller's fallback is "rebuild the whole thing right now", which is
|
||
precisely what must not happen.
|
||
|
||
**Two debts this round created and paid.** A buffer can now be *opened* during
|
||
the startup scan, so `Server::started` owes what `reindex` has always owed at
|
||
the end of a scan — a code-lens refresh, a generation bump and a republish —
|
||
and pays it when any buffer is open (which is nothing at all for a session
|
||
whose client did not get a `didOpen` in edgeways). And `reindex_one` can no
|
||
longer patch one file mid-scan without the scan overwriting it with older bytes
|
||
a moment later, so it defers too.
|
||
|
||
**A test seam, named as one.** `Server::started` grew a `queued: Vec<Message>`
|
||
parameter — what the client had already sent when the server was built, put
|
||
straight onto the queue the startup scan drains. `Server::new` passes an empty
|
||
one. The alternative was for the test to send on the client end and race the
|
||
forwarder thread for it, which made the first version of
|
||
`a_request_the_client_had_already_sent_is_answered_during_the_startup_scan`
|
||
pass alone and fail under a loaded suite. A coin-toss test is worse than no
|
||
test.
|
||
|
||
**Files touched.** `crates/vlog_semantic/src/workspace.rs`,
|
||
`crates/vlog_semantic/tests/workspace.rs`,
|
||
`crates/lucisv_server/src/{server.rs,state.rs,candidates.rs,includes.rs,perf.rs}`,
|
||
`crates/lucisv_server/tests/e2e.rs`, this README,
|
||
`docs/features/hover-line-index/README.md`, `docs/perf/README.md`, `TODO.md`.
|
||
No new dependency, no `unsafe`, no `#[allow]`, no version bump, no commits.
|
||
Single-threaded throughout: the only thread this round touches is the message
|
||
forwarder, which existed already and still only moves messages.
|
||
|
||
**Tests added** (14).
|
||
|
||
| test | where | pins |
|
||
|---|---|---|
|
||
| `absorbing_a_batch_gives_the_index_a_whole_build_would_have` | `vlog_semantic/tests/workspace.rs` | the house witness for the new entry point: a file replaced, two added (one sorting first, so every id moves), one dropped |
|
||
| `absorbing_one_batch_and_absorbing_it_in_pieces_are_the_same_index` | same | what makes a publish free of consequence — how records are grouped into batches cannot reach the result |
|
||
| `absorbing_nothing_changes_nothing` | same | the empty publish and the empty finish |
|
||
| `publishing_between_every_file_leaves_what_a_one_shot_scan_leaves` | `lucisv_server/src/state.rs` | the round's central invariant, over index **and** completion tables **and** include graph, publishing after every single file |
|
||
| `a_rescan_that_publishes_as_it_goes_still_drops_what_left_the_scope` | same | a publish only folds records *in*, so the removal a rescan owes has to survive every publish before it |
|
||
| `a_buffer_opened_or_changed_mid_scan_does_not_change_what_the_scan_indexes` | same | fingerprint equality with a `didChange` injected mid-scan |
|
||
| `a_file_opened_mid_scan_is_indexed_next_and_the_index_cannot_tell` | same | `Scan::index_next` moves it, does not move it twice, refuses a file not waiting — and the finished index is byte-identical |
|
||
| `a_scan_reports_the_same_events_in_the_same_order_however_it_is_driven` | same | progress and log continuity: interleaving adds drains between events, never events |
|
||
| `a_request_the_client_had_already_sent_is_answered_during_the_startup_scan` | `lucisv_server/src/server.rs` | the point of the round, over the real dispatch: the response goes out before the bar comes down |
|
||
| `a_scan_short_enough_to_wait_for_answers_nothing_in_the_middle_of_itself` | same | the other side of `INTERLEAVE_ABOVE` |
|
||
| `a_request_queued_behind_a_rescan_waits_for_that_rescan` | same | the order contract: the request sees the index the push asked for, not the one it was sent into |
|
||
| `a_held_request_keeps_its_place_and_takes_its_cancel_with_it` | same | the two corners holding creates: a burst's own request stays in front of one the scan it started held later, and a cancel consumed on the way in goes back with what it cancels |
|
||
| `a_rescan_asked_for_mid_scan_is_coalesced_into_exactly_one_more_scan` | same | three settings pushes inside one scan cost one more scan, two bars, two tokens, no nesting |
|
||
| `a_shutdown_answered_mid_scan_stops_the_scan_where_it_stands` | same | the bar never comes down, the index is short, `run` returns at once |
|
||
|
||
Two `#[ignore]`d probes added
|
||
(`perf::publishing_a_half_built_index_mid_scan`,
|
||
`perf::what_a_scan_does_before_its_first_file`); one existing probe flipped and
|
||
renamed (`e2e::a_hover_issued_during_the_initial_scan_waits_for_it` →
|
||
`..._is_answered_during_it`), which is the before/after pair this README's
|
||
latency table is read from.
|
||
|
||
**Gates.** `cargo fmt --all -- --check` clean. `cargo clippy --all-targets
|
||
--workspace` silent. `cargo test --workspace` green, 0 failed:
|
||
`lucisv_server`'s unit tests **1 225 passed / 26 ignored** (+11 tests, +2
|
||
`#[ignore]`d probes), its `e2e` suite **56 passed / 2 ignored** (unmodified
|
||
except the flipped probe), `vlog_semantic`'s `workspace` suite **70 passed**
|
||
(+3). `node editors/vscode/smoke.js ./target/debug/lucisv-server`: `smoke: OK`.
|
||
|
||
## QA log
|
||
|
||
### 2026-08-28 — QA
|
||
|
||
Read `CLAUDE.md`, the dev brief, and this README's Handshakes/Work log before
|
||
attacking. Traced `process_batch`'s held-message splice, `must_wait`,
|
||
`scan_until_settled`/`scan_once`/`answer_what_is_waiting`, `Scan`, and
|
||
`WorkspaceIndex::absorb` line by line against the charter's five attack
|
||
classes, then exercised the parts a trace alone couldn't settle. Two real
|
||
findings, both narrow; one confirmed-correct-but-untested behavior now pinned;
|
||
gates and numbers reproduced.
|
||
|
||
**Finding 1 (low, doc-contract) — `WorkspaceIndex::absorb` does not dedupe a
|
||
duplicate path in one batch the way `WorkspaceIndex::build` does.**
|
||
`crates/vlog_semantic/src/workspace.rs:472-489` (`absorb`). `build` goes
|
||
through `index_order`, which keeps the *first* of a duplicate path
|
||
(`Vec::dedup_by`'s contract, `crates/vlog_semantic/src/workspace.rs:1034`).
|
||
`absorb`'s own loop walks `records` left to right and overwrites on a
|
||
`binary_search` hit, keeping the *last*. `absorb`'s doc comment claims "what
|
||
comes out is the index a full build over the records it now holds would have
|
||
produced" — that equivalence does not hold for a batch with a duplicate path.
|
||
Not reachable through the scan that actually feeds `absorb` today: `Scan::work`
|
||
is built from `index_order` before the scan starts, so it can never contain two
|
||
entries for the same path, and `scan_step` therefore never stages a duplicate.
|
||
But `absorb` is `pub` on `WorkspaceIndex`, its doc comment states the
|
||
equivalence unconditionally, and a future caller (or a future change to how
|
||
`Scan::work` is assembled) could reintroduce the gap silently. Repro and
|
||
permanent regression test added and passing:
|
||
`crates/vlog_semantic/tests/workspace.rs`,
|
||
`absorbing_a_batch_with_a_duplicate_path_diverges_from_a_build_over_the_same_records`
|
||
— builds `[("a.sv", module first_shape), ("a.sv", package second_shape)]` both
|
||
ways and asserts the fingerprints differ, then pins which one `absorb` actually
|
||
keeps (the last). Not fixed here — whether `absorb` should match `build`'s
|
||
first-wins or the doc comment should be narrowed to describe last-wins is a
|
||
design call, not a QA fix. Verified harmless in production as things stand
|
||
today, precisely because the scan can't construct the input that trips it.
|
||
|
||
**Finding 2 (very low, stale doc comment) — `refresh_code_lenses`'s doc comment
|
||
contradicts what this round now does.**
|
||
`crates/lucisv_server/src/server.rs:1979-1984`: "Nothing is sent at startup
|
||
either: no buffer is open there, so there are no lenses to invalidate." That
|
||
was true before this round; `Server::started` now calls exactly this method at
|
||
the end of construction whenever a `didOpen` answered mid-scan left a buffer
|
||
open (`crates/lucisv_server/src/server.rs:347-354`), and the new test below
|
||
confirms it fires. The comment should say client-refresh-capable + a buffer
|
||
open, no longer "never at startup." Not fixed here per QA's remit not to edit
|
||
outside the change's own tests, but it is a one-line fix the dev should make in
|
||
the same file the round already touched.
|
||
|
||
**Verified correct, previously untested — the two-publish behavior for a file
|
||
opened mid-startup-scan.** Traced through `Server::started`'s new "pay the
|
||
`reindex` debt" block and found it produces *two* `publishDiagnostics` for the
|
||
file a mid-scan `didOpen` opens: one from `didOpen`'s own always-existing
|
||
handler (against the half-built index, mid-scan — correct, not new), and one
|
||
from the debt-payment block after the bar comes down (against the finished
|
||
index — the new behavior). That is correct, not a duplicate-publish bug, but
|
||
it was unverified by any test in the round's own "Tests added" table. Added
|
||
`crates/lucisv_server/src/server.rs`,
|
||
`a_buffer_opened_during_the_startup_scan_is_published_and_lenses_refreshed_once`:
|
||
asserts exactly two publishes for the opened file, the first before the `end`
|
||
progress event and the second after it, and exactly one `workspace/codeLens/refresh`
|
||
(also after `end`, implicitly, since it can only fire once open_uris is
|
||
non-empty at the end of construction). Passes.
|
||
|
||
**Also added, no bug found — `INTERLEAVE_ABOVE` exact-boundary test.** The
|
||
charter asked for the 64/65 edge explicitly; the round's own tests exercise
|
||
`INTERLEAVE_ABOVE + 6` and `4`, neither of which pins the `>` vs `>=` choice in
|
||
`scan_once`. Added
|
||
`crates/lucisv_server/src/server.rs`,
|
||
`interleave_above_is_a_hard_boundary_at_the_file_count_not_before_or_after`: a
|
||
scan of exactly 64 files answers nothing mid-construction (one-shot), a scan of
|
||
65 answers before the bar comes down (interleaved). Passes as written — no
|
||
off-by-one found, now locked in.
|
||
|
||
**Attacks traced and found sound, not turned into new tests (existing coverage
|
||
or structurally excluded):**
|
||
- *Order-contract, cancel-through-a-wait*: traced `process_batch`'s
|
||
`consumed_cancels` splice by hand against
|
||
`a_held_request_keeps_its_place_and_takes_its_cancel_with_it`
|
||
(`crates/lucisv_server/src/server.rs:2985`-ish) with a constructed batch
|
||
where a cancel's target is answered *before* the wait point is reached — the
|
||
stale cancel does get re-queued into `held`, but `cancelled_in` re-filters by
|
||
the ids actually present in the replayed batch, so it is inert on replay,
|
||
never mis-cancels an unrelated request. Not a bug; not worth a dedicated
|
||
test since it changes nothing observable.
|
||
- *Gone-file races during a scan that also answers mid-way*: `finish_scan`
|
||
defers the `gone` computation to one `absorb` call at the very end, so a
|
||
file leaving scope is not removed from the live index until the scan
|
||
finishes. This only matters if a mid-scan answer could see a file that
|
||
should already be gone — and every scan capable of having `gone` files
|
||
non-empty is a *rescan* (`answering_a_rescan = true`), which `must_wait`
|
||
already blocks from answering anything mid-way. The startup scan (the only
|
||
one that answers mid-way) always starts from an empty index, so it can never
|
||
have a `gone` file. Structural, not incidental — traced through
|
||
`scan_until_settled`'s `asked_for` threading, not tested further.
|
||
- *Include graph's `known` set includes not-yet-scanned files mid-scan*:
|
||
intentional per the Handshakes section ("which files exist is settled the
|
||
moment the scope is resolved"); this can make an `` `include `` targeting an
|
||
unscanned file resolve to a path with no edges of its own yet, which is the
|
||
same "not there yet" story the index already tells for symbols. Not a
|
||
divergence from the round's own stated contract.
|
||
- *Shutdown delivered twice (queue-injection copy + forwarder-relayed copy) in
|
||
`a_shutdown_answered_mid_scan_stops_the_scan_where_it_stands`*: the test
|
||
deliberately sends the same logical `shutdown` through two paths and says so
|
||
in its own comment ("whichever of the two ... the scan stops here"). Traced
|
||
the `forward`/`handle_shutdown` interaction and confirmed the real `exit`
|
||
notification can never be stolen by the forwarder (it stops at the first
|
||
shutdown it relays and never reads again), so the raciness is a test-harness
|
||
artifact for reaching the scenario at all, not a client-facing bug. Ran the
|
||
test 20x in a loop (`cargo test ... -- --test-threads=1`, repeated) with no
|
||
flake.
|
||
|
||
**Gates.** `cargo fmt --all -- --check` clean (after formatting the one test I
|
||
added that needed it). `cargo clippy --all-targets --workspace` silent.
|
||
`cargo test --workspace` run 3x after all QA additions: **0 failures each run,
|
||
2457 total passed each run**, identical every time. One transient failure seen
|
||
*before* the final 3-run check
|
||
(`large::tests::references_on_one_giant_line_locate_their_hits_in_linear_time`,
|
||
a pre-existing wall-clock perf gate unrelated to any file this round touches)
|
||
under self-inflicted contention (I had a background `cargo test` and a 3-run
|
||
loop racing on the same machine at once); reproduced clean on both master
|
||
(pre-round, 3/3) and this round's tree (3/3) once run without that
|
||
contention — not a regression, not flagged further.
|
||
`node editors/vscode/smoke.js ./target/debug/lucisv-server`: `smoke: OK`.
|
||
|
||
**Numbers reproduced**, same machine, `--release`, `--test-threads=1`:
|
||
- `e2e::a_hover_issued_during_the_initial_scan_is_answered_during_it`: 16.1 ms
|
||
cold / 14.0 ms warm (README claims 15.5 / 12.8, and says a rerun elsewhere
|
||
saw 19.8 / 14.0 — this sits inside that band).
|
||
- `perf::publishing_a_half_built_index_mid_scan`, all three sizes including
|
||
800 (not skipped — it ran in 5.4s, not slow): 200-file whole merge 3.85 ms
|
||
(claimed 3.35 ms), 800-file per-file-feeding-would-cost 12.9 s (claimed
|
||
11.7 s) against 2.06 s of parsing (claimed 1.78 s) — same shape, same
|
||
conclusion (deferred-batched, not per-file), numbers within normal
|
||
machine-to-machine variance.
|
||
- `state::tests::qa_perf_cold_warm_and_half_warm_scans`: no-cache 347 ms /
|
||
cold 387 ms / warm 203 ms (claimed 322/353/189) — store size **exactly**
|
||
2 380 790 bytes, matching the README bit for bit, which is the number that
|
||
actually matters (deterministic index size, unaffected by machine noise).
|
||
|
||
**Verdict: SHIP.** No masked-corruption, no order-contract violation, no
|
||
non-settling loop found across five attack classes and direct code tracing.
|
||
Two findings filed above are both low severity, both narrow (one is
|
||
structurally unreachable through the round's own code paths today, the other
|
||
is a one-line stale comment), and neither touches the hard invariants
|
||
(never-corrupt, idempotent, comments-preserved) or the round's own claimed
|
||
equivalences in the paths actually exercised. Three regression tests added,
|
||
all passing, all documenting real (if narrow) findings or previously-untested
|
||
correct behavior — none required a design change.
|
||
|
||
## Review
|
||
|
||
**2026-08-28 — lead.** Reviewed after QA's SHIP; gates re-run
|
||
independently (fmt clean, clippy silent, 2457 workspace tests green,
|
||
QA ran the suite ×3 with identical results). This was the riskiest
|
||
round of the wave — interleaving is where order contracts go to die —
|
||
and the two rules that survived the dev's own 16-test intermittent
|
||
failure (`must_wait`, so only the startup scan answers mid-way; and
|
||
`INTERLEAVE_ABOVE` as a count, not a clock) are the reason the whole
|
||
existing suite passes unmodified and deterministic. The measure-first
|
||
discipline paid again: per-file merging looked obvious and would have
|
||
been quadratic (11.7 s over 800 files); one absorb per non-empty-queue
|
||
drain costs the idle scan a `try_recv` per file and nothing else. The
|
||
structural fingerprint argument — one-shot and interleaved are
|
||
literally the same three-line loop over `Scan` — is the strongest
|
||
equivalence guarantee of the wave. First hover of a session:
|
||
780 → 15.5 ms cold, 287 → 12.8 ms warm, scan totals inside noise; the
|
||
remaining 6.9 ms of eager pre-scan reads is measured and filed, not
|
||
hidden. QA's two low findings were the lead's to settle and are fixed
|
||
in this commit: `absorb`'s doc now states the distinct-paths
|
||
precondition and why last-wins is the right update semantic (behavior
|
||
unchanged — the one production caller feeds deduped work, and QA's
|
||
divergence test pins the edge), and `refresh_code_lenses`' comment
|
||
caught up with `started`. The double-publish for a buffer opened
|
||
mid-scan (half-built answer, then finished answer) is correct by the
|
||
scope-relative-in-time doctrine and now pinned. Accepted; committed by
|
||
the lead.
|