Files

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

/// [`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.

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 neighbourhood_indexed(&self) -> bool;   // perf5-p4 §P4b3
    pub fn remaining(&self) -> Vec<PathBuf>;       // perf5-p4 §P4b3
    pub fn reorder(&mut self, ordered: WorkList);  // perf5-p4 §P4b3
}

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

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

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

  • Measure the merge cost before choosing a rhythm; per-file feeding rejected on the numbers above, deferred-and-batched chosen.
  • 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).
  • Scan + begin_scan/scan_step/publish_scan/finish_scan, with rebuild_index_with rewritten as the loop over them.
  • The server drives the scan and drains the queue between files; the queue moved onto Server so a scan and run share it.
  • 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.
  • Coalescing: a rescan asked for mid-scan is a flag, and scan_until_settled is a loop — never a scan inside a scan.
  • Shutdown mid-scan stops the scan where it stands and run returns without taking another message.
  • The completion tables and the include graph are published with the index, so a mid-scan answer is one generation and not three.
  • A file opened mid-scan is indexed next (Scan::index_next).
  • The startup scan republishes and refreshes lenses when a buffer was opened during it — a debt that did not exist before this round.
  • The e2e probe flipped and renamed; the before-numbers kept above.
  • 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_strings. 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-09-08 — §61.4: how often a scan publishes, and what [] is worth

Neither of these is a contract change. The three tables are still published together and never one of them; the order contract is must_wait's and is untouched; INTERLEAVE_ABOVE still decides which scans interleave at all. What moved is when the drain pays for a publish, and what it does with an answer that names nowhere (docs/features/perf5r-publication/README.md).

  • A publication cadence. answer_what_is_waiting used to publish whenever anything at all was waiting — one whole-index merge per burst of requests. Measured under a definition every 100 ms on opentitan, that was 14 publishes in a warm scan and 41 in a cold one, and absorb + candidates alone were 46 % of the warm session and 52 % of the cold one. It now publishes when something was waiting — the startup's held requests, which is the session's first useful answer and is never deferred — or when Scan::publish_is_due() says PUBLISH_EVERY (512) records have been staged since the last one. A request may now read an older prefix; it can never read an inconsistent one, which is the distinction this feature's decision 1 rests on. A quiet scan still pays nothing at all: the cadence is asked only when there is something for a publish to be for.
  • An empty navigation answer computed mid-scan is not an answer. A definition, a typeDefinition or a references that comes back [] while the index is still growing cannot be told apart from "the scan has not reached that file", so the request is put back and asked again at the next publish, and at the latest when the scan ends — where [] is the honest answer and goes out. This closes the case perf5r-first-answer pinned openly as its honest limit (a target in the folder next door answered [] at the head publish). It is a rule in the drain, not a second computation of the answer: the response is computed once through the ordinary handler and either sent or set aside, and a set-aside request is re-asked once per publish rather than once per step. The deferred set is deliberately not part of must_wait — a hover, a completion or a code action behind a deferred definition is answered exactly as before, and one is pinned.

2026-09-08 — §61.3: a scan that owes itself the rest of its own scope

The coherence contract is untouched — the three tables are still published together, a scan a message asked for still takes no held message, and head_owed still decides the drain. What changed is that a startup scan's work list can grow once: a workspace-scoped session with a buffer open walks that buffer's folders, steps them, publishes them and answers what is waiting, and only then walks the rest of the workspace (docs/features/perf5r-first-answer/README.md).

Three consequences for this feature, all in server/index.rs:

  • A scan with a pending discovery always interleaves, whatever INTERLEAVE_ABOVE says about its work list so far. A 124-file head is under the threshold, and the request waiting for it is precisely the one this feature exists to answer inside the scan. interleave is now total > INTERLEAVE_ABOVE || scan.discovery_pending().
  • The remaining discovery is its own step. scan_step runs it when the work list is exhausted and returns true without indexing anything, so the publish/drain point sits between it and the next file, and no file is ever reported against a denominator that grew inside its own step.
  • A burst's didOpen finishes the discovery before re-ordering. The user has jumped somewhere the walk has not reached; re-ordering a work list that cannot yet contain that folder would answer the request behind the didOpen off a prefix that cannot hold its target. Workspace::open_next does the walk first, and scan_order::worth_waiting then bounds the new head against the whole scope exactly as it always did.

Measured coherence, both binaries, cold and warm: mismatched_answers 0 and — under a new, stricter counter that treats an empty interim answer as a failure too — unsettled_answers 0 over 54 mid-scan definitions. The mid-scan answers also arrive sooner: the first one of a warm session at 26–42 ms where the reference took 143–153.

2026-09-08 — §P4b3: when a held request is drained, and what it reads

