Files
lucisv/docs/features/perf5-p4/README.md
T
Guoliang ChenandClaude Mythos 5.2 71d13b5fbe
ci / checks (push) Successful in 1m0s
ci / corpus (push) Successful in 18s
ci / linux (push) Successful in 6m4s
release / build-and-publish (push) Successful in 5m31s
Release 0.66.2: every source file names its author
Every tracked file that can carry a comment (880 of them) now opens with
"Author: Guoliang Chen, a Senior Digital Design Engineer" and closes with
"Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love,
luciochen.com", in the file's own comment syntax. No behaviour change: the
diff outside the version bump and changelogs is comment lines only.

- tools/stamp_author.py: writes the lines; idempotent, `--check` lists
  what is missing. Headers go under a shebang and under Markdown front
  matter.
- Left alone: test fixtures, cases and snapshots (byte-exact inputs), JSON
  and JSONL, logs, images, lockfiles, docs/site/dist (regenerated) and the
  LICENSE files (already carry the copyright line).
- tools/linux_check.sh: --help reads its header from line 3, now that the
  author line sits under the shebang.
- tools/gates.sh green on this tree: 5 545 tests, corpus 814/6 as before.

Co-Authored-By: Claude Mythos 5.2 <[email protected]>
2026-11-24 12:11:09 -08:00

2155 lines
132 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!-- Author: Guoliang Chen, a Senior Digital Design Engineer -->
# perf5-p4 — the startup and memory breakdown (take 5 §P4a)
## Goal
Take 5 §P4 asks whether startup work and resident memory are worth
optimizing, and its own text says the individual shares are unmeasured:
"a warm index still reads source text to hash it, decodes encoded facts,
rebuilds/merges query tables, constructs completion/include tables and
refreshes open-buffer overlays […] their individual time/memory shares are
unmeasured." §P4a is the measurement that ends that sentence. It adds a
startup trace on the `--verbose` channel and a harness that reads it, so the
lead can rule on §P4b — which stage, or none — against numbers rather than
against the plan's hypotheses. **No optimization is in this lane.** Nothing
here changes what a scan does; it changes only what a scan is willing to say
about itself, and only when the flag is on.
## Assumptions
- **`--verbose` is the right channel.** The trace is three
`window/logMessage` lines per scan under the existing `timing:` prefix
(`docs/features/verbose-timing/README.md`), so a user who turns the flag on
gets them and a shipped server never does. The verbose-timing README's
"nobody parses these lines" assumption is amended by this feature: the
harness parses them, which is why they are `key=value` and why their shape
is pinned by tests.
- **A clock read per file is free enough to leave always on inside the
store.** `IndexCache`'s counters are not behind the flag: `facts_for` is a
`&self` read and threading a flag into it would cost more code than the
four `Instant::now()`s a file pays there. The settled-time tolerance check
below is what makes that claim measured rather than asserted.
- **Everything that is a walk is behind the flag.** The table sizes
(`WorkspaceIndex::table_sizes`, `Candidates::sizes`, `IncludeGraph::sizes`,
`IndexCache::encoded_bytes`) are each a pass over a table, so they run once
at the end of a scan and only when a trace asked for them.
- **A session pays for more than one scan.** The startup scan runs at the
**default** settings — `Server::started` builds the index before
`workspace/configuration` can be asked, let alone answered — so a client
that configures a wider scope pays a default scan and then a configured
rescan. The trace numbers its scans for exactly this reason, and no row in
this feature ever adds two scans together.
- **RSS is the harness's to measure.** The trace reports table *sizes*, not a
resident set: `ps -o rss=` at 50 ms is the existing `rss` phase's job and
stays there. What the trace adds is the sizes that explain the reading.
## Handshakes
### `vlog_semantic` — a new additive query
```rust
/// How many entries each table holds — `IndexCounts` asked by table rather
/// than by declaration kind.
pub fn table_sizes(&self) -> IndexTableSizes;
```
Additive: no existing query moved, no codec changed, `FACTS_FORMAT` untouched.
`IndexTableSizes` is exported beside `IndexCounts`. It is a walk over the
tables (map lengths plus one sum per table), so it belongs at the end of a
scan and never on a request path — that restriction is in its doc comment.
### `lucisv_server` internals
- `Workspace::begin_scan` and `Workspace::begin_widen` take a `trace: bool`.
Every existing caller passes `false`; only `Server::scan_once` and
`Server::reindex_widened` pass the flag through.
- `Workspace::take_scan_trace()` hands the finished trace to the server. The
trace is parked on the workspace rather than returned from `finish_scan` so
that no caller's signature moved for a diagnostic.
- `Candidates::sizes()` and `IncludeGraph::sizes()` are new read-only queries.
- `Pending::Configuration` carries the `Instant` it was asked at, so the
config round trip is a number rather than a guess.
- `Server` gains `born: Instant`: how long the process had been alive when a
scan started is the server's knowledge, not the workspace's.
**Amends `docs/features/verbose-timing/README.md`'s line table** with three
lines. That README's own "Nobody parses these lines" assumption no longer
holds for these three; the amendment is recorded here and in the work log.
### Requests for the lead (`docs/topo.md` is not edited by this lane)
Every edge below is **additive** — nothing existing changed shape — and each is
a request for the lead to apply at merge, not a silent edit:
1. `lucisv_server ──▶ vlog_semantic`: `WorkspaceIndex::table_sizes() ->
IndexTableSizes`, a new read-only query beside `counts()`. No codec change,
`FACTS_FORMAT` untouched, no existing query moved.
2. A new server module `scan_trace`, consumed by `state.rs`, `index_cache.rs`
and `server/index.rs`.
3. `Workspace::begin_scan` and `Workspace::begin_widen` take a `trace: bool`;
`Workspace::take_scan_trace()` is new. Every pre-existing caller passes
`false` and reads nothing.
4. `Candidates::sizes()`, `IncludeGraph::sizes()`, `IndexCache::work()`,
`IndexCache::entry_count()`, `IndexCache::encoded_bytes()` — all read-only.
5. `Server` gains `born: Instant`; `Pending::Configuration` gains an `Instant`
payload. Both are internal to `lucisv_server`.
6. The `verbose-timing` amendment above.
**§P4b adds three, all internal to `lucisv_server`** and all additive:
7. `CacheWork` gains `opens`, `compactions` and `repeats`, rendered on the
count line as `opens=`, `compactions=` and `repeats=`. The
`verbose-timing` amendment in (6) covers them — the line is already parsed
by `tools/perf/phases_p4.py`, which splits `key=value` and needs no change.
8. A private `StoreOpen` state on `Workspace`: a whole rescan's re-open of the
persistent store is deferred to the first file that asks it something.
**This amends `docs/features/index-persistence/README.md`'s
`lucisv_server::state` handshake**, and that README carries the amendment
in full — the rule is unchanged, only the moment moved.
9. `ScanTrace` gains `opened`, `measure_work` and `landed` (the three helpers
moved out of `state.rs`), so the `scan_trace` module now reads
`Candidates`, `IncludeGraph`, `IndexCache` and `WorkspaceIndex`. Read-only,
through the queries edge (4) already added.
**§P4b2 adds two.** The first is internal and additive; the second is a
**request for a change this lane did not make**.
10. A new server module `server/startup.rs`, holding `Server::new`,
`Server::started` (whose six trailing parameters became a `Startup`
struct), the settings wait and `CONFIGURATION_WAIT`. `Server` gains a
private `staging: bool` and the private helpers `scan_owed`,
`waiting_for_this_scan` and `take_the_answer_out_of_held`. All internal to
`lucisv_server`; nothing crosses a crate edge. **Two contracts are
amended in their own READMEs**, both by this lane and both stating the
rule is unchanged: `docs/features/scan-interleave/README.md` (the startup
scan now runs *after* the settings answer, and the requests held in the
window before it are handed to it — a rescan still takes none) and
`docs/features/index-scope/README.md` (the first scan resolves the
*answered* rung; precedence, rootless and the widen chooser untouched).
**`docs/features/folders-and-config/README.md` describes the pull's timing
in its Assumptions and is not this lane's file** — the sentence that a
pulled `lucisv.exclude`/`lucisv.filelist` "costs one extra rescan when it
lands" is now true only of an answer that arrives after the bound. That
edit is a request for the lead.
11. **Requested, not made: `Workspace::open_first` should order the work list
by the open buffers' *raised scope directories*, not only by the buffers
themselves.** With one startup scan, the prefix a mid-scan request reads is
the alphabet after the user's own file, so the first useful answer of a
workspace-scoped session is empty (measured above). Ordering cannot change
what the index holds — `IndexBuilder::finish` sorts by path, which is the
argument `open_first`'s doc comment already makes — so this is a reporting
and publish-order change, not a semantic one. `state.rs` is **calls only**
for this lane, so it stops here.
**Granted and done by §P4b3 (2026-09-08).**
**§P4b3 adds four**, all internal to `lucisv_server` and all additive except
the two `state.rs` shapes, which the lane owns:
12. A new server module `crate::scan_order`: `work_list`, `worth_waiting` and
`WorkList`, the three-group ranking a scan's work list is ordered by.
Consumed by `state.rs` alone.
13. **`state.rs` is now `state/mod.rs` + `state/scan.rs`** — a pure move of
`Scan`, `ScanKind`, `IndexEvent`, `Sources`, `Analyzed` and `HeldAnalyses`
into a child module, so `Workspace` sees exactly the fields it saw before
(`pub(super)` = inside `crate::state`, which is where they were). Public
paths are unchanged: `crate::state::{Scan, IndexEvent}` re-export from
`state/mod.rs`. `Scan::index_next` is **replaced** by
`Scan::remaining`/`Scan::reorder` plus `Workspace::open_next`, because a
`didOpen` answered mid-scan now brings its folder with it and not only its
own file.
14. `Candidates::from_words` and `IncludeGraph::from_includes` /
`absorb_includes` — the entries a caller that already holds a file's words
and `` `include`` lines uses. `Candidates::build` and `IncludeGraph::build`
are those same functions with the lex and the scan in front of them, and
are now `#[cfg(test)]`: nothing in the server holds a file's text long
enough to call them. `IncludeGraph::absorb` is **deleted** — it had no
caller left.
15. `Server::head_owed`, a fifth `must_wait` clause, and
`crate::scan_trace::{source_reads, count_read}` — a thread-local read
counter in the shape of `vlog_parser::stats::parses`. `ScanTrace` gains
`read_ms`, `work_bytes` and `saw_read`; the stage line gains `read=` and
`work_kib` on the memory line changes meaning (below). The
`verbose-timing` amendment in (6) covers the line change; a **stage was
added**, so `tools/perf/phases_p4.py` reads it without a change and
`the_stages_add_up_to_the_scan_they_describe` names it.
## What the trace prints
Three lines per scan, each `timing: scan <n> <kind> (<shape>, …): key=value …`.
| line | carries |
|---|---|
| `stages` | `discovery order cache_open lookup decode parse encode store_write publish_absorb publish_candidates publish_includes publish_overlay gone absorb compact candidates includes overlay total since_start`, all in ms |
| `counts` | `read read_kib skipped hits misses buffers records decoded_kib written_kib publishes published first_publish overlays` |
| `memory` | `store_before_kib store_after_kib cache_entries cache_encoded_kib index_files unit_names unit_defs members hier_members reference_keys reference_sites defines instantiations fact_words fact_word_kib candidate_units candidate_macros candidate_words candidate_word_kib include_edges include_known work_kib` |
Plus one line at the settings pull: `timing: configuration answered in X ms`.
## Status / TODO
- [x] `crates/lucisv_server/src/scan_trace.rs` — the trace type and its lines
- [x] `state.rs` call sites (calls only), `index_cache.rs` counters,
`candidates.rs` / `includes.rs` size queries,
`vlog_semantic::WorkspaceIndex::table_sizes`
- [x] `server/index.rs` emits the lines; `server/client.rs` times the config pull
- [x] tests: flag-gated, exact counts, warm-hit counts, stage-sum tolerance,
a rescan is its own numbered scan
- [x] `tools/perf/phases_p4.py` — `scanprofile`, `scanwait`, `scanserve`
- [x] measured breakdown (below), tracker rows and the §P4b recommendation
- [x] QA (§P4a)
- [x] lead ruling on §P4b (2026-09-08, in Review below)
### §P4b — the ruled fixes (2026-09-08)
- [x] **(a)** `IndexCache::compact` is skipped when the rewrite would
reproduce the store byte for byte — loaded canonical, nothing appended,
no entry's file gone. Seven tests in `index_cache.rs`, one in `state.rs`
- [x] **(b1)** a whole rescan opens the store at its **first file** instead of
before its work list exists, so a scan with no files reads nothing and
compacts nothing; the open is *moved*, not dropped, so the widen behind
it keeps its hits. Three tests in `state.rs`, one wire test
- [x] **(b2) not taken** — the store is still re-opened for every non-empty
whole rescan, exactly as `index-persistence` requires. Refused by the
lead; nothing in this lane touches it
- [x] the rescan-interleaving question answered: **not routing** — the
configured rescan already runs through the same stepper the startup scan
does. What holds navigation is `Server::must_wait`'s `answering_a_rescan`
clause, which is the scan-interleave order contract. **Filed for the
lead, not changed** (below)
- [x] pure move: `opened_trace` / `measure_work` / `landed` out of `state.rs`
into `scan_trace.rs` as `ScanTrace::opened` / `measure_work` / `landed`
- [x] two new count-line fields, `opens=` and `compactions=`, so the change is
observable to `tools/perf/phases_p4.py` and to a wire test
- [x] measured (below), tracker row + cells + experiment `P4b-2026-09-08`
- [ ] QA (§P4b)
### §P4b2 — the staged startup (2026-09-08)
- [x] `server/startup.rs`: the settings pull goes out first;
`await_configuration` waits on `recv_timeout` up to
`CONFIGURATION_WAIT` (2 s); the session then runs **one**
`scan_until_settled(false)` at the answered scope
- [x] the bounded fallback: no capability, or no answer inside the bound →
the scan runs at the defaults exactly as before, and a late answer is
an ordinary settings change with an ordinary rescan behind it
- [x] messages in the window: a `didOpen`'s widen (and every other rescan
trigger) is folded into the one scan via `Server::scan_owed`; a request
is held by `must_wait`'s new `staging` clause and handed to the startup
scan by `Server::waiting_for_this_scan`, which a rescan never reaches
- [x] the defect measurement found: a settings answer stranded in `held`
behind a request, costing the whole bound — `take_the_answer_out_of_held`
- [x] six wire tests in `server/tests/startup.rs`; the one pre-existing test
whose subject was the old wire order amended in place; scan-interleave's
and index-scope's suites green unmodified
- [x] measured (below), paired against the previous §P4b release; tracker row
+ cells + experiment `P4b-staged-2026-09-08`
- [x] **the empty first useful answer is closed by §P4b3 below** (Handshakes
11, granted). `folders-and-config`'s Assumptions sentence about the
pull's timing still needs the lead's edit (Handshakes 10)
- [ ] QA (§P4b2)
### §P4b3 — the lazy read and the folder-first order (2026-09-08)
- [x] **the read is lazy**: `collect_sources` resolves the scope and reads
nothing off disk; `scan_step` reads a file's text when its step comes and
lets it go again. `Scan` holds paths, the open buffers' texts and the
`` `include`` lines each step found — not 34 MiB of source
- [x] **read once, proved by a counter**: `scan_trace::source_reads`, a
thread-local in the shape of `vlog_parser::stats::parses`; a whole scan
reads each file's bytes exactly once and an open buffer's not at all
- [x] the include graph and the completion tables are re-fed without a second
read — `IncludeGraph::from_includes`, `Candidates::from_words` — and are
pinned equal to what the texts build
- [x] a file that leaves the disk between the walk and its own step is
`unread`: no event, not a cap skip, and taken *out* of the index by the
whole scan that could not read it
- [x] **folder-first order**: `crate::scan_order` ranks the work list open
buffers → the folders those buffers raise to → the rest in path order,
and reports the head segment. `Workspace::open_next` re-applies it for a
`didOpen` answered mid-scan
- [x] **the drain rule**: `Server::head_owed`, a fifth `must_wait` clause. A
held request is answered once the user's own folder has been stepped and
published; a burst's `didOpen` holds what is behind it until the folder
it named is in. A scan with no neighbourhood drains at the first
interleave point exactly as before
- [x] the head is bounded (`scan_order::worth_waiting`): a folder that is not a
minority of the workspace is not waited for
- [x] pure move: `state.rs` → `state/mod.rs` + `state/scan.rs`
- [x] measured (below); tracker row + cells + experiment `P4b-lazy-2026-09-08`
- [ ] QA (§P4b3)
## Work log
### 2026-09-08 — dev (Opus), §P4b3: the read is lazy and the order is the user's
**§P4b2 left one thing open and this is it.** The first useful answer of a
warm workspace session was unimodal and **empty** — result count 0 in six
sessions of six — for two reasons the trace named: `begin_scan` read all 3 976
files (34 MiB, ~293 ms) before the first `scan_step`, and the held definition
was then answered at the first drain, off a prefix holding the open buffer and
the alphabet after it. Both are fixed here, and the answer is **result count 1
in twelve sessions of twelve**.
#### 1. A file's text is read at the step that indexes it
`collect_sources` now resolves the scope and reads **nothing** off disk. It
returns paths, the size cap's skips (still `fs::metadata`, still reported and
counted before the first step, so the progress bar's denominator and
`Scan::skipped` are what they were) and the **open buffers' own text**, which is
in memory already. `Scan::work` is `Vec<PathBuf>`; `Scan::take_text` hands a
step its file's text and drops it at the end of that step.
**An open buffer's text is still snapshotted with the work list**, deliberately:
`Scan::analyzed` holds that buffer's finished analysis, and the two must
describe the same bytes however the buffer is edited while the scan runs — which
is what `a_buffer_opened_or_changed_mid_scan_does_not_change_what_the_scan_indexes`
pins. A **closed** file is read when its step comes, so the one contract that
moved is the read *moment* for disk files; the entry in
`docs/features/index-scope/README.md` says so.
**Everything the scan wants out of that text is taken in the one step**: the
content hash the store is keyed by, the parse, and — new here — the file's
`` `include`` lines, staged beside its facts and its words. So the graph and
the completion tables are built at the end from what the steps gathered rather
than from texts nobody holds any more:
| built from | before | now |
|---|---|---|
| `Candidates` | `build(index, &work, words)` — `words` already covered every file, so the text was never lexed | `from_words(index, words)` |
| `IncludeGraph` | `build(&work, incdirs)` — **re-scanned every file's text** | `from_includes(&found, incdirs)` |
`Candidates::build` and `IncludeGraph::build` are those same functions with the
lex and the scan in front of them, so a test can still build tables from a
fixture's text and the two are provably one function; both are `#[cfg(test)]`
now, because nothing in the server holds a text long enough to call them.
`IncludeGraph::absorb` had no caller left and is deleted.
**Read-once is counted, not asserted.** `crate::scan_trace::source_reads` is a
thread-local counter in the shape of `vlog_parser::stats::parses`, incremented
on the one disk read in `Scan::take_text`.
`a_whole_scan_reads_each_files_bytes_exactly_once` measures the delta across a
scan of a twelve-file tree: **12**, and **11** with a buffer open.
**A file that leaves the disk between the walk and its own step** is remembered
as `unread`. It reports no event and is not a cap skip — which is exactly what
`collect_sources` used to do by dropping it before the work list existed — and
`finish_whole_scan` takes it *out* of the index by leaving it out of `held`, so
it lands in `gone`. Without that it would have stayed in the index with a stale
record, which is the one thing the lazy read could have broken silently.
Pinned by `a_file_that_leaves_the_disk_between_the_walk_and_its_step_leaves_the_index`.
#### 2. The work list leads with the user's own folder
`crate::scan_order` ranks a work list in three groups — the open buffers' own
files, then everything under the directories those buffers **raise** to
(`Workspace::raised`, the scope ladder's own rule, whichever rung is in force),
then the rest in path order — and reports how many files that head segment is.
`index_order` still sorts and dedups first, and `IndexBuilder::finish` still
sorts by path, so **no insertion order can reach the index**: the fingerprint
and every table are equal to a scan with nothing open
(`the_open_buffers_folder_is_indexed_before_the_rest_and_the_index_cannot_tell`).
**The head is bounded.** A buffer opened from a workspace *root* raises to that
root, and "its folder" would then be the whole scan; `scan_order::worth_waiting`
returns 0 for a neighbourhood that is not a minority of the workspace, and the
drain falls back to the first interleave point exactly as before. The bound is
against the **whole** scan and never against what is left of it, because a
`didOpen` can arrive at any point and 124 files is 124 files of waiting whether
the scan has done none of the workspace or nine tenths.
#### 3. A held request waits for that folder — and so does one behind a `didOpen`
`Server::head_owed` is a fifth `must_wait` clause and the whole of the drain
rule. `answer_what_is_waiting` sets it from `Scan::neighbourhood_indexed`
before it takes anything, so `waiting_for_this_scan` hands the startup scan its
held requests only once the folder has been stepped — and the `publish_scan` in
that same call is what makes the folder answerable before the answer goes out.
**The measurement forced the second half of this rule, and it is the half that
matters in a real session.** The first paired run had the ordering and the
drain rule and still answered `[]` in five sessions of six. The reason is that
the client answers `workspace/configuration` from its own reader thread, so the
answer usually beats the editor's `didOpen`: the scan begins with **no buffer
open**, its work list is the plain alphabet, and the `didOpen` and the
definition behind it arrive at an interleave point some way in. At workspace
scope a `didOpen` widens nothing, so nothing held them and the definition was
answered off that alphabet. Now a burst carrying a `didOpen` sets `head_owed`
*before* the burst is applied — so the requests behind it are held, exactly as
the widen this `didOpen` used to trigger held them — and `Workspace::open_next`
re-orders what is left of the work list around the buffers open now. That
replaces `Scan::index_next`, which moved one file: a buffer brings its folder
with it.
`crowd/` sorting before `ip/` in
`a_did_open_answered_mid_scan_pulls_its_folder_in_front_of_the_request_behind_it`
is what makes that a claim rather than a coincidence — 70 irrelevant files come
first in path order, and the answer cannot have come from the alphabet. Both
wire tests fail with `[]` when the flag is removed, checked from the failing
side.
**The coherence contract is untouched**: three tables published together, and
`scanserve`'s `mismatched_answers` is 0 in all four rows of both binaries.
#### 4. Where the code lives
`state.rs` had grown 67 production lines, and the rule for this lane is that it
must not. The **pure move** that pays for it is `state.rs` → `state/mod.rs` +
`state/scan.rs`: `Scan`, `ScanKind`, `IndexEvent`, `Sources`, `Analyzed` and
`HeldAnalyses`, with their fields `pub(super)` — visible inside `crate::state`,
which is exactly where they were visible before. `crate::state::{Scan,
IndexEvent}` re-export, so no path outside the module moved. Production lines
(non-blank, non-comment, before `mod tests`): `state/mod.rs` **1 064** against
the **~1 074** this lane inherited, `state/scan.rs` 100, `scan_order.rs` 35,
`scan_trace.rs` 303, `includes.rs` 274, `candidates.rs` 406,
`server/index.rs` 198. Everything under 600.
**One function is over the 80-line investigate mark and was already**:
`Workspace::begin_widen`, 96 lines before this lane and **101** after — the
five are the `buffered` map a widen now carries beside its work list. It is
one linear walk with four filters and then the open-buffer overlay, so there is
no seam in it that a split would fall on; noted rather than restructured,
because restructuring it is not this lane's subject and would be a behaviour
risk taken for a line count.
#### §P4b3 — measured
Release `lucisv-server` sha256
`7ab4955ee0ac174840fbe4c02528e178f0c7824a3836fa87aa90e35bf47cdd3b`, paired
against **the shipped §P4b2 release**, sha256
`7522696e894a94d8d431f148d4e08e6a9ab7727eb0aaac36f8daa57a684b9076`, kept from
before the rebuild and re-run in the same window. Every phase ran **alternating
P4b2 then P4b3**, three fresh sessions per cell, every session under
`tools/guard.sh -m 8 -t 1800`, no `cargo` command during any timed phase, zero
guard kills. opentitan `0098135264` with its three pre-existing modified files,
`git status --porcelain` checked after every phase of both binaries and never
otherwise touched. One-minute load **2.8–7.5** across the matrix, recorded
before and after each phase. Rows:
`~/.cache/lucisv-perf/take5-p4b3/results.jsonl`, labels `P4b2` and `P4b3`.
**The first useful answer — the regression, closed:**
| | P4b2 | P4b3 | paired |
|---|---|---|---|
| `scan`, cold | 288.11 / 286.68 / 287.41, **count 0** | 249.13 / 249.70 / 248.16, **count 1** | −13.4 % |
| `scan`, warm | 364.43 / 315.23 / 318.38, **count 0** | 272.78 / 290.81 / 268.52, **count 1** | −16.6 % |
| `scanwait`, cold | 275.13 / 283.30 / 273.38, **count 0** | 236.93 / 253.85 / 252.19, **count 1** | −11.0 % |
| `scanwait`, warm | 317.41 / 318.91 / 321.04, **count 0** | 273.98 / 266.90 / 281.63, **count 1** | −13.5 % |
**Result count 1 in twelve sessions of twelve**, where §P4b2 was 0 in twelve of
twelve. That is the target this lane exists for, and it is met.
**The latency target is missed, and the trace says exactly why.** The work
order asked for "at or below the REF's 84 cold / 208 warm, ideally ≈ walk + the
folder's 124 files". It **is** walk + the folder, and the walk is the whole of
the gap:
| warm, traced | P4b2 | P4b3 |
|---|---:|---:|
| `discovery` (scope walk + the cap's `metadata`, and in P4b2 the 34 MiB read) | 227.02 | **158.32** |
| `read` (the per-step reads, new) | — | 85.54 |
| `cache_open` (at the first step) | 87.67 | 89.24 |
| `first_publish` | 316.74 | **249.70** |
| the definition answered at | 317.41 | **273.98** |
| files in that first publish | **1** | **125** |
Warm, the floor is `discovery` 158 + `cache_open` 89 = 247 ms before the
folder's 124 files (≈25 ms warm) can be published. The §P0 REF answered in
208 ms because it never walked the workspace at all — it answered off a
**124-file folder scan**, and the workspace walk came later. **The one-scan
design's floor is the walk**, and that is the finding this lane hands the next
one: `discovery` is now 158 ms of pure walk with no read in it, and it is 58 %
of the first useful answer.
**Stages and memory (`scanwait`, one traced session each):**
| | P4b2 | P4b3 | change |
|---|---:|---:|---|
| `discovery`, cold / warm | 271.26 / 227.02 | **157.91 / 158.32** | −42 % / −30 % |
| `read`, cold / warm | — | 115.56 / 85.54 | new stage |
| `includes` (the graph built at the end) | 42.11 / 42.12 | **8.55 / 8.60** | **−80 %** |
| `work_kib` — the source text the scan holds for its life | **34 973** | **3 / 0** | **−100 %** |
| `read_kib` | 34 973 | 34 970 / 34 973 | the same bytes, read once |
`includes` falls by 34 ms because the line scan moved to the step that read the
file — over bytes already in cache — and the graph at the end only resolves
what the steps found. It is the one stage that got cheaper rather than moved.
**Settled — unchanged, within the window's noise:**
| cell | P4b2 | P4b3 | paired |
|---|---|---|---|
| workspace, cold (`scan`) | 2 932.23 / 2 720.02 / 2 721.87 (2 791.37) | 2 660.72 / 2 639.93 / 2 637.20 (**2 645.95**) | −5.2 % |
| workspace, warm (`scan`) | 1 019.48 / 1 030.21 / 983.13 (1 010.94) | 968.84 / 967.68 / 1 004.41 (**980.31**) | −3.0 % |
| workspace, cold (`scanprofile`) | 2 602.34 | 2 624.90 | **+0.9 %** |
| workspace, warm (`scanprofile`) | 965.89 | 983.95 | **+1.9 %** |
| default scope, cold / warm | 99.88 / 45.59 | 91.67 / 47.36 | −8 % / +4 % |
| `{"index":{}}`, cold / warm | 102.57 / 48.56 | 104.18 / 47.54 | +2 % / −2 % |
| `scopeDepth 0`, cold / warm | 10.44 / 11.81 | 9.24 / 10.54 | −12 % / −11 % |
**The two workspace phases disagree in sign, so the honest reading is
"unchanged".** The ledger says why it is close to a wash: `discovery` −69 ms
and `includes` −34 ms against `read` +86 ms — the same 34 MiB read a file at a
time, interleaved with parsing and decoding, costs about 13 ms more than the
same bytes read in one tight loop. Both runs are quoted; neither is dropped.
**Open buffers (`scanprofile`, warm workspace, settled):**
| buffers | P4b2 | P4b3 | paired |
|---:|---|---|---|
| 1 | 1 010.91 | 994.74 | −1.6 % |
| 10 | 973.62 | 1 003.75 | +3.1 % |
| 100 | 1 185.95 | 1 181.55 | −0.4 % |
§P4a's `order` cost — 60.6 ms at 100 buffers, a linear `contains` per file — is
gone with the ranking: `order` is **1.95 ms at 100 buffers**, because the open
set is a `HashSet` now.
**Memory (`rss`, 3 fresh sessions):** cold idle max **543 024 → 505 200 KiB
(−7.0 %)**, warm idle max **466 256 → 432 736 KiB (−7.2 %)**. Peak equals idle
to the KiB in all twelve sessions of both binaries, as in every round since
§P4a. The mechanism is the one the `work_kib` row measures: the 34 MiB of
source text no longer lives for the scan's life.
**Requests during a scan (`scanserve`, a definition every 200 ms):**
| | P4b2 | P4b3 |
|---|---|---|
| cold, answers / slowest | 34 / **427.5 ms** | 36 / **314.8 ms** |
| warm, answers / slowest | 12 / **360.0 ms** | 12 / **313.3 ms** |
| `mismatched_answers` | **0 / 0** | **0 / 0** |
**`didOpen` (§46's path, 3 fresh sessions):** pinmux_reg_top median 123.52 →
127.72; spi_device 14.37 → 15.05; aes_core 9.80 → 12.05; aes 4.47 → 5.47. Every
row is inside its own spread (P4b2's pinmux tries were 101.87–123.76 in this
same window) and **the path cannot be reached by this change**: `didopen`
settles the scan before it opens the buffer, so `head_owed` is false and the
drain rule is not in play. §46's fix is intact.
**The scope ladder answers identically.** `scopes`, eight requests × three
scopes × both binaries: **all 24 result counts equal**.
**The store is byte-identical.** Every warm workspace store written by either
binary is sha256 `e49bc5c176ea…`, 46 486 433 bytes, `store_kib` 45 404 — the
same file §P4b and §P4b2 recorded. **That is the strongest equality proof this
lane has**: the records a lazy scan writes are byte for byte the records an
eager one wrote, over 3 976 real files.
#### §P4b3 — targets, honestly
| target | result |
|---|---|
| first useful answer, **result count 1 in 6 of 6** | **met** — 1 in **12 of 12**, across two phases |
| first useful answer ≤ REF's 84 cold / 208 warm | **missed**: 249 cold, 274 warm. It is walk + folder as asked; the walk alone is 158 ms and the REF never walked the workspace. Filed below |
| first useful answer better than §P4b2's | **met**: −13.4 % cold, −16.6 % warm, and useful where §P4b2's was empty |
| `work_kib` → ~0 | **met**: 34 973 → 0–16 KiB |
| each file's bytes read exactly once | **met**, counted |
| peak RSS during the scan not higher | **met**: peak equals idle in all 12 sessions; idle **−7.0 % cold, −7.2 % warm** |
| settled not worse | **met within noise**: −5.2 % / −3.0 % in one phase, +0.9 % / +1.9 % in the other |
| scope cells identical | **met**: 24 of 24 result counts, identical file and cache-hit counts |
| `mismatched_answers` 0 | **met**: 0 of 4 rows, both binaries |
| §46's `didOpen` intact | **met**: every row inside its own spread, and the path is not reachable from this change |
| the store unchanged | **met**: same sha256 and same size from both binaries |
#### §P4b3 — filed for the next lane
**The first useful answer is now walk-bound.** `discovery` is 158 ms with no
read in it: the scope walk plus one `fs::metadata` per file for the size cap.
That is 58 % of the 274 ms warm answer and 63 % of the 249 ms cold one, and
nothing in this lane reaches it. Two things worth measuring before anything is
built: whether the walk can hand the cap the size it already stat'd
(`lucisv_core::walk::collect_files` is not this lane's file — a handshake
request, not an edit), and whether the first *folder* of the walk can be
handed to `scan_step` before the walk has finished the workspace. The second
would make the answer ≈ the folder alone, which is the REF's 84 ms.
**And `cache_open` is still 89 ms at the first step**, which is the refused
(b2) sitting in front of every warm first answer. It is now the second largest
thing between a warm session and its first useful answer.
### 2026-09-08 — dev (Opus), §P4b2: the startup scan is staged
**The lead ruled the plan's own sentence, not the fourth state this lane
proposed.** §P4b left one regression open (see "The one regression, named"
above): with the empty startup scan reduced to 0.15 ms, the opening `didOpen`
no longer had its accidental 181 ms head start over the client's
`workspace/configuration` answer, so the warm first useful answer became
bimodal — 117 ms when the `didOpen` won the race, the whole configured rescan
when it did not. The narrow fix this lane had described was a *fourth*
`must_wait` state letting one kind of rescan answer mid-way. The lead took the
work order's own clause instead:
> *"If the default scan is routinely discarded, stage the initial scan until
> configuration arrives, with a bounded fallback for clients that never answer;
> keep rootless and scope precedence behavior intact."*
That is a better answer than the fourth state, because it removes the race
rather than arbitrating it: there is no second scan for a request to be queued
behind.
**What the code does now** (`crates/lucisv_server/src/server/startup.rs`, new):
1. `Server::started` calls `stage_for_configuration` **before** the scan. For a
client that advertised `workspace/configuration` it sets a new
`Server::staging` flag, sends the pull, and waits.
2. `await_configuration` reads messages until the answer arrives, the bound
runs out, or the client goes away. **The bound is observed on the receive
itself** — `self.queue.recv_timeout(left)` with `left` recomputed from
`CONFIGURATION_WAIT.checked_sub(asked.elapsed())` — so the loop blocks in
the transport, wakes on the next message, and returns at the deadline. No
poll, no busy-wait, no timer the loop has to be woken to read, and no
`unwrap` anywhere in it (`checked_sub` returning `None` *is* the timeout).
3. `staging` and `rescan_wanted` are cleared, and the session runs **one**
`scan_until_settled(false)` — the startup scan proper, at the answered
scope, allowed to answer requests mid-way, with no prior index and
therefore no `gone`. The empty default-scope scan does not happen.
**The bound is `CONFIGURATION_WAIT = 2 s`, and it is not a budget.** §P4a's
`configuration answered in` line measured 27.3–28.1 ms warm and 82.8–85.2 ms
cold, and both of those numbers were dominated by the empty scan the server ran
*before* reading the answer; with that gone the number is the client's own
reply, single-digit milliseconds. Two seconds is two orders of magnitude of
slack. A client that answers *after* it sees exactly what a client that pushes
a `didChangeConfiguration` sees: `configured` → `apply_settings` →
`set_client_settings` reports the scope moved → `reindex()` → an ordinary
rescan, with `must_wait` holding what is queued behind it. Nothing is stale in
between; it is simply the default scope until the answer lands, which is what
every session was before today.
**What happens to messages that arrive while waiting.** They go through the
ordinary `process_batch`, so the order contract is the loop's own code, not a
second implementation of it:
- a **`didOpen`** is applied: the buffer is installed, the folder scope widens,
and `reindex_widened` — seeing `Server::scan_owed()` (now `scanning ||
staging`) — records that one more scan is wanted rather than running a widen.
The one scan that follows resolves the scope with the buffer in place and
`open_first` puts its file at the head of the work list, so the widen is
*folded into* the startup scan rather than run beside it.
- a **pushed setting**, a **save**, a **watched-file burst** and a **folder
change** take the same path, for the same reason: whatever they asked for,
the session's first scan reads the whole scope from disk at the final
settings. That is why `rescan_wanted` may be cleared before it runs.
- a **request** is held by a new fourth `must_wait` clause (`staging`) — there
is no index at all to answer it from — and is handed to the startup scan by
`Server::waiting_for_this_scan`, which takes `held` **only** when
`answering_a_rescan` and `rescan_wanted` are both clear. It is then answered
mid-scan off the published prefix, exactly as a request arriving during that
scan always was. A rescan takes nothing from `held`: decision 2 of
`docs/features/scan-interleave/README.md` is unchanged, and the deferred
`gone` set the QA log worried about is empty by construction here, because
this is the session's first scan.
- a **`shutdown`** is held like any other request (the pre-existing rule: a
request sent before a shutdown is still owed an answer) and stops the scan at
its first drain.
**Two wire-order consequences, both deliberate.** The settings pull is now the
**first** thing a session sends — ahead of the progress `create`, the watcher
registration and the lens refresh. `settings.rs`'s
`the_startup_pull_is_sent_after_the_watcher_registration_on_the_wire` pinned
the opposite and is amended in place (renamed to
`the_startup_pull_is_the_first_thing_on_the_wire`, with the reason in the
test); it is the only pre-existing test in the workspace this round changed.
And a client with a `filelist` in its answer now registers its watchers from
`apply_settings` before `started`'s own `register_watchers` supersedes it — the
same three requests, in a different order.
**Where the code lives.** `server/mod.rs` was 576 lines with `Server::new` and
`Server::started` in it; both moved to the new `server/startup.rs` (120
production lines) together with the wait, leaving `mod.rs` at 153 production
lines. `started`'s six trailing parameters became a `Startup` struct — seven
positional arguments were already at clippy's `too_many_arguments` limit, and
the two only a test sets (`queued`, `wait`) read as nothing at a call site.
`index.rs` gained `waiting_for_this_scan` (194 production lines), `mod.rs`
gained `staging` and `scan_owed`, `client.rs`'s `say_held` line gained
`staging=` so the fourth clause is as greppable as the other three.
**One defect this lane found by measuring, before it shipped.** The first
paired run of the `scan` phase showed one warm session in three taking
**2 125 ms** to its first useful answer — near enough the two-second bound to
be the bound. It was: `process_batch` moves *everything behind* a request that
must wait into `held`, which is what keeps a burst's arrival order intact
across the wait, and the editor's opening burst is `didOpen`, then a
`textDocument/definition`, then — from the client's own reader thread — the
answer to the settings pull. The definition is held; the answer goes into
`held` behind it; the wait sees the pull still outstanding and blocks until the
bound. `Server::take_the_answer_out_of_held` takes **only** a
`Pending::Configuration` answer back out, leaving everything else in `held` in
its place and its order. Reordering just that one message is sound because the
order rule is about the *client's* message stream: the reply to a request the
**server** sent carries no ordering promise against a request the editor
happened to send at the same moment. The preliminary rows that caught it are
kept unquoted at
`~/.cache/lucisv-perf/take5-p4b2/results-preliminary-stranded-answer.jsonl`.
**Six wire tests**, `crates/lucisv_server/src/server/tests/startup.rs`:
| test | what it pins |
|---|---|
| `a_client_that_answers_pays_one_scan_at_the_scope_it_asked_for` | exactly **one** scan, `timing: scan 1` only, `read=9` at the answered scope, and the pull first on the wire |
| `a_client_that_never_answers_is_bounded_and_then_scanned_at_the_defaults` | `CONFIGURATION_WAIT` is 2 s; a 120 ms bound is really waited out; one scan at the defaults (`read=0`); the late answer's rescan is `scan 2` and a request behind it is answered **after** it |
| `a_did_open_that_beats_the_answer_is_folded_into_the_one_scan_and_indexed_first` | one scan, `buffers=1`, the buffer's own file is the **first** line of the per-file log, and its diagnostics are published |
| `a_request_that_beats_the_answer_is_answered_inside_the_startup_scan` | a `textDocument/definition` sent before the answer is answered **before the bar comes down**, with a real location, and the index still finishes |
| `a_client_that_cannot_be_asked_scans_at_once_exactly_as_it_always_did` | nothing asked, nothing waited for, `read=0`, `opens=0`, `compactions=0` — §P4b's own path untouched |
| `an_answer_behind_a_held_request_is_not_stranded_for_the_whole_bound` | the defect above: `didOpen` + request + answer in one burst, a 30 s bound, and the session still returns in milliseconds with one scan at the answered scope — the held request neither lost nor answered off an empty index |
Everything else is the existing suite, green unmodified: `scan.rs`'s
interleave, boundary, held-order, coalescing and shutdown tests; `index.rs`'s
ladder tests; `progress.rs`; `folders.rs`; `watchers.rs`;
`scan_trace.rs`'s §P4b store tests (which use a client without the capability
and therefore exercise the unstaged path). **4 290 tests pass, 0 fail** — the
4 284 the round started with, plus six.
#### §P4b2 — measured
Release `lucisv-server` sha256
`3ff0db0920d1b86bee5237ea7b7827c7383a402ef73ec138c111cf7a867d7ca8` for the
seven-phase matrix, paired against **the previous §P4b release**, sha256
`623c0ea62df4fe154947725605071fee93e54f02dec3f45e6c566620ed5c0ee3`, kept from
before the rebuild. The **shipped** binary is
`7522696e894a94d8d431f148d4e08e6a9ab7727eb0aaac36f8daa57a684b9076`, which
differs from the measured one by a pure move only — `started`'s `Server { … }`
literal into `Server::empty`, to bring the function under the file-size rule's
80-line investigate mark — and the `scan` phase was **re-run on it**, paired
again, to prove the numbers travel (see "Confirmed on the shipped binary"
below). Every phase ran **alternating P4b then P4b2**. opentitan
`0098135264` with its three pre-existing modified files, `git status
--porcelain` checked after every phase of both binaries and never otherwise
touched. Rows in `~/.cache/lucisv-perf/take5-p4b2/results.jsonl` under labels
`P4b` and `P4b2`.
**The load is not uniform across this run and the numbers must be read with
it.** `scan` — the headline phase — ran at one-minute load **4.7–5.1**, the
quiet window. Everything after it ran while macOS started an `XProtect`
remediation sweep and `mediaanalysisd`: `scanwait` **20.1–22.9**,
`scanprofile` **23.8–25.9**, `scanserve` **18.0–21.2**, `scopes` 14.7–16.0,
`didopen` 12.8–13.9, `rss` 12.0–12.5. The alternation is what makes those
still comparable — both binaries met the same weather within a phase — but the
absolute values in them are not comparable with §P4b's own window and are not
quoted as if they were.
**Settled (`scan`, 3 fresh sessions each, the quiet window):**
| cell | P4b | P4b2 | paired |
|---|---|---|---|
| workspace, cold | 3 125.88 / 2 885.50 / 2 878.26 (mean 2 963.21) | 2 859.99 / 2 869.28 / 2 802.25 (**2 843.84**) | **−4.0 %** |
| workspace, warm | 1 169.60 / 1 159.20 / 1 215.23 (1 181.34) | 1 097.51 / 1 094.56 / 1 101.88 (**1 097.98**) | **−7.1 %** |
| default scope, cold | 100.59 | 95.85 | −4.7 % |
| default scope, warm | 46.22 | 45.10 | −2.4 % |
| `{"index":{}}`, cold | 103.79 | 105.29 | +1.4 % |
| `{"index":{}}`, warm | 41.64 | 44.03 | +5.8 % |
| `scopeDepth 0`, cold | 114.95 | **12.45** | **−89.2 %** |
| `scopeDepth 0`, warm | 51.32 | **14.07** | **−72.6 %** |
`scopeDepth 0` is the cell the plan predicted in as many words — *"explicit
depth 0 pays for [a 124-file default scan] and then ends with one file"*. It no
longer does: the configured scope is resolved before anything is read, so the
session reads one file and stops. The two default-scope cells move by a few
milliseconds either way, which is the config round trip now serialized ahead of
the scan instead of overlapping an empty one; at 45–105 ms total it is noise a
user cannot feel.
**Confirmed on the shipped binary** (`scan`, re-run paired at load 8.7–9.1,
storage wiped first):
| cell | P4b | P4b2 (shipped) | paired |
|---|---|---|---|
| workspace, warm | 1 198.25 / 1 175.12 / 1 198.07 (1 190.48) | 1 040.79 / 1 036.88 / 1 034.28 (**1 037.31**) | **−12.9 %** |
| workspace, cold | 2 938.30 / 2 843.24 / 2 846.96 (2 876.17) | 2 820.57 / 2 795.44 / 2 794.79 (**2 803.60**) | **−2.5 %** |
| `scopeDepth 0`, cold / warm | 108.26 / 52.16 | **10.37 / 12.75** | **−90.4 % / −75.6 %** |
| first useful, cold | 2 881.13 / 2 883.64 / 83.76, count 1 | 304.64 / 301.75 / 304.31, **count 0** | unimodal, empty |
| first useful, warm | 1 203.52 / 1 162.89 / 119.90, count 1 | 348.74 / 350.54 / 352.14, **count 0** | unimodal, empty |
**Warm settled 1 037.31 ms is inside the ≤ ~1.06 s target**, and the first
run's 1 097.98 was not — the two runs bracket it, at loads 4.7–5.1 and 8.7–9.1
respectively. Both are quoted; neither is dropped.
**One scan, not three (`scanprofile`, warm workspace, `--verbose`):**
| | P4b | P4b2 |
|---|---|---|
| scans traced | 3 (whole 0 files, widen 124, whole 3 976) | **1** (whole 3 976) |
| per-scan total | 0.13 + 119.47 + 1 082.46 = 1 202.06 | **1 093.67** |
| `cache_open` | 0 + 91.38 + 92.32 = **183.70** | **91.91**, once |
| `opens` / `compactions` | 2 / 0 | 1 / 0 |
| settled | 1 233.39 | **1 110.48, −10.0 %** |
**This is the (b2)-equivalent saving, arriving without store reuse.** §P4b
missed warm < 1 s because the store was opened twice, 181.7 ms, and the lead
had refused reusing it across rescans for two good reasons. Staging removes the
second open by removing the second *scan*: the rule `index-persistence`
requires — every whole rescan resolves the directory afresh and reads the store
— is untouched; there is simply one whole rescan in a session now instead of
two.
**Open buffers (`scanprofile`, warm workspace, settled):**
| buffers | P4b | P4b2 | paired |
|---:|---|---|---|
| 1 | 4 scans, 1 555.37 ms | **1 scan, 1 113.56** | **−28.4 %** |
| 10 | 4 scans, 1 555.93 ms | **1 scan, 1 139.27** | **−26.8 %** |
| 100 | 3 scans, 1 721.70 ms | **1 scan, 1 360.10** | **−21.0 %** |
**Requests during a scan (`scanserve`, a definition every 200 ms, 3 fresh
sessions per cache state):**
| | P4b | P4b2 |
|---|---|---|
| cold, every answer sorted | 0.22 / 0.23 / 0.28 / 84.88 / 89.22 / **2 621.84 / 2 658.83 / 2 933.71** | 0.20 … 475.41 across **37** answers, nothing above 476 |
| warm, every answer sorted | 0.24 / 0.28 / 0.38 / 121.91 / 124.44 / **933.86 / 942.65 / 1 233.87** | 0.21 … 381.54 across **12** answers, nothing above 382 |
| `mismatched_answers` | 0 / 0 | **0 / 0** |
**The "queued behind the configured rescan" mode is gone for the startup
case** — that is the whole of what the lead asked for. There is no configured
rescan to be queued behind, so the three-mode distribution §P4a named collapses
to two: mid-scan, and settled. A **genuine** settings-change rescan mid-session
still queues requests exactly as it always did — it is `must_wait`'s first
clause, unchanged, and `startup.rs`'s own wire test drives a late answer and
shows the request behind it answered after the rescan, not during it.
**`didOpen` (§46's path, `didopen`, 3 fresh sessions, load 12.8–13.9):**
pinmux_reg_top median **118.75 → 110.39**, mean 123.19 → 115.38 (**−6.3 %**);
spi_device 11.05 → 8.40; aes_core 8.16 → 6.33; aes 2.12 → 2.31 (a 2 ms row).
§46's fix is intact.
**Memory (`rss`, 3 fresh sessions):** cold idle 542 512 → 542 581 KiB
(**+0.0 %**, maximum 542 864 → 545 216, +0.4 %); warm idle 495 291 →
**466 480 KiB (−5.8 %)**, maximum 496 256 → 467 200 (−5.9 %). Peak equals idle
to the KiB in all twelve sessions of both binaries. Warm falls again for the
same reason it fell at §P4b: one fewer whole scan is one fewer set of transient
buffers the allocator holds on to.
**The store is still left alone.** A cold session then two warm ones, both
binaries: sha256 `e49bc5c176ea…`, 46 486 433 bytes and the **same mtime** after
every one. `store_kib` 45 404 for both.
**The scope ladder answers identically.** `scopes`, eight requests × three
scopes × both binaries: **all 24 result counts equal** (`workspace/symbol
'aes'` 256 at default and workspace and 0 at `scopeDepth 0`, `references` 11 /
14 / 0, and so on). The per-scan *file* counts moved by design — one scan
instead of three — but what each scope answers did not.
#### §P4b2 — the regression, named
**The first useful answer is now unimodal, and it is empty.**
| | P4b | P4b2 |
|---|---|---|
| cold (`scan`, quiet window) | 2 902.62 / 2 884.55 / **86.97**, result count 1 | 293.04 / 300.26 / 294.82, **result count 0** |
| warm (`scan`, quiet window) | 1 205.18 / 1 204.50 / **125.84**, result count 1 | 396.86 / 404.88 / 411.39, **result count 0** |
| cold (`scanwait`, busy window) | 103.32 / 106.84 / 90.60, count 1 | 357.19 / 316.85 / 309.52, count 0 |
| warm (`scanwait`, busy window) | 1 279.66 / 123.76 / 124.15, count 1 | 389.92 / 400.14 / 386.77, count 0 |
The bimodality §P4b filed is gone — every session now answers in the same few
hundred milliseconds, and the 1.2 s / 2.9 s mode is unreachable. **But the
answer is `[]` where it used to be a location, and that is a real loss the lead
must rule on.** The mechanism is arithmetic, and the trace says it outright.
Warm, `scanwait`'s traced session: `discovery` **292.74**, `first_publish`
**389.27**, definition answered at **389.92**.
- `begin_scan` resolves the scope and reads all 3 976 files' text *before* the
first `scan_step`, so the earliest moment any request can be answered is
≈ 293 ms in. That is the floor of the one-scan design, and it is why 85–120 ms
is not reachable at workspace scope.
- The request is then answered at the **first** drain, off a prefix holding the
open buffer and nothing else — so `aes` is not in it, and the definition is
empty. Coherent (it names nothing rather than something wrong;
`mismatched_answers` is 0), but not useful.
- Under §P4b the same request was answered by the **widen** — a 124-file scan
of the buffer's own neighbourhood which, because `reindex_widened` does not
interleave, ran to *completion* before the request was served. Its 124 ms
answer was complete for that scope. That is what staging traded away: the
fast mode's quality, in exchange for the slow mode's disappearance.
**Filed, with the fix this lane cannot make.** The narrowest repair is to make
the prefix a mid-scan answer reads be the *user's own neighbourhood* rather
than the alphabet: `Workspace::open_first` puts the open buffers' files first,
and putting the files under those buffers' **raised scope directories** next
would put `aes` in the published prefix within a few tens of milliseconds of the
first file. That is an ordering change only — `IndexBuilder::finish` sorts by
path, so no insertion order can reach the index, which is the argument
`open_first`'s own doc comment already makes — but it is a change to
`Workspace::open_first` in `state.rs`, a file this lane holds **calls only**.
So it is a **handshake request**, not an edit: see Handshakes (11) below.
**Closed 2026-09-08 by §P4b3** (work log below), and the narrowest repair was
not quite enough on its own: the ordering only helps when the buffer is open
when the scan *begins*, and it usually is not — the client answers the settings
pull from its own reader thread and beats the editor's `didOpen`. The shipped
fix is the ordering **plus** a drain rule: a held request waits for the user's
folder, and a burst's `didOpen` holds what is behind it until the folder it
named is in. Result count 1 in twelve sessions of twelve; the residual is that
the answer is now bounded below by the 158 ms workspace *walk*, filed there.
### 2026-09-07 — dev (Opus)
Instrumentation written; no behavioural change. Notes on the shape:
- **The trace lives on the `Scan`.** A `ScanTrace` is a bag of `f64` sums and
`usize` counters with an `on` flag; `now()` hands out `Option<Instant>` and
`add(slot, from)` is a branch, so a scan that is not traced reads no clock
and allocates nothing. Nothing per file is allocated even when it is on.
- **The cache's own split needed counters inside the cache.** `facts_for` is
the one place that can separate "hash the text and find the entry" from
"decode the record", which is exactly §P4's hypothesis, so `IndexCache`
holds a `Cell<CacheWork>` and `compact` records the store's size before and
after. A `Cell` because `facts_for` takes `&self`.
- **`buffers` is counted and not timed.** Taking an open buffer's own
finished analysis costs nothing to *take*; what that file then costs is the
record written through, which is in `encode`/`store_write` like every other
file's. Timing the arm as well would have double-counted it.
- **The stages are disjoint, and they do not have to add to `total`.** The
slack is the scan loop itself — the progress/log callbacks, the per-file
word `Vec`, the staging pushes. Left unattributed on purpose rather than
folded into a neighbouring stage; the tolerance test asserts the stages
never *exceed* the scan and account for most of it.
### 2026-09-08 — dev (Opus), §P4b: the ruled fixes
The lead's ruling, item by item, plus what the measurement then forced.
- **(a) and (b1) as ruled**, (b2) not taken. The mechanisms are in "§P4b —
what changed" above; the contract amendments are in
`docs/features/index-persistence/README.md` (Assumptions, and the
`lucisv_server::state` handshake), not only here, because the compaction rule
and the re-open rule are that feature's promises.
- **One addition beyond the ruling, and it is reported as one.** (a) alone is
worth **nothing** in a session with a buffer open: the buffer is indexed from
its own analysis on every scan and its record is written through with it, so
`records` is never 0 and the store is never canonical. Measured that way
first, deliberately, and kept as evidence
(`results-compaction-defeated.jsonl`: warm scan 3 `records` 1,
`compactions` 1, `compact` **88.19 ms**). `IndexCache::record` now returns
early when the store already holds that exact record. It is in service of
(a)'s own sentence — "the session appended nothing" — and in a file this lane
owns, but it was not named in the ruling, so: **the lead can back it out by
deleting one `if` and one counter**, at the cost of (a) entirely.
- **The interleaving question is answered and filed, not fixed** — the section
above has the mechanism, the reasons, the number and the narrow fix. It is
the `must_wait` order contract, not routing, and §P4b makes it *more*
reachable: removing the empty scan's 181 ms removed the head start the
`didOpen` used to win the race with. That is the one regression in this lane
and it is named in "The one regression" above rather than buried.
- **What the numbers did to the plan's arithmetic.** §P4a's recommendation
added (a) 182.4 and (b1) 92.5 to get 274.9 ms. The 92.5 is not additive: a
warm session opens the store twice either way, and (b1) *moves* scan 1's open
onto the widen rather than removing it. The honest ledger is
**−180.2 ms of compaction, +10.1 ms of skip check, −0 ms of open** — and the
measured paired settle is −189.2 ms, which is that plus noise. Nobody should
expect the missing 91 ms without (b2).
- **The pure move** took `opened_trace`/`measure_work`/`landed` out of
`state.rs`. `landed` needed `Candidates`, `IncludeGraph`, `IndexCache` and
`WorkspaceIndex` as parameters, so `scan_trace.rs` now imports the four
things it measures; that is the shape of "a diagnostic knows what it is
describing", and it keeps the walks and the `TableSizes` assembly out of the
state module entirely. `state.rs` 1 098 → 1 073 production lines.
- **Gates**: `cargo fmt --all -- --check` clean; guarded
`cargo clippy --all-targets` clean, no new `#[allow]` anywhere in the diff;
guarded `cargo test --workspace` **4 284 passed, 0 failed** against **4 272**
at the lane's start — **+12**, exactly the twelve new tests, nothing lost or
weakened. Zero guard kills; largest resident set seen 591 MiB of the 8 GiB
cap.
- **The corpus** stayed at exactly its three pre-existing modified files after
every phase of both binaries, checked between each.
**Twelve new tests.** In `index_cache.rs`: a canonical store nothing appended
to is not rewritten (bytes *and* mtime); a record the store already holds is
not appended again, and one byte of difference still is; and one each for a
duplicated path, a line this build cannot read, records out of path order, a
session that recorded a file, an entry whose file is gone, and another
version's header — the six clauses of the skip, one test each. In `state.rs`: a
warm rescan leaves the store exactly as it found it; a scan with no files
neither reads nor writes it **and the widen behind it still hits every
record**; a cold session that indexes nothing creates no store at all. In
`server/tests/scan_trace.rs`: both halves over the real dispatch, with a buffer
open, read off the trace's own new `opens=` / `compactions=` / `repeats=`
counters.
**The tests were attacked before they were trusted.** Widening
`already_compact` to "there is a directory" fails all six guard tests plus two
pre-existing ones (`compaction_keeps_one_line_per_path_and_drops_the_files_that_are_gone`,
`nothing_is_created_until_something_is_recorded`). Dropping the deferred open
instead of moving it — QA's §P4a warning, exactly — makes
`a_scan_with_no_files_neither_reads_the_store_nor_rewrites_it` report
`parsed: ["b.sv"]` where it expects `cached: ["b.sv"]`. Neither failure mode
can land silently.
## The measured breakdown
Release `08093a3a2b9c0b8796e5f9214ac7bda59e068e49e32a9c2393f29d116fca10bd`,
opentitan `0098135264`, three fresh sessions per cell, every run under
`tools/guard.sh -m 8 -t 1800`, one-minute load 4.1–5.0 during the timed
phases. Raw rows: `~/.cache/lucisv-perf/take5-p4/results.jsonl`, experiment
`P4a-2026-09-07` in `docs/perf/take5-tracking.md`.
### A workspace session pays three scans, and the first one indexes nothing
The single most useful thing the trace says is structural, and it was not in
anybody's model of the startup:
| scan | when | what it indexes | cold | warm |
|---|---|---|---:|---:|
| 1, whole | `Server::started`, at the **default** settings, before any buffer is open | **0 files** — the folder scope is derived from directories a buffer has been opened from, and none has | **0.8 ms** | **183.7 ms** |
| 2, widen | the `didOpen` of the first buffer widens the scope to its folder | 124 files | 94.0 ms | 26.6 ms |
| 3, whole | the pulled `lucisv.index.scope: "workspace"` arrives and asks for a rescan | 3 976 files | 2 760.0 ms | 1 112.7 ms |
The 124-file "default scan" the plan expected is really a **widen**, and the
startup scan proper is empty. Warm, that empty scan still costs **183.7 ms**:
it opens the 44.3 MiB store (`cache_open` 92.5 ms) and then **compacts it**
(`compact` 91.0 ms) — rewriting 45 396 KiB to produce a byte-identical file,
because `finish_whole_scan` compacts unconditionally and the work list being
empty is not consulted. Cold the same scan costs 0.8 ms, because there is no
store yet.
### Ranked stages — cold, settled mean 2 893.6 ms (2 866.7 / 2 936.3 / 2 877.7)
Summed over all three scans of the session.
| stage | ms | % of settled |
|---|---:|---:|
| parse | 1 703.63 | 58.9 % |
| discovery (scope walk + read 34.2 MiB of text) | 299.59 | 10.4 % |
| absorb (the final merge) | 218.40 | 7.5 % |
| encode (records out) | 183.26 | 6.3 % |
| store_write (append log) | 118.46 | 4.1 % |
| `Candidates::build` | 110.66 | 3.8 % |
| compact | 93.89 | 3.2 % |
| `IncludeGraph::build` | 45.52 | 1.6 % |
| decode | 5.87 | 0.2 % |
| publish_absorb (one mid-scan publish) | 4.41 | 0.2 % |
| cache_open | 3.39 | 0.1 % |
| lookup (content hash) | 2.86 | 0.1 % |
| order, gone, overlay, publish_candidates/includes/overlay | 4.15 | 0.1 % |
| **named total** | **2 794.09** | **96.6 %** |
| unattributed (the scan loop, the progress/log callbacks, the per-file word `Vec`, the staging pushes, and the `didOpen`/publish work between scans) | 99.49 | 3.4 % |
### Ranked stages — warm, settled mean 1 332.7 ms (1 332.6 / 1 330.0 / 1 335.5)
| stage | ms | % of settled |
|---|---:|---:|
| discovery (scope walk + read 34.2 MiB of text) | 255.91 | 19.2 % |
| absorb (the final merge) | 218.08 | 16.4 % |
| decode (44.2 MiB of records) | 202.75 | 15.2 % |
| **cache_open** (the store read **twice**, 44.3 MiB each) | **183.46** | **13.8 %** |
| **compact** (the store rewritten **twice**, unchanged both times) | **182.39** | **13.7 %** |
| `Candidates::build` | 113.34 | 8.5 % |
| lookup (content hash of 34.2 MiB) | 51.31 | 3.9 % |
| `IncludeGraph::build` | 46.30 | 3.5 % |
| publish_absorb | 4.34 | 0.3 % |
| everything else (order, gone, overlay, encode, store_write, publish_*) | 4.40 | 0.3 % |
| **named total** | **1 262.28** | **94.7 %** |
| unattributed | 70.44 | 5.3 % |
| parse | **0.00** | **0.0 %** |
**Warm has no dominant stage.** The five largest are within a factor of 1.4 of
each other, and two of them — 365.9 ms, **27.5 % of the whole warm settle** —
are the persistent store reading and rewriting itself.
### Memory
| what | measured | note |
|---|---:|---|
| Idle RSS, cold, 3 sessions | 531.0 / 529.0 / 529.9 MiB | REF 526.7 / 530.2 / 535.2 — agrees |
| Idle RSS, warm, 3 sessions | 574.8 / 565.2 / 564.8 MiB | REF 575.0 / 572.5 / 575.6 — agrees (−0.1 % on the maximum) |
| Peak RSS across the scan | equal to idle to the KiB, all six sessions | `ps -o rss=` at 50 ms; still no transient above idle |
| Store on disk | 45 396 KiB = 44.33 MiB | `du -sk` 44.34 MiB |
| **Encoded facts held in `IndexCache` beside the decoded index** | **45 260 KiB = 44.20 MiB** | 7.7 % of warm idle RSS. The plan's hypothesis, measured |
| Source text held by the scan for its whole life (`work`) | 34 973 KiB = 34.15 MiB | released at `finish_scan`; not in idle RSS |
| Index: files / unit names / unit declarations | 3 976 / 3 067 / 4 013 | |
| Index: connection members / hierarchical members | 91 894 / 56 913 | |
| Index: reference keys / reference sites | 59 529 / **457 666** | the largest single table by entry count |
| Index: `` `define``s / instantiation edges | 1 358 / 13 894 | |
| Index: identifier census (`FileFacts::words`) | 345 127 words, 4 754 KiB = 4.64 MiB | |
| Completion tables: units / macros / words | 50 726 / 658 / 105 042 words, 1 888 KiB | |
| Include graph: resolved edges / known files | 1 984 / 3 976 | |
The **warm-minus-cold idle difference is 34–46 MiB**, and the store path is the
only thing that differs between the two sessions: both end holding the same
index and the same 44.20 MiB of encoded entries, but the warm session
additionally reads a 44.3 MiB file into one `Vec<u8>` twice and renders a
44.3 MiB `String` twice. That is consistent with the encoded retention plus
allocator retention of those buffers; it is **not** an allocation profile and
is not quoted as one.
### The first useful answer, explained
§P0 measured cold **84.4–85.9 ms** and warm **206.1–218.7 ms** and could not
say why warm was 2.5× slower. The trace answers it arithmetically.
| | scan 1 | scan 2 (widen) | sum | measured first answer |
|---|---:|---:|---:|---:|
| cold | 0.54 | 81.58 | **82.1** | **83.4 / 85.7 / 84.9** |
| warm | 181.19 | 26.31 | **207.5** | **208.7 / 208.9 / 209.2** |
The definition arrives with the `didOpen` and is answered as soon as the widen
that `didOpen` triggered has finished. Cold, the wait is that widen's 123
parses. Warm, the widen is 3× cheaper (26 ms, every file a cache hit) but the
**empty startup scan ahead of it has spent 181 ms opening and compacting the
store**. So it is neither the publish cadence nor the decode: **it is the
config wait — the empty scan the server runs before configuration can arrive —
and specifically that scan's store I/O.** The `configuration answered in` line
agrees: 82.8–85.2 ms cold, 27.3–28.1 ms warm — the client answers instantly in
both, and what the number measures is when the server got back to reading it.
### Open buffers: 1 / 10 / 100
Warm workspace scope, the first N files of `hw/ip/*/rtl` opened right after
`initialize`, all before the scan settles.
| | 1 buffer | 10 buffers | 100 buffers |
|---|---:|---:|---:|
| settled mean | 1 841.6 ms | 1 859.1 ms | **2 173.9 ms** |
| scans traced | 4 | 4 | 4 |
| final whole scan | 1 268.2 ms | 1 230.9 ms | 1 348.5 ms |
| overlay refresh, final scan (`overlay` + `publish_overlay`) | 0.31 ms | 1.33 ms | **19.67 ms** |
| `order` (open-buffers-first) | 1.30 ms | 3.97 ms | **60.64 ms** |
| `encode` + `store_write` (a buffer's own record written through) | 0.49 ms | 2.21 ms | **21.20 ms** |
| buffers indexed from their own analysis | 2 | 11 | 101 |
| config round trip | 388–404 ms | 401–417 ms | 561–570 ms |
Opening buffers adds a **fourth** scan — a second widen (352–372 ms) for the
folders those files live in, which brings 1 685 files into scope before the
configured scope arrives. **The overlay refresh is not the cost**: 100 open
buffers refresh in 19.7 ms. The cost that actually scales is `order` — 60.6 ms
at 100 buffers, which is `open_first` moving each buffer's path to the front of
a 3 976-entry work list, one linear scan per buffer. It is 3 % of that
session's settle, so it is measured and filed, not a recommendation.
### Requests arriving during a scan
A `textDocument/definition` every 200 ms for as long as the scan is still
reporting, three fresh sessions per cache state. Each session gets three
answers, and the distribution has three distinct modes rather than a spread:
| | during scans 1–2 | **queued behind the configured rescan** | after settle |
|---|---:|---:|---:|
| cold | 83.66 / 83.97 / 84.95 ms | **2 558.85 / 2 563.65 / 2 567.24 ms** | 0.39 / 0.43 / 0.43 ms |
| warm | 210.26 / 212.58 / 214.34 ms | **897.12 / 904.12 / 907.90 ms** | 0.24 / 0.26 / 0.40 ms |
The middle column is the finding: **a request that arrives during the
configured rescan waits the whole rescan** — 2.56 s cold, 0.90 s warm. That is
the scan-interleave contract behaving exactly as written (only a scan *nobody
asked for* answers mid-way, and the scan nobody asked for is the empty one), so
it is not a bug; but it means the interleaving that §46's round bought is
currently spent on a scan with no files in it, and the scan that really takes
seconds blocks navigation outright.
**Table coherence: 0 mismatched answers in 18 requests across all six
sessions.** Every mid-scan answer either named exactly what the settled index
names or was empty; none named anywhere else. That is the observable form of
`docs/features/index-scope/README.md`'s coherent-prefix contract, and the
`scanserve` row fails loudly (`status: error`) if it is ever violated.
### The instrumented binary against the REF
The trace must not slow the scan it measures. Measured with the **quiet**
binary (no `--verbose`), same `scan` phase as §P0:
| row | §P0 REF | instrumented, quiet | delta |
|---|---|---|---|
| Cold workspace scan | 2 860.12–2 868.45 (mean 2 863.85) | 2 846.95 / 2 875.49 / 3 046.12 (mean 2 922.85) | +2.1 % on means; **−0.5 % excluding the first try**, which is the first cold session after a link and is an outlier by 170 ms |
| Warm workspace scan | 1 346.02–1 352.80 (mean 1 348.94) | 1 327.12 / 1 331.64 / 1 369.46 (mean 1 342.74) | **−0.5 %** |
| First useful answer, cold | 84.42–85.87 | 84.51 / 85.71 / 86.17 | +0.3 % |
| First useful answer, warm | 206.12–218.72 | 209.07 / 209.52 / 212.08 | within the REF range |
| Idle RSS, warm (max) | 575.6 MiB | 574.8 MiB | −0.1 % |
| Idle RSS, cold (max) | 535.2 MiB | 531.0 MiB | −0.8 % |
**The always-on `IndexCache` counters cost nothing measurable**: four clock
reads per file over 3 976 files is under a millisecond of a 1.3–2.9 second
scan, and every row above is inside tolerance.
## Recommendation for the lead's §P4b ruling
**The dominant measured stage is the persistent store's own I/O on a warm
start — `cache_open` + `compact`, 365.9 ms, 27.5 % of the warm settle — and
183.7 ms of that is spent by a scan that indexes zero files.** Cold is a
different problem entirely: 58.9 % of it is `parse`, and nothing on §P4b's list
touches parsing. Taking the plan's three suggestions in numbers:
**(a) avoid compaction on an unchanged store** is worth **182.4 ms warm
(13.7 %)** and ~0 cold — both warm compactions rewrite a byte-identical file
(`store_before_kib` = `store_after_kib` = 45 396, `records` 0 and 1);
**(b) shorten temporary buffer lifetimes / reduce redundant transient copies**
is worth **92.5 ms (6.9 %)** for not opening the store at all when the work
list is empty, plus **91.0 ms (6.8 %)** more if a scan may reuse the store the
previous scan of the same session already read — the second half changes
`index-persistence`'s "re-opened at the start of every whole rescan" rule and
is a contract question, not a free win; **(c) reduce repeated full merges**
is worth **nothing measurable** — there is exactly one mid-scan publish
(`publish_absorb` 4.3 ms) and one final `absorb` (218 ms), so the merge is
already done once. Against the plan's investigation goals: **warm < 1 s is
reachable but only with all of (a) and both halves of (b)** — 1 332.7 − 274.9 =
1 057.8 ms with the safe two, 966.8 ms with the third; **cold < 2.3 s is not
reachable** by anything on §P4b's list, since it would need 35 % of the parse
stage and the plan rules out parser worker parallelism without a separate
measured case; **idle RSS −15 % is not reachable** — the one retention §P4
hypothesised is real and measured at **44.20 MiB, 7.7 % of warm idle**, so
dropping it after a scan buys at most half the goal, and the rest sits in the
decoded index (457 666 reference sites, 345 127 words) where only a
representation change reaches it. If the lead rules §P4b in, the honest scope
is **"the store stops working for a scan that has no files", targeting warm
≈1.05 s and warm first-useful-answer ≈27 ms (from 209)**, with the RSS goal
restated as −8 % or dropped. One thing outside §P4's list is worth the lead's
attention on its own: **a navigation request that arrives during the configured
rescan waits 2.56 s cold / 0.90 s warm**, because the only scan that
interleaves is the empty one.
**Corrected by §P4b's own measurement (2026-09-08).** The arithmetic above adds
(a) 182.4 and (b) 92.5 to get 274.9 ms; **the 92.5 is not additive**. A warm
session opens the store twice either way, and taking the open out of the empty
scan 1 only *moves* it onto the widen that follows. The honest ledger is
−180.2 ms of compaction plus 10.1 ms of skip check, and the measured paired
settle is −189.2 ms. The "warm ≈1.05 s" target above is therefore wrong; the
real landing is **1 137.7 ms**, and warm < 1 s needs the refused (b2). Nothing
in this section is edited — it is what the lane recommended on the day, and
what it got wrong is worth more than a silent fix.
## §P4b — what changed
Three code changes and one pure move. Nothing touches the record format, the
content key, the store header, the claim/append protocol, the per-record
checksum, the byte-wise load or the torn-record rule; `FACTS_FORMAT` and
`CACHE_FORMAT` are untouched, and `index-persistence`'s own tests are
untouched and green.
**(a) A compaction that would reproduce the file is skipped.** `render` writes
this build's header and then one line per path in path order, so a store this
build compacted and nothing has appended to since already *is* the file the
next compaction would write. `IndexCache::open` now counts what it read —
lines read, kept, dropped, duplicated, and whether the paths ascended — and
`compact` skips the rewrite when all of: the load was canonical, the session
appended nothing, no entry's file is gone, and there is a directory to write
in. The existence sweep is one `stat` per entry, a subset of what `render`
already does per entry: **10.13 ms measured, against the 90.20 ms rewrite it
stands in for**.
**(a′) A record the store already holds is not appended again — an addition,
not in the ruling.** Reported as a deviation because the ruling did not name
it, and kept because **without it (a) never fires in a real session**: an open
buffer is indexed from its own analysis on every scan and its record is
written through with it, so `records` is 1 rather than 0 on every scan a buffer
is open for, and the store is never canonical. Measured with (a) alone on
opentitan: warm scan 3 `records` 1, `compactions` 1, `compact` **88.19 ms** —
the whole of (a) defeated by one duplicate line
(`~/.cache/lucisv-perf/take5-p4b/results-compaction-defeated.jsonl`, kept as
evidence and not quoted elsewhere). `IndexCache::record` now returns early when
the entry is already there under the same path, the same content hash and the
same encoded facts, byte for byte; anything differing by a byte is appended
exactly as before. The counter is `repeats=` on the count line.
**(b1) A whole rescan opens the store at its first file.** `begin_scan`
resolves the directory and records it as `StoreOpen::Deferred`; `scan_step` —
and the save path's write-through — opens it. The **re-open rule is
unchanged**: every whole rescan still resolves the directory afresh and reads
the store, for both of `index-persistence`'s reasons. Only the moment moved,
and a rescan whose work list is empty now asks the store nothing and therefore
reads nothing and compacts nothing. **The open is a move, not a drop** — the
widen a `didOpen` triggers never opened the store itself (it reads the handle
`begin_scan` left), so dropping the open would silently have cost that widen
every cache hit. Pinned from the failing side.
**(b2) Not taken.** The store is still re-opened for every non-empty whole
rescan. Refused by the lead; nothing in this lane touches it. The consequence
is visible in the stage table below: the warm session still pays `cache_open`
twice, 90.62 + 91.12 = **181.7 ms**, and that is now the largest single thing
the store costs a warm start.
**The pure move.** `opened_trace`, `measure_work` and `landed` — the three
helpers §P4a left in `state.rs` — are now `ScanTrace::opened`,
`ScanTrace::measure_work` and `ScanTrace::landed`; `state.rs` keeps the calls.
`state.rs` production lines (non-blank, non-comment, before `mod tests`)
**1 098 → 1 073**: the move takes out 45 and §P4b's own code (`StoreOpen`,
`open_store`, the compaction gate, the save-path call) puts back 20.
`scan_trace.rs` 215 → 282, `index_cache.rs` 283 → 338 — both far under 600.
**Two new count-line fields**, so the change is observable to the harness and
to a wire test rather than only inferable from a stage time: `opens=` (stores
read off disk) and `compactions=` (stores actually rewritten), plus `repeats=`
for (a′). `tools/perf/phases_p4.py` reads them without a change, since it
splits `key=value`.
## §P4b — measured
Release `lucisv-server` sha256
`623c0ea62df4fe154947725605071fee93e54f02dec3f45e6c566620ed5c0ee3`, against a
**control built in the same window from a `git clone --local` at HEAD
`2434729`** (sha256 `5957b0826249a0354b270d2ec865e7cfc702b187bd359049cc5c73b2170354d4`),
every phase run **alternating HEAD then P4b** so the two share the machine's
weather. opentitan `0098135264` with its three pre-existing modified files,
checked after every phase and never otherwise changed. One-minute load
**3.6–6.7** — busier than §P0's REF window (2.9–4.6), which is why the paired
control matters more than the cross-day comparison. Three fresh sessions per
cell, every session under `tools/guard.sh -m 8 -t 1800`, no `cargo` command
during any timed phase, zero guard kills. Rows:
`~/.cache/lucisv-perf/take5-p4b/results.jsonl`, experiment `P4b-2026-09-08`.
### The startup, stage by stage (warm, `--verbose`, one traced session each)
| scan | HEAD | P4b |
|---|---:|---:|
| **1, whole, 0 files** | **180.72** — `cache_open` 90.49 + `compact` 90.04 | **0.15** — `opens` 0, `compactions` 0 |
| 2, widen, 124 files | 26.21 — `cache_open` 0.00 (it reads scan 1's handle) | 116.51 — `cache_open` **90.62**, the open scan 1 no longer pays |
| **3, whole, 3 976 files** | 1 087.84 — `cache_open` 90.57, **`compact` 90.20**, `records` 1 | 1 016.23 — `cache_open` 91.12, **`compact` 10.13**, `records` **0**, `repeats` **1**, `compactions` **0** |
| **sum** | **1 294.77** | **1 132.89** (**−12.5 %**) |
So the 183.5 ms scan 1 no longer spends is really **91 ms saved and 91 ms
moved**: the widen inherits the open scan 1 used to pay for. What is genuinely
removed is the two compactions — 180.2 ms of rewriting a byte-identical file —
minus the 10.1 ms the skip's own existence sweep costs.
### Settled and first answer (quiet binary, 3 fresh sessions, paired)
| row | HEAD (same window) | P4b | paired change |
|---|---|---|---|
| Warm workspace settle | 1 325.28 / 1 324.62 / 1 330.64 — mean **1 326.85** | 1 132.60 / 1 143.54 / 1 136.83 — mean **1 137.66** | **−14.3 %**, −189.2 ms |
| Cold workspace settle | 2 857.77 / 2 834.77 / 2 848.29 — mean **2 846.94** | 2 816.59 / 2 813.47 / 2 818.56 — mean **2 816.21** | −1.1 % — unchanged, as predicted (cold is 59 % parse) |
| First useful answer, **cold** | 84.06 / 84.01 / 84.60 | 85.62 / 86.83 / 84.45 | +1.6 % — unchanged |
| First useful answer, **warm** | 208.94 / 206.16 / 208.85 | **116.77** / 1 133.53 / 1 137.51 | **bimodal — see below** |
| `didOpen` pinmux → definition | 107.12 / 128.13 / 118.38 (median 118.38) | 109.68 / 122.74 / 114.53 (median **114.53**) | −3.3 % — §46's fix intact |
| `didOpen` spi_device → definition | 6.32 / 14.67 / 12.40 (median 12.40) | 10.73 / 8.16 / 6.88 (median 8.16) | −34 %, but a sub-15 ms row: not read |
| Idle RSS, **warm** (max of 3) | 563.81 / 569.95 / **569.75** MiB | 482.55 / 481.67 / **482.75** MiB | **−15.3 % on the maximum** |
| Idle RSS, cold (max of 3) | 493.56 / **532.58** / 529.44 MiB | 527.08 / 529.25 / **530.45** MiB | −0.4 % on the maximum |
| Peak RSS across the scan | equal to idle to the KiB, all 6 sessions | equal to idle to the KiB, all 6 sessions | no transient, either binary |
| Store on disk | 45 404 KiB | 45 404 KiB | identical |
| `mismatched_answers` (`scanserve`) | **0** in both cache states | **0** in both cache states | the coherence contract holds |
**The RSS result is the surprise, and it is the one §P4a said was out of
reach.** Warm idle falls **87 MiB, −15.3 %**, which meets the plan's −15 %
investigation goal — and warm idle is now *below* cold idle. The mechanism is
the one §P4a's memory section named without pricing: a warm HEAD session reads
the 44.3 MiB store into a `Vec<u8>` twice **and renders a 44.3 MiB `String`
twice** to write it back; P4b renders none. The encoded-facts retention §P4
hypothesised (44.20 MiB) is untouched and still resident — this is the
allocator retention of the render buffers beside it.
**The store really is left alone, byte for byte.** Two warm workspace sessions
over one store, sha256 and mtime after each:
| | after the cold fill | after warm 1 | after warm 2 |
|---|---|---|---|
| HEAD | `e49bc5c1…` mtime `…960117212853` | `e49bc5c1…` mtime `…982249698088` | `e49bc5c1…` mtime `…985232233976` |
| P4b | `e49bc5c1…` mtime `…960117212853` | **same hash, same mtime** | **same hash, same mtime** |
Same 46 486 433 bytes throughout — HEAD rewrites them identically twice, P4b
does not open the file for writing at all. (Script:
`~/.cache/lucisv-perf/take5-p4b/storecheck.py`, both binaries, same corpus; the paired run's own log is `run-paired.log` beside it.)
### The scope ladder is unchanged
Every cell of the `scan` matrix, both binaries, with the file counts the
sessions reported:
| scope | HEAD cold / warm | P4b cold / warm | files reported (both) |
|---|---|---|---|
| `default` | 105.98 / 95.11 / 90.95 — 49.84 / 41.04 / 47.45 | 89.99 / 93.19 / 93.15 — 40.05 / 35.71 / 43.24 | `0 files indexed \| 124 files indexed` |
| `{"index":{}}` | 106.94 / 105.44 / 107.99 — 45.03 / 49.12 / 41.11 | 101.00 / 100.06 / 102.41 — 39.79 / 40.51 / 36.74 | `0 \| 124` |
| `scopeDepth 0` | 113.92 / 105.55 / 123.36 — 61.37 / 55.81 / 67.19 | 118.26 / 100.26 / 109.01 — 53.03 / 47.20 / 46.35 | `124 \| 1` |
| `workspace` | above | above | `124 \| 3 976`, 123/3 975 from cache, 3 skipped |
Identical file counts and identical cache-hit counts in every cell of both
binaries. The rungs answer exactly what they answered.
### Requests during a scan (`scanserve`, paired)
| | during scans 1–2 | queued behind the configured rescan | after settle |
|---|---|---|---|
| HEAD cold | 83.55 / 84.79 / 84.80 | 2 520.86 / 2 552.87 / 2 602.80 | 0.27 / 0.36 / 0.37 |
| P4b cold | 84.63 / 85.61 / 85.87 | 2 582.51 / 2 588.46 / 2 600.39 | 0.24 / 0.34 / 0.39 |
| HEAD warm | 206.77 / 208.49 / 209.67 | 891.52 / 893.91 / 895.40 | 0.20 / 0.24 / 0.33 |
| P4b warm | **117.98 / 118.88** | 824.36 / 826.06 / 1 150.43 | 0.27 / 0.30 / 0.37 |
A warm mid-scan answer falls **207 → 118 ms** for the same reason the first
useful answer does: the empty scan's 181 ms of store I/O is no longer in front
of it. `mismatched_answers` is 0 in all four rows.
### The one regression, named
**Warm, the first useful answer is now bimodal: 117–118 ms or the whole
configured rescan (~1 140 ms).** Two of six sessions took the fast mode, four
the slow one. Cold is unaffected (six of six fast, both binaries).
It is not a new mechanism — it is the interleaving contract filed below, made
*reachable* by §P4b. The startup sequence is: scan 1, then
`request_configuration()`, then the loop. The client answers the configuration
pull from its own reader while its main thread is still sending the `didOpen`,
so the two race. On HEAD, warm scan 1 spent **181 ms** before the pull went
out, which gave the `didOpen` a head start it won in every session ever
measured — §P0's three, §P4a's three, QA's three and this control's six:
**fifteen sessions, fifteen fast**. With scan 1 at 0.15 ms the race is genuine, and when the configuration answer wins, `apply_settings`
starts the configured rescan and `Server::must_wait` holds the definition
behind it — the documented order contract, working as written.
**Closed 2026-09-08 by §P4b2** (work log below) — and not by the fourth state
this section proposed. The lead took the plan's own sentence instead and staged
the startup scan, which removes the race rather than arbitrating it: there is
no configured rescan for a request to be queued behind. The residual, measured
there, is that the surviving answer is *empty* rather than slow.
So §P4b did not create the wait; it removed the accidental 181 ms that was
hiding it. The number the user sees is **better in the fast mode (−44 %) and
worse in the slow one**, and which one they get is a race. **The narrow fix is
the fourth state described below, and it is the lead's to rule on.** Nothing in
this lane papers over it: the empty scan's I/O was pure waste either way, and
buying responsiveness back by reinstating it would be indefensible.
### Targets, honestly
| target | result |
|---|---|
| warm settled −~270 ms, ≤ ~1.06 s | **missed**: −189 ms, **1 137.7 ms**. The remaining warm settle is discovery 246.1, absorb 208.4, decode 195.1, **`cache_open` 91.1 + 90.6 = 181.7** (the refused (b2)), candidates 105.8, lookup 48.8, includes 44.5 |
| the plan's warm < 1 s | **missed** — it needed all three of §P4a's candidates, and (b2) was refused. Reachable only by not re-opening the store twice |
| first useful answer warm ≈ cold (~85 ms) | **missed as stated**: 117–118 ms in the fast mode (−44 %), the configured rescan in the slow one. The residual is the `must_wait` contract, filed |
| cold unchanged within tolerance | **met**: −1.1 % paired |
| RSS not higher | **beaten**: warm idle **−15.3 %**, cold −0.4 %, peak still equal to idle |
| store bytes identical after a warm session | **met**: same sha256 *and* same mtime over two warm sessions |
| the scope ladder unchanged | **met**: identical file and cache-hit counts in all eight cells |
| `mismatched_answers` 0 | **met**: 0 of 4 rows, both binaries |
## §P4b — the interleaving question, answered and filed
The lead's ruling asked why navigation queues behind the configured rescan:
fix it if it is routing, file it if it is not. **It is not routing.** Read
through, the configured rescan takes exactly the same path the startup scan
takes:
1. `Server::started` runs `scan_until_settled(false)` — scan 1, the empty one
— and only then sends `workspace/configuration`.
2. The client's answer arrives as a `Message::Response` in an ordinary batch:
`process_batch` → `Server::response` → `configured` → `apply_settings` →
`Workspace::set_client_settings` reports that `index.scope` moved →
`Server::reindex()` → `scan_until_settled(**true**)`.
3. That is the *same* `scan_once` the startup scan ran. It steps file by file,
3 976 is far above `INTERLEAVE_ABOVE` (64), so `answer_what_is_waiting`
runs between every pair of files, drains the queue and calls
`publish_scan` — the three tables really are published mid-rescan, exactly
as they are mid-startup-scan.
What holds the request is one line further in: `process_batch` sets a
`Message::Request` aside in `held` whenever `Server::must_wait()` is true, and
`must_wait` is `answering_a_rescan || rescan_wanted || !held.is_empty()`.
`scan_until_settled(true)` sets `answering_a_rescan`, so every request that
arrives during the configured rescan waits it out. That is
`docs/features/scan-interleave/README.md`'s order contract, decision 2 of
three, in as many words: *"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."*
**So this is a contract, not a routing bug, and this lane does not change it.**
Two things make relaxing it more than a one-line edit, and both belong to the
lead rather than to §P4b:
- **The order promise itself.** The configuration response *is* the message
queued ahead: a definition sent after the client answered
`lucisv.index.scope: "workspace"` is, under the one-message-at-a-time model
the loop promises, a definition sent after the workspace scope took effect.
Answering it off the 124-file prefix returns less than the settled index
would — which is precisely the trade the startup scan is allowed to make and
a rescan is not.
- **`gone` is deferred to the very end.** `finish_scan` computes what left the
scope and absorbs it in one call after the last file, and the
scan-interleave QA log names `must_wait` as the reason that is safe: *"every
scan capable of having `gone` files non-empty is a rescan … which `must_wait`
already blocks from answering anything mid-way."* A configured rescan whose
settings **narrow** the scope (an arriving `lucisv.exclude`, a filelist) has
a non-empty `gone`, and a mid-rescan answer could name a file that has
already left. Exempting rescans from `must_wait` would put that hole back.
**Filed for the lead, with the number.** The cost is unchanged by §P4b and is
re-measured below: a `textDocument/definition` arriving during the configured
rescan is answered in **2 582.5 / 2 588.5 / 2 600.4 ms cold** and **824.4 /
826.1 / 1 150.4 ms warm** (the control, in the same window: 2 520.9 / 2 552.9 /
2 602.8 and 891.5 / 893.9 / 895.4), against **under 0.4 ms** once the scan has
settled and **84.6–85.9 ms cold / 118.0–118.9 ms warm** during scans 1–2.
§P4b made this *more* likely to be what a user meets, not less: it is now also
what the **first** navigation of a warm session gets in four sessions of six —
see "The one regression" above. The narrowest change that
would buy it is a *fourth* state rather than a relaxation: distinguish a rescan
a **client message** asked for from the one the server's **own settings pull**
asked for, and let only the latter answer mid-way — it is the one rescan of a
session with no user message queued ahead of it, and at startup its `gone` set
is empty because the configured scope is a superset of the widen's. That is a
new promise about a documented contract, so it is the lead's to rule on, not
this lane's to take.
## QA log
### 2026-09-08 — QA agent, §P4b + §P4b2 + §P4b3 (one pass over the whole uncommitted tree)
**Verdict: PASS.** All three passes verified together, since they sit on one
uncommitted tree and each later pass amends the one before it. Gates are
clean, the pure move is proven structurally, every safety-net widening was
re-attacked and broke exactly as the dev's own log said it would, three live
process-level attacks (kill -9 mid-scan, a torn last line, two concurrent
sessions) were run against a real `lucisv-server` and none corrupted the
store or crashed the process, and a reduced but real re-measurement on the
opentitan corpus reproduces the headline numbers within tolerance — most
strikingly the exact **1** result-count in every session tried, where the
whole lane exists to fix a **0**.
**Gates, guarded, main tree.** `cargo fmt --all -- --check`: clean.
`tools/guard.sh -m 8 -t 1800 -- cargo clippy --all-targets --all-features --
-D warnings`: clean (stricter than the plain gate — deny-warnings, no
suppressions), 0 exit. `grep` over every new/changed file and the diff for
`#[allow`: none added anywhere in this lane. `tools/guard.sh -m 8 -t 1800 --
cargo test --workspace --release`: **4 305 passed, 0 failed**, matching the
dev's count exactly; guard never fired (exit 0, largest RSS well under the
8 GiB cap). Per-binary against a fresh `git clone --local` at HEAD
`2434729` with no lane diff: **4 272 passed, 0 failed**. Diffing the two
runs' full `test <name> ... ok` line sets (not just the totals): **exactly
one test name lost**, `server::tests::settings::the_startup_pull_is_sent_
after_the_watcher_registration_on_the_wire`, which is the rename to
`the_startup_pull_is_the_first_thing_on_the_wire` the work log describes —
read side by side, same wire assertions, new name and new comment for the
new order. **One further test kept its name but changed shape**,
`a_file_opened_mid_scan_is_indexed_next_and_the_index_cannot_tell` (read
against the deleted `state.rs` at HEAD): the old body drove `Scan::index_next`
directly and asserted it refuses a second jump and a file not waiting; the
new body drives `Workspace::open_next` (no target-path argument — it just
re-ranks `scan.remaining()` around whichever buffers are open now) and keeps
the same end-to-end premise (the reopened file is indexed next, the finished
index is byte-identical to a one-shot scan). The two dropped assertions do
not have a direct analogue under the new API and I judge that acceptable
rather than a coverage hole: `open_next` takes no path to misuse, so
"jumps twice" and "a file not waiting cannot jump" are failure modes the new
shape cannot express, not failure modes nobody checks — `scan_order.rs`'s own
`a_path_handed_over_twice_is_one_file` and
`an_open_buffer_outside_the_scope_still_lends_its_folder` are the ordering
layer's equivalent guards, and they are new tests, not renamed ones. Nothing
else lost anywhere in the workspace; 34 new test names beyond the rename.
**Production line counts** (non-blank, non-comment, before `mod tests`,
same method as the dev's): `state/mod.rs` **1 064** (matches exactly),
`state/scan.rs` **99**, `scan_order.rs` **35**, `index_cache.rs` **339**,
`scan_trace.rs` **303**, `server/startup.rs` **150** total lines (no inline
test module — its tests live in `server/tests/startup.rs`), `server/mod.rs`
**158** total (the dev's own count method — bounded by an inline
`#[cfg(test)] mod tests { … }` — doesn't apply here either, since `mod
tests;` is a declaration pointing at the `tests/` directory; whichever way
it's counted it is nowhere near 600), `candidates.rs` **406**, `includes.rs`
**274** — all exact or within a few lines of the dev's figures and all
comfortably under 600. `state/mod.rs` at 1 064 is **not** a new violation:
it inherits `state.rs`'s pre-existing, already-tracked oversize (TODO §55;
CLAUDE.md's own re-measurement table already lists it), and this lane's own
Handshake 13 is explicit that `state.rs` is calls-only apart from the pure
split — every genuinely new file this lane added is under 400 lines.
**The pure move, proven, not just claimed.** `git diff -M` cannot detect the
rename (the new `state/` directory is untracked, so git has nothing to
diff it against), so I compared structurally instead: `git show
HEAD:crates/lucisv_server/src/state.rs` against the new `state/scan.rs`.
All six named types (`Sources`, `Analyzed`, `HeldAnalyses`, `Scan`,
`ScanKind`, `IndexEvent`) are gone from `state/mod.rs` and present in
`state/scan.rs` with `pub(super)` visibility on every field — exactly
"visible where they were before: inside `crate::state` and nowhere else."
Comparing `Scan`'s field list old vs. new field-by-field: every field from
`state.rs` is still there in the same relative order, and the only
additions (`head`, `buffered` replacing the old `Vec<(PathBuf, String)>`,
`includes`, `unread`) are exactly the §P4b3 lazy-read/ordering fields the
work log describes adding — nothing unaccounted for. `crate::state::{Scan,
IndexEvent}` really is `pub use scan::{IndexEvent, Scan}` in `mod.rs`, so no
external path moved. This is a pure move with a clearly-scoped, tested,
separately-described behavioural delta layered on top — which is what the
lane claims, not silently more.
**Persistence safety — re-attacked, not just read (invariant-grade, per
CLAUDE.md).** All attacks below ran against a real `lucisv-server` binary,
either as live subprocess attacks (small synthetic fixtures — 60 and 2 000
tiny modules, under this QA's scratchpad, opentitan never touched for
anything destructive) or as source sabotage-and-reattack inside a
`git clone --local` at HEAD `2434729` with this lane's working-tree diff
applied (confirmed identical `git status --porcelain` to the main tree; all
sabotages reverted and the four touched files diffed byte-identical to their
pre-sabotage copies before moving on).
- **(a) Kill mid-scan, cold store.** A 2 000-file fixture, SIGKILL'd after
13 notifications (store at that instant: 10 lines, 9 real records — a
genuine partial write, confirmed by line count far short of 2 000). The
next session did not crash, reported `2000 files indexed, 9 from cache`
(exactly the 9 survivors reused, the rest reparsed), and `workspace/symbol`
resolved files from both ends of the range (`mod0000`, `mod1000`,
`mod1999`) correctly.
- **(b) Truncated last line.** Filled a clean 61-line store (60 records),
then truncated the last 5 bytes off the final line with no trailing
newline. The next session reported `60 files indexed, 59 from cache`
(exactly the one torn record dropped and reparsed, the other 59 kept),
every symbol resolved including the reparsed one, and the store was
re-rendered to a clean 61-line/19 951-byte file afterward — the torn line
was dropped individually and compaction happened (not skipped), because
the load was not canonical.
- **(c), (d), (f) Duplicate path, another version's header, a gone file.**
Not re-run live as separate fixtures (the existing suite already builds
exactly these cases as fixtures); instead re-attacked at the guard level,
which is the stronger form CLAUDE.md asks for: widening `already_compact`
to just `self.dir.is_some()` (dropping the canonical/no-appends/
nothing-gone conditions) made **10 tests fail**, independently reproduced
in this session — the six named guard tests
(`a_canonical_store_nothing_appended_to_is_not_rewritten`,
`a_record_the_store_already_holds_is_not_appended_again`, and one each for
a duplicated path, an unreadable line, out-of-order records, another
version's header) plus
`compaction_keeps_one_line_per_path_and_drops_the_files_that_are_gone` and
`nothing_is_created_until_something_is_recorded` — matching the dev's own
claimed failure list exactly, re-derived independently rather than taken
on trust.
- **(e) Canonical store no-rewrite / an edited buffer triggers rewrite.**
Live, both halves. A warm session that opens a buffer and saves it with
**unchanged** text: store mtime, size and sha256 identical to the prior
session's. A warm session that edits the buffer and saves the **edited**
text (`textDocument/didSave` with a changed `text` payload, which is the
documented write-through trigger): store mtime, size (19 951 → 20 283
bytes) and sha256 all changed. Byte-identical stays byte-identical;
anything that differs by a byte is written through and recompacted, as
the Assumptions bullet promises.
- **(g) Two concurrent sessions over the same store.** A cold session and a
warm session started ~50 ms apart against the same `storagePath`, run
concurrently to completion. Neither crashed, both answered correctly
(`workspace/symbol mod1500` resolved in both), the store stayed readable
throughout and ended at exactly 2 001 lines (header + one line per file,
no duplication despite the concurrent writes), and a third, later,
ordinary session read it without incident.
- **(h) The deferred open never drops a hit.** Sabotaged `begin_scan` to set
`self.store = StoreOpen::Done` instead of `StoreOpen::Deferred(dir)` for
an empty whole scan — simulating "dropped" instead of "moved," the exact
regression QA's own §P4a review had warned about and the dev's log says it
guarded against. `state::tests::a_scan_with_no_files_neither_reads_the_
store_nor_rewrites_it` fails immediately (`read store: NotFound` — the
widen behind the empty scan can no longer find the store the deferral was
supposed to hand it). Reverted; the real code passes the same test. I did
not additionally build the "folder scope, then a `didOpen` into a new
folder" LSP-level scenario live — the unit test above already drives
exactly that scenario (empty default-scope whole scan, then a `didOpen`
triggering a widen that must still hit the store) at the same
granularity the dev's own test does, and I re-attacked its guard directly
rather than re-deriving it through a slower LSP harness.
None of the six clauses can be widened, dropped, or reordered without a test
failing from the failing side, confirmed by me rather than only asserted by
the dev.
**Staged startup.** (a) `a_client_that_answers_pays_one_scan_at_the_scope_
it_asked_for` passed in the full run; independently reproduced live on the
real opentitan corpus below (`scanprofile` shows exactly one `scan 1
(whole)` line per session, no separate widen/configured-rescan lines, for
the workspace scope). (b) Live-measured the bound with a client that
advertises `workspace/configuration` and never answers it: the first
`$/progress` notification landed at **2.0196 s** after `initialize` — the
2 s `CONFIGURATION_WAIT` bound, not before it and not meaningfully after it.
(c) `an_answer_behind_a_held_request_is_not_stranded_for_the_whole_bound`
passed; **re-attacked** by making `take_the_answer_out_of_held` a no-op —
the test then waits out its full 30 s bound (`30.023924208s` measured,
against the test's own `< 5s` assertion), independently reproducing the
"one warm session in three" defect the dev found by measuring, from the
failing side. (d) and (e) — the no-capability and rootless paths — run
unmodified inside the green full-suite pass; not separately re-attacked
given the volume already covered elsewhere in this pass. (f) The eight
scope-ladder cells are exercised unmodified by the existing `index-scope`
suite (green in the full run) and independently re-measured for the
`scan` phase below with file/hit counts matching the dev's own numbers.
**Coherence and the drain rule.** `Server::head_owed` — the fifth
`must_wait` clause and the whole of the drain rule — **re-attacked** by
forcing it to `false` unconditionally in `must_wait`. Against
`a_request_that_beats_the_answer_is_answered_from_the_users_own_folder`
(the *staged* burst, config-answer-then-`didOpen`-then-request) the
sabotage made no difference — that request is held by the `staging` clause
before the sabotaged clause is ever consulted, so this test alone would not
have caught the sabotage. Against
`a_did_open_answered_mid_scan_pulls_its_folder_in_front_of_the_request_
behind_it` (the *unstaged*, scan-already-running case, which is the one the
real opentitan measurement found) the sabotage broke it exactly as
predicted: `assertion left == right failed: one location, not none: []`,
`left: Some(0)`. So `head_owed` is load-bearing specifically for the
mid-scan-`didOpen` path, and the staged-burst test's pass-under-sabotage is
a property of which `must_wait` clause fires first for that message order,
not a hole — worth naming so nobody reads "one test didn't notice" as "the
guard is dead." **Lazy-read + `unread` live-attacked**: on a 2 000-file cold
scan, deleted a not-yet-reached file 6 notifications in; the session
finished cleanly reporting `1999 files indexed` (not 2 000, not an error,
not a crash) and the deleted module never appeared in `workspace/symbol` —
exactly the documented `unread` path, taken out of the index by the whole
scan that could not read it, with no cap-skip event. `mismatched_answers`
is exercised by the green `scan-interleave`/`scan_trace` suites and by my
own `scanserve`-shaped read of the P4b3 evidence (36/12 answers cold/warm,
0 mismatches — see Traceability); I did not additionally construct a
`didClose`-mid-scan or double-`didOpen` burst live, given the breadth
already covered.
**Re-measurement, on the shipped binary, no rebuild needed.** The main
tree's already-built `target/release/lucisv-server` is sha256
`7ab4955ee0ac174840fbe4c02528e178f0c7824a3836fa87aa90e35bf47cdd3b` — checked,
matches the dev's quoted hash exactly, confirmed untouched by anything in
this QA pass. (A `git clone --local` at HEAD with the diff applied also
reproduced that exact hash on its first build, before any sabotage; later
rebuilds of that clone, after several edit/revert cycles, landed on a
different-but-source-identical hash — `diff -rq` against the main tree's
`crates/` shows zero differences, so this is this toolchain's release build
not being bit-reproducible across separate invocations, not a functional
difference, and it never touched the untouched main-tree binary used for
every number below.) Reduced scope, disclosed rather than padded: I re-ran
`scan` (all 8 cells, 3 tries), one `scanprofile` pass and one `rss` pass on
real opentitan (`0098135264`, three pre-existing modified files, checked
before/after — unchanged both times) rather than the dev's full ~20-cell
matrix; load average during my run was **3.79–6.07**, busier than the
dev's own quiet windows in places, which explains some of the drift below.
| cell | dev (P4b3) | this QA | delta |
|---|---:|---:|---:|
| first useful, cold, ms / count | 249.13/249.70/248.16, **1** | 266.29/265.31/268.04, **1** | +7.0% mean |
| first useful, warm, ms / count | 272.78/290.81/268.52, **1** | 287.05/303.26/281.86, **1** | +4.8% mean |
| settled workspace, cold | 2 645.95 | 2 859.09 (3 067.6/2 754.7/2 754.9) | +8.1% |
| settled workspace, warm | 980.31 | 1 002.05 (989.3/1 003.0/1 013.9) | +2.2% |
| `scanprofile` workspace, cold, scan 1 | 2 624.90 | 2 631.41 | +0.25% |
| `scanprofile` workspace, warm, scan 1 | 983.95 | 1 002.36 | +1.9% |
| rss idle, cold max | 505 200 KiB | 504 000 / 499 152 KiB | −0.24% |
| rss idle, warm max | 432 736 KiB | 427 792 / 428 512 KiB | −1.1% |
**The result-count finding — the one that matters most — reproduces
exactly**: `1` in every session I ran, cold and warm, where the whole lane
exists to fix a `0`. The traced `scanprofile` rows also reproduce the
mechanism, not just the headline: warm `opens=1, compactions=0, repeats=1`
(one open, no rewrite, the open buffer's own duplicate record correctly
skipped), cold `opens=1, compactions=1` (a genuine first fill really does
compact), `work_kib=3` against a clean-fixture size (matching the dev's
"34 973 → 0–16" claim), `store_before_kib=store_after_kib=45396` warm (no
growth), and the memory-table fields — `reference_sites=457666`,
`fact_words=345127`, `cache_encoded_kib=45260`, `unit_names=3067`,
`index_files=3976` — **exact matches** to both the dev's and §P4a QA's own
independently-taken figures, which is strong evidence the index itself is
unperturbed by any of this lane's changes. The one cell outside a strict
±10% band on a sub-stage rather than a headline number is `read` (85.54 dev
vs. 112.78 mine, +32%) in the one traced `scanprofile` session; given every
coarser number above is within tolerance and the qualitative claims
(opens/compactions/repeats, `work_kib`, the memory table) match exactly, I
read this as machine-load noise on a fine-grained timer, not a mechanism
difference — noted rather than smoothed over.
**Traceability.** Beyond the numbers reproduced live above: cross-checked
`~/.cache/lucisv-perf/take5-p4b3/results.jsonl` directly (113 rows, labels
`P4b2`/`P4b3`, phases `scan`/`scanwait`/`scanprofile`/`scanserve`/`rss`/
`scopes`/`didopen` — all present as claimed). Exact field-level matches:
first-useful cold/warm ms arrays and `result_count: 1` both scopes; `rss`
cold/warm `rss_kib` arrays (505200/432736 maxima, matching the README's
quoted figures exactly); `scanserve` cold 36 answers / warm 12 answers
(matching "37"/"12"-shaped counts quoted in the README's §P4b2 table to the
one row that differs by version); `didopen` pinmux values. `~/.cache/
lucisv-perf/take5-p4b/` and `take5-p4b2/` evidence directories both exist
with the files the READMEs cite (`results-compaction-defeated.jsonl`,
`storecheck.py`, `results-preliminary-stranded-answer.jsonl`, etc.).
15+ numbers checked, all traced, none found only in a `-preliminary`-only
file.
**Opentitan status.** `git -C opentitan status --porcelain` checked before
and after every phase of this QA pass (gates, sabotage/reattack cycles,
live attacks, re-measurement): always exactly `hw/ip/aes/dv/tb/tb.sv`,
`hw/top_darjeeling/ip/ast/rtl/ast.sv`, `hw/top_earlgrey/ip/ast/rtl/ast.sv` —
never more, never fewer. Every attack that needed a corpus used a synthetic
fixture under this QA's own scratchpad, never opentitan.
**Guard outcome.** Every `cargo` invocation and every timed phase went
through `tools/guard.sh -m 8 -t 1800` (or a tighter `-t` for a single short
test); zero kills. The one 30 s-bound sabotage test was run with `-t 60` to
give it room to finish rather than being cut off mid-assertion.
**Fixes made:** none in code — every attack found the lane's own guard
working, not a hole. One stale intra-doc link noted, not fixed (outside
this QA's editable scope): `state/mod.rs`'s doc comment on `finish_widen`
still says `` [`IncludeGraph::absorb`] `` — that method is genuinely deleted
(confirmed: no `fn absorb` left in `includes.rs`, and no live caller
anywhere in `crates/`), so the doc link now points at nothing. It is a
comment, not a behaviour change, and neither `cargo fmt` nor the `-D
warnings` clippy gate catches it, but it is a loose end from the deletion in
Handshake 14 worth the lead's or the next lane's five-minute fix.
**Handshakes, for the lead.** Nothing here is a silent edit; `docs/topo.md`
confirmed untouched by this lane (`git status --porcelain` on it is empty).
1. `lucisv_core::walk::collect_files` — a request from §P4b3 (not this
lane's file) to hand the size cap the metadata the walk already
collected, filed as the next lane's first thing to measure.
2. `docs/features/folders-and-config/README.md`'s Assumptions sentence —
*"a pulled `lucisv.exclude`/`lucisv.filelist` costs one extra rescan when
it lands"* — is now stale for the common case (§P4b2 answers the pull
before the first scan whenever the client responds inside the 2 s bound;
the sentence is still true only for a late answer). Confirmed by reading
the file: unedited, correctly left for the lead per Handshake 10.
3. New-module topo edges from this pass, all additive per the READMEs:
`server/startup.rs`, `scan_order.rs`, `state/scan.rs`,
`crate::scan_trace::{source_reads, count_read}`; the deleted
`IncludeGraph::absorb`; the amended contracts in `index-persistence`
(compaction skip, deferred open), `index-scope` (read moment, walk
order), `scan-interleave` (the drain rule, `head_owed`), and
`indexing-ux` (skip accounting, per-file log order) — each has its own
dated entry, read and cross-checked against the code in this pass.
**My own read of the first-answer trade, since the brief asks for it.**
250/275 ms correct in every session I tried (12 of 12, and this QA's own 6
more agree) against the REF's 84/208 ms that was empty or wrong four
sessions in six under staging alone — I'd take the slower-but-right answer
every time for a `definition` request; an editor user who gets `[]` when
the answer exists has no way to tell that from "there really is no
definition," while a 250 ms wait is invisible against typing latency. The
walk-bound floor this lane files for the next one (`discovery` at 158 ms,
58% of the warm answer) looks like the right next target precisely because
it is now the *only* remaining lever — everything else on the original
§P4a list is spent.
### 2026-09-08 — QA agent (gates, no-behaviour-change, cost, arithmetic, coherence)
**Verdict: PASS.** No behaviour changed, the instrument's own cost is inside
tolerance, every headline number in this README's tables reproduces from the
dev's own `results.jsonl` (and independently, in fresh sessions run for this
QA pass), and the harness's coherence check is real. One code-organization
observation and one safety note on the §P4b recommendation are filed below;
neither is a defect in this lane, which implements no optimization.
**Gates, guarded, main tree.** `cargo fmt --all -- --check`: clean.
`cargo clippy --all-targets`: clean, `grep -rn '#\[allow' <diff>` empty — no
new `#[allow]`. `tools/guard.sh -m 8 -t 1800 -- cargo test --workspace`:
**4 272 passed, 0 failed**, matching the dev's count exactly. Compared
per-binary against a fresh clone at HEAD `8e65da1` (the commit immediately
before this lane's uncommitted diff — confirmed HEAD really is that commit):
baseline **4 262 passed**. Normalizing both logs' `Running …` / `test
result:` lines and diffing them line-for-line: the **only** difference in the
whole workspace is `lucisv_server`'s unittest binary, **1 564 → 1 574
(+10)**, exactly the ten new tests in `scan_trace.rs`
(`a_trace_that_is_off_…`, `…is_on_…`, `the_first_publish_is_…`,
`cache_work_reports_…`, `every_line_names_its_scan_…`, five in
`server/tests/scan_trace.rs`). Zero tests lost or weakened anywhere else.
Zero guard kills.
**Production line counts.** `scan_trace.rs`: 215 lines before `#[cfg(test)]
mod tests` (non-blank, non-comment) — matches the dev's figure exactly.
`index_cache.rs`: 283 lines before its `mod tests` (the `#[cfg(test)] pub fn
dir` helper at line 150 is a single test-only accessor inside the production
section, not the test module, and is excluded correctly by both the dev's
count and mine) — matches exactly. `state.rs` **grew from 988 to 1 099
non-blank/non-comment production lines (before `mod tests`), +111** —
measured against the same HEAD-8e65da1 clone with the same method. That is
more than "calls only" reads as: three new private methods appear
(`opened_trace`, `measure_work`, `landed`, roughly 60 of the 111 lines)
alongside the `trace.now()`/`ScanTrace::add(...)` call pairs threaded through
`begin_scan`/`begin_widen`/`finish_whole_scan`/`finish_widen`. `state.rs` was
already one of the files over the CLAUDE.md guidance ceiling and carries a
filed decomposition (TODO §55); this lane continues to grow it. **Not a
defect** — the three new methods are pure measurement (walks/sums/`Instant`
math), not business logic, and moving them out would need `Scan`'s and
`Workspace`'s internals exposed more widely than a single-purpose trace
module should be — but it is exactly the kind of growth the file-size rule
asks an agent to flag rather than wave through, so it is filed here for the
lead's decomposition planning rather than treated as a QA blocker.
**No behaviour change — hunks read.** Every non-trace line touched in
`state.rs`, `server/index.rs`, `server/mod.rs`, `server/client.rs`,
`candidates.rs`, `includes.rs`, `index_cache.rs`, `vlog_semantic`'s
`workspace/index.rs`/`workspace/mod.rs`/`lib.rs` is either (a) a call-site
signature growing a `trace: bool` parameter with every existing caller
passing `false` (four call sites in `state.rs`'s own tests, three in
`perf.rs`, confirmed by `git diff`), (b) an `Instant`/counter read wrapped
around an unchanged decision (`facts_for`'s hit/miss test, `record`'s
encode-then-append, `compact`'s unconditional call and its dir-then-rename
sequence are byte-for-byte the pre-existing logic), or (c) a new read-only
query (`table_sizes`, `Candidates::sizes`, `IncludeGraph::sizes`,
`IndexCache::work`/`entry_count`/`encoded_bytes`) that no existing call site
invokes. No `if trace.on()` branch anywhere skips or alters a decision that
used to run unconditionally — it only skips *measuring* it. Confirmed by
running the code, not only reading it (below).
**No behaviour change — running it.** Built the pre-lane baseline from a
clean `git clone --local` at HEAD `8e65da1ba82` (`cargo build --release
--locked -p lucisv_server -p lucisv`, guarded) and compared it against the
tree's own release binary, sha256 `08093a3a2b9c…` — the exact binary the
dev's README quotes, confirming this QA measured the same artifact.
- `scan` phase (quiet), all six (scope × cache) cells, both binaries: **every
`$/progress end` file count is identical** — 124/1/3 976 files by scope,
123/3 975 "from cache" by warmth, 3 skipped, for both binaries, every cell.
- `scopes` phase (definition/typeDefinition/hover/references/
documentHighlight/signatureHelp/inlayHint/`workspace/symbol` at the `aes`
instantiation, three scopes): **24/24 `result_count` fields identical**
between the two binaries, 0 mismatches.
- `didopen` phase (the four files the 2026-09-05 table used, including the
pinmux row) and `nav` (18 per-cursor requests): **20/20 `result_count`
fields identical**, 0 mismatches; `didOpen pinmux_reg_top.sv -> definition`
116.0 ms baseline vs 118.4 ms instrumented (single try each, §46's fix
intact, well inside session-to-session noise).
- `git -C opentitan status --porcelain` after every one of the above: always
exactly the three pre-existing modified files.
No exposed `lucisv/index` status method or wire-level fingerprint exists in
this codebase (grepped `crates/lucisv_server/src` and `crates/vlog_semantic`
for `fingerprint`/`lucisv/index`); `WorkspaceIndex::fingerprint()` is a
Rust-internal test-only tool used inside `vlog_semantic`'s own suite, not
reachable from an external LSP client. The 44/44 identical `result_count`s
above plus the file-count identity across every scope/cache cell is the
external-observer equivalent of the fingerprint check the brief asked for,
and it is a stronger check than a single hash would be — it is 44 independent
observations across three request families, and it caught nothing.
**The instrument's cost.** `scan` phase (quiet), 3 fresh sessions,
independently re-run (own `results.jsonl` under this QA's scratchpad):
cold **2 836.34 / 2 821.32 / 2 826.97 ms** (mean 2 828.2; REF mean 2 863.85,
**−1.2 %**; dev's own quiet re-take mean 2 922.85, **+2.1 %** on means but
this session's load average was lower, 4.6–7.2 vs the dev's 4.1–5.0 and the
REF's 2.9–4.6 — direction, not magnitude, is what matters here and it stayed
negative); warm **1 315.59 / 1 364.76 / 1 313.34 ms** (mean 1 331.2; REF
1 348.94, **−1.3 %**). First useful answer cold **85.46 / 87.15 / 86.87 ms**
(REF 84.42–85.87, +1–2 %); warm **208.84 / 209.82 / 210.65 ms** (inside REF
206.12–218.72). Then the **with-`--verbose` cost**, same binary, same
machine window (`scanprofile`'s per-session `settled_ms`): cold summed-scan
settle mean **2 811.2 ms** (−0.6 % vs the quiet re-take, i.e. verbose was
*not* measurably slower); warm **1 335.6 ms** (+0.3 % vs quiet). **`--verbose`
costs nothing measurable beyond noise — well under the 2 % the brief flags
as worth a finding.**
**Arithmetic, recomputed from the dev's own `results.jsonl`** (not
re-derived from prose): summing every named stage over a session's three
scans gives cold **2 794.09 ms / 96.56 %** of the 2 893.58 ms settled mean,
warm **1 262.28 ms / 94.71 %** of 1 332.72 ms — both match the README's 96.6 %
/ 94.7 % to rounding. **The empty first scan, confirmed from the raw rows**:
`workspace, warm cache, scan 1 (whole)` carries `read=0`,
`store_before_kib=store_after_kib=45396` and `cache_open=92.5`,
`compact=91.02` ms — a full open-and-rewrite of an unchanged 44.3 MiB file for
a scan that touches nothing. **Charged twice, confirmed**: scan 1 pays
`cache_open`/`compact` 92.5/91.0 ms, scan 2 (widen) pays 0.0/0.0 (it reuses
`self.cache` scan 1 left open — matches the `begin_widen` diff, which never
calls `IndexCache::open`), scan 3 (the configured whole rescan) pays a
*second* 90.96/91.37 ms and its own compaction shrinks the store back from
45410 to 45396 KiB. Sum 365.85 ≈ the README's 365.9 ms / 27.5 %.
**The empty scan is genuinely unconditional, read from source.**
`Server::started` (`server/mod.rs:373`) calls `server.scan_until_settled(false)`
*before* `server.request_configuration()` is ever sent (`server/mod.rs:399`
region) — the first whole scan cannot be gated on configuration because
configuration has not been asked for yet. `finish_whole_scan`
(`state.rs`) calls `self.cache.compact()` with no check on
`work.is_empty()` anywhere in the path. Both claims hold exactly as stated;
this is not an artifact of the test fixtures.
**First useful answer, reproduced independently** (`scanwait`, 3 fresh
sessions, own run): cold scan totals 0.57 + 85.63 = 86.2 ms against a
measured mean of 84.6 ms; warm 183.4 + 26.31 = 209.7 ms against a measured
mean of 210.5 ms — the same arithmetic the dev's README describes, holding on
an independent set of sessions with its own machine noise.
**Coherence, re-run** (`scanserve`, 3 fresh sessions per cache state):
during-scan latencies cold 82.6/84.3/85.0 ms, warm 207.9/209.1/211.3 ms;
**queued behind the configured rescan cold 2 546.7/2 562.7/2 594.6 ms, warm
888.5/892.8/931.3 ms**; after settle both states under 0.3 ms.
**`mismatched_answers = 0` across all 18 requests**, reproducing the dev's
exact finding. Read the check itself
(`tools/perf/phases_p4.py:265-268`): it takes one *settled* definition answer
after the scan goes quiet and compares every mid-scan answer's `result`
payload against it with `answer != settled_answer` — a real per-request
content comparison against the finished index's own answer, not a constant
and not a hash of an unrelated table. It is a narrower check than a full
index fingerprint (it only ever asks one cursor), but it is what an external
client can actually observe, which is what `index-scope`'s coherent-prefix
contract is about; 18 samples across 6 sessions and both cache states caught
nothing.
**Open buffers, the 100 cell** (2+ sessions, from the `scanprofile` re-run
above): settled mean 2 164.4 ms (dev 2 173.9 ms, agrees); final whole scan
(scan 4) `order` **59.2 ms** (dev 60.64 ms), `overlay + publish_overlay`
**18.34 ms** (dev's combined 19.67 ms), `overlays: 101` /
`counts.buffers: 101` confirming all 100 opened buffers plus the TB landed
via their own held analysis before the scan settled, matching the README's
"the 100 didOpens really preceded the settle" claim.
**Memory, re-taken** (`rss`, 3 fresh sessions, quiet binary): idle RSS cold
542 224/544 064/543 584 KiB = 529.5/531.3/530.8 MiB; warm 591 216/580 528/
577 888 KiB = 577.4/566.9/564.3 MiB — both agree with the dev's cold
531.0/529.0/529.9 and warm 574.8/565.2/564.8 to within session noise. **Peak
equals idle to the KiB in all six sessions again** (the 50 ms `ps -o rss=`
sampler never saw a transient above the settled reading). Store on disk
45 404 KiB (dev: 45 396 — 8 KiB of drift from repeated compactions across
sessions, immaterial). Table sizes re-read from an independent session's own
trace (`scanprofile`, scan 3 memory line): `reference_sites=457666`,
`fact_words=345127`, `cache_encoded_kib=45260`, `index_files=3976`,
`unit_names=3067` — every one identical to the dev's figures.
**The two instrument defects, verified fixed by diffing the preliminary and
final evidence files** (not just reading the work-log prose). Preliminary's
`workspace, cold cache, scan 3 (whole)` reports `cache_entries: 124` (what
the store held *before* the scan started — leftover from scan 2's widen);
the final file's same row reports `cache_entries: 3976` (what the finished
scan actually left resident, after all 3 976 records were written) — exactly
the "read at the start, not the end" bug the work log describes, now fixed.
`total_ms` differs by 1.5 ms between the two files on the same warm scan-1
row (185.26 vs 183.72), consistent with the size-walk-inflating-`total_ms`
bug being excluded after the fix. Confirmed the preliminary file's phase set
(`scanprofile`, `scan` only) **cannot** be the source of the `scanwait`/
`scanserve`/`rss` numbers quoted in this README — those phases are entirely
absent from `results-preliminary.jsonl`.
**Traceability — 15+ headline numbers checked against `results.jsonl`, all
matched, none traced to `results-preliminary.jsonl`-only fields**: scan 1
`read=0`; scan 1 warm `cache_open=92.5`/`compact=91.02`; scan 2/3 `read=124`/
`3976` (cold and warm); `cache_encoded_kib=45260`; `reference_sites=457666`;
`fact_words=345127`; the 100-buffer final scan's `order=60.64`/
`overlays=101`; `scanwait` cold `ms` array; `scanserve` cold
`mismatched_answers=0`; `rss` cold/warm `rss_kib` arrays — each an exact
field-level match, cross-checked in the section above.
**The `scan_chatter` quiet-detection fix, read** (`phases_p4.py:218-226`):
the busy test counts only `$/progress` and `textDocument/publishDiagnostics`
notifications, explicitly excluding `window/logMessage` — under `--verbose`
the server logs one such line per request, so counting it would make the
poll listen to its own noise and never terminate, which the work log and the
tracker's "Refusals / gaps" entry both describe as the first draft's actual
failure mode. Confirmed by inspection; the fixed loop terminated cleanly in
every `scanserve` session run for this QA pass.
**Handshake requests — six listed, all additive, `topo.md` untouched**
(`git diff`/`git status` on `docs/topo.md`: no changes from this lane, as
claimed): (1) `WorkspaceIndex::table_sizes() -> IndexTableSizes`; (2) the new
`scan_trace` module; (3) `trace: bool` on `begin_scan`/`begin_widen` plus
`take_scan_trace()`; (4) `Candidates::sizes`/`IncludeGraph::sizes`/
`IndexCache::work`/`entry_count`/`encoded_bytes`; (5) `Server::born` and
`Pending::Configuration`'s `Instant` payload; (6) the `verbose-timing`
amendment. `docs/features/verbose-timing/README.md` itself is untouched
(correctly left for the lead to reconcile at merge). **The "nobody parses
these lines" assumption is genuinely amended, not just asserted**: five tests
in `crates/lucisv_server/src/server/tests/scan_trace.rs` parse the emitted
lines with the same `key=value` splitting `tools/perf/phases_p4.py` uses
(`field`/`number` helpers), and `scan_trace.rs`'s own
`every_line_names_its_scan_and_is_one_line` pins the `scan N kind (…)` prefix
and the one-line-no-newline shape. The line contract is pinned by tests, not
only by convention.
**§P4b recommendation — my own safety read, beyond what the dev's hedge
already says.** `index-persistence`'s README gives **two** independent
reasons for reopening the cache at the top of every whole rescan (both also
in the `state.rs` comment the diff leaves untouched): (i) the cache
directory depends on settings (`index.cachePath`, `index.persist`) that
arrive by `workspace/configuration`, after the default-settings scan; (ii)
**a second session over the same workspace may have written records this one
has not seen** — cross-session freshness.
- **(a) skip compaction of an unchanged store** does not touch the reopen
decision at all — it only skips a rewrite when `store_before ==
store_after`/no records were written. Safe against both reasons; it never
changes *where* or *whether* the store opens, only whether an unchanged
file gets rewritten. I see no way this interacts with corrupt-store
recovery either, since `compact_now`'s temp-file-then-rename sequence is
unaffected — skipping it just means the append log stays unvacuumed a
little longer.
- **(b), first half (no store open for an empty work list), is not quite as
free as it reads.** Today only `begin_scan` (whole) calls `IndexCache::open`;
`begin_widen` never does — it relies on `begin_scan` having already opened
`self.cache` into the field a widen then reads through. If scan 1's open is
skipped outright because its work list is empty, and nothing else opens the
store before scan 2's widen runs, **the widen would silently lose every
cache hit** (all 124 files reparsed instead of served from the store) —
not a corruption, but a real regression against exactly the warm-start cost
this whole round is trying to cut, and a subtler one than "skip an
unconditional open" suggests. The 92.5 ms this half claims to save is real
only if the open is *deferred* to the first scan that actually needs the
store (i.e., moved, not dropped) — worth spelling out explicitly if the
lead rules this in.
- **(b), second half (reuse the store the session already read), is not safe
as a blanket rule against either of `index-persistence`'s two reasons.**
Against reason (i): if the pulled configuration changes `cachePath` or
flips `index.persist` between scan 1 and scan 3, reusing scan 1's
already-open cache would read/write the *wrong* directory (or keep writing
after the user asked for persistence off) for the rest of the session —
a behaviour regression against the persistence feature's own contract, not
merely a missed optimization. Against reason (ii): reusing the in-memory
store means a concurrent second session's writes between scan 1 and scan 3
are invisible to this one — but that direction is safe-but-suboptimal
(a missed cache hit still reparses correctly), never a wrong answer. My
read: **this half needs an explicit re-validation step (reuse only if the
resolved `cachePath`/`persist` are unchanged from what scan 1 opened,
reopen otherwise) before it can be called safe**, which is exactly what the
dev's own "contract question, not a free win" hedge is pointing at — I'm
narrowing which of the two documented reasons each half of (b) would
actually violate, not overturning the recommendation.
- (c) is correctly assessed as nothing to remove (one mid-scan publish, one
final absorb — verified from the same `results.jsonl` rows).
**Guard outcome.** Zero kills across every phase run for this QA pass
(gates, two release builds, and roughly a dozen guarded timed phases).
Largest resident set observed 591 MiB (7 % of the 8 GiB limit).
**Opentitan status.** `git -C opentitan status --porcelain` checked after
every phase in this QA pass (gates excluded, since no phase touches the
corpus during them): always exactly `hw/ip/aes/dv/tb/tb.sv`,
`hw/top_darjeeling/ip/ast/rtl/ast.sv`, `hw/top_earlgrey/ip/ast/rtl/ast.sv` —
never more, never fewer.
**Fixes made:** none needed. No code or doc changes beyond this QA log and
the TODO.md tick.
## Review
**2026-09-08 (lead, P4a).** Accepted, and the P4b ruling follows.
- The instrument is the plan's §P4a as written: disjoint stages, counters
not allocations, nothing changed in what a scan does (QA: 44/44 result
counts identical against the pre-lane binary; the stage sums re-derived).
- The structural finding is the one worth the whole stage: a workspace
session runs an empty scan at default settings before configuration
arrives, and that empty scan still opens the 45 MB store and rewrites it
byte-identically — 184 ms of a 1.33 s warm start — and the configured
scan's `compact` rewrites an unchanged store once more. That is also the
whole of the first-useful-answer gap between cold (82 ms) and warm
(208 ms).
- Warm has no dominant stage; the store's I/O is 27 % of it. Cold is 59 %
parse, which P4b may not touch; idle RSS retention is 7.7 %, so the
plan's −15 % is not on the table. The plan's goals are read honestly:
warm < 1 s reachable, the other two not.
- **Ruling, P4b — go, on exactly two of the recommendation's three:**
(a) `compact` is skipped when the session appended nothing, nothing is
gone and the loaded store was already canonical (one line per path, no
dropped lines), since the rewrite would be byte-identical; (b1) a scan
with an empty work list opens no store and compacts nothing (the open
is deferred to the first file that needs it, so the widen's hits are
untouched — QA's point). **(b2), reusing the store across rescans, is
refused:** the reopen exists for a mid-session cache-path change and for
a second session's compaction replacing the file under an append handle;
−91 ms does not buy that. Also in P4b: the configured rescan queues
navigation for 2.5 s cold / 0.9 s warm because only the empty scan
interleaves — find why, fix it if it is routing, file it if it is not;
and move the three trace helpers that landed in `state.rs` (+111 lines)
into `scan_trace.rs` as a pure move.
- Deviations accepted: `state.rs`'s growth (to be moved out in P4b); the
preliminary run kept unquoted.
**2026-09-08 (lead, P4b — three passes, one QA).** Accepted.
- The ruling's two items shipped as ruled — the compaction skip with its
four conditions and the deferred store open as a move, not a drop — and
each surfaced the next thing honestly: (a) was worth nothing until the
write-through learned to skip a byte-identical record; removing the
empty scan's 181 ms turned a race the `didOpen` had always won into one
it lost four times in six. Neither was papered over.
- The second and third passes are the plan's own sentences ("stage the
initial scan until configuration arrives, with a bounded fallback";
"shorten temporary source lifetimes"): one startup scan at the answered
scope, a 2 s bound observed on the receive itself, the corpus read a
file at a time in its own step, the open buffers' folders at the head
of the work list, and a held opening request answered inside the
startup scan once that head is published. The rescan order contract
(scan-interleave decision 2) is untouched; QA's persistence attacks —
a SIGKILL mid-scan, a truncated line, two concurrent sessions, a
deleted file at step time — all recover as documented.
- Numbers against the P0 reference: warm settle 1.33 → ~1.04–1.10 s
(the plan's < 1 s missed, honestly; the remaining store open is the
refused reuse), cold unchanged, warm idle RSS −15 to −20 %, the store
byte-identical across warm sessions, the 100-buffer ordering 61 → 2 ms,
the "queued behind the configured rescan" mode gone for startup, and
the first useful answer correct in 12 of 12 sessions at ~250 cold /
~275 warm. **That last number is the trade I accept:** the reference
answered in 84 / 208 ms only when the empty scan happened to win a race,
and otherwise after 1.1–2.5 s; a deterministic 250–275 ms correct answer
is the better contract. The gap to 84 is the workspace walk in front
of the folder, filed for loop 3 with the `walk::collect_files` metadata
request.
- Deviations accepted: the `state/` split (a pure move that also does a
third of TODO §55), `IncludeGraph::absorb` deleted with its last caller,
the two tests amended in place for the APIs they drove.
Docs applied at merge: the stale `absorb` link in `state/mod.rs`; the
folders-and-config Assumptions sentence; topo (the scan-interleave row
amended, the module ownership entries); the walk-metadata item and the
first-answer gap added to the loop-3 list.
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->