Files
lucisv/docs/features/index-lifecycle-r2/README.md
T

175 lines
37 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 -->
# Index Lifecycle & Fast Tombstone Removal (Round 2)
## Goal
Close four index/buffer lifecycle and symlink bugs identified in `docs/topo.md` (`#49`, `#63`, `#50`, `#51`):
1. **Topo #49 (`vlog_semantic` fast tombstone removal + `lucisv_server` `didClose`)**:
- Keep `FileId` slots stable across `WorkspaceIndex::remove_file` via a parallel `tombstoned: Vec<bool>` mask and localized `replace_facts(at, empty_facts(path))` instead of shifting `FileId`s and running a full `merge()`.
- Compact tombstones on `merge()` / `absorb()`, revive tombstoned slots cleanly on `update_facts`, hide tombstones from all public queries (`files`, `file_id`, `path`, `defines`, `facts_for`, `files_spelling`, `files_mentioning`, `files_naming_in_macros`, `counts`, `table_sizes`), and remap dense IDs inside `fingerprint()` so a tombstoned index matches a fresh `WorkspaceIndex::build` byte-for-byte.
- Reconcile `didClose` in `lucisv_server` (`notification.rs` / `state/incremental.rs`): remove closed excluded/unlisted buffers via the fast tombstoned `remove_one` path (using `set_file_words` + `refresh_names` to keep removal sub-millisecond), and re-index dirty/unsaved closed in-scope buffers from disk via localized `replace_facts` (or remove if missing on disk).
2. **Topo #63 (Owner decision 2: always keep disk index record for `doc.large`)**:
- Standardize on always keeping the on-disk index record (subject to `lucisv.index.maxFileSize`) for open `doc.large` buffers across open, close, save, `largeFile.threshold` flips, widen, and whole scans (`state/discover.rs`, `state/rescan.rs`, `state/buffers.rs`, `state/incremental.rs`), achieving zero index mutation on `didOpen`, `didClose`, and `largeFile.threshold` flips.
3. **Topo #50 (Unheld buffers opened mid-scan)**:
- Reconcile buffers opened mid-scan (`state/rescan.rs`, `state/scan.rs`, `server/index.rs`) so excluded, unlisted, or unsaved-edited non-large buffers opened while a scan is in flight are absorbed into the running scan equivalently to being opened before the scan started.
4. **Topo #51 (Symlinked files — one file, one canonical spelling)**:
- Deduplicate and resolve file identity via `(dev, ino)` on Unix / `fs::canonicalize` fallback on non-Unix without basename-equality gating across discovery walks, `overlay_buffers`, `begin_widen`, `state/buffers.rs`, `state/incremental.rs`, and `state/watched.rs`, enforcing one deterministic canonical spelling in the index regardless of which symlink is open.
## Assumptions
- `WorkspaceIndex::files()` keeps returning `&[PathBuf]` containing only live files in path order so existing slice callers remain source- and ABI-compatible.
- Within a scope, canonical symlink spelling precedence follows deterministic path-sorted discovery order (the lexicographically smallest in-scope spelling for a given file identity), matching existing directory-symlink precedence and preserving symlinked workspace roots.
- During non-interleaved small scans (`scan.total() <= INTERLEAVE_ABOVE && !scan.discovery_pending()`), notifications remain queued until after `scan_once()` finishes, consistent with `server/index.rs`.
## Handshakes
- **Dense `FileId(i)` callers closed (`vlog_semantic`, `lucisv_server`, `lucisv_mcp`)**:
- After tombstoned `WorkspaceIndex::remove_file`, `index.files()` shrinks while remaining live files retain their pre-tombstone `FileId`s until the next full `merge()` or `absorb()`.
- Added `WorkspaceIndex::live_files(&self) -> impl Iterator<Item = (FileId, &PathBuf)> + '_` (`crates/vlog_semantic/src/workspace/index.rs`) yielding only live `(FileId, &PathBuf)` pairs.
- Updated `crates/lucisv_server/src/state/sources.rs` (`want_macro_text`), `crates/lucisv_server/src/candidates.rs` (`macros_of`, used by `from_words`, `remove_file`, `absorb`, and `update_words`), `crates/lucisv_mcp/src/tools/names.rs` (`similar`), `crates/lucisv_mcp/src/tools/diagnostics.rs` (`Census::of`), and `crates/lucisv_server/src/state/tests/reindex_perf.rs` to iterate `index.live_files()` instead of `0..index.files().len()` / `.enumerate()`.
- **Symlinked open-buffer identity lookup wired across server handlers**:
- `Workspace` (`crates/lucisv_server/src/state/mod.rs`, `state/buffers.rs`) exposes `index_file_id`, `held_path_for`, `index_path_for`, `is_same_file`, `open_document_for_path`, and `document_for_path`, matching exact path first and falling back to `(dev, ino)` / canonical path while preserving ASCII case-mismatch separation (`case_only_mismatch`).
- Wired into `crates/lucisv_server/src/nav.rs`, `crates/lucisv_server/src/lint.rs` (`own` in `IndexMentions` and canonical `LintContext` path for `module-filename` / `package-filename` / config discovery), `crates/lucisv_server/src/state/sources.rs`, `crates/lucisv_server/src/ports.rs`, `crates/lucisv_server/src/rename.rs`, `crates/lucisv_server/src/extract.rs`, `crates/lucisv_server/src/inline_module.rs`, `crates/lucisv_server/src/imports.rs`, `crates/lucisv_server/src/completion/related.rs`, `crates/lucisv_server/src/hierarchy/calls.rs`, `crates/lucisv_server/src/includes.rs` (`resolve_for_doc`, `reachable_from`), and `crates/lucisv_server/src/hover.rs` (`narrowed_to_the_include_graph`).
- **Active-scan absorbed buffer tracking (`Workspace` -> `didClose`)**:
- `Workspace` (`crates/lucisv_server/src/state/mod.rs`) maintains `ScanAbsorbed` (canonical/open paths plus `DirId -> PathBuf` with `case_only_mismatch` guard), cleared on `begin_scan` and `finish_scan` (`state/rescan.rs`), and populated whenever open-buffer text/facts are absorbed in `begin_scan`, `scan_step`, or `reconcile_open_buffers_into` (`state/reconcile.rs`, covering `pos >= scan.at`, `pos < scan.at` staged updates, and `pos == None` excluded/unlisted/oversize entries).
- `Workspace::closing_affects_running_scan` (`state/incremental.rs`) consults `scan_absorbed` alongside out-of-scope and disk-mismatch checks without changing `server/mod.rs` or `server/index.rs` signatures.
- **`IncludeGraph::remove_file` linear rebuild outside owned files**:
- `IncludeGraph::remove_file` (`crates/lucisv_server/src/includes.rs:284`) calls `relearn(known)` across all live paths and lowercase folded strings on each removal. That rebuild dominates excluded-file `didClose` latency on a 4k-file index (~2.49 ms/removal in release, ~10.19 ms in debug) while `WorkspaceIndex::remove_file` itself is tombstoned and constant-slot (in-scope clean open+close cycles average ~88.9 µs in release / ~134.7 µs in debug on a 2k-file index). Left untouched per lane file ownership for a follow-up incremental `IncludeGraph` update.
## Status / TODO
- [x] Topo #49: Fast tombstoned `WorkspaceIndex::remove_file` and `didClose` index reconciliation + 4k/2,000-cycle perf test
- [x] Topo #63: Always keep disk index record for `doc.large` + differential tests
- [x] Topo #50: Reconcile unheld/unsaved buffers opened mid-scan + regression tests
- [x] Topo #51: Canonicalize symlinked file identities without basename gating across discovery, widen, buffers, incremental, watched + all 6 `filelink` scenario tests
- [x] QA Fix Pass (F1–F5): `WorkspaceIndex::live_files` + `0..files().len()` audit across `lucisv_server`/`lucisv_mcp`, non-canonical symlink handler wiring, mid-scan/widen oversize symlink canonicalization, and `largeFile.threshold` drop disk reconciliation
- [x] R2 Closing Pass (R2-F2 & R2-F3): Symlink-aware `` `include `` resolution / macro hover narrowing (`includes.rs`, `hover.rs`) and `Workspace::scan_absorbed` tracking across `begin_scan` / `scan_step` / `reconcile_open_buffers_into` / `closing_affects_running_scan` (`state/{mod.rs,rescan.rs,reconcile.rs,incremental.rs}`)
## Work log
- **Topo #49 (`vlog_semantic` + `lucisv_server`)**: Added `tombstoned: Vec<bool>` to `WorkspaceIndex` (`crates/vlog_semantic/src/workspace/{mod.rs,index.rs,update.rs}`) so `remove_file` clears the slot via `replace_facts(at, empty_facts(path))` without shifting `FileId`s or running full `merge()`, revives tombstones on `update_facts`, compacts on `merge()`/`absorb()`, hides tombstones from queries/counts, and monotonically remaps `FileId`s in `fingerprint()` to match a fresh build. Wired `DidCloseTextDocument` in `crates/lucisv_server/src/server/notification.rs` and `close_and_reconcile` / `remove_one` in `crates/lucisv_server/src/state/incremental.rs` so closed excluded/missing buffers are removed via fast tombstones and dirty/unsaved in-scope buffers revert from disk.
- **Topo #63 (`lucisv_server`)**: Standardized on Owner decision 2 (keeping on-disk index records subject to `maxFileSize` for open `doc.large` buffers) across `state/{buffers.rs,discover.rs,rescan.rs,incremental.rs}` and updated `state/tests/{large_file.rs,open_buffers.rs,widen.rs}` + `server/large_file.rs` comment.
- **Topo #50 (`lucisv_server`)**: Added `reconcile_open_buffers_into` in `state/rescan.rs` (invoked from `open_next`) so unheld or unsaved-edited buffers opened mid-scan are absorbed into the finished index consistently with pre-scan opens.
- **Topo #51 (`lucisv_server`)**: Replaced basename-gated symlink aliasing with `(dev, ino)` / canonical-path deduplication (`dedup_by_identity`) and deterministic canonical precedence across `state/{mod.rs,buffers.rs,discover.rs,scan.rs,rescan.rs,watched.rs,incremental.rs}`.
- **Tests**: Added 9 server lifecycle integration tests in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs` (including all 6 same-name/different-name symlink scenarios, `doc.large` differential checks, mid-scan opens, and 2,000-cycle `didClose` / open+close timings) alongside new `WorkspaceIndex` tombstone/perf tests in `crates/vlog_semantic/tests/workspace.rs`.
- **2026-11-26 QA Fix Pass (F1–F5)**:
- **F1**: Added `WorkspaceIndex::live_files()` (`crates/vlog_semantic/src/workspace/index.rs`) and replaced `0..index.files().len()` / `.enumerate()` `FileId` indexing across `state/sources.rs` (`want_macro_text`), `candidates.rs` (`macros_of`), `lucisv_mcp/src/tools/names.rs` (`similar`), `lucisv_mcp/src/tools/diagnostics.rs` (`Census::of`), and `state/tests/reindex_perf.rs`. Added MCP unit tests for tombstoned slot 0 in `names.rs` and `diagnostics.rs` and un-ignored both F1 tests in `lifecycle_r2.rs` (extending `Candidates::remove_file` coverage).
- **F2**: Added `Workspace::index_path_for` / `Workspace::is_same_file` (`state/mod.rs`) and `Workspace::open_document_for_path` (`state/buffers.rs`) while preserving `case_only_mismatch` separation in `index_file_id` and open-buffer lookup; wired across `nav.rs`, `lint.rs` (`own` and canonical `LintContext` path), `state/sources.rs`, `ports.rs`, `rename.rs`, `extract.rs`, `inline_module.rs`, `imports.rs`, `completion/related.rs`, and `hierarchy/calls.rs`. Un-ignored `qa_topo_51_non_canonical_symlink_open_buffer_breaks_references_lint_and_rename`.
- **F3 & F4**: Extracted `crates/lucisv_server/src/state/reconcile.rs` (keeping `state/rescan.rs` well under 600 production lines), carried in-scope `canonical_ids` across `oversize` skips on `Sources` / `Scan` (`state/{scan.rs,discover.rs,reconcile.rs}`) so mid-scan non-canonical symlinks over `maxFileSize` canonicalize identically to pre-scan, and updated `begin_widen` (`state/rescan.rs`) so open non-large buffers promote to lexicographically earlier symlinks even when over `maxFileSize`. Un-ignored both F3 and F4 tests in `lifecycle_r2.rs`.
- **F5**: Added `Workspace::reconcile_large_buffer` (`state/reconcile.rs`) and wired `Server::reclassify_large_buffers` (`server/large_file.rs`, `server/notification.rs`) so buffers flipping `large == false -> true` reconcile back to disk (or drop if outside scope/oversize/missing) when dirty/previously indexed unsaved edits exist, while doing zero index work for clean buffers whose disk record matches. Un-ignored `qa_topo_63_threshold_drop_after_unsaved_edit_indexed_via_widen_diverges_from_fresh`.
- **2026-11-26 Closing Pass (R2-F3 Option B)**:
- **R2-F3**: Added `ScanAbsorbed` (`paths: HashSet<PathBuf>`, `ids: HashMap<DirId, PathBuf>` with `case_only_mismatch` guard) on `Workspace` (`crates/lucisv_server/src/state/mod.rs`), cleared in `begin_scan` and `finish_scan` (`state/rescan.rs`), and recorded whenever open-buffer text/facts enter the running scan (`begin_scan` overlays, `scan_step` pops from `buffered`/`analyzed`, and `reconcile_open_buffers_into` across `pos >= scan.at`, `pos < scan.at` staged updates, and `pos == None` excluded/unlisted/oversize entries in `state/reconcile.rs`). Updated `Workspace::closing_affects_running_scan` (`state/incremental.rs`) to return `true` when `scan_absorbed` matches (including aliases before mid-scan publish and buffers flipped to `doc.large` with no surviving alias), keeping `server/mod.rs` and `server/index.rs` untouched. Un-ignored `qa_r2_f3_mid_scan_dirty_open_reverted_and_closed_leaves_stale_index` and added `r2_f3_mid_scan_dirty_reverted_and_closed_converges_across_all_scan_phases` in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`.
- **2026-11-26 Plan Review Surgical Fix (R2-F2b, R2-F3a, R2-F3b)**:
- **R2-F2b**: Normalized `includes::resolve_for_doc` (`crates/lucisv_server/src/includes.rs`) output through `ws.index_path_for(&found)` so symlinked-directory includes resolve to canonical indexed paths.
- **R2-F3a & R2-F3b**: Simplified `Workspace::closing_affects_running_scan` (`crates/lucisv_server/src/state/incremental.rs`) to return `true` whenever `self.scan_absorbed.contains(path, &target) || self.has_other_document_for(uri, path)`, covering both `already_same` skipped secondary symlinks and `doc.large`-flipped absorbed symlinks closed mid-scan while a second alias remains open. Un-ignored all three `qa_r2_*` repro tests in `lifecycle_r2.rs`.
## QA log
- **Verdict**: `FAIL` (5 concrete findings blocking acceptance: F1–F2 handshake regressions/breakages across `lucisv_server` and `lucisv_mcp`, F3–F4 `#51`/`#50` oversize symlink canonicalization gaps in `state/rescan.rs`, F5 `#63` threshold-drop stale unsaved index in `server/large_file.rs`).
### Audit & Hygiene
- **Production line counts & safety** (verified on all 12 modified production files before `mod tests`): `crates/lucisv_server/src/server/large_file.rs` (110), `server/notification.rs` (287), `state/buffers.rs` (110), `state/discover.rs` (487), `state/incremental.rs` (221), `state/mod.rs` (104), `state/rescan.rs` (590), `state/scan.rs` (137), `state/watched.rs` (123), `crates/vlog_semantic/src/workspace/index.rs` (351), `workspace/mod.rs` (167), `workspace/update.rs` (380) — all `<= 600` non-blank, non-comment lines with 0 `unwrap()`, `expect()`, `unsafe`, `panic!`, or `#[allow` in modified production code.
- **Author stamp**: `python3 tools/stamp_author.py --check` exited `0` (`would stamp 0 files; left 249 untouched`).
### Findings
- **Finding F1 — `#49` Handshake Drift: callers iterating `0..index.files().len()` misalign/skip live `FileId`s after tombstone removal**
- `crates/lucisv_server/src/state/sources.rs:338` (`want_macro_text`): Closing an excluded file (`ignored/a_excl.sv`, `FileId(0)`) shrinks `index.files().len()` to `2` while `z_mac.sv` remains at `FileId(2)`. `want_macro_text` skips `FileId(2)`, omitting `z_mac.sv` from `rename_traced` macro-text checks and causing divergent macro warnings vs a fresh server. Reproduced in `qa_topo_49_tombstone_before_live_macro_breaks_rename_macro_text_fanout` (`#[ignore]` in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`).
- `crates/lucisv_server/src/candidates.rs:837` (`macros_of` via `Candidates::from_words` / `Candidates::remove_file`): With `a_excl.sv` tombstoned (`files().len() == 1`, `z_mac.sv` at `FileId(1)`), `macros_of` returns `[]` instead of `["LIVE_MAC"]`. Reproduced in `qa_topo_49_candidates_macros_of_breaks_when_tombstone_precedes_live_macro_file` (`#[ignore]` in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`).
- `crates/lucisv_mcp/src/tools/names.rs:191-192` (`similar`) and `crates/lucisv_mcp/src/tools/diagnostics.rs:267-269` (`Census::of`): Same `0..index.files().len()` / `enumerate()`-to-`FileId` assumption skips `FileId(1)` defines (`[]` vs `["LIVE_MAC"]`) and assigns shifted `FileId(0)` inside `Census::of` against `own = Some(FileId(1))` (making `Census::outside` falsely return `true`). Verified via transient unit tests on tombstoned `WorkspaceIndex` and reverted cleanly from `crates/lucisv_mcp`; note `lucisv_mcp`'s `Project::refresh` (`crates/lucisv_mcp/src/project/mod.rs:175`) currently updates `self.index` only through `absorb(...)` (which compacts tombstones), so `lucisv_mcp` hits this only via direct `WorkspaceIndex::remove_file` callers.
- **Finding F2 — `#51` Handshake Drift: non-canonical symlink open buffer fails references, lint, and rename**
- When `a_link/link_a.sv -> z_real/real_b.sv` is canonically indexed as `a_link/link_a.sv` and the client opens `z_real/real_b.sv`, callers matching `doc.path` verbatim instead of `Workspace::index_file_id` / `Workspace::held_path_for` / `Workspace::document_for_path` break live LSP operations. Reproduced in `qa_topo_51_non_canonical_symlink_open_buffer_breaks_references_lint_and_rename` (`#[ignore]` in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`):
- `textDocument/references` (`crates/lucisv_server/src/nav.rs:232,295`) returns `1` ref instead of `2` (cross-file reference in `tb/tb.sv` dropped).
- Diagnostics (`crates/lucisv_server/src/lint.rs:244`) pass `own = None` to `IndexMentions`, so `mentioned_outside("dead_sig", None)` sees `dead_sig` in canonical `a_link/link_a.sv` and suppresses `unused-signal` (and `module-filename` checks against `real_b.sv` rather than `link_a.sv`).
- `rename_traced` (`crates/lucisv_server/src/state/sources.rs:206`) overlays `z_real/real_b.sv` over indexed `a_link/link_a.sv` and refuses both from `z_real/real_b.sv` and from `tb/tb.sv` with ``Err("`dut` is declared in more than one indexed file; lucisv will not guess which declaration this rename means.")`` (and `crates/lucisv_server/src/ports.rs:555` `encode_edit` similarly checks `doc.path.as_deref() == Some(path)`).
- **Finding F3 — `#50` + `#51`: mid-scan non-canonical symlink over `maxFileSize` diverges from pre-scan open**
- `crates/lucisv_server/src/state/rescan.rs:518-524` (`reconcile_open_buffers_into`): When both `z_real/dut.sv` and `a_link/dut.sv -> z_real/dut.sv` exceed `maxFileSize` (remaining `<= largeFile.threshold`), `a_link/dut.sv` is excluded by `oversize` and absent from `scan.work`. Opening `z_real/dut.sv` mid-scan gets `pos = None` and indexes non-canonical `z_real/dut.sv` instead of canonical `a_link/dut.sv` (unlike pre-scan `overlay_buffers`). Reproduced in `qa_topo_50_mid_scan_non_canonical_symlink_over_max_file_size_matches_pre_scan` (`#[ignore]` in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`).
- **Finding F4 — `#51`: widening into lexical-earlier symlink over `maxFileSize` fails to promote canonical spelling**
- `crates/lucisv_server/src/state/rescan.rs:167` (`begin_widen`): When `z_real/real.sv` (`> maxFileSize`, `<= largeFile.threshold`) is open in folder scope and widening into `a_link/` discovers `a_link/alias.sv -> z_real/real.sv`, `if path < existing && oversize(...).is_none()` blocks promoting to `a_link/alias.sv`, leaving `z_real/real.sv` in `index.files()` instead of `a_link/alias.sv` as a fresh server does. Reproduced in `qa_topo_51_widen_symlink_over_max_file_size_converges_like_fresh` (`#[ignore]` in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`).
- **Finding F5 — `#63`: threshold drop after unsaved edit indexed via widen leaves stale unsaved index**
- `crates/lucisv_server/src/server/large_file.rs:179-199` (`reclassify_large_buffers`): When an unsaved edited in-scope buffer is indexed while `doc.large == false` (e.g. via widen) and `didChangeConfiguration` drops `lucisv.largeFile.threshold` so `doc.large` flips `true`, `reclassify_large_buffers` does not restore the on-disk record into the workspace index (stale unsaved buffer remains indexed while `doc.large == true` until next save/widen/close). Reproduced in `qa_topo_63_threshold_drop_after_unsaved_edit_indexed_via_widen_diverges_from_fresh` (`#[ignore]` in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`).
### Live OpenTitan Probe & Passing QA Coverage
- **OpenTitan `/Users/lucio/repo/opentitan/hw` (`#63`, read-only)**: Probed `/Users/lucio/repo/lucisv/target/release/lucisv-server` (`persist: false`, scratch env, `largeFile.threshold = 50000`) on `hw/ip/aes/rtl/aes_reg_top.sv` (`55,523 B`) and `hw/ip/aes/rtl/aes.sv` (`13,993 B`) across pre-scan open, post-scan open, threshold flips (`20000`, `10000` vs fresh `10000`, `500000`, `50000`), `didClose`, and folder-scope widen into `hw/ip/aes/rtl`. Settled `workspace/symbol`, `definition`, `references`, `codeLens`, and `lucisv/moduleHierarchy` matched fresh server answers 100% (`hier_files=1577, refs=2, syms=1` in workspace scope); `git -C /Users/lucio/repo/opentitan status --porcelain` stayed clean.
- **Un-ignored QA checks passing**: `qa_tombstones_survive_mixed_remove_add_revive_absorb_and_all_queries_match_fresh` (`crates/vlog_semantic/tests/workspace.rs`) plus `qa_topo_49_tombstone_at_zero_and_middle_navigation_symbols_hierarchy_codelens_diagnostics_completion`, `qa_topo_63_all_paths_and_threshold_drop_after_unsaved_edit`, `qa_topo_50_first_scope_passed_unreached_and_mid_scan_close`, and `qa_topo_51_same_name_nested_both_open_dirty_close_and_filelist_close` (`crates/lucisv_server/src/server/tests/lifecycle_r2.rs`).
### Final Gates (after last edit)
- `python3 tools/stamp_author.py --check` -> exit `0` (`would stamp 0 files; left 249 untouched`)
- `cargo fmt -p vlog_semantic -p lucisv_server -- --check` -> exit `0`
- `./tools/guard.sh -m 6 -t 600 -- cargo clippy --workspace --all-targets -- -D warnings` -> exit `0`
- `./tools/guard.sh -m 6 -t 600 -- cargo test -p vlog_semantic -p lucisv_server -p vlog_refactor -p lucisv_mcp -p vlog_linter --all-targets` -> exit `0` (`lucisv_server` unit: `2061 passed; 0 failed; 53 ignored` [includes 6 QA finding reproductions], `e2e`: `106 passed; 3 ignored`, `grammar`: `3 passed`, `ifdef_folding`: `1 passed`, `opentitan_references`: `0 passed; 2 ignored`; `vlog_semantic` `workspace`: `92 passed; 2 ignored` + remaining 19 binaries `0 failed`; `vlog_linter`: `658` unit + `14` `lint_cases` passed; `vlog_refactor`: all 20 binaries `0 failed`; `lucisv_mcp`: all 16 binaries `0 failed`).
### 2026-11-26 Round 2 Re-Verification (after DEV F1–F5 Fix Pass)
- **Verdict**: `FAIL` (F1, F4, F5, and core F2/F3 scenarios pass; 2 new edge defects reproduced under adversarial F2/F3 attacks in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`).
- **Audit & Hygiene**:
- Verified all 27 modified/created production `.rs` files remain `<= 600` non-blank, non-comment lines before `mod tests` (max `crates/lucisv_server/src/state/discover.rs` = `505`), with `0` `unwrap()`, `expect()`, `panic!`, `unsafe`, or `#[allow` in added/modified production lines.
- Audited every `.files()` and `FileId(` call site across `crates/` — zero remaining dense `0..files().len()` or `.files().enumerate()` assumptions over potentially tombstoned indexes in production code.
- `python3 tools/stamp_author.py --check` -> exit `0` (`would stamp 0 files; left 249 untouched`).
- **Confirmed Resolved**:
- **F1 (`live_files()`)**: All `qa_topo_49_*` pass; added `qa_r2_f1_multiple_tombstones_candidates_absorb_update_words_rename_and_completion` (`lifecycle_r2.rs`) and `qa_r2_f1_mcp_find_and_check_with_multiple_tombstones_preceding_live_files` (`crates/lucisv_mcp/src/tools/diagnostics.rs`), confirming `Candidates::from_words`/`update_words`/`absorb`, `rename_traced` macro-text warnings, `Completion`, `mcp::check`, and `mcp::find` (`refs` + near-match suggestions) pass with 3 tombstones preceding live files.
- **F2 (core LSP handlers)**: `qa_topo_51_non_canonical_symlink_open_buffer_breaks_references_lint_and_rename` passes, plus `qa_r2_f2_non_canonical_symlink_open_buffer_across_all_handlers_and_case_mismatch` passes for symbol `hover`, symbol `gotoDefinition`, `ports::offers`/`resolve_for`, `extract::code_actions`/`execute`, `imports::offers`/`resolve`, `completion` `related_tier`, `callHierarchy` (`incoming` + `outgoing`), `design_hierarchy`, and macOS `case_only_mismatch` (`Foo.sv` vs `foo.sv`).
- **F3 (simple mid-scan close) & F4 (widen symlinks)**: `qa_topo_50_mid_scan_non_canonical_symlink_over_max_file_size_matches_pre_scan`, `qa_r2_f3_mid_scan_open_dirty_symlink_and_close_mid_scan_matches_fresh` (in-scope and over `maxFileSize`), `qa_topo_51_widen_symlink_over_max_file_size_converges_like_fresh`, and `qa_r2_f4_widen_symlink_pointing_outside_root_converges_like_fresh` (under/over cap, closed/open outside targets) all pass.
- **F5 (`reclassify_large_buffers`)**: `qa_topo_63_threshold_drop_after_unsaved_edit_indexed_via_widen_diverges_from_fresh` and `qa_r2_f5_reclassify_large_buffers_excluded_dirty_clean_and_round_trip` pass (clean `false -> true` does 1 empty `Document::large("")` parse and leaves `index().fingerprint()` / `derived_fingerprint()` unchanged; excluded unsaved drops from index; in-scope dirty preserves disk record across `false -> true` and `true -> false -> true` flips).
- **Remaining / New Findings**:
- **Finding R2-F2 (`includes.rs:552,584` & `hover.rs:101`) — Non-canonical symlink open buffer fails `` `include `` resolution & macro hover narrowing**: `includes::resolved` (`crates/lucisv_server/src/includes.rs:552`) and `includes::definition` (`:584`) pass raw `doc.path.as_deref()` instead of `ws.index_path_for`, and `hover::narrowed_to_the_include_graph` (`crates/lucisv_server/src/hover.rs:101`) filters `ws.index().path(*file)` via `reachable.contains(p)` without file-identity matching. Reproduced in `#[ignore]`d `qa_r2_f2_symlink_include_related_macros_links_def_and_hover_narrowing`: opening `z_real/real_b.sv` (when `a_link/link_a.sv -> z_real/real_b.sv` is indexed alongside `a_link/link_h.svh`) degrades `completion` `related_macros` (`sortText` `"5\`LINK_HDR_MAC"` vs `"4\`LINK_HDR_MAC"`), returns `[]` for `textDocument/documentLink` and `` `include `` `textDocument/definition`, and fails macro include-graph narrowing on `` `SHARED_MAC `` (`"defined 2 times"`).
- **Finding R2-F3 (`state/incremental.rs:192-203`) — Mid-scan `didOpen(dirty symlink)` -> `didChange(disk)` -> `didClose` leaves stale `IN_BUF` edit**: `Workspace::closing_affects_running_scan` checks `fs::read_to_string(&target).ok().as_ref() != Some(&doc.text)`, returning `false` after `didChange` restores disk text even though the earlier mid-scan `didOpen(dirty)` had already been absorbed into the running scan. Reproduced in `#[ignore]`d `qa_r2_f3_mid_scan_dirty_open_reverted_and_closed_leaves_stale_index` (`ON_DISK = 0`, `IN_BUF = 1`).
- **Final Gates**:
- `python3 tools/stamp_author.py --check` -> exit `0` (`would stamp 0 files; left 249 untouched`)
- `cargo fmt --all -- --check` -> exit `0`
- `./tools/guard.sh -m 6 -t 600 -- cargo clippy --workspace --all-targets -- -D warnings` -> exit `0`
- `./tools/guard.sh -m 6 -t 600 -- cargo test -p vlog_semantic -p lucisv_server -p vlog_refactor -p lucisv_mcp -p vlog_linter --all-targets` -> exit `0` (`lucisv_server` unit: `2072 passed; 0 failed; 49 ignored` [includes 2 `qa_r2_*` `#[ignore]`d reproductions], `e2e`: `106 passed; 0 failed; 3 ignored`, `grammar`: `3 passed`, `ifdef_folding`: `1 passed`, `opentitan_references`: `0 passed; 2 ignored`; `lucisv_mcp`: all 16 binaries `0 failed`; `vlog_linter`: `658` unit + `14` `lint_cases` passed; `vlog_refactor`: all 24 binaries `0 failed`; `vlog_semantic`: all 21 binaries `0 failed`, `workspace`: `92 passed; 0 failed; 2 ignored`).
### 2026-11-26 Round 2 Closing-Pass QA Verification (after R2-F2 & R2-F3 Fixes)
- **Verdict**: `FAIL` (both previously `#[ignore]`d R2-F2 and R2-F3 reproductions now pass un-ignored, and `didOpen(dirty) -> didSave(None) -> didClose` converges, **but** adversarial multi-hop symlinked-directory and `has_other_document_for` two-URI mid-scan close attacks uncover 3 concrete defects: `R2-F2b`, `R2-F3a`, `R2-F3b`).
- **Audit & Hygiene**:
- `git status --short` / `git diff --stat`: 35 modified + 2 untracked `.rs` files (`reconcile.rs`, `lifecycle_r2.rs`) + `docs/features/index-lifecycle-r2/`.
- Verified all 29 modified/created production `.rs` files remain `<= 600` non-blank, non-comment lines before `mod tests` (max `crates/lucisv_server/src/state/discover.rs` = `505`, `state/reconcile.rs` = `225`, `state/rescan.rs` = `480`, `state/incremental.rs` = `225`, `state/mod.rs` = `149`, `includes.rs` = `353`, `hover.rs` = `323`), with `0` `unwrap()`, `expect()`, `panic!`, `unsafe`, or `#[allow` in added/modified production lines.
- `python3 tools/stamp_author.py --check` -> exit `0` (`would stamp 0 files; left 249 untouched`).
- **Confirmed Resolved & New Passing QA Checks**:
- **R2-F2**: `qa_r2_f2_symlink_include_related_macros_links_def_and_hover_narrowing` runs un-ignored and passes. Added un-ignored `qa_r2_f2_multihop_transitive_symlink_headers` (confirming `documentLink`, `` `include `` `definition`, `completion` `related_macros` for transitive `H2_DEEP_MAC`, and `hover` macro narrowing over `z_real/real_b.sv` -> `a_link/link_h1.svh` -> `a_link/link_h2.svh`) and `qa_r2_f2_multihop_symlink_directory_completion_and_hover_narrowing` (confirming transitive `completion` `related_macros` and `hover` macro narrowing over symlinked directory `a_link_dir -> z_real_dir`, including non-canonical open `z_real_dir/real_b.sv` and external caller `rtl/caller.sv` -> `../z_real_dir/h1.svh`), all passing.
- **R2-F3**: `qa_r2_f3_mid_scan_dirty_open_reverted_and_closed_leaves_stale_index` and `r2_f3_mid_scan_dirty_reverted_and_closed_converges_across_all_scan_phases` run un-ignored and pass. Added un-ignored `qa_r2_f3_mid_scan_dirty_open_saved_none_and_closed` (covering `didOpen(dirty) -> didSave(None) -> didClose` mid-scan for `in_scope_future`, `in_scope_past`, and `excluded`) and `qa_r2_f3_two_symlink_uris_both_dirty_one_closed_mid_scan_converges` (`pos >= scan.at`), all passing.
- **New Findings (Reproduced as `#[ignore]`d tests in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`)**:
- **Finding R2-F2b (`crates/lucisv_server/src/includes.rs:544-552`) — `resolve_for_doc` returns non-canonical target for symlinked directory**: When `a_link_dir -> z_real_dir` is a symlinked directory (`a_link_dir/{real_b.sv,h1.svh,h2.svh}` indexed) and the client opens `z_real_dir/real_b.sv` containing `` `include "h1.svh" ``, `resolve_for_doc` returns `graph.resolve(doc.path.as_deref(), include)` directly (`z_real_dir/h1.svh`) without normalizing through `ws.index_path_for(...)`, so `documentLink` and `` `include `` `definition` point to non-canonical `z_real_dir/h1.svh` instead of canonical `a_link_dir/h1.svh` (diverging from `via_canon` and `nav.rs`). Reproduced in `#[ignore]`d `qa_r2_f2_multihop_symlink_directory_links_and_def_return_non_canonical`.
- **Finding R2-F3a (`crates/lucisv_server/src/state/reconcile.rs:192-194` & `crates/lucisv_server/src/state/incremental.rs:197-203`) — closing clean canonical symlink at `pos < scan.at` with `has_other_document_for` drops surviving dirty symlink buffer**: When `0_link/dut.sv -> z_real/dut.sv` (`pos < scan.at`, already stepped cleanly from disk `ON_DISK`) is opened with `ON_DISK` alongside `z_real/dut.sv` with `DIRTY_Z`, `reconcile_open_buffers_into` handles `0_link/dut.sv` first, takes `if already_same { continue; }` without calling `scan_absorbed.record(...)`, and skips `z_real/dut.sv` via `matched_positions.insert(pos)`. Mid-scan `didClose(0_link/dut.sv)` then sees `scan_absorbed == false` and `has_other == true` in `closing_affects_running_scan`, returning `false` at `if has_other { return false; }`, so the scan finishes with `ON_DISK` instead of surviving open `z_real/dut.sv`'s `DIRTY_Z`. Reproduced in `#[ignore]`d `qa_r2_f3_two_symlink_uris_one_closed_already_same_drops_surviving_dirty`.
- **Finding R2-F3b (`crates/lucisv_server/src/state/incremental.rs:198-203`) — closing `doc.large`-flipped absorbed symlink with `has_other_document_for` leaves stale absorbed edits**: When `a_link/dut.sv` (`DIRTY_A`, absorbed into `scan` and recorded in `scan_absorbed`) and `z_real/dut.sv` (`ON_DISK`) are both open, `didChange` flips `a_link/dut.sv` to `doc.large = true`, and `didClose(a_link/dut.sv)` runs mid-scan while `z_real/dut.sv` remains open, `closing_affects_running_scan` evaluates `(!doc.large || !has_other)` as `false` and returns `false` at `if has_other { return false; }`. No follow-up rescan runs, leaving stale `DIRTY_A` from the closed `a_link/dut.sv` in the finished index instead of `z_real/dut.sv`'s `ON_DISK`. Reproduced in `#[ignore]`d `qa_r2_f3_two_symlink_uris_large_flip_one_closed_leaves_stale_index`.
- **Final Gates**:
- `python3 tools/stamp_author.py --check` -> exit `0` (`would stamp 0 files; left 249 untouched`)
- `cargo fmt --all -- --check` -> exit `0`
- `./tools/guard.sh -m 6 -t 600 -- cargo clippy --workspace --all-targets -- -D warnings` -> exit `0`
- `./tools/guard.sh -m 6 -t 600 -- cargo test -p vlog_semantic -p lucisv_server -p vlog_refactor -p lucisv_mcp -p vlog_linter --all-targets` -> exit `0` (`lucisv_server` unit: `2079 passed; 0 failed; 50 ignored` [includes the 3 `qa_r2_*` `#[ignore]`d reproductions], `e2e`: `106 passed; 0 failed; 3 ignored`, `grammar`: `3 passed`, `ifdef_folding`: `1 passed`, `opentitan_references`: `0 passed; 2 ignored`; `lucisv_mcp`: all 16 binaries `0 failed`; `vlog_linter`: `658` unit + `14` `lint_cases` passed; `vlog_refactor`: all 24 binaries `0 failed`; `vlog_semantic`: all 21 binaries `0 failed`, `workspace`: `92 passed; 0 failed; 2 ignored`).
- `/tmp` clean (`0` `lucisv` temp files leftover); `/Users/lucio/repo/opentitan` untouched (`git status --porcelain` empty).
### 2026-11-26 Round 2 Final QA Sign-Off (after R2-F2b, R2-F3a, R2-F3b & Cross-Platform `DirId` Fixes)
- **Verdict**: `PASS`
- **Resolved Repros (un-ignored and passing in `crates/lucisv_server/src/server/tests/lifecycle_r2.rs`)**:
- `qa_r2_f2_multihop_symlink_directory_links_and_def_return_non_canonical` (`ok`)
- `qa_r2_f3_two_symlink_uris_one_closed_already_same_drops_surviving_dirty` (`ok`)
- `qa_r2_f3_two_symlink_uris_large_flip_one_closed_leaves_stale_index` (`ok`)
- `crates/lucisv_server/src/server/tests/lifecycle_r2.rs` now has `0` `#[ignore]`d tests.
- **Edge-Case & Cross-Platform Audit**:
- `crates/lucisv_server/src/includes.rs:544-552` (`resolve_for_doc`): `ws.index_path_for(&found)` delegates to `held_path_for(found).unwrap_or_else(|| found.to_path_buf())` (`state/mod.rs:219-221`), returning `found` unchanged when `found` is a closed excluded header not present in `self.index` (and returning the indexed spelling if opened as non-large or if another symlink of the same file is indexed, while honoring `case_only_mismatch`).
- `crates/lucisv_server/src/state/incremental.rs:193-204` (`closing_affects_running_scan`): returning `true` on `self.scan_absorbed.contains(path, &target) || self.has_other_document_for(uri, path)` preserves surviving dirty/clean/`doc.large` symlink buffers on mid-scan `didClose` across all `scan.at` phases (`pos < scan.at` `already_same` skips, `pos >= scan.at`, `doc.large` flips, and `case_only_mismatch` isolation in `has_other_document_for`) without breaking any existing `lucisv_server` test.
- `crates/lucisv_server/src/state/discover.rs:715-735` and `crates/lucisv_server/src/state/reconcile.rs:206-215`: non-Unix `DirId` (`PathBuf`) borrow-before-move ordering (`&id` / `id.as_ref()` before `canonical_ids.entry(id)` and `added_ids.insert(k)`) passes `cross` for both `x86_64-pc-windows-gnu` and `x86_64-unknown-linux-musl`.
- **Audit & Hygiene**:
- Verified all 29 modified/created production `.rs` files remain `<= 600` non-blank, non-comment lines before `mod tests`: `crates/lucisv_server/src/includes.rs` (`353`), `state/incremental.rs` (`221`), `state/discover.rs` (`510`, max across all modified prod files), `state/reconcile.rs` (`231`), with `0` `unwrap()`, `expect()`, `panic!(`, `unsafe`, or `#[allow` in production sections.
- `python3 tools/stamp_author.py --check` -> exit `0` (`would stamp 0 files; left 249 untouched`).
- **Final Gates (`./tools/gates.sh --only fmt,clippy,suite:vlog_semantic,suite:lucisv_server,suite:lucisv_mcp,cross`, logs in `target/gates/20261126-111210`)**:
- `fmt` -> `pass` (exit `0`)
- `clippy` -> `pass` (exit `0`)
- `suite:vlog_semantic` -> `pass` (`21` binaries: `438 passed; 0 failed; 4 ignored`)
- `suite:lucisv_server` -> `pass` (`5` binaries: `2192 passed; 0 failed; 52 ignored`; unit `2082 passed; 0 failed; 47 ignored`, `e2e` `106 passed; 3 ignored`, `grammar` `3 passed`, `ifdef_folding` `1 passed`, `opentitan_references` `0 passed; 2 ignored`)
- `suite:lucisv_mcp` -> `pass` (`16` binaries: `391 passed; 0 failed; 4 ignored`)
- `cross` -> `pass` (`x86_64-pc-windows-gnu` & `x86_64-unknown-linux-musl` for `lucisv`, `lucisv_server`, `lucisv_mcp`, exit `0`)
- `/tmp` clean; `/Users/lucio/repo/opentitan` untouched (`git status --porcelain` empty).
## Review
### 2026-11-26 — Lead review: PASS (Round 2 complete)
- Verified all Round 2 deliverables (`#49` fast tombstones via `WorkspaceIndex::remove_file` + `live_files()`, `#50` mid-scan open buffer reconciliation, `#51` `(dev, ino)` canonical symlink deduplication across handlers/includes/hover, `#63` least-performance-impact disk record preservation for `doc.large`, and `ScanAbsorbed` tracking + cross-platform `DirId` borrow fixes) and checked that `crates/lucisv_server/src/server/tests/lifecycle_r2.rs` has 0 `#[ignore]`d tests left.
- All 29 modified/created production files stay `<= 600` non-blank, non-comment lines before `mod tests`, with `0` `unwrap`/`expect`/`panic!`/`unsafe`.
- Handshakes closed in `docs/topo.md`: `#48` (closed won't-fix per owner ruling: rely on VS Code), `#49`, `#50`, `#51`, `#63`. Full `./tools/gates.sh` (including `cross`) and final QA sign-off gates verified green.
<!-- Author: Guoliang Chen. Lucisv is made by Guoliang Chen with love, luciochen.com -->