The order contract is unchanged. The moment a held request is drained moved, and it moved later. Written here because this README is where "only the startup scan answers mid-way" lives, and it is now "…once the user's own folder is in it" (docs/features/perf5-p4/README.md §P4b3).

Three things changed, none of them a promise:

  1. A held request is answered once the scan has stepped the user's own neighbourhood — the open buffers and the directories those buffers raise to — rather than at the first interleave point. Server::waiting_for_this_scan consults a new Server::head_owed, set from Scan::neighbourhood_indexed, and the publish_scan that already ran in the same call is what makes that neighbourhood answerable before the answer goes out. A scan with no neighbourhood (nothing open, an untitled: buffer, or a folder that covers the workspace) reports it with a head of 0 and drains at the first interleave point exactly as it always did. Why: §P4b2 measured what draining at the first file answers, and it is [] — coherent, and useless. Holding a request longer is always safe under this contract; answering it earlier is what was not.
  2. head_owed is a fifth must_wait clause, and it is what a request behind a didOpen in a mid-scan burst now waits on. That reinstates, inside one scan, exactly what the widen the didOpen used to trigger did: the requests behind it were owed its effect. Workspace::open_next then re-orders what is left of the work list around the buffers open now, replacing Scan::index_next — a didOpen brings its folder, not only its own file.
  3. Scan::index_next is gone, replaced by Scan::remaining / Scan::reorder and Workspace::open_next. Reordering the tail still cannot reach the index (IndexBuilder::finish sorts by path), which is the argument the removed method's own doc comment made.

The coherence contract is untouched: an answer mid-scan still sees a published prefix of all three tables, published together, and scanserve's mismatched_answers is 0 in every row of both binaries. What a scan holds while it runs did change — a file's text is read at the step that indexes it and dropped there, so Scan carries paths rather than 34 MiB of source — and docs/features/index-scope/README.md carries that amendment.

2026-09-08 — dev (Opus), §P4b2: the startup scan is now staged

The order contract is unchanged; what changed is which scan the opening burst waits for. Before today a session ran its startup scan at the default settings and only then asked the client for its own (workspace/configuration); a client whose lucisv.index.scope differs paid a second, configured scan when the answer landed, and — because that second scan is one a message asked for — Server::must_wait's answering_a_rescan clause held every request that arrived during it. §P4b measured what that cost on opentitan: 0.9 s warm, 2.6 s cold, and named it a contract rather than a routing bug (docs/features/perf5-p4/README.md, "the interleaving question, answered and filed").

The lead's ruling took the plan's own sentence — "if the default scan is routinely discarded, stage the initial scan until configuration arrives" — rather than the fourth must_wait state this lane had proposed. So:

  • Server::started now sends the settings pull first and waits up to CONFIGURATION_WAIT (2 s) for the answer, then runs one scan_until_settled(false) — the startup scan proper — at the scope that answer decided. The empty default-scope scan no longer happens at all, and neither does the configured rescan behind it.
  • A client that never answers, or answers after the bound, gets the scan at the defaults exactly as before, and its late answer is an ordinary settings change with an ordinary rescan behind it — held requests and all. A client that never advertised workspace/configuration is untouched: nothing is asked, nothing is waited for.

Decision 2 of this feature's three is not relaxed. "Only the startup scan answers mid-way. A scan a message asked for has that message queued ahead of everything else" still holds, word for word. What the staging adds is that requests arriving in the configuration window — before the startup scan has begun — are held by a fourth must_wait clause (staging) and then handed to that scan by Server::waiting_for_this_scan, which takes held only when answering_a_rescan and rescan_wanted are both clear. The justification is this feature's own, unchanged:

  • the scan they wait for is the startup scan: nothing is queued ahead of it, because the message that would have been — the client's settings answer — has already been applied before it starts;
  • it is the session's first scan, so finish_scan's deferred gone set is empty by construction. The QA log's argument below ("every scan capable of having gone files non-empty is a rescan … which must_wait already blocks") is therefore satisfied, not weakened: a rescan still takes nothing from held.

The widen is folded in rather than run. A didOpen arriving in the window installs its buffer and records that a scan is wanted; the one scan that follows resolves the scope with that buffer in place and open_first puts its file at the head of the work list. rescan_wanted is cleared before that scan because the scan is what every trigger in the window was asking for — it is the session's first, it resolves the scope afresh and reads every file in it.

Pinned by server/tests/startup.rs (five wire tests: one scan at the answered scope; the bounded fallback and the late answer's ordinary rescan; a didOpen folded in and indexed first; a definition answered inside the startup scan, before the bar comes down; a client that cannot be asked, unchanged) and by this feature's own suite, green unmodified — INTERLEAVE_ABOVE's hard boundary, the held-order tests, the coalescing and shutdown tests included.

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.