shared-fence-filter
Goal
There were two answers to "which bytes does a // verilog_format: off fence
protect from an automatic edit", and one of them was missing. The formatter
had fence::collect; lucisv check --fix had its own union of that plus a
line-scan backstop, written inside crates/lucisv/src/lint.rs because the
linter crate deliberately does not depend on vlog_formatter; and
lucisv_server's quick fixes had none, so a lightbulb in an editor happily
rewrote bytes lucisv check --fix refused to touch (server-lint Handshake 3,
reproduced live by that round's QA). This round moves the CLI's computation
down into vlog_formatter::fence as protected_regions + is_protected and
has both front ends call it, so the fence answer is defined once. The CLI's
behavior is unchanged byte for byte; the server gains the CLI's
reported-but-never-auto-fixed semantics.
Assumptions
- The union is the right answer for an editing tool, and the front ends
must not each decide that.
fence::collectis authoritative wherever the tree is good; a line scan pairing eachoffwith the nexton(or EOF) is the backstop for the tolerant-parse population — files where error recovery swallows the item structure a region hangs on andcollectreturns nothing. That population is the linter's and the server's whole world: a buffer mid-keystroke rarely parses. This is inherited unchanged from linter-core's QA round, including its measurement thatcollectalone was not enough. - Protecting more than the formatter emits verbatim is the harmless
direction. The scan has no notion of scope and would be fooled by a fence
spelled inside a block comment; both only ever decline an edit, which costs
a fix, not correctness. (Lead note, per lint-rules-2 QA: a concrete
example of that width — the formatter's
collectdoes not yet fire inside class bodies, the classes round's filed gap, but the scan backstop does, so a fence inside a class body protects--fixand server quick fixes even thoughlucisv formatignores it there.) protected_regionstakes&strand parses internally, on purpose. The alternative — accepting a caller'sSourceFile— would let the two front ends feed different trees and get different answers, which is the drift this feature exists to end. The cost is one tolerant parse per call, paid only on paths that are about to apply a fix:lucisv check --fix(already re-parsing per round) andtextDocument/codeAction. The server's per-keystroke diagnostics path pays nothing, because it never reads a fix.- The regions this function returns are for
is_protectedonly. Unlikecollect's output they may overlap and are not sorted, soregion_at's binary search must not be pointed at them.is_protectedis a linear scan, which is right for a list this size and immune to the ordering question. - An insertion is protected too. An empty edit range covers the byte it would land in front of, so nothing can be spliced into a region.
- A fix is all-or-nothing, so one edit inside a fence withholds the whole
fix — never half of it. Both front ends apply that rule; it belongs to the
fix model (
linter-core), not to the fence. - Fences never suppress a finding. Both front ends still report a
violation inside a fence; only its automatic fix is withheld. Silencing a
finding is what waivers,
--ignoreand--selectare for.
Handshakes
Promised by vlog_formatter::fence (new; nothing existing changed):
pub fn protected_regions(src: &str) -> Vec<Region>— every byte range insrcno tool may edit automatically. The union described above.pub fn is_protected(regions: &[Region], start: usize, end: usize) -> bool— whether a byte range overlaps any of them, with the empty-range (insertion) rule folded in.
Both are documented at the item and are the only supported way to ask the
question. fence_of, collect, region_at, Fence and Region are
unchanged, and the formatter's own use of collect is untouched — this is
additive.
Consumed by crates/lucisv/src/lint.rs: fixable_outside_fences now calls
protected_regions, and touches_fence is a one-line map over
is_protected. The file's own scanned_fence_regions was moved, not
copied — it no longer exists there.
Consumed by crates/lucisv_server/src/lint.rs: fixable — the code-action
path, and only that path — drops any violation whose fix would edit a
protected byte. violations/diagnostics (the publishing path) are
deliberately untouched, which is what keeps a fenced finding reported.
Relied on from vlog_parser: parse_source_tolerant never panics and
returns a usable tree for any input, and LineIndex::{line_count, line_range}
are byte ranges over the same text. vlog_formatter already depended on
vlog_parser; no crate gained a dependency and no Cargo.toml was edited.
Deliberately not done — vlog_linter still has no notion of fences. Its
dependency list stays vlog_parser + std (the property linter-core's QA
verified with cargo tree), so the filter lives in each front end, one line
each, over a shared answer. Moving it into the linter would invert that
dependency for no gain: the two lines that remain are "which violations does
this tool offer", not "what is fenced".
Status / TODO
fence::protected_regions+fence::is_protectedincrates/vlog_formatter/src/fence.rs, with the scan (scanned_regions) moved down fromcrates/lucisv/src/lint.rs.- Unit tests in
fence.rs: the boundary matrix (first/last byte inside, adjacent-outside both ends, straddling either edge, insertions, empty region list), a good-tree region, the broken-file backstop (asserting the premise —collectreally does return nothing there), an unclosed fence running to EOF, and ordinary comments protecting nothing. crates/lucisv/src/lint.rsrewired; the boundary test matrix and every CLI test pass unmodified.crates/lucisv_server/src/lint.rs:fixablefilters through the shared answer;fix_touches_fenceis the all-or-nothing rule.- Server tests: a fenced violation is reported but not fixable, a fence
holds in a file that does not parse, an unfenced file is unaffected;
no
quickfixaction on a fenced line while the neighbouring free line still has one;fixAllleaves fenced bytes byte-identical. - e2e through both real binaries: the server's
fixAlledit is byte-identical to whatlucisv check --fixwrites for the same content, with the CLI still exiting 1 for the finding it declined to fix. docs/features/server-lint/README.mdHandshake 3 annotated as delivered.- Not done: statement-level fences.
collectis item-scoped by design (format-fences), and the scan is line-based, so a fence inside a statement body is protected only by the scan half. Unchanged by this round, and filed where it belongs (format-fences). - Not done: sharing the parse.
protected_regionsre-parses rather than accepting a tree — see Assumptions; it is the same "one parse, two tools" TODO (§4) the linter and the server already carry, and when that lands this function is one of the call sites it simplifies.
Work log
2026-08-19 — dev
- Read
CLAUDE.md,docs/features/{server-lint,linter-core,format-fences}/README.mdin full (QA logs and Reviews included) before writing anything. - The API shape was the whole design decision. Three candidates: pass the
caller's parsed tree (rejected — two callers, two trees, the same drift in a
new costume), return a filter closure over violations (rejected —
vlog_formatterwould have to knowvlog_linter::Fix, inverting a dependency linter-core deliberately keeps out), or take&strand answer in byte ranges (chosen — the tiniest surface that both front ends can share, andRegionwas already the vocabulary). What is not shared is which violations a tool offers, because that is genuinely each tool's own question; what is shared is every byte of "what is fenced". - The scan was moved verbatim from
crates/lucisv/src/lint.rsintofence.rsasscanned_regions(private;protected_regionsis the only way in), withfence::fence_ofcalls becoming barefence_of. Same pairing, same EOF rule, sameRegionconstruction. The CLI'stouches_fencebody becamefence::is_protectedunchanged, including theend.max(start + 1)insertion rule. - Byte-identity of the CLI filter was the constraint, and it holds by
construction:
fixable_outside_fencesstill computescollect(tolerant) ∪ scan, still short-circuits when the union is empty, and still filters on the same predicate. Its four behavior tests — the boundary matrix, the multi-edit fix, the fenced/unfenced pair and the fence-free file — pass unmodified, as do all 48 CLI integration tests includingcheck_reports_inside_a_fence_but_never_fixes_thereanda_fence_holds_even_in_a_file_that_does_not_parse. - Three unit tests in
crates/lucisv/src/lint.rsdid have to change, because they called the privatescanned_fence_regionsthat no longer lives there. They were rewritten to assert the same three behaviors (broken-file backstop, unclosed fence to EOF, ordinary comments) throughfixable_outside_fences, which is the CLI's own remaining seam; the region-shape assertions they used to make now live infence.rs, against the code that produces them. No assertion was weakened: each still fails if the scan stops finding its region. - Server side is deliberately one filter in one place.
fixableis the only caller of the code-action path'slint, so filtering there covers quick fixes andfixAllat once and cannot be forgotten by a future third action kind.violationswas left alone, on purpose and with a doc comment saying why: the finding must still be published. - The e2e test finds the
lucisvbinary by path next toCARGO_BIN_EXE_lucisv-server(Cargo names no env var for another package's binary) and skips with a printed note if it is absent, which can only happen undercargo test -p lucisv_serverin a tree wherelucisvwas never built. Under the--workspacegate it always runs. A test that fails for a reason that is not about the code under test is worse than one that says it skipped. - Did not touch
verify.rs,format.rs, any.casesfile,vlog_parser,vlog_linter,vlog_semantic,lucisv_coreoreditors/**. No new dependency, noCargo.tomledit, no#[allow], nounwrap/expect/panic!/unsafeoutside#[cfg(test)]. Did not rungit commit/git push. - Concurrency note. Another agent was live in
crates/vlog_parser(the directives-in-instances round) for part of this session; the workspace did not compile for a stretch, exactly as the previous round recorded. Nothing was touched in response; the gates below were run oncevlog_parserbuilt again.cargo fmtwas scoped to-p vlog_formatter -p lucisv -p lucisv_serverrather than--allfor the same reason. That round'sformat.rshad landed in the tree by then;git diffon it shows four hunks, every one of them their own semantic edit and none a whitespace-only reflow, so the package-scopedfmtleft their work as they wrote it.
Results.
cargo test --workspace: 574 passed, 0 failed, up from 563 at the session's start commit6e6aacb. The +11 are all this round's: 5 invlog_formatter'sfence.rs, 3 inlucisv_server'slint.rs, 2 in itscode_action.rs, 1 e2e.crates/lucisvis net 0 — three scan tests became three filter tests.cargo clippy --workspace --all-targets: silent (re-run after touching every file this round changed, to rule out a cached result).cargo fmt -p vlog_formatter -p lucisv -p lucisv_server -- --check: clean.--allwas deliberately not used:crates/vlog_parserbelongs to the concurrent round and is not this round's to reformat.
Byte-identity of the CLI, measured rather than argued. Two git worktree
builds — old at 6e6aacb, new at 6e6aacb + this round's diff to
fence.rs and crates/lucisv/src/lint.rs and nothing else, so the concurrent
round's uncommitted parser work perturbs neither:
lucisv check corpus/ --output-format json: byte-identical (2 407 345 bytes of JSON), stderr byte-identical, both exit 1.- 22 crafted fence shapes (simple, unclosed, broken-parse-before-the-fence,
long spelling,
off-by-one, block comment, indented fence, trailing fence, twooffs, strayon, fence at EOF, generate scope, top-level, multi-byte, CRLF, trailing-whitespace-only, a fence spelled inside a string, two regions, an all-garbage file, a package, a waiver inside a fence, and a file with no fence at all), each in two identical directories run throughcheck --fix: every fixed file byte-identical, stdout identical, stderr identical (found 19 violations, fixed 28 violationsfrom both), exit 1 from both. tools/corpus_check.shwith each binary: md531ffdb18c96d4e79057178f7de269756from both — exactly the value this round's brief named as the expected one, reproduced with the debug and the release build of the baseline alike.
One finding that is not this round's to fix: the checked-in
corpus-check-results.tsv is md5 6af28a6d4942c4ddce0a061262eb5d68, which is
not what the binary at 6e6aacb produces (456 differing rows, and it
carries a verification-error row for common_cells/src/cdc_4phase.sv that
6e6aacb does not reproduce — that binary reports the file as
would-reformat). The committed file appears to predate several rounds
rather than to describe HEAD. Left untouched: regenerating it is out of this
round's scope and the working tree currently holds another agent's
in-progress parser and formatter changes, so a regeneration here would record
their round, not this one.
QA log
2026-08-19 — QA
Read CLAUDE.md, this feature's README (dev's Work log included), and the
diff to fence.rs, crates/lucisv/src/lint.rs, crates/lucisv_server/src/lint.rs,
code_action.rs, tests/e2e.rs, and server-lint's annotations, before
touching anything. Scoped to -p vlog_formatter -p lucisv -p lucisv_server
throughout, per the concurrency note (vlog_parser/format.rs/.cases were
live under another agent for part of this session).
Gates. cargo test -p vlog_formatter -p lucisv -p lucisv_server: all 11 test
binaries green (lucisv-server unittests 109, cli.rs 48, e2e.rs 5,
vlog_formatter unittests 13, its verification.rs 63, fences.rs 6, etc.)
— 0 failures. crates/lucisv/tests/cli.rs has an empty git diff,
i.e. the 48 CLI tests are not merely passing, they are byte-for-byte
unmodified, confirming the README's claim directly rather than by count.
cargo clippy -p vlog_formatter -p lucisv -p lucisv_server --all-targets:
silent. cargo fmt -p vlog_formatter -p lucisv -p lucisv_server -- --check: clean
at the time of this check. Note: mid-session it briefly reported diffs, all
three confined to crates/vlog_formatter/tests/verification.rs lines
600-679 — git diff on that file attributes those lines to the concurrent
directives-in-instances round (new tests added there), not to this diff; the
five files this feature actually touches (fence.rs,
lucisv/src/lint.rs, lucisv_server/src/lint.rs, code_action.rs, e2e.rs)
were independently checked with rustfmt --check and are clean on their own,
and the workspace-wide check is clean again as of this writing (the other
agent evidently ran its own cargo fmt since). No #[allow], unwrap/
expect/panic!/unsafe in library code — every instance in the diff is
inside #[test]/mod tests. Cargo.toml/Cargo.lock: no diff from this
feature (nor is there a stray one at the repo root — that's an unrelated,
already-committed state).
Claim 1 (ownership moved, not copied). grep -rn scanned_fence_regions crates/ returns nothing anywhere in the tree; scanned_regions exists only
in fence.rs (private, called only from protected_regions). git diff on
fence.rs is pure addition (git diff | grep '^-' — excluding ---
headers — is empty): collect, fence_of, region_at are untouched.
Confirmed.
Claim 2 (CLI byte-identity). Built two release binaries in isolated
git worktrees: old at 6e6aacb, new at 6e6aacb plus only this
feature's diff to fence.rs and crates/lucisv/src/lint.rs (copied the two
files directly; git diff --stat in that worktree confirmed exactly those
two files, 171 lines, matching the dev's own isolation). Ran 8 crafted fence
shapes (simple, unclosed-to-EOF, broken-parse-before-the-fence/scan-backstop,
block-comment spelling, indented, double-off/stray-on, fence-inside-a-
string-literal, CRLF) through check --fix on both binaries: every fixed
file byte-identical (cmp clean on all 8), stdout identical
(found 15 violations, fixed 8 violations from both), exit 1 from both.
This is a smaller sample than the dev's 22-shape run but corroborates it
independently rather than repeating it. The 3 rewritten unit tests in
crates/lucisv/src/lint.rs were read: they now call fixable_outside_fences
end-to-end with a no-tabs-shaped violation instead of asserting on
scanned_fence_regions's return shape directly, but assert the same three
behaviors (broken-file backstop, unclosed-to-EOF, ordinary-comment-is-not-
a-fence) — confirmed by reading, and by the sabotage below, which fails two
of exactly these three.
Claim 3 (server drops fenced fixes, diagnostics untouched). Drove the
real lucisv-server debug binary live over hand-framed LSP JSON-RPC (Python,
not the Rust talk() helper, so this is independent of the e2e test's own
plumbing):
- Fenced tab: diagnostic published at both the fenced and unfenced lines;
codeActionat the fenced line →[]; at the unfenced line → onequickfixaction with the expected edit. Matches Handshake 3 exactly. fixAll:\twire a;(fenced) survives byte-for-byte in the returnednewText;\twire b;(unfenced) becomeswire b;.- Non-parsing buffer (
@@@ junk;before the fence, a real parse error): diagnostics still published (including the fenced tab'sno-tabs), andcodeActionat the fenced tab still returns[]— the scan backstop holds through the server's path too, not just the CLI's. - Fence + waiver:
// lucisv: waive no-tabson the line before a fenced, tabbedwire a;→ zero diagnostics for that violation (not "reported but unfixable" — genuinely absent), while the unfenced tab two lines later is still reported. This is correct and is not a fence property: waivers drop the violation invlog_linterbefore either front end's fence filter ever runs, so the fence has nothing left to decline. Confirms the Assumptions section's claim that fences and waivers are orthogonal mechanisms, live.
Claim 4 (gates, drift). Addressed under Gates above. cargo tree -p vlog_linter still shows only vlog_parser; its Cargo.toml still lists
only that one path dependency — the "vlog_linter still has no notion of
fences" handshake holds structurally, not just by inspection.
Claim 5 (stale corpus-check-results.tsv). Confirmed exactly. The
committed file's md5 is 6af28a6d4942c4ddce0a061262eb5d68. Regenerated it
fresh with the old (6e6aacb) worktree's release binary via
tools/corpus_check.sh: got 31ffdb18c96d4e79057178f7de269756 — the value
the dev's brief and work log both cite as expected, reproduced independently.
Row-level diff (diff <(sort ...) <(sort ...) | grep -c '^[<>]') is 454
changed lines against the committed file (dev's log says 456; close enough
to be the same finding under a slightly different counting method, not a
discrepancy worth chasing). Spot-checked the specific example the dev
named: the committed file has a verification-error row for
common_cells/src/cdc_4phase.sv; the freshly generated one has
would-reformat for the same file, matching the dev's description exactly.
Left the committed file untouched, as instructed — this is filed for the
lead, not fixed here.
Attacks on the shared API (standalone Rust harness in scratch, linking
vlog_formatter/vlog_parser as path deps, so as not to touch any crate
under test):
protected_regions("")→ 0 regions.- Fence spelled inside a string literal (
string s = "// lucisv: off";) → 0 regions — correct, the line as a whole does not start with//after trimming, sofence_ofnever fires on it. - Block-comment spelling (
/* verilog_format: off */) → 0 regions — correct, same reason (fence_ofrequires a//-prefixed, single-line comment). - CRLF: found exactly 1 region, with the fenced tab protected and the
unfenced one (past the
on) not — the\ris absorbed intoLineIndex's line ranges rather than desyncing the pairing. - Unclosed
offat EOF: 1 region running tosrc.len(). off/onin an all-garbage file (no valid tokens at all): 1 region found — the scan backstop needs no successful parse whatsoever, onlyLineIndex, which never fails.- Double
off(second one while one is already open) then a strayonbefore the pair, then a closingon: 1 region, spanning from the firstoffto the first matchingon— the secondoffis swallowed as "just text" per the_ => {}arm, which is the documented crude-but-safe behavior (protects more, never less). - 1 MB file, 1000 fence pairs:
protected_regions~68ms (parser-dominated, a tolerant parse of a 1MB file),is_protectedlinear scan over the resulting ~1000 regions ~6.6µs per call across 1000 calls — sane, informational only, no regression risk flagged. is_protectedboundary arithmetic against a synthetic10..20region: reproduced the exact table infence.rs's ownprotection_is_decided_exactly_at_the_region_boundariestest independently (first/last byte inside, adjacent-outside both ends, straddling both edges, insertion inside, insertion at the start boundary — protected, per theend.max(start+1)rule — insertion just past the end — not protected). Both front ends callfence::is_protectedwith identical argument shape ((range.start as usize, range.end as usize)in bothlucisv/src/lint.rs::touches_fenceandlucisv_server/src/lint.rs::fix_touches_fence), so "both front ends refuse identically" is a structural guarantee, not merely an observed one — there is no live rule today that emits a pure-insertion fix to exercise this end-to-end (no-tabsandno-trailing-whitespaceboth replace non-empty ranges), so the unit-level equivalence is the strongest available evidence.
Sabotage. Edited protected_regions in the working tree to drop the
regions.extend(scanned_regions(src)) line (tree-only). Result:
crates/lucisv/src/lint.rs unit tests — 3 failures (the_line_scan_backstops_ a_file_that_does_not_parse, an_unclosed_fence_runs_to_the_end_of_the_file,
fixes_outside_a_fence_survive_the_filter); crates/lucisv's own CLI
integration test a_fence_holds_even_in_a_file_that_does_not_parse —
failed; lucisv_server's lint::tests::a_fence_holds_even_when_the_file_ does_not_parse — failed; vlog_formatter's own
the_line_scan_backstops_a_file_that_does_not_parse — failed, as expected.
Reverted by hand (restored the two-line body exactly); git diff on
fence.rs afterward is byte-identical to the pre-sabotage diff (same
index a7bf341..5edc8c3 hashes), and the full scoped suite is green again.
The non-parsing-buffer backstop is real and load-bearing in both front
ends, not just asserted to be.
One incidental finding — not blocking, worth a look. fence.rs's own
new unit test a_fence_in_a_good_tree_protects_its_whole_region is named
and commented as exercising the tree path (collect) on "a fence in a good
tree," but its source — \ta = 1; as a bare module item — is not
actually valid Verilog at item position (needs assign or a procedural
block); parse_source_tolerant reports 2 errors on it and collect alone
returns 0 regions for it (checked directly, bypassing protected_ regions). The test only passes today because of the scan half it claims
not to be testing — which is exactly why it failed under the sabotage above
alongside the tests that are honestly about the scan. This is not a
production bug: the tree path is genuinely exercised elsewhere
(crates/vlog_formatter/tests/fences.rs, unchanged by this round, uses
real wire declarations and passes collect alone). It is a test-fidelity
gap in the new suite: nothing in fence.rs's own tests currently proves
protected_regions finds a region via collect on a genuinely clean
tree, independent of the scan. Left as-is per "QA verifies, doesn't
redesign" — flagging here rather than editing the test file, which is
outside this round's QA-log-only write scope.
Verdict: PASS on all 5 claims, no BLOCKING findings. Server never edits
a fenced byte on either the quickfix or fixAll path (live-verified, not just
unit-tested); CLI behavior is unchanged (spot-verified independently via
isolated worktrees, 8/8 shapes byte-identical, 48/48 tests untouched); the
scan backstop is genuinely load-bearing on both front ends (sabotage
confirmed); no third copy of fence knowledge exists; the stale-corpus-tsv
claim is accurate and correctly left unfixed. The one finding above (test
naming/coverage gap in fence.rs) is cosmetic — informational for the lead,
not a correctness issue.
Review
2026-08-19 — lead. Verdict: accepted; commits with round 15. The fence promise now holds identically across all three surfaces: the formatter, CLI fixes, and editor fixes.
Points reviewed and accepted:
- Moved, not copied — and proven.
grepfinds one owner of the scan; the CLI's behavior was shown byte-identical via isolated-diff worktrees (8 fence shapes, identical fixed files/stdout/exit), and the 48 CLI tests are diff-empty, not merely green. "One definition of what is fenced" was the round's whole point and it is now structurally true. protected_regionsparsing internally is the right signature for exactly the stated reason: letting callers pass their own trees is how two front ends get two answers. The ~2-line per-front-end "which violations does this tool offer" residue is the correct remainder.- The sabotage evidence is the strongest yet: removing the scan union failed six tests across three crates — the backstop is load-bearing everywhere it's claimed to be.
- Waiver/fence orthogonality confirmed live (a waived violation inside a fence produces zero diagnostics — waivers act first), which is the composition question nobody had asked yet.
Lead fix on acceptance (QA's non-blocking find): the good-tree test's
fenced content didn't parse at item position, so it exercised only the
scan half it claimed not to test. Rewritten with valid items plus
explicit assertions that the tree is clean AND collect itself finds
the region — the tree path of protected_regions is now genuinely
pinned in fence.rs.
The stale committed corpus-check-results.tsv both this round's agents flagged is removed from tracking in this commit (generated artifact, already gitignored; staleness confirmed by two independent QAs).