Files
lucisv/docs/features/mcp-hardening-r3

MCP Hardening + vlog_refactor References / L-9 Support (Round 3)

Goal

Harden lucisv_mcp and vlog_refactor on the concrete bugs, performance gaps, and protocol edges identified across audit rounds:

  1. Cached FileFacts in references & MCP tools (#37 / #40): Add find_references_with, find_references_batch, and find_references_batch_with in crates/vlog_refactor/src/references.rs accepting &dyn KnownFacts, sharing one Scope::build_keeping + occurrence walk; implement KnownFacts on Project keyed by FNV-1a content_hash(text) and wire it into find, rename, and edit_item (item/refs.rs).
  2. Future-mtime settlement (#54): Anchor monotonic first-observation time (Stamp::first_mono) and inherit it across unchanged re-reads (Stamp::inherit_observation) in crates/lucisv_mcp/src/project/files.rs and project/mod.rs so files with future timestamps settle after RACY while reacting to wall-clock catch-up, clock step-backs, and edits.
  3. Windows --all-targets test build (#56): Gate Unix-only symlink and PermissionsExt::from_mode tests in crates/lucisv_mcp/tests/qa_m3.rs with #[cfg(unix)] and add non-Unix mode_bits in snapshot().
  4. L-9 Parity & Qualified find Focus Scoping: Expose after_dot and bind-aware home_set_for / home_sets_for from vlog_refactor, wire mentions.rs, edit.rs, and find.rs to match the engine's dotted-mention and K2 bind rules, and wire Focus::unit on qualified unit.name (and single-unit) queries in find.
  5. check Directory & Glob Support: Allow check (diagnostics.rs / tools/glob.rs) to accept directory and glob file arguments matching format's indexing/root-containment rules, keeping unused_waivers whole-design-only.
  6. Protocol & Budgets (rpc.rs, wire.rs, read_only.rs, docs/mcp/PLAN.md): Drop unused "prompts": {} from initialize capabilities and raise catalogue/instruction ceilings to 2,000 / 330 B (read-only) and 3,800 / 440 B (full) while preserving the hierarchy {} lazy-walk freshness contract.

Assumptions

  • KnownFacts on Project must return None whenever content_hash(text.as_bytes()) != stamp.hash so a disk modification between Project::refresh and WholeSet::read always triggers a fresh parse.
  • Existing INSTRUCTIONS and INSTRUCTIONS_READ_ONLY texts remain within <= 400 B / <= 300 B for compatibility with qa_m6.rs and qa_f1.rs, while wire.rs, read_only.rs, and rpc.rs pin the updated 440 / 330 / 3,800 / 2,000 B ceilings.
  • hierarchy {} continues calling project.ensure_walked_for_miss() when unpopulated (preserving M1 freshness).

Handshakes

  • vlog_refactor ↔ lucisv_mcp:
    • find_references_with, find_references_batch, find_references_batch_with take &dyn KnownFacts.
    • after_dot(&str) -> bool is the shared boundary check for dotted spellings across rename::scoped and lucisv_mcp::tools::mentions.
    • home_set_for / home_sets_for expose the engine's include + K2 bind home set cleanly to edit.rs and find.rs.
  • tools/glob ↔ tools/diagnostics:
    • glob::normalize_glob validates root containment before glob::path_match evaluates indexed files; Project::resolve_existing validates file or directory existence within roots.

Status / TODO

  • vlog_refactor: find_references_with, find_references_batch, find_references_batch_with, after_dot, home_set_for, home_sets_for + unit/integration tests
  • lucisv_mcp::project: #54 future-mtime first_mono settlement + KnownFacts on Project
  • lucisv_mcp::tools & rpc.rs: KnownFacts wiring, L-9 parity, qualified find, check dir/glob, remove "prompts": {}, updated budgets
  • Cross-platform gate (#56) in qa_m3.rs + docs (PLAN.md, this doc)
  • Full verification suite (fmt, stamp_author, clippy, guarded cargo test, Windows --all-targets check, live OpenTitan stdio probe)

Work log

  • Implemented find_references_with, find_references_batch, and find_references_batch_with in crates/vlog_refactor/src/references.rs sharing collect_batch / build_scope / collect_one, and exported them alongside after_dot, home_set_for, and home_sets_for from crates/vlog_refactor/src/lib.rs (with pub(crate) use / pub use in crates/vlog_refactor/src/rename/mod.rs).
  • Added first_mono and inherit_observation to Stamp in crates/lucisv_mcp/src/project/files.rs and wired observation inheritance + vlog_refactor::KnownFacts for Project (keyed by stamp.hash == content_hash(text.as_bytes())) in crates/lucisv_mcp/src/project/mod.rs.
  • Wired KnownFacts into find.rs (find_references_batch_with), edit.rs (rename_traced_with), and tools/item/refs.rs (find_references_batch_with); updated mentions.rs (vlog_refactor::after_dot), edit.rs / find.rs (home_set_for / home_sets_for), and qualified Focus::unit scoping in find.rs.
  • Added directory and glob support to check (diagnostics.rs, tools/glob.rs::normalize_glob, Project::resolve_existing); removed "prompts": {} from initialize capabilities in rpc.rs; raised catalogue/instruction ceilings to 2,000 / 330 B (RO) and 3,800 / 440 B (full) in docs/mcp/PLAN.md, rpc.rs, wire.rs, and read_only.rs (measured sizes: 1,826 B / 297 B RO, 3,469 B / 398 B full).
  • Gated Unix-specific symlink/permission tests in crates/lucisv_mcp/tests/qa_m3.rs with #[cfg(unix)] and added cross-platform mode_bits helper for snapshot().
  • Verified:
    • cargo fmt & python3 tools/stamp_author.py --check (would stamp 0 files; left 249 untouched).
    • cargo clippy -p vlog_refactor -p lucisv_mcp --all-targets -- -D warnings: passed (0 errors/warnings on crate code).
    • cargo check --target x86_64-pc-windows-gnu --all-targets -p lucisv_mcp: passed (0 errors).
    • ./tools/guard.sh -m 8 -t 600 -- cargo test -p vlog_refactor -p lucisv_mcp --all-targets: 0 failures across all targets (lucisv_mcp: 88 unit + 23 attacks + 4 cache + 2 hierarchy_cap + 21 qa_f1 + 6 qa_f2 + 48 qa_m1 + 35 qa_m2 + 36 qa_m3 + 45 qa_m4 + 17 qa_m6 + 19 qa_m7 (+1 ignored) + 6 qa_m8 + 5 read_only + 44 wire + 3 ignored opentitan; vlog_refactor: 218 unit + 54 ansi + 11 corpus (+1 ignored) + 33 expand + 41 extract + 9 import_offers + 35 imports + 37 inline + 3 ignored opentitan_top_rooted + 7 parsed_selectors + 10 port_offers + 54 ports + 11 preflight_oracle + 11 qa_correctness_r1 + 26 qa_generate_label + 26 qa_rename_implicit (+1 ignored) + 24 qa_warning_scope + 2 references_and_scope + 71 rename + 15 rename_bind (+1 ignored) + 17 rename_generate_label + 24 rename_implicit + 10 rename_macro_carry + 8 rename_warning_scope + 15 top_rooted_paths).
    • Release stdio probe (./target/release/lucisv-mcp --root /Users/lucio/repo/opentitan/hw --read-only, no --index-cache): initialize capabilities {'resources': {}, 'tools': {}} (no "prompts"); hierarchy {} returned 4043 files, 1355 modules, 372 top (301 lines); check on ip/aes/rtl (34.4 ms, ok) and ip/aes/rtl/*.sv (34.5 ms, ok, matching dir), bad glob refused cleanly; find with refs: true on aes_core.AES192Enable ran in 1,460.1 ms cold / 461.4 ms warm (rst_ni batch of REFS_CAP=5 ran in 1,938.6 ms cold / 1,915.1 ms warm, identical output); /Users/lucio/repo/opentitan git working tree verified clean.

QA log

Verdict: PASS (Round 3 QA audit against HEAD 4d384ec uncommitted diff).

  • Invariants & deduplication:
    • Every changed/added library file (crates/vlog_refactor/src/{lib.rs,references.rs,rename/mod.rs,rename/home.rs,rename/scoped.rs} and crates/lucisv_mcp/src/{project/files.rs,project/mod.rs,rpc.rs,tools/diagnostics.rs,tools/edit.rs,tools/find.rs,tools/glob.rs,tools/item/refs.rs,tools/mentions.rs}) has <= 312 non-blank non-comment production lines before mod tests (well under 600) and 0 .unwrap(), .expect(), panic!, or unsafe occurrences in non-test production code.
    • Shared helpers verified without duplication: references.rs (collect_single, collect_batch, build_scope, collect_one), home.rs (home_sets_for, home_with_graph), scoped.rs/home.rs (file_binds_into, push_defines, defs_from_sources), scoped.rs/mentions.rs (vlog_refactor::after_dot), and diagnostics.rs (lint_paths, match_with_rewalk).
  • Adversarial code & contract checks:
    • #37 / #40 (KnownFacts): Project::facts_for verifies stamp.hash == lucisv_core::cache::content_hash(text.as_bytes()) so stale FileFacts are never returned after on-disk edits between refresh and WholeSet::read; Scope::take also checks facts.path() == path. find_references_batch_with / find_references_with match find_references identically on find.rs, edit.rs (rename_traced_with), and tools/item/refs.rs.
    • #54 (Future-mtime settlement): Stamp::first_mono, Stamp::inherit_observation, and Stamp::racy(now) preserve observation age across unchanged re-reads (same && !prev.clock_stepped_back(now)), settle after RACY monotonic elapsed, force re-read into normal rules on wall-clock catch-up (now.wall >= time), reset on hash/metadata changes, and mark Suspect on wall-clock step-backs.
    • #56 (Windows --all-targets): qa_m3.rs gates only Unix-specific symlink/PermissionsExt::from_mode tests with #[cfg(unix)] while keeping portable tests active with mode_bits. cargo check --target x86_64-pc-windows-gnu --all-targets -p lucisv_mcp compiled with 0 errors.
    • L-9 & Qualified find: after_dot handles blanks, /* ... */ comments, and `` pastes identically in scoped.rs and mentions.rs; home_set_for/home_sets_for include direct and macro-expanded bind home sets (K2); find.rs populates Focus::unit on qualified unit.name and single-unit queries.
    • check dir/glob, budgets & hierarchy {}: tools/glob.rs::normalize_glob + Project::resolve_existing enforce root containment and refuse empty, missing, non-matching, and outside-root (.., ../../etc/*.sv) targets; lint_paths(..., false) omits whole-design unused_waivers on subset checks. rpc.rs initialize returns capabilities: {"tools": {}, "resources": {}} (no "prompts"). Budgets verified in rpc.rs, wire.rs, read_only.rs, and docs/mcp/PLAN.md (measured: RO 1,826 B catalogue / 297 B instructions vs 2,000 / 330 B caps; full 3,469 B catalogue / 398 B instructions vs 3,800 / 440 B caps). hierarchy.rs:107 retains project.ensure_walked_for_miss() for hierarchy {}.
  • Executed verification commands:
    • python3 tools/stamp_author.py --check: would stamp 0 files; left 249 untouched.
    • ./tools/gates.sh --only fmt,clippy,suite:vlog_refactor,suite:lucisv_mcp,docs,node,cross: PASS across all 7 steps (fmt pass, clippy pass, suite:vlog_refactor 769/0, suite:lucisv_mcp 399/0, docs 1/0, node 37/0, cross pass).
    • Windows --all-targets: env RUSTC="$HOME/.rustup/toolchains/stable-aarch64-apple-darwin/bin/rustc" "$HOME/.rustup/toolchains/stable-aarch64-apple-darwin/bin/cargo" check --target x86_64-pc-windows-gnu --all-targets -p lucisv_mcp passed with 0 errors.
    • OpenTitan stdio probe (./target/release/lucisv-mcp --root /Users/lucio/repo/opentitan/hw --read-only): initialize capabilities {'resources': {}, 'tools': {}} (297 B instructions); hierarchy {} -> 4043 files, 1355 modules, 372 top (301 lines, 1069.8 ms); find aes_core.AES192Enable (refs: true, 486.9 ms cold / 459.5 ms warm, identical output) and aes_control_fsm.aes_ctrl_ns (refs: true, returned aes_bind.sv:65 + aes_control_fsm.sv uses + unresolved line 909); find rst_ni (refs: true, 1944.3 ms -> 1937.3 ms, 301 lines); check on ip/aes/rtl (34.8 ms, ok), ./ip/aes/rtl/ (33.8 ms, ok), ip/aes/rtl/*.sv (34.5 ms, ok), ip/aes/**/rtl/aes_core.sv (19.7 ms, ok), ip/uart/dv vs ip/uart/dv/**/*.sv (identical 5 findings), ip/uart/dv/*.sv / ip/aes/rtl/*.none (isError=true, no indexed file matches ...), ../../etc/*.sv / .. (isError=true, resolves outside every root), ip/aes/no_such_dir (isError=true, does not exist under any root).
    • git -C /Users/lucio/repo/opentitan status --porcelain: empty (strictly clean).

Review

Lead Self-Inspect (2026-11-26): APPROVED for trunk commit.

  • Verified Plan Review rulings were respected: hierarchy.rs retains ensure_walked_for_miss() on no-root hierarchy {} calls; rename/mod.rs and lib.rs export after_dot, home_set_for, and home_sets_for; find_references_with / find_references_batch_with match find_references error and tuple types (Result<Vec<(PathBuf, TextRange)>, String>).
  • Checked rpc.rs ("prompts": {} removed from initialize capabilities), references.rs (KnownFacts hash-checked caching with shared collect_single/collect_batch/build_scope/collect_one), files.rs (first_mono/inherit_observation #54 future-mtime settlement), qa_m3.rs (#[cfg(unix)] #56 portability), diagnostics.rs/glob.rs (check dir/glob support), and owner-ruled catalogue/instruction ceilings (2,000/330 B RO, 3,800/440 B full).
  • Pending final full ./tools/gates.sh + stamp_author.py --check before local commit and closing #37, #40, #54, #56 in docs/topo.md.