Release 0.65.9: lucisv-mcp no longer serves stale contents; the suite runs on Linux
TODO §70, closed. - lucisv_mcp/src/project/files.rs: Stamp's racy rule (re-check by content a stamp taken too close to a timestamp it trusts) covered the mtime alone. On Linux, where ctime moves in 1 ms ticks, a same-size rewrite that restored the old mtime inside the tick of the server's read matched in every field and index-based answers came from the old text indefinitely. The rule now covers every trusted timestamp (mtime, and ctime where there is one), the window is 3 s, and a wall clock stepped back since the read distrusts the stamp. The decision is a pure compare(Seen, Clocks) with deterministic unit tests. - Test-only: two stdin helpers tolerate BrokenPipe on the write to a child that exits before reading (lucisv cli.rs, lucisv_mcp qa_m8.rs); the didOpen latency test's budget is six parses of the same buffer, not 200 ms (lucisv_server e2e.rs); qa_m3's server is spawned before its checker thread, which removes a hang on a pipe inherited across threads on macOS. - .gitea/workflows/ci.yml: a linux job on the luhpe-linux-x64 runner — clippy and cargo test --workspace on Linux x86-64. - docs/features/mcp-transport describes the new rule and what it cannot see (Windows has no ctime; writable mmaps). Linux: whole suite green 10/10 as root and 10/10 as a user (dev), 6/6 and 6/6 (QA). QA reproduced the stale read on 0.65.8 (65/65, 87/87 when the stat was identical) and got 0 here. Dev, QA and lead review: docs/features/linux-test-portability/README.md, Round 2. Version bump (Cargo.toml, Cargo.lock, editors/vscode/package.json and both package-lock.json spots); notes in CHANGELOG.md (## 0.65.9) and editors/vscode/CHANGELOG.md. Gates: tools/gates.sh PASS on this tree including cross; lucisv_mcp 388/0. Co-Authored-By: Claude Mythos 5.2 <[email protected]>
This commit is contained in:
1 parent
934d472af2
commit
a8c22dcab0
17 files changed
+1083
-84
No files matched your search
+25
-2
@@ -1,7 +1,9 @@
|
|||||||
# CI: the three checks CLAUDE.md requires before any work is finished,
|
# CI: the three checks CLAUDE.md requires before any work is finished,
|
||||||
# plus the extension's JavaScript tests and the corpus gate, enforced on
|
# plus the extension's JavaScript tests and the corpus gate, enforced on
|
||||||
# every push. Runs on the self-hosted mac-arm64 runner in host mode (no
|
# every push. Runs on the self-hosted macOS runner in host mode (no
|
||||||
# containers), so the toolchain is the same one releases are built with.
|
# containers), so the toolchain is the same one releases are built with —
|
||||||
|
# and, since 0.65.9, the same checks on Linux (the `linux` job below), where
|
||||||
|
# the released Linux binaries had never been compiled-and-tested before.
|
||||||
name: ci
|
name: ci
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -41,3 +43,24 @@ jobs:
|
|||||||
run: cargo build --release -p lucisv
|
run: cargo build --release -p lucisv
|
||||||
- name: Score and gate
|
- name: Score and gate
|
||||||
run: scripts/corpus_gate.sh "$CORPUS"
|
run: scripts/corpus_gate.sh "$CORPUS"
|
||||||
|
|
||||||
|
# The suite on Linux x86-64: the luhpe-linux-x64 runner starts each job in
|
||||||
|
# the runner image (as root, 4 CPUs / 8 GB for the whole runner), with no
|
||||||
|
# Rust in it, so the toolchain is installed per job and the build is cold
|
||||||
|
# (a few minutes). Clippy is here as well as on macOS because code behind
|
||||||
|
# cfg(unix)/cfg(target_os) is only compiled on the platform it names: the
|
||||||
|
# first Linux trial failed clippy on imports macOS never saw. To run the
|
||||||
|
# same thing from a working tree without a push: tools/linux_check.sh.
|
||||||
|
linux:
|
||||||
|
runs-on: linux-x64
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- name: Install the Rust toolchain
|
||||||
|
run: |
|
||||||
|
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs \
|
||||||
|
| sh -s -- -y --profile minimal -c clippy,rustfmt
|
||||||
|
echo "$HOME/.cargo/bin" >> "$GITHUB_PATH"
|
||||||
|
- name: cargo clippy
|
||||||
|
run: cargo clippy --all-targets -- -D warnings
|
||||||
|
- name: cargo test
|
||||||
|
run: cargo test --workspace
|
||||||
@@ -4,6 +4,43 @@ All notable changes to lucisv are recorded here. Versions follow
|
|||||||
[semantic versioning](https://semver.org/); until 1.0 the CLI's exit codes
|
[semantic versioning](https://semver.org/); until 1.0 the CLI's exit codes
|
||||||
(see `README.md`) are the only frozen contract.
|
(see `README.md`) are the only frozen contract.
|
||||||
|
|
||||||
|
## 0.65.9 — 2026-11-19
|
||||||
|
|
||||||
|
### `lucisv-mcp` no longer serves stale contents; the suite runs on Linux
|
||||||
|
|
||||||
|
(`docs/features/linux-test-portability`, Round 2; TODO §70.)
|
||||||
|
|
||||||
|
- **`lucisv-mcp` no longer answers from a file's old contents after a
|
||||||
|
same-size rewrite that restores its old modification time.** The server
|
||||||
|
decides whether a file changed from its size, mtime, change time and
|
||||||
|
inode, and re-reads a file whose mtime is too fresh to trust — but it did
|
||||||
|
not apply that caution to the change time. On Linux, where the change time
|
||||||
|
moves in 1 ms ticks, a file rewritten at the same size with its mtime put
|
||||||
|
back (`cp -p`, `rsync -t`, `touch -r`, a rename-over) inside the same tick
|
||||||
|
as the server's read matched in every field, and index-based answers
|
||||||
|
(`find`, `hierarchy`, `check`) came from the old text until the file
|
||||||
|
changed again. `read` and `outline` were never affected. The rule now
|
||||||
|
covers every timestamp the stamp trusts, its window is 3 s (2 s was too
|
||||||
|
close to FAT's 2-second timestamps), and a wall clock stepped backwards
|
||||||
|
since a read distrusts the stamp. Reproduced on purpose on 0.65.8 (every
|
||||||
|
run with an identical stat was stale) and gone on this build across
|
||||||
|
overlayfs, tmpfs and APFS; ordinary reads cause no extra re-read.
|
||||||
|
- **What it still cannot see**, now written down in
|
||||||
|
`docs/features/mcp-transport`: on Windows there is no change time or
|
||||||
|
inode, so a same-size rewrite that restores the old mtime more than 3 s
|
||||||
|
after a read goes unseen; and a store through a writable memory map that
|
||||||
|
the kernel has not yet reflected in the file's timestamps. A tree whose
|
||||||
|
files carry modification times in the future is re-read on every call.
|
||||||
|
- **The test suite is stable on Linux, and CI runs it there.** It was green
|
||||||
|
on Linux most of the time and failed about one run in three: two test
|
||||||
|
helpers insisted that writing to a child's input succeed (a usage error
|
||||||
|
exits before reading), one latency test used a fixed 200 ms budget (it now
|
||||||
|
measures against a parse of the same buffer in the same process), and one
|
||||||
|
MCP test could hang on macOS under load on a pipe inherited across
|
||||||
|
threads. Ten consecutive green runs as root and ten as an unprivileged
|
||||||
|
user, then six and six by QA. `ci.yml` has a `linux` job (clippy and the
|
||||||
|
whole suite on Linux x86-64) beside the macOS one.
|
||||||
|
|
||||||
## 0.65.8 — 2026-11-19
|
## 0.65.8 — 2026-11-19
|
||||||
|
|
||||||
### Find References next to a name, edits kept in order, and a startup that could take minutes
|
### Find References next to a name, edits kept in order, and a startup that could take minutes
|
||||||
|
|||||||
Generated
+9
-9
@@ -97,7 +97,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lucisv"
|
name = "lucisv"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lucisv_core",
|
"lucisv_core",
|
||||||
"rayon",
|
"rayon",
|
||||||
@@ -108,11 +108,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lucisv_core"
|
name = "lucisv_core"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lucisv_mcp"
|
name = "lucisv_mcp"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lucisv_core",
|
"lucisv_core",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -126,7 +126,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "lucisv_server"
|
name = "lucisv_server"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lsp-server",
|
"lsp-server",
|
||||||
"lsp-types",
|
"lsp-types",
|
||||||
@@ -262,14 +262,14 @@ checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vlog_formatter"
|
name = "vlog_formatter"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"vlog_parser",
|
"vlog_parser",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vlog_linter"
|
name = "vlog_linter"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"lucisv_core",
|
"lucisv_core",
|
||||||
"vlog_formatter",
|
"vlog_formatter",
|
||||||
@@ -279,11 +279,11 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vlog_parser"
|
name = "vlog_parser"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vlog_refactor"
|
name = "vlog_refactor"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"vlog_formatter",
|
"vlog_formatter",
|
||||||
"vlog_parser",
|
"vlog_parser",
|
||||||
@@ -292,7 +292,7 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "vlog_semantic"
|
name = "vlog_semantic"
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"vlog_parser",
|
"vlog_parser",
|
||||||
]
|
]
|
||||||
+1
-1
@@ -13,7 +13,7 @@ members = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
version = "0.65.8"
|
version = "0.65.9"
|
||||||
authors = ["Guoliang Chen"]
|
authors = ["Guoliang Chen"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
@@ -7299,9 +7299,9 @@ as the trial shows. One lane, `docs/features/linux-test-portability`;
|
|||||||
left implicit, assertions on wall-clock or environment that the runner
|
left implicit, assertions on wall-clock or environment that the runner
|
||||||
shows to be fragile. No test is deleted and the test count does not
|
shows to be fragile. No test is deleted and the test count does not
|
||||||
drop; no production code and nothing in `verify.rs` changes.
|
drop; no production code and nothing in `verify.rs` changes.
|
||||||
- [ ] `cargo test --workspace` green on Linux as root and with `--user`,
|
- [x] `cargo test --workspace` green on Linux as root and with `--user`,
|
||||||
and `tools/gates.sh` green on macOS.
|
and `tools/gates.sh` green on macOS.
|
||||||
- [ ] (lead) `.gitea/workflows/ci.yml` gains a `linux` job on `linux-x64`;
|
- [x] (lead) `.gitea/workflows/ci.yml` gains a `linux` job on `linux-x64`;
|
||||||
`docs/topo.md` and `tools/RELEASING.md` updated.
|
`docs/topo.md` and `tools/RELEASING.md` updated.
|
||||||
|
|
||||||
## 71. The overnight queue (2026-11-19, owner's order) — eight features, one release each
|
## 71. The overnight queue (2026-11-19, owner's order) — eight features, one release each
|
||||||
@@ -7451,3 +7451,21 @@ indexing, collide with each other and with §70's test files, and wait for
|
|||||||
registration — the owner's call), excluded buffers after close (a
|
registration — the owner's call), excluded buffers after close (a
|
||||||
cheap fix belongs in the index layer: adding a file is a wide
|
cheap fix belongs in the index layer: adding a file is a wide
|
||||||
change), symlink spellings.
|
change), symlink spellings.
|
||||||
|
|
||||||
|
- §70 closed (lead, 2026-11-19), shipped with 0.65.9. Once ssh was back the
|
||||||
|
suite proved flaky on Linux (3 of 9 runs): two test helpers that insisted
|
||||||
|
a write to a child's stdin succeed, a 200 ms wall-clock bound, an MCP test
|
||||||
|
that could hang on an inherited pipe — and one real bug, `lucisv-mcp`
|
||||||
|
serving stale contents after a same-tick, same-size rewrite on Linux
|
||||||
|
(`project/files.rs`, the racy rule covered the mtime alone). All fixed in
|
||||||
|
lane 70b (`docs/features/linux-test-portability`, Round 2); Linux is green
|
||||||
|
10/10 as root and as a user (dev) and 6/6 each (QA); `ci.yml` has its
|
||||||
|
`linux` job. Left open:
|
||||||
|
- [ ] A file with an mtime in the future is re-read by `lucisv-mcp` on
|
||||||
|
every call, forever (67 ms against 7 ms per `find` on 4 000 files).
|
||||||
|
- [ ] `crates/lucisv/tests/cli.rs:2149` asserts only an empty stdout, no
|
||||||
|
exit code.
|
||||||
|
- [ ] `crates/lucisv_mcp/tests/qa_m3.rs` uses unix-only APIs with no cfg:
|
||||||
|
`cargo check --all-targets` for Windows fails there (tests only).
|
||||||
|
- [ ] The release is still gated on macOS alone; Windows is compile-checked
|
||||||
|
(`cross`), never executed.
|
||||||
+24
-10
@@ -92,16 +92,29 @@ fn run_in(dir: &TempDir, args: &[&str]) -> Output {
|
|||||||
Command::new(LUCISV).args(args).current_dir(&dir.path).output().expect("run lucisv")
|
Command::new(LUCISV).args(args).current_dir(&dir.path).output().expect("run lucisv")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs lucisv with the cache switched off, `input` on its stdin.
|
||||||
fn run_with_stdin(args: &[&str], input: &str) -> Output {
|
fn run_with_stdin(args: &[&str], input: &str) -> Output {
|
||||||
let mut child = Command::new(LUCISV)
|
run_with_stdin_raw(&with_no_cache(args), input)
|
||||||
.args(with_no_cache(args))
|
}
|
||||||
.stdin(Stdio::piped())
|
|
||||||
.stdout(Stdio::piped())
|
/// Writes `input` to the child's stdin and closes it.
|
||||||
.stderr(Stdio::piped())
|
///
|
||||||
.spawn()
|
/// A child that exits without reading — a usage error refuses before it
|
||||||
.expect("spawn lucisv");
|
/// looks at stdin — is legitimate, and the write then races its exit: it
|
||||||
child.stdin.as_mut().expect("stdin").write_all(input.as_bytes()).expect("write stdin");
|
/// fails with `BrokenPipe` when the child is already gone. That one error is
|
||||||
child.wait_with_output().expect("run lucisv")
|
/// not the test's business; the exit code and output the caller asserts on
|
||||||
|
/// are. (A successful write never meant the child read anything either:
|
||||||
|
/// every input here is far smaller than a pipe's buffer, so the write lands
|
||||||
|
/// in the buffer whether or not the child ever reads it.) Any other error is
|
||||||
|
/// a failure.
|
||||||
|
fn feed(child: &mut std::process::Child, input: &str) {
|
||||||
|
let mut stdin = child.stdin.take().expect("stdin");
|
||||||
|
match stdin.write_all(input.as_bytes()) {
|
||||||
|
Err(error) if error.kind() != std::io::ErrorKind::BrokenPipe => {
|
||||||
|
panic!("write stdin: {error:?}")
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn code(out: &Output) -> i32 {
|
fn code(out: &Output) -> i32 {
|
||||||
@@ -1755,6 +1768,7 @@ fn lines_neither_reads_nor_writes_the_cache() {
|
|||||||
assert!(!fresh.cache_file().exists(), "a range run must not seed the cache");
|
assert!(!fresh.cache_file().exists(), "a range run must not seed the cache");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Runs lucisv exactly as given, cache and all, `input` on its stdin.
|
||||||
fn run_with_stdin_raw(args: &[&str], input: &str) -> Output {
|
fn run_with_stdin_raw(args: &[&str], input: &str) -> Output {
|
||||||
let mut child = Command::new(LUCISV)
|
let mut child = Command::new(LUCISV)
|
||||||
.args(args)
|
.args(args)
|
||||||
@@ -1763,7 +1777,7 @@ fn run_with_stdin_raw(args: &[&str], input: &str) -> Output {
|
|||||||
.stderr(Stdio::piped())
|
.stderr(Stdio::piped())
|
||||||
.spawn()
|
.spawn()
|
||||||
.expect("spawn lucisv");
|
.expect("spawn lucisv");
|
||||||
child.stdin.as_mut().expect("stdin").write_all(input.as_bytes()).expect("write stdin");
|
feed(&mut child, input);
|
||||||
child.wait_with_output().expect("run lucisv")
|
child.wait_with_output().expect("run lucisv")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io;
|
use std::io;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, Instant, SystemTime};
|
||||||
|
|
||||||
use lucisv_core::cache::content_hash;
|
use lucisv_core::cache::content_hash;
|
||||||
use lucisv_core::config::Discovery;
|
use lucisv_core::config::Discovery;
|
||||||
@@ -16,11 +16,25 @@ use lucisv_core::walk::collect_files_with;
|
|||||||
/// something an agent wants summarised.
|
/// something an agent wants summarised.
|
||||||
pub const MAX_FILE_BYTES: u64 = 1024 * 1024;
|
pub const MAX_FILE_BYTES: u64 = 1024 * 1024;
|
||||||
|
|
||||||
/// A file whose mtime is this close to the moment it was read may have been
|
/// A file whose mtime or ctime is this close to the moment it was read may
|
||||||
/// written again within the filesystem's timestamp resolution, so its stamp
|
/// have been written again within the filesystem's timestamp resolution, so
|
||||||
/// proves nothing: it is re-read (and re-hashed) until it is older than
|
/// its stamp proves nothing: it is re-read (and re-hashed) until it is older
|
||||||
/// this. Git's "racy clean" rule, for the same reason.
|
/// than this. Git's "racy clean" rule, for the same reason.
|
||||||
const RACY: Duration = Duration::from_secs(2);
|
///
|
||||||
|
/// The window must outlast the coarsest timestamp a filesystem keeps plus
|
||||||
|
/// how far its clock can lag the one `read_at` comes from. Linux stamps
|
||||||
|
/// files from a clock that moves in 1–4 ms ticks; ext3 and many network
|
||||||
|
/// mounts keep whole seconds, FAT two. Three seconds covers FAT's two with
|
||||||
|
/// a second to spare. A just-changed file costs a few more re-reads; a
|
||||||
|
/// window too short costs stale contents.
|
||||||
|
const RACY: Duration = Duration::from_secs(3);
|
||||||
|
|
||||||
|
/// How far the wall clock may fall behind the monotonic one since a read
|
||||||
|
/// before the stamp stops being trusted: a clock stepped back can give a
|
||||||
|
/// later write the very timestamp the stamp holds. Large next to the
|
||||||
|
/// microseconds between the paired clock reads, small next to the margin
|
||||||
|
/// [`RACY`] keeps over the coarsest timestamps.
|
||||||
|
const STEP_BACK: Duration = Duration::from_millis(100);
|
||||||
|
|
||||||
/// The files one discovery found, and what it had to say about the rest.
|
/// The files one discovery found, and what it had to say about the rest.
|
||||||
#[derive(Debug, Default)]
|
#[derive(Debug, Default)]
|
||||||
@@ -137,13 +151,16 @@ pub struct Stamp {
|
|||||||
pub mtime: Option<SystemTime>,
|
pub mtime: Option<SystemTime>,
|
||||||
/// `content_hash` of its bytes.
|
/// `content_hash` of its bytes.
|
||||||
pub hash: u64,
|
pub hash: u64,
|
||||||
/// When it was read.
|
/// When it was read, by the wall clock file timestamps are compared with.
|
||||||
pub read_at: SystemTime,
|
pub read_at: SystemTime,
|
||||||
|
/// The same moment by the monotonic clock: what tells a wall clock that
|
||||||
|
/// was stepped back since the read.
|
||||||
|
pub read_mono: Instant,
|
||||||
/// Its ctime and inode — what still moves when a same-size rewrite puts
|
/// Its ctime and inode — what still moves when a same-size rewrite puts
|
||||||
/// the old mtime back (`cp -p`, `rsync -t`, `touch -r`), git's answer to
|
/// the old mtime back (`cp -p`, `rsync -t`, `touch -r`), git's answer to
|
||||||
/// the same problem. Zero off Unix, where size, mtime and the racy rule
|
/// the same problem. `None` off Unix, where size, mtime and the racy rule
|
||||||
/// are all there is.
|
/// are all there is.
|
||||||
pub identity: (i64, i64, u64),
|
pub identity: Option<Identity>,
|
||||||
/// Whether its text spells `endprogram` — the cheap test that says a
|
/// Whether its text spells `endprogram` — the cheap test that says a
|
||||||
/// `Module`-kind unit in it might be a `program` (the semantic layer
|
/// `Module`-kind unit in it might be a `program` (the semantic layer
|
||||||
/// models both as a module).
|
/// models both as a module).
|
||||||
@@ -161,6 +178,42 @@ pub enum Change {
|
|||||||
Gone,
|
Gone,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A file's inode change time and inode number (Unix only).
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub struct Identity {
|
||||||
|
/// The ctime, `None` when it does not fit a `SystemTime`.
|
||||||
|
pub ctime: Option<SystemTime>,
|
||||||
|
/// The inode number.
|
||||||
|
pub ino: u64,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What one `stat` says about a file, as far as a stamp is concerned.
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
struct Seen {
|
||||||
|
size: u64,
|
||||||
|
mtime: Option<SystemTime>,
|
||||||
|
identity: Option<Identity>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Seen {
|
||||||
|
fn of(meta: &fs::Metadata) -> Seen {
|
||||||
|
Seen { size: meta.len(), mtime: meta.modified().ok(), identity: identity(meta) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The two clocks, read back to back.
|
||||||
|
#[derive(Debug, Clone, Copy)]
|
||||||
|
struct Clocks {
|
||||||
|
wall: SystemTime,
|
||||||
|
mono: Instant,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Clocks {
|
||||||
|
fn now() -> Clocks {
|
||||||
|
Clocks { wall: SystemTime::now(), mono: Instant::now() }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Stamp {
|
impl Stamp {
|
||||||
/// Compare the file on disk with this stamp, by one `stat`.
|
/// Compare the file on disk with this stamp, by one `stat`.
|
||||||
pub fn check(&self, path: &Path) -> Change {
|
pub fn check(&self, path: &Path) -> Change {
|
||||||
@@ -170,18 +223,56 @@ impl Stamp {
|
|||||||
if !meta.is_file() || meta.len() > MAX_FILE_BYTES {
|
if !meta.is_file() || meta.len() > MAX_FILE_BYTES {
|
||||||
return Change::Gone;
|
return Change::Gone;
|
||||||
}
|
}
|
||||||
let mtime = meta.modified().ok();
|
self.compare(Seen::of(&meta), Clocks::now())
|
||||||
let racy = match mtime {
|
}
|
||||||
Some(mtime) => mtime + RACY > self.read_at,
|
|
||||||
None => true,
|
/// The decision [`Stamp::check`] makes, from what the `stat` saw and
|
||||||
};
|
/// what the clocks say now.
|
||||||
let moved = meta.len() != self.size || mtime != self.mtime;
|
fn compare(&self, seen: Seen, now: Clocks) -> Change {
|
||||||
if moved || identity(&meta) != self.identity || racy {
|
let moved =
|
||||||
|
seen.size != self.size || seen.mtime != self.mtime || seen.identity != self.identity;
|
||||||
|
if moved || self.racy() || self.clock_stepped_back(now) {
|
||||||
Change::Suspect
|
Change::Suspect
|
||||||
} else {
|
} else {
|
||||||
Change::Same
|
Change::Same
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// **Invariant: a stamp is trusted on a later match only if every
|
||||||
|
/// timestamp it trusts (the mtime, and the ctime where there is one) is
|
||||||
|
/// at least [`RACY`] older than the moment the stamp was taken** —
|
||||||
|
/// otherwise a write inside the same timestamp tick, after the read,
|
||||||
|
/// leaves every one of them as it was. A timestamp that is missing, or
|
||||||
|
/// later than the read (a clock behind the filesystem's), is racy too.
|
||||||
|
fn racy(&self) -> bool {
|
||||||
|
let ctime = self.identity.map(|identity| identity.ctime);
|
||||||
|
[Some(self.mtime), ctime].into_iter().flatten().any(|stamped| match stamped {
|
||||||
|
Some(time) => time.checked_add(RACY).is_none_or(|settled| settled > self.read_at),
|
||||||
|
None => true,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Whether the wall clock is now more than [`STEP_BACK`] behind where
|
||||||
|
/// the monotonic clock says it would be had it only run forward since
|
||||||
|
/// the read. After such a step a new write can be stamped with an old
|
||||||
|
/// time, so no timestamp match means anything until the file is re-read.
|
||||||
|
fn clock_stepped_back(&self, now: Clocks) -> bool {
|
||||||
|
let expected = match now.mono.checked_duration_since(self.read_mono) {
|
||||||
|
Some(elapsed) => self.read_at.checked_add(elapsed),
|
||||||
|
None => self.read_at.checked_sub(self.read_mono - now.mono),
|
||||||
|
};
|
||||||
|
match (expected, now.wall.checked_add(STEP_BACK)) {
|
||||||
|
(Some(expected), Some(tolerated)) => tolerated < expected,
|
||||||
|
_ => true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// This stamp as if it had been taken `by` later, on both clocks: how a
|
||||||
|
/// test ages a stamp past the racy window without waiting for it.
|
||||||
|
#[cfg(test)]
|
||||||
|
pub(crate) fn taken_later(self, by: Duration) -> Stamp {
|
||||||
|
Stamp { read_at: self.read_at + by, read_mono: self.read_mono + by, ..self }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Read one source file and stamp it. `Err` for a file that is gone or is
|
/// Read one source file and stamp it. `Err` for a file that is gone or is
|
||||||
@@ -191,33 +282,43 @@ pub fn read_source(path: &Path) -> io::Result<(String, Stamp)> {
|
|||||||
// Stat before reading: a write that lands between the two leaves a stamp
|
// Stat before reading: a write that lands between the two leaves a stamp
|
||||||
// older than the bytes, which the next sweep sees as a change.
|
// older than the bytes, which the next sweep sees as a change.
|
||||||
let meta = fs::metadata(path)?;
|
let meta = fs::metadata(path)?;
|
||||||
let read_at = SystemTime::now();
|
let read = Clocks::now();
|
||||||
let bytes = fs::read(path)?;
|
let bytes = fs::read(path)?;
|
||||||
let hash = content_hash(&bytes);
|
let hash = content_hash(&bytes);
|
||||||
let text = String::from_utf8(bytes)
|
let text = String::from_utf8(bytes)
|
||||||
.map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "not UTF-8 text"))?;
|
.map_err(|_| io::Error::new(io::ErrorKind::InvalidData, "not UTF-8 text"))?;
|
||||||
|
let seen = Seen::of(&meta);
|
||||||
let stamp = Stamp {
|
let stamp = Stamp {
|
||||||
size: meta.len(),
|
size: seen.size,
|
||||||
mtime: meta.modified().ok(),
|
mtime: seen.mtime,
|
||||||
hash,
|
hash,
|
||||||
read_at,
|
read_at: read.wall,
|
||||||
identity: identity(&meta),
|
read_mono: read.mono,
|
||||||
|
identity: seen.identity,
|
||||||
program: text.contains("endprogram"),
|
program: text.contains("endprogram"),
|
||||||
};
|
};
|
||||||
Ok((text, stamp))
|
Ok((text, stamp))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A file's ctime (seconds, nanoseconds) and inode number.
|
/// A file's ctime and inode number.
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn identity(meta: &fs::Metadata) -> (i64, i64, u64) {
|
fn identity(meta: &fs::Metadata) -> Option<Identity> {
|
||||||
use std::os::unix::fs::MetadataExt;
|
use std::os::unix::fs::MetadataExt;
|
||||||
(meta.ctime(), meta.ctime_nsec(), meta.ino())
|
let nanos = Duration::from_nanos(u64::try_from(meta.ctime_nsec()).unwrap_or(0));
|
||||||
|
let ctime = match u64::try_from(meta.ctime()) {
|
||||||
|
Ok(secs) => SystemTime::UNIX_EPOCH.checked_add(Duration::from_secs(secs) + nanos),
|
||||||
|
Err(_) => SystemTime::UNIX_EPOCH
|
||||||
|
.checked_sub(Duration::from_secs(meta.ctime().unsigned_abs()))
|
||||||
|
.and_then(|time| time.checked_add(nanos)),
|
||||||
|
};
|
||||||
|
Some(Identity { ctime, ino: meta.ino() })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// No ctime or inode off Unix: the stamp falls back to size and mtime.
|
/// No ctime or inode off Unix (std has no change time on Windows): the
|
||||||
|
/// stamp falls back to size and mtime, and the racy rule on the mtime.
|
||||||
#[cfg(not(unix))]
|
#[cfg(not(unix))]
|
||||||
fn identity(_: &fs::Metadata) -> (i64, i64, u64) {
|
fn identity(_: &fs::Metadata) -> Option<Identity> {
|
||||||
(0, 0, 0)
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
@@ -273,7 +374,7 @@ mod tests {
|
|||||||
let (_, stamp) = read_source(&path).unwrap();
|
let (_, stamp) = read_source(&path).unwrap();
|
||||||
// Just written: racy, so suspect even though nothing moved.
|
// Just written: racy, so suspect even though nothing moved.
|
||||||
assert_eq!(stamp.check(&path), Change::Suspect);
|
assert_eq!(stamp.check(&path), Change::Suspect);
|
||||||
let settled = Stamp { read_at: stamp.read_at + RACY + RACY, ..stamp };
|
let settled = stamp.taken_later(RACY + RACY);
|
||||||
assert_eq!(settled.check(&path), Change::Same);
|
assert_eq!(settled.check(&path), Change::Same);
|
||||||
fs::write(&path, "module a2; endmodule\n").unwrap();
|
fs::write(&path, "module a2; endmodule\n").unwrap();
|
||||||
assert_eq!(settled.check(&path), Change::Suspect);
|
assert_eq!(settled.check(&path), Change::Suspect);
|
||||||
@@ -281,4 +382,129 @@ mod tests {
|
|||||||
assert_eq!(settled.check(&path), Change::Gone);
|
assert_eq!(settled.check(&path), Change::Gone);
|
||||||
fs::remove_dir_all(dir).unwrap();
|
fs::remove_dir_all(dir).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The racy rule, decided from values: no file, no waiting, no clock but
|
||||||
|
// the ones given.
|
||||||
|
|
||||||
|
/// A stamp taken at `read` (wall) / `mono`, of a file whose mtime and
|
||||||
|
/// ctime are `mtime_age` and `ctime_age` before the read.
|
||||||
|
fn stamp_aged(
|
||||||
|
read: SystemTime,
|
||||||
|
mono: Instant,
|
||||||
|
mtime_age: Duration,
|
||||||
|
ctime_age: Duration,
|
||||||
|
) -> Stamp {
|
||||||
|
Stamp {
|
||||||
|
size: 20,
|
||||||
|
mtime: Some(read - mtime_age),
|
||||||
|
hash: 7,
|
||||||
|
read_at: read,
|
||||||
|
read_mono: mono,
|
||||||
|
identity: Some(Identity { ctime: Some(read - ctime_age), ino: 42 }),
|
||||||
|
program: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// What a `stat` of the unchanged file sees.
|
||||||
|
fn unchanged(stamp: &Stamp) -> Seen {
|
||||||
|
Seen { size: stamp.size, mtime: stamp.mtime, identity: stamp.identity }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The clocks a second after the read, both having run forward.
|
||||||
|
fn a_second_later(stamp: &Stamp) -> Clocks {
|
||||||
|
let second = Duration::from_secs(1);
|
||||||
|
Clocks { wall: stamp.read_at + second, mono: stamp.read_mono + second }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_match_is_trusted_only_when_every_timestamp_was_settled_at_the_read() {
|
||||||
|
let (read, mono) = (SystemTime::now(), Instant::now());
|
||||||
|
let old = Duration::from_secs(3600);
|
||||||
|
let fresh = Duration::from_millis(1);
|
||||||
|
let cases = [
|
||||||
|
("neither racy", old, old, Change::Same),
|
||||||
|
("mtime racy", fresh, old, Change::Suspect),
|
||||||
|
// The Linux hole: an old mtime put back, a ctime from this tick.
|
||||||
|
("ctime racy", old, fresh, Change::Suspect),
|
||||||
|
("both racy", fresh, fresh, Change::Suspect),
|
||||||
|
("just inside the window", old, RACY - Duration::from_nanos(1), Change::Suspect),
|
||||||
|
("exactly the window old", old, RACY, Change::Same),
|
||||||
|
];
|
||||||
|
for (what, mtime_age, ctime_age, expected) in cases {
|
||||||
|
let stamp = stamp_aged(read, mono, mtime_age, ctime_age);
|
||||||
|
assert_eq!(
|
||||||
|
stamp.compare(unchanged(&stamp), a_second_later(&stamp)),
|
||||||
|
expected,
|
||||||
|
"{what}"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_timestamp_later_than_the_read_or_missing_is_racy() {
|
||||||
|
let (read, mono) = (SystemTime::now(), Instant::now());
|
||||||
|
let old = Duration::from_secs(3600);
|
||||||
|
let mut ahead = stamp_aged(read, mono, old, old);
|
||||||
|
ahead.identity = Some(Identity { ctime: Some(read + Duration::from_secs(60)), ino: 42 });
|
||||||
|
assert_eq!(ahead.compare(unchanged(&ahead), a_second_later(&ahead)), Change::Suspect);
|
||||||
|
let mut no_ctime = stamp_aged(read, mono, old, old);
|
||||||
|
no_ctime.identity = Some(Identity { ctime: None, ino: 42 });
|
||||||
|
assert_eq!(
|
||||||
|
no_ctime.compare(unchanged(&no_ctime), a_second_later(&no_ctime)),
|
||||||
|
Change::Suspect
|
||||||
|
);
|
||||||
|
let mut no_mtime = stamp_aged(read, mono, old, old);
|
||||||
|
no_mtime.mtime = None;
|
||||||
|
assert_eq!(
|
||||||
|
no_mtime.compare(unchanged(&no_mtime), a_second_later(&no_mtime)),
|
||||||
|
Change::Suspect
|
||||||
|
);
|
||||||
|
// Off Unix there is no ctime to trust: the mtime alone decides.
|
||||||
|
let mut off_unix = stamp_aged(read, mono, old, old);
|
||||||
|
off_unix.identity = None;
|
||||||
|
assert_eq!(off_unix.compare(unchanged(&off_unix), a_second_later(&off_unix)), Change::Same);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_wall_clock_stepped_back_since_the_read_distrusts_the_stamp() {
|
||||||
|
let (read, mono) = (SystemTime::now(), Instant::now());
|
||||||
|
let old = Duration::from_secs(3600);
|
||||||
|
let stamp = stamp_aged(read, mono, old, old);
|
||||||
|
let ten = Duration::from_secs(10);
|
||||||
|
// Ten seconds of real time, but the wall clock shows one: stepped back.
|
||||||
|
let back = Clocks { wall: read + Duration::from_secs(1), mono: mono + ten };
|
||||||
|
assert_eq!(stamp.compare(unchanged(&stamp), back), Change::Suspect);
|
||||||
|
// Behind the read itself.
|
||||||
|
let behind = Clocks { wall: read - ten, mono: mono + Duration::from_secs(1) };
|
||||||
|
assert_eq!(stamp.compare(unchanged(&stamp), behind), Change::Suspect);
|
||||||
|
// A wall clock that ran ahead (a suspend the monotonic clock slept
|
||||||
|
// through) is no reason to doubt anything.
|
||||||
|
let ahead = Clocks { wall: read + ten, mono: mono + Duration::from_secs(1) };
|
||||||
|
assert_eq!(stamp.compare(unchanged(&stamp), ahead), Change::Same);
|
||||||
|
// Jitter under the tolerance is not a step.
|
||||||
|
let jitter = Clocks { wall: read + ten - STEP_BACK / 2, mono: mono + ten };
|
||||||
|
assert_eq!(stamp.compare(unchanged(&stamp), jitter), Change::Same);
|
||||||
|
// A stamp aged on both clocks at once is not a step either.
|
||||||
|
let aged = stamp.taken_later(ten);
|
||||||
|
assert_eq!(aged.compare(unchanged(&aged), a_second_later(&stamp)), Change::Same);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn any_moved_field_is_suspect_however_settled() {
|
||||||
|
let (read, mono) = (SystemTime::now(), Instant::now());
|
||||||
|
let old = Duration::from_secs(3600);
|
||||||
|
let stamp = stamp_aged(read, mono, old, old);
|
||||||
|
let now = a_second_later(&stamp);
|
||||||
|
let same = unchanged(&stamp);
|
||||||
|
let identity = stamp.identity.unwrap();
|
||||||
|
let moved = [
|
||||||
|
Seen { size: 21, ..same },
|
||||||
|
Seen { mtime: Some(read), ..same },
|
||||||
|
Seen { identity: Some(Identity { ino: 43, ..identity }), ..same },
|
||||||
|
Seen { identity: Some(Identity { ctime: Some(read - old / 2), ..identity }), ..same },
|
||||||
|
];
|
||||||
|
for seen in moved {
|
||||||
|
assert_eq!(stamp.compare(seen, now), Change::Suspect, "{seen:?}");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::Duration;
|
||||||
|
|
||||||
use vlog_semantic::WorkspaceIndex;
|
use vlog_semantic::WorkspaceIndex;
|
||||||
|
|
||||||
@@ -29,9 +29,8 @@ fn rebuilt(project: &Project) -> String {
|
|||||||
|
|
||||||
/// Age every stamp past the racy window, so only a real change is suspect.
|
/// Age every stamp past the racy window, so only a real change is suspect.
|
||||||
fn settle(project: &mut Project) {
|
fn settle(project: &mut Project) {
|
||||||
let later = SystemTime::now() + Duration::from_secs(10);
|
|
||||||
for stamp in project.files.values_mut() {
|
for stamp in project.files.values_mut() {
|
||||||
stamp.read_at = later;
|
*stamp = stamp.taken_later(Duration::from_secs(10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -706,6 +706,15 @@ fn qa_lucisv_check_over_the_same_tree_while_the_server_formats() {
|
|||||||
copy_tree(&scratch.0, &reference.0);
|
copy_tree(&scratch.0, &reference.0);
|
||||||
let status = Command::new(&cli).arg("--no-cache").arg(&reference.0).output().unwrap();
|
let status = Command::new(&cli).arg("--no-cache").arg(&reference.0).output().unwrap();
|
||||||
assert!(status.status.success(), "{status:?}");
|
assert!(status.status.success(), "{status:?}");
|
||||||
|
// The server is spawned before the checker starts, never while it runs.
|
||||||
|
// A spawn on one thread can inherit a pipe another thread is just
|
||||||
|
// creating for its child: macOS has no `pipe2`, so close-on-exec is set
|
||||||
|
// in a second step. Seen once under load (2026-11-19, `lsof`): the
|
||||||
|
// server held the write end of a `lucisv --check`'s stdout. That
|
||||||
|
// `output()` never saw EOF, `join` below waited on it, and the server,
|
||||||
|
// which lives until this test ends, never let go, so the test hung.
|
||||||
|
// Spawned first, the server cannot hold any of the checker's pipes.
|
||||||
|
let mut server = Session::over(&scratch);
|
||||||
let stop = Arc::new(AtomicBool::new(false));
|
let stop = Arc::new(AtomicBool::new(false));
|
||||||
let checker = {
|
let checker = {
|
||||||
let (stop, cli, root) = (Arc::clone(&stop), cli.clone(), scratch.0.clone());
|
let (stop, cli, root) = (Arc::clone(&stop), cli.clone(), scratch.0.clone());
|
||||||
@@ -719,7 +728,6 @@ fn qa_lucisv_check_over_the_same_tree_while_the_server_formats() {
|
|||||||
codes
|
codes
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
let mut server = Session::over(&scratch);
|
|
||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
for (name, text) in &messy {
|
for (name, text) in &messy {
|
||||||
scratch.write(name, text);
|
scratch.write(name, text);
|
||||||
|
|||||||
@@ -113,7 +113,14 @@ fn run(args: &[&str], lines: &[Value]) -> Output {
|
|||||||
Value::String(raw) => raw.clone(),
|
Value::String(raw) => raw.clone(),
|
||||||
other => other.to_string(),
|
other => other.to_string(),
|
||||||
};
|
};
|
||||||
writeln!(stdin, "{text}").unwrap();
|
// A refused argument list exits 2 before reading a byte, so the write
|
||||||
|
// races that exit and can fail with `BrokenPipe`. That is the child
|
||||||
|
// being gone, not the test failing: what it said and its exit code
|
||||||
|
// are what the caller asserts on. Any other error is a failure.
|
||||||
|
match writeln!(stdin, "{text}") {
|
||||||
|
Err(error) if error.kind() == std::io::ErrorKind::BrokenPipe => break,
|
||||||
|
result => result.unwrap(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
drop(stdin);
|
drop(stdin);
|
||||||
child.wait_with_output().unwrap()
|
child.wait_with_output().unwrap()
|
||||||
|
|||||||
@@ -8474,11 +8474,19 @@ fn indexed_neighbours(dir: &Path, files: usize) {
|
|||||||
/// leave the request behind it waiting.
|
/// leave the request behind it waiting.
|
||||||
///
|
///
|
||||||
/// **An upper bound, not a benchmark, and a debug-build one.** `cargo test`
|
/// **An upper bound, not a benchmark, and a debug-build one.** `cargo test`
|
||||||
/// builds unoptimized, where one tolerant parse of 2 000 lines is ~53 ms all
|
/// builds unoptimized, where one tolerant parse of 2 000 lines is 11–53 ms
|
||||||
/// by itself — measured on this machine, and stable to a millisecond across
|
/// all by itself on the dev machines and 50–70 ms on the Linux runner. The
|
||||||
/// runs. So the 200 ms here is that floor with room for a loaded CI box, not
|
/// ≤ 25 ms §46 asked for is **a release number** (the release binary opens
|
||||||
/// the ≤ 25 ms §46 asked for: **that figure is a release number**, and the
|
/// the same buffer in 2–4 ms), so it is not what is asserted here.
|
||||||
/// release binary opens the same buffer in 2–4 ms.
|
///
|
||||||
|
/// **The budget is measured, not written down.** A fixed 200 ms was that
|
||||||
|
/// floor with room on the dev machine, and nothing anywhere else: the Linux
|
||||||
|
/// CI box (4 CPUs, under the whole suite) took 205 ms for its *best* of
|
||||||
|
/// three. So the floor is measured in this process, next to every open: one
|
||||||
|
/// tolerant parse of the same buffer, through the same parser in the same
|
||||||
|
/// build. The open must cost at most [`OPEN_OVER_PARSE`] of those — which is
|
||||||
|
/// what "bounded" means for an open that must parse its buffer anyway — and
|
||||||
|
/// a machine or a moment that is slower slows both.
|
||||||
///
|
///
|
||||||
/// **What this test does and does not catch.** It catches an open that starts
|
/// **What this test does and does not catch.** It catches an open that starts
|
||||||
/// doing something *unbounded* — the shape §46 fixed. It cannot catch the
|
/// doing something *unbounded* — the shape §46 fixed. It cannot catch the
|
||||||
@@ -8490,15 +8498,16 @@ fn indexed_neighbours(dir: &Path, files: usize) {
|
|||||||
/// which counts the questions instead of timing them
|
/// which counts the questions instead of timing them
|
||||||
/// (`docs/features/didopen-cost/README.md`).
|
/// (`docs/features/didopen-cost/README.md`).
|
||||||
///
|
///
|
||||||
/// Best of three distinct buffers: the first open of a process pays cold code
|
/// Best of [`OPEN_ROUNDS`] distinct buffers, and the best of as many parses:
|
||||||
/// paths that have nothing to do with the buffer, and a wall-clock assertion
|
/// the first open of a process pays cold code paths that have nothing to do
|
||||||
/// that cannot tolerate one scheduling hiccup is a flake, not a pin.
|
/// with the buffer, and a wall-clock assertion that cannot tolerate one
|
||||||
|
/// scheduling hiccup is a flake, not a pin.
|
||||||
#[test]
|
#[test]
|
||||||
fn opening_a_two_thousand_line_buffer_does_not_delay_the_request_behind_it() {
|
fn opening_a_two_thousand_line_buffer_does_not_delay_the_request_behind_it() {
|
||||||
let dir = temp_dir("didopen_cost");
|
let dir = temp_dir("didopen_cost");
|
||||||
indexed_neighbours(&dir, 40);
|
indexed_neighbours(&dir, 40);
|
||||||
let mut generated = Vec::new();
|
let mut generated = Vec::new();
|
||||||
for n in 0..3 {
|
for n in 0..OPEN_ROUNDS {
|
||||||
let name = format!("gen{n}");
|
let name = format!("gen{n}");
|
||||||
// The generator the perf tables use: a thousand declarations, every
|
// The generator the perf tables use: a thousand declarations, every
|
||||||
// one declared, driven and read — the cheap case for the *findings*
|
// one declared, driven and read — the cheap case for the *findings*
|
||||||
@@ -8514,20 +8523,51 @@ fn opening_a_two_thousand_line_buffer_does_not_delay_the_request_behind_it() {
|
|||||||
let warm = format!("file://{}", dir.join("pkg0.sv").display());
|
let warm = format!("file://{}", dir.join("pkg0.sv").display());
|
||||||
open_then_hover(&mut live, 10, &warm, "package pkg0;\n localparam int K0 = 0;\nendpackage\n");
|
open_then_hover(&mut live, 10, &warm, "package pkg0;\n localparam int K0 = 0;\nendpackage\n");
|
||||||
|
|
||||||
let mut best = std::time::Duration::MAX;
|
// Each round times the floor, then the open, so load that comes and goes
|
||||||
|
// lands on both kinds of sample alike.
|
||||||
|
let (mut open, mut parse) = (std::time::Duration::MAX, std::time::Duration::MAX);
|
||||||
for (n, (path, text)) in generated.iter().enumerate() {
|
for (n, (path, text)) in generated.iter().enumerate() {
|
||||||
|
parse = parse.min(one_tolerant_parse(text));
|
||||||
let uri = format!("file://{}", path.display());
|
let uri = format!("file://{}", path.display());
|
||||||
best = best.min(open_then_hover(&mut live, 20 + n as u32, &uri, text));
|
open = open.min(open_then_hover(&mut live, 20 + n as u32, &uri, text));
|
||||||
}
|
}
|
||||||
live.finish();
|
live.finish();
|
||||||
let _ = std::fs::remove_dir_all(&dir);
|
let _ = std::fs::remove_dir_all(&dir);
|
||||||
|
|
||||||
|
let ratio = open.as_secs_f64() / parse.as_secs_f64();
|
||||||
|
eprintln!("didOpen of 2 000 lines: best open {open:?}, best parse {parse:?}, {ratio:.2}x");
|
||||||
assert!(
|
assert!(
|
||||||
best <= std::time::Duration::from_millis(200),
|
ratio <= OPEN_OVER_PARSE,
|
||||||
"a didOpen of a 2 000-line buffer delayed the next request by {best:?}"
|
"a didOpen of a 2 000-line buffer delayed the next request by {open:?}, \
|
||||||
|
{ratio:.2}x one parse of it ({parse:?}); the budget is {OPEN_OVER_PARSE}x"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Distinct 2 000-line buffers opened, and parses timed, by the test above.
|
||||||
|
const OPEN_ROUNDS: usize = 5;
|
||||||
|
|
||||||
|
/// How many parses of its own buffer an open may cost, request included.
|
||||||
|
///
|
||||||
|
/// Measured 2026-11-19 (best of five each, debug build): the open costs
|
||||||
|
/// 2.5–3.2 parses on the dev machine, quiet or under 36 busy loops on its 18
|
||||||
|
/// CPUs; 2.3–3.6 on the 4-CPU Linux runner when quiet; and 2.5–3.3 there
|
||||||
|
/// under 8 busy loops, where the open itself took ~1 s (the old fixed
|
||||||
|
/// 200 ms would have failed every run there). The ratio holds still while the wall
|
||||||
|
/// clock moves 6x. Six is ~1.7x over the worst ratio seen; an open made to
|
||||||
|
/// parse its buffer four extra times fails it (6.9x on the dev machine,
|
||||||
|
/// where the old 200 ms passed that at 84 ms), three extra times is ~5.9x
|
||||||
|
/// (`docs/features/linux-test-portability/README.md`, round 2).
|
||||||
|
const OPEN_OVER_PARSE: f64 = 6.0;
|
||||||
|
|
||||||
|
/// The wall clock of one tolerant parse of `text`, in this process.
|
||||||
|
fn one_tolerant_parse(text: &str) -> std::time::Duration {
|
||||||
|
let started = std::time::Instant::now();
|
||||||
|
let (file, _) = vlog_parser::parse_source_tolerant(text);
|
||||||
|
let took = started.elapsed();
|
||||||
|
std::hint::black_box(file);
|
||||||
|
took
|
||||||
|
}
|
||||||
|
|
||||||
/// The other half of §46's contract: the request after an open is answered
|
/// The other half of §46's contract: the request after an open is answered
|
||||||
/// from the **buffer**, not from what is on disk.
|
/// from the **buffer**, not from what is on disk.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -36,13 +36,52 @@ the assertion where it *can* run.
|
|||||||
## Handshakes
|
## Handshakes
|
||||||
|
|
||||||
- Consumes nothing new from production code. No production file, no
|
- Consumes nothing new from production code. No production file, no
|
||||||
`verify.rs`, no workflow, version file or changelog changes.
|
`verify.rs`, no workflow, version file or changelog changes — **except**
|
||||||
|
the round 2 product fix the lead granted (2026-11-19):
|
||||||
|
`crates/lucisv_mcp/src/project/files.rs` and its test fixture
|
||||||
|
`project/tests.rs`. `Stamp`'s public shape changed (`identity` is now
|
||||||
|
`Option<Identity>`, new `read_mono`); its only users are inside
|
||||||
|
`lucisv_mcp::project`, nothing outside the crate sees it.
|
||||||
- `tools/linux_check.sh` (the lead's): used as written in round 1; changed
|
- `tools/linux_check.sh` (the lead's): used as written in round 1; changed
|
||||||
in the fix round (QA finding 5, see the work log). Its usage line gained
|
in the fix round (QA finding 5, see the work log). Its usage line gained
|
||||||
`--dry-run`; the single-string form is unchanged.
|
`--dry-run`; the single-string form is unchanged.
|
||||||
- Scope extension granted by the lead in the fix round:
|
- Scope extension granted by the lead in the fix round:
|
||||||
`crates/lucisv_server/src/server/tests/scan_trace.rs` (test file only).
|
`crates/lucisv_server/src/server/tests/scan_trace.rs` (test file only).
|
||||||
- Requests: none.
|
- Requests: none (round 1).
|
||||||
|
- **Round 2 request: a product bug, not a test flake. Owner: `lucisv_mcp`.**
|
||||||
|
`crates/lucisv_mcp/src/project/files.rs:166-184`, `Stamp::check`. The
|
||||||
|
racy rule (`mtime + RACY > read_at`, line 175) covers the mtime only. The
|
||||||
|
ctime half of `identity` (line 214) has no racy rule. On Linux 6.8
|
||||||
|
(luhpe: ext4 under overlayfs, `CONFIG_HZ=1000`) the kernel stamps ctime
|
||||||
|
from the coarse clock, in 1 ms steps. Suppose a file's ctime moves (here a
|
||||||
|
rename-over), the server stats and reads it, and the file is rewritten at
|
||||||
|
the same size with its old mtime put back (`cp -p`, `rsync -t`,
|
||||||
|
`touch -r`), all within the same 1 ms tick. Then size, mtime, ctime and
|
||||||
|
inode all match the stamp. The check answers `Same`, and the stale
|
||||||
|
contents are served **for good**, because every later stat says the same.
|
||||||
|
- Reproduction:
|
||||||
|
`tools/linux_check.sh 'for i in $(seq 150); do cargo test -q -p lucisv_mcp --test qa_m1 qa_rework_a_rename_over_with_an_old_mtime_and_the_same_size_is_seen -- --exact; done'`.
|
||||||
|
Result: 12/150 failed as root with nothing else running, and 39/300 in
|
||||||
|
an earlier loop. It also failed once in the full suite as `--user` before
|
||||||
|
this round.
|
||||||
|
- Instrumented, by printing `(ctime, ctime_nsec, ino)` of `c.sv` after the
|
||||||
|
rename and after the rewrite (a temporary edit, since reverted). Every
|
||||||
|
failure had the two identical to the nanosecond. In every pass (261
|
||||||
|
printed) they were 1 or 2 ms apart, never 0. The `find` between them
|
||||||
|
took 0.44–0.66 ms. The failing answer was
|
||||||
|
``no declaration named `chyrlie`.``
|
||||||
|
- macOS: APFS ctime comes from a fine clock, so it always moves, and the
|
||||||
|
test has never failed there.
|
||||||
|
- **Resolved in round 2 by the lead's scope extension** (work log,
|
||||||
|
"the stamp fix"). The suggestion was: give ctime the racy
|
||||||
|
rule mtime has. A stamp whose ctime is within `RACY` of `read_at` is
|
||||||
|
`Suspect`, so it is re-read and re-hashed until it is older. The same
|
||||||
|
argument as git's racily-clean entries.
|
||||||
|
- The test was **left unchanged** on purpose, and still is. It is right,
|
||||||
|
and making it wait for the clock to tick would hide the bug. Before the
|
||||||
|
fix it failed about 1 in 10 runs alone on that box. Under load it fails less
|
||||||
|
often, because the `find` then takes longer than a tick: 0/200 under
|
||||||
|
8 busy loops.
|
||||||
|
|
||||||
## Status / TODO
|
## Status / TODO
|
||||||
|
|
||||||
@@ -67,8 +106,31 @@ the assertion where it *can* run.
|
|||||||
times a copy of the `Server::large_scan` loop, not the production loop
|
times a copy of the `Server::large_scan` loop, not the production loop
|
||||||
at `server/large_file.rs:151`, so a per-hit rescan reintroduced there
|
at `server/large_file.rs:151`, so a per-hit rescan reintroduced there
|
||||||
would not be caught. Needs a test that drives the production path.
|
would not be caught. Needs a test that drives the production path.
|
||||||
- [ ] Re-run on Linux once ssh to luhpe is back: everything in the fix round
|
- [x] Re-run on Linux once ssh to luhpe is back. Done in round 2, against
|
||||||
and everything since 0.65.2 is unverified there (list in the work log).
|
0.65.6 plus this round (see the round 2 work log).
|
||||||
|
|
||||||
|
### Round 2 (flakes on Linux)
|
||||||
|
|
||||||
|
- [x] Census: 2 090 single-test iterations on Linux (alone and under load)
|
||||||
|
and 57 whole-suite runs (Linux root and `--user`, macOS under load).
|
||||||
|
Every test that failed even once is in the table in the work log.
|
||||||
|
- [x] stdin `BrokenPipe` on a child that exits before reading: `cli.rs`
|
||||||
|
(both stdin helpers) and `qa_m8.rs` (`run`) tolerate that one error
|
||||||
|
and still assert on the exit code and output.
|
||||||
|
- [x] `e2e.rs` didOpen budget: a multiple of one parse of the same buffer
|
||||||
|
measured in the same process, instead of a fixed 200 ms.
|
||||||
|
- [x] `qa_m3.rs` CLI-while-formatting hang on macOS (an inherited pipe):
|
||||||
|
the server is spawned before the checker thread starts.
|
||||||
|
- [x] Every other wall-clock assertion reviewed; each left as it was, with
|
||||||
|
the reason (work log).
|
||||||
|
- [x] **Product bug, fixed (scope extended by the lead):** `qa_m1.rs`
|
||||||
|
`qa_rework_a_rename_over_with_an_old_mtime_and_the_same_size_is_seen`
|
||||||
|
failed on Linux about 1 run in 10 alone — a real staleness bug in
|
||||||
|
`Stamp::check` (Handshakes). The racy rule now covers the ctime, the
|
||||||
|
window is 3 s, and a wall clock stepped back distrusts every stamp;
|
||||||
|
the test itself is unchanged.
|
||||||
|
- [x] Audit of the other caches for the same hole: none has it (work log).
|
||||||
|
- [x] Deterministic unit tests of the racy decision; mutations shown.
|
||||||
|
|
||||||
## Work log
|
## Work log
|
||||||
|
|
||||||
@@ -276,6 +338,335 @@ Unverified on Linux (all of it rests on round 1, against 88546c8 + lane):
|
|||||||
- everything trunk added in 0.65.2 and 0.65.3;
|
- everything trunk added in 0.65.2 and 0.65.3;
|
||||||
- the second root run, which never happened in round 1 either.
|
- the second root run, which never happened in round 1 either.
|
||||||
|
|
||||||
|
### Round 2
|
||||||
|
|
||||||
|
**2026-11-19 (dev, round 2: the Linux flakes).** Tree: 58d3db3 (0.65.6) plus
|
||||||
|
this round, in `lucisv-wt/70b`. The brief reported master's record on Linux
|
||||||
|
as 9 full runs, 3 with a failure, each from a different test. Linux means
|
||||||
|
`tools/linux_check.sh` on luhpe: the CI job image, 4-CPU cap, kernel
|
||||||
|
6.8.0, ext4 under overlayfs, `CONFIG_HZ=1000`, debug build. macOS means
|
||||||
|
arm64 with 18 CPUs; another lane was running there too. Every macOS
|
||||||
|
`cargo test` went through `tools/guard.sh`, and there was no guard kill.
|
||||||
|
|
||||||
|
*Method.*
|
||||||
|
- Loops of the single test, in the job image, run alone and then under 8
|
||||||
|
busy loops on the 4-CPU cap. The baseline was rebuilt in the same
|
||||||
|
container with `git apply -R` of this round's patch, so before and after
|
||||||
|
share one build cache and one box.
|
||||||
|
- Whole-suite runs with `--no-fail-fast`. Each one keeps its result totals
|
||||||
|
and every failing test's output.
|
||||||
|
- Temporary instrumentation where the output was not enough. It was taken
|
||||||
|
out again, and each touched file was restored from a copy and checked
|
||||||
|
with `cmp`.
|
||||||
|
|
||||||
|
**Flake census**
|
||||||
|
|
||||||
|
| test | platform | before | cause | fix | after |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| `lucisv/tests/cli.rs` `stdin_and_lines_are_usage_errors_with_a_filelist` | Linux root | 2/9 master runs; 1/5 baseline runs; loop 0/200 alone, **42/200 loaded** | `run_with_stdin` `expect`ed the stdin write. A usage error exits before reading, so the write races the exit and gets `BrokenPipe`. | Both stdin helpers write through `feed`, which ignores `BrokenPipe` only; `run_with_stdin` is now `run_with_stdin_raw` plus `--no-cache`. | loop 0/200 alone, **0/200 loaded**; 0 in 30 Linux suite runs |
|
||||||
|
| `lucisv_mcp/tests/qa_m8.rs` `qa_argument_order_and_repetition_cannot_undo_read_only` | Linux root | 1/5 baseline runs; loop 0/200 alone, **37/100 loaded** | Same race: `run` `unwrap`ped `writeln!` to a server that refuses `--read-only=false` and friends with exit 2. Found by the census; not in the brief. | `run` stops writing on `BrokenPipe` and `unwrap`s any other error. | loop 0/200 alone, **0/100 loaded**; 0 in 30 suite runs |
|
||||||
|
| `lucisv_server/tests/e2e.rs` `opening_a_two_thousand_line_buffer_does_not_delay_the_request_behind_it` | Linux root | 2/9 master runs (205.15 ms against 200) | A fixed 200 ms against a measured floor of 146–179 ms best of three, quiet. Under 8 busy loops the open took 0.5–1.1 s, so the old bound would fail every time. | The budget is `OPEN_OVER_PARSE` (6) times the best of 5 in-process tolerant parses of the same buffer, interleaved with the 5 opens. | 0/20 alone, 0/20 loaded; 0 in 30 suite runs |
|
||||||
|
| `lucisv_mcp/tests/qa_m1.rs` `qa_rework_a_rename_over_with_an_old_mtime_and_the_same_size_is_seen` | Linux | 1/9 master runs (`--user`); loop **39/300 and 12/150 alone**, 0/200 loaded | **A product bug** (Handshakes): ctime moves in 1 ms ticks, and a same-size rewrite with the old mtime put back inside the tick is invisible to `Stamp::check`. All 12 instrumented failures had identical `(ctime, nsec, ino)`; all 261 instrumented passes were 1–2 ms apart. | **None, on purpose.** The test is right. | unchanged: 0 in the last 30 Linux suite runs, but about 1 in 10 alone |
|
||||||
|
| `lucisv_mcp/tests/qa_m3.rs` `qa_lucisv_check_over_the_same_tree_while_the_server_formats` | macOS, under 18 busy loops | **hung** once in 2 runs (still running after 9 min) | `sample` showed the checker thread in `Command::output` → `read`, with no `lucisv` child alive. `lsof` showed the test's `lucisv-mcp` server holding the other end of that pipe: it had inherited the pipe when it was spawned while the checker was making one (macOS has no `pipe2`). `join` waited on the checker, and the server lived until the test ended. Found by the census. | The server is spawned before the checker thread starts. | 0 hangs in 20 macOS runs under load; 0 in 20 Linux runs |
|
||||||
|
|
||||||
|
Nothing else failed in any run: Linux root 5 baseline runs, then 10 + 10 on
|
||||||
|
the fixed tree; Linux `--user` 10; macOS 2 + 20 under load (the second
|
||||||
|
batch under 9 busy loops, since 18 put one suite run over 20 min). Round 1's
|
||||||
|
`scan_trace` and `large.rs` fixes ran on Linux in all of them and never
|
||||||
|
failed.
|
||||||
|
|
||||||
|
**The wall-clock assertions** (an inventory of every test-code assertion on
|
||||||
|
measured time):
|
||||||
|
- **Changed:** e2e.rs didOpen (above).
|
||||||
|
- **Ratios already:** `large.rs` `assert_grows_linearly` (round 1);
|
||||||
|
`lens.rs:756` (`whole_file * 10 < walk`); `scan_trace.rs` (round 1).
|
||||||
|
- **Algorithmic guards with absolute bounds, left as they are:**
|
||||||
|
`pairs.rs:1159/1171/1190` (2 s, ~45x the honest 5–44 ms, against 7–17 s
|
||||||
|
quadratic); `regex.rs:631` (500 ms against microseconds, exponential
|
||||||
|
matcher far past it); `lexer.rs:1313` (5 s, "three orders of magnitude"
|
||||||
|
in either build); `e2e.rs:5780` (10 s, 25x the measured 0.4 s). The
|
||||||
|
regression each one guards is two or more orders of magnitude past its
|
||||||
|
bound, and the honest cost is one or more below it, so a ratio would buy
|
||||||
|
nothing. None failed in any run.
|
||||||
|
- **"Nothing was waited for" bounds, left as they are:** `startup.rs:488`
|
||||||
|
and `:1071` (< 1 s, against a 2 s bound and a 25 ms bound),
|
||||||
|
`startup.rs:528` (< 5 s against a 30 s bound), `e2e.rs:9118/9130` (< 1 s
|
||||||
|
against the 1.5 s grace). Each has to stay under the wait it proves was
|
||||||
|
skipped, so raising it is not free, and none failed.
|
||||||
|
- **Lower bounds** (`e2e.rs:9096/9193`, `startup.rs:182`): load can only
|
||||||
|
make them pass.
|
||||||
|
- **Corpus-only latency budgets**: `hierarchy.rs:1123`, `lens.rs:754`,
|
||||||
|
`type_hierarchy.rs:1289/1291`, `completion/mod.rs:787-789/856`,
|
||||||
|
`vlog_refactor/tests/corpus.rs:100/175`, `vlog_semantic/tests/workspace.rs:977`.
|
||||||
|
These skip without `corpus/`, which the Linux tree does not have. They
|
||||||
|
are budgets for a known machine. Not changed, and not exercised on
|
||||||
|
Linux.
|
||||||
|
- **`#[ignore]`d:** `large.rs:727-735`, `:764`.
|
||||||
|
|
||||||
|
**The mtime/sleep review.**
|
||||||
|
- `set_modified` users:
|
||||||
|
- `wire.rs:1250`, `qa_m6.rs:568` and `qa_f1.rs:666` set an hour-old mtime
|
||||||
|
on purpose. They do not rely on it moving.
|
||||||
|
- `qa_m1.rs:588`, a rename-then-recreate, gets a new inode.
|
||||||
|
- `qa_m1.rs:605`, a same-mtime rewrite, rests on the racy rule.
|
||||||
|
- `qa_m1.rs:617` restores an old mtime. Its ctime moves across a process
|
||||||
|
spawn and two calls, far more than a tick.
|
||||||
|
- `qa_m1.rs:936` is the product bug above.
|
||||||
|
- Sleeps: `qa_m3.rs:598/622`, `e2e.rs:9151` (the 1.7 s that outlasts the
|
||||||
|
1.5 s grace) and `cancel.rs:347`. None failed, so all are left.
|
||||||
|
|
||||||
|
**Stdin writers reviewed.** Every test that writes to a child's stdin was
|
||||||
|
checked:
|
||||||
|
- The interactive sessions (`cache`, `qa_m2/3/4/6`, `qa_f1/f2`, `attacks`,
|
||||||
|
`read_only`, `wire`, `opentitan*`, `e2e`'s `Live`) only write to a server
|
||||||
|
the test expects to be alive. A `BrokenPipe` there means the server died,
|
||||||
|
which is a failure, so those writes stay strict.
|
||||||
|
- The one-shot sessions write to a server that reads to EOF and exits only
|
||||||
|
when told to, so the strict write stays: `e2e.rs` `talk_with`,
|
||||||
|
`ifdef_folding.rs` `talk`, `qa_m7.rs`, `hierarchy_cap.rs`.
|
||||||
|
- `qa_m1.rs` `one_shot` already ignored write errors.
|
||||||
|
|
||||||
|
**Evidence the stdin fixes neither hide anything nor weaken anything** (macOS):
|
||||||
|
- With a 300 ms sleep before the write (the race made certain), the **old**
|
||||||
|
helpers fail 1/1 with `BrokenPipe` (`cli.rs:104`, `qa_m8.rs:117`). The
|
||||||
|
fixed ones pass, and so does the whole of `cli` (113/113) and `qa_m8`
|
||||||
|
(6/6) with the sleep in. So no test needed the write to succeed. It never
|
||||||
|
meant the child had read anything: every input is far smaller than a pipe
|
||||||
|
buffer.
|
||||||
|
- Sleeps removed; both files compared with `cmp` against copies.
|
||||||
|
|
||||||
|
**Mutation table** (production sabotage on macOS, restored from a copy and
|
||||||
|
checked with `cmp` / `git status`):
|
||||||
|
|
||||||
|
| test | sabotage | failed? | restored |
|
||||||
|
|---|---|---|---|
|
||||||
|
| cli `stdin_and_lines_are_usage_errors_with_a_filelist` | `args.rs:486` `if false && …` (accept `-` with `-f`) | yes, cli.rs:1942 `left: 0, right: 2` | yes |
|
||||||
|
| qa_m8 `qa_argument_order_and_repetition_cannot_undo_read_only` | `lucisv_mcp/src/main.rs:93` accept `--readonly` as `--read-only` | yes, qa_m8.rs:342 "started a server" | yes |
|
||||||
|
| e2e didOpen | `server/notification.rs` didOpen: parse the buffer 4 extra times | yes, 3/3 at 6.94x (84 ms; the old 200 ms would pass) | yes |
|
||||||
|
| e2e didOpen (sensitivity) | the same, 3 extra times | no, 3/3 passed at 5.82–5.97x | yes |
|
||||||
|
| qa_m3 `qa_lucisv_check_over_the_same_tree_while_the_server_formats` | `apply.rs` `commit` writes `after` plus `"\n"` | yes, qa_m3.rs:745 `m00.sv` | yes; then 3/3 pass |
|
||||||
|
|
||||||
|
*The didOpen ratio, measured.*
|
||||||
|
|
||||||
|
| where | load | best open | best parse | ratio |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| macOS | quiet, 8 runs | 31 ms | 11 ms | 2.66–2.77x |
|
||||||
|
| macOS | 36 busy loops on 18 CPUs, 15 runs | 34–41 ms | 12–14 ms | 2.48–3.15x |
|
||||||
|
| Linux root | quiet, 20 runs | 146–179 ms | 50–73 ms | 2.29–3.55x |
|
||||||
|
| Linux root | 8 busy loops on 4 CPUs, 20 runs | 0.50–1.12 s | 188–394 ms | 2.50–3.29x |
|
||||||
|
|
||||||
|
The wall clock moves 6x and the ratio stays in 2.3–3.6x, so 6 has about
|
||||||
|
1.7x headroom over the worst ratio seen.
|
||||||
|
- What it buys: on this Mac the new bound is *stricter* than the old one.
|
||||||
|
Four extra parses fail it at 84 ms, where 200 ms needed about 15 extra.
|
||||||
|
- What it costs: on the quiet Linux runner it is looser. There the old
|
||||||
|
bound sat at the box's floor, which is why it flaked.
|
||||||
|
- What it still cannot catch: the §46 defect itself, at this fixture's
|
||||||
|
size, as the test's doc comment always said.
|
||||||
|
|
||||||
|
**Counts.**
|
||||||
|
- `#[test]` attributes: 5 471 at HEAD and in this tree. No test was added
|
||||||
|
or removed.
|
||||||
|
- macOS whole suite: 97 result lines, **5413 passed, 0 failed, 64 ignored**
|
||||||
|
on every run here.
|
||||||
|
- Linux: **5407 passed, 0 failed, 64 ignored**. The six macOS/Windows-only
|
||||||
|
tests are not compiled there.
|
||||||
|
|
||||||
|
**Final runs on the final tree** (Linux, all of the above changes):
|
||||||
|
- root: `cargo clippy --all-targets -- -D warnings` exit 0; `cargo test
|
||||||
|
--workspace --no-fail-fast` green **10 consecutive runs of 10**, each 97
|
||||||
|
result lines, 5407 passed, 0 failed, 64 ignored.
|
||||||
|
- `--user`: clippy exit 0; tests green **10 consecutive runs of 10**, the same
|
||||||
|
totals.
|
||||||
|
- macOS, after the last `crates/` edit: `tools/gates.sh` **PASS**
|
||||||
|
(`target/gates/20261119-111810/`). That covers fmt, clippy, build and docs,
|
||||||
|
suites 521/435/743/376/672/119/151/2011/384 all with 0 failed, corpus 814/6
|
||||||
|
and node 37/0. The 20 loaded macOS runs above were also on this tree.
|
||||||
|
- No guard kill anywhere. The `lucisv-wt/70b/.lane70b/` probe scripts the
|
||||||
|
Linux runs used are deleted from the tree; copies are in the session
|
||||||
|
scratchpad.
|
||||||
|
|
||||||
|
Not done or not verified:
|
||||||
|
- The `qa_m1` product bug: reported, not fixed. Its test still fails about
|
||||||
|
1 run in 10 on Linux when run alone.
|
||||||
|
- The `qa_m3` fix is argued, and the `lsof` evidence shows the mechanism,
|
||||||
|
but the hang has no deterministic reproduction.
|
||||||
|
- The corpus-only budgets never ran on Linux.
|
||||||
|
|
||||||
|
**2026-11-19 (dev, round 2 continued: the stamp fix; scope extended by the
|
||||||
|
lead to `lucisv_mcp/src/project/files.rs`).**
|
||||||
|
|
||||||
|
*How the stamp works.*
|
||||||
|
- `read_source` stats a file, notes the time, reads it and hashes it. That
|
||||||
|
gives the `Stamp`: size, mtime, hash, `read_at` and `identity`.
|
||||||
|
`identity` was the `(ctime, ctime_nsec, ino)` triple on Unix and zeros
|
||||||
|
elsewhere.
|
||||||
|
- `Project::refresh` calls `check` on every file per tool call. `Same`
|
||||||
|
means the file is skipped. `Suspect` means `reread`: read and hash it
|
||||||
|
again, re-index only when the hash moved, and replace the stamp.
|
||||||
|
- So an extra `Suspect` costs one read and one hash. A missed change costs
|
||||||
|
stale answers, and stale *edit plans* in a tool agents use to write
|
||||||
|
files.
|
||||||
|
- The racy rule before: `current mtime + 2 s > read_at`. Nothing for the
|
||||||
|
ctime.
|
||||||
|
|
||||||
|
*What git does.* An index entry whose mtime is not older than the index
|
||||||
|
file itself is "racily clean": stat data cannot prove it unchanged, so it
|
||||||
|
is compared by content. The same idea applies to every timestamp the stat
|
||||||
|
comparison trusts.
|
||||||
|
|
||||||
|
*The fix* (`files.rs`, production lines ~150 → ~240):
|
||||||
|
- **Invariant**, as it is written in `Stamp::racy`: a stamp is trusted on
|
||||||
|
a later match only if every timestamp it trusts (the mtime, and the ctime
|
||||||
|
where there is one) is at least `RACY` older than the moment the stamp
|
||||||
|
was taken. A missing timestamp counts as racy, and so does one later than
|
||||||
|
the read.
|
||||||
|
- The test runs on the stamp's own values. On a match they equal the
|
||||||
|
current ones; on a mismatch the answer is `Suspect` anyway. All the
|
||||||
|
arithmetic is `checked_*`: the old `mtime + RACY` could panic on an
|
||||||
|
absurd mtime.
|
||||||
|
- **`RACY` 2 s → 3 s.** The window has to outlast the coarsest timestamp
|
||||||
|
plus the filesystem clock's lag behind `read_at`'s clock:
|
||||||
|
- Linux ticks (1–4 ms) and 1 s stamps (ext3, many NFS/SMB mounts) fit in
|
||||||
|
2 s.
|
||||||
|
- FAT's 2 s stamps do not. Take a timestamp `T` and a read at `T + 2 s`.
|
||||||
|
A write a tick later, from a coarse clock that lags, can truncate to
|
||||||
|
the same `T`. 3 s leaves a second of margin.
|
||||||
|
- Cost: a just-changed file is re-read on every call for 3 s instead
|
||||||
|
of 2.
|
||||||
|
- Not covered: a file server whose clock is more than ~1 s *behind*
|
||||||
|
ours. Git has the same assumption.
|
||||||
|
- **A wall clock stepped back** (new): after the read, a step back can give
|
||||||
|
a new write the very timestamp the stamp holds.
|
||||||
|
- The stamp now also keeps `read_mono` (an `Instant` taken with
|
||||||
|
`read_at`).
|
||||||
|
- `check` distrusts any stamp whose wall clock is now more than
|
||||||
|
`STEP_BACK` (100 ms) behind where the monotonic clock says it should
|
||||||
|
be. That holds until the file is re-read.
|
||||||
|
- A wall clock that ran *ahead*, as across a suspend the monotonic clock
|
||||||
|
slept through, is not doubted.
|
||||||
|
- A step back smaller than 100 ms stays inside `RACY`'s one-second
|
||||||
|
margin.
|
||||||
|
- **`identity` is `Option<Identity { ctime: Option<SystemTime>, ino }>`.**
|
||||||
|
`None` off Unix; a ctime that does not fit a `SystemTime` is racy.
|
||||||
|
- **The decision is a pure function**, `Stamp::compare(Seen, Clocks)`.
|
||||||
|
`check` is one `stat`, then `compare(Seen::of(meta), Clocks::now())`.
|
||||||
|
That is what lets the unit tests feed values without a file or a clock.
|
||||||
|
- **Off Unix** (no ctime in std on Windows): the racy rule still applies to
|
||||||
|
the mtime. The hole that remains there is old: a same-size rewrite that
|
||||||
|
restores an old mtime *outside* the window is invisible. There is
|
||||||
|
nothing else in the stat to see it with, as the `identity` doc says.
|
||||||
|
- **Test fixtures**: `project/tests.rs` `settle` and the existing
|
||||||
|
`a_stamp_sees_an_edit…` used to age a stamp by moving `read_at` alone.
|
||||||
|
That now looks exactly like a clock stepped back. They use the new
|
||||||
|
`#[cfg(test)] Stamp::taken_later`, which moves both clocks.
|
||||||
|
|
||||||
|
*New unit tests* (`project::files::tests`, deterministic, no file):
|
||||||
|
- `a_match_is_trusted_only_when_every_timestamp_was_settled_at_the_read`:
|
||||||
|
neither racy, mtime, ctime, both, `RACY − 1 ns` (suspect) and exactly
|
||||||
|
`RACY` old (same).
|
||||||
|
- `a_timestamp_later_than_the_read_or_missing_is_racy`: ctime after the
|
||||||
|
read, ctime `None`, mtime `None`, and off-Unix `identity: None` (mtime
|
||||||
|
decides).
|
||||||
|
- `a_wall_clock_stepped_back_since_the_read_distrusts_the_stamp`: stepped
|
||||||
|
back, behind the read, ahead (suspend), jitter under the tolerance, and a
|
||||||
|
stamp aged on both clocks.
|
||||||
|
- `any_moved_field_is_suspect_however_settled`: size, mtime, inode and
|
||||||
|
ctime each moved on a settled stamp.
|
||||||
|
|
||||||
|
*Mutations* (copies restored, `cmp` clean):
|
||||||
|
|
||||||
|
| sabotage | result |
|
||||||
|
|---|---|
|
||||||
|
| ctime dropped from the trusted list (`[Some(self.mtime), None]`) | FAILED: `…every_timestamp_was_settled…` at "ctime racy" (`Same` ≠ `Suspect`), and `…later_than_the_read…` |
|
||||||
|
| `clock_stepped_back` never consulted | FAILED: `a_wall_clock_stepped_back…` |
|
||||||
|
|
||||||
|
*The other caches, audited for the same hole* (none has it, so nothing was
|
||||||
|
stopped on):
|
||||||
|
- **Language server views** (`state/views.rs` `file_view`): no stamp at
|
||||||
|
all. A view is dropped on `set_document`, `close_document`, `update_one`,
|
||||||
|
`rebuild_index_with` and `begin_widen`, that is, on notifications. A disk
|
||||||
|
change no one reports is stale by design, as its doc says, with `hover`'s
|
||||||
|
`spells_exactly` guard. It never trusts a timestamp, so a same-tick
|
||||||
|
rewrite does nothing worse to it than any unreported write.
|
||||||
|
- **Persistent index cache** (`index_cache.rs`, `known_facts` →
|
||||||
|
`facts_now`/`facts_for`): keyed by `content_hash` of the text about to be
|
||||||
|
indexed. The bytes are always read, so there is no timestamp to fool.
|
||||||
|
- **MCP own store** (`lucisv_mcp/src/cache.rs`, `Records::take(path,
|
||||||
|
hash)`): by content hash, after `read_source` read the bytes. Its one
|
||||||
|
`modified()` only ages temporary files for removal. `Project::analysis`
|
||||||
|
reads the file every time and caches by hash.
|
||||||
|
- **CLI format cache** (`lucisv_core/src/cache.rs`): `Entry.content` is the
|
||||||
|
FNV-1a of the bytes, read on every run; no mtime.
|
||||||
|
- No `modified()`/ctime freshness check exists anywhere else outside tests
|
||||||
|
(`rg modified\(\)|mtime` over `lucisv_server`, `vlog_semantic`,
|
||||||
|
`lucisv_core` and `lucisv` sources).
|
||||||
|
|
||||||
|
*Performance* (temporary `eprintln!` of stat checks and suspects per
|
||||||
|
`refresh` in `project/mod.rs`, one binary before and one after, the source
|
||||||
|
restored with `cmp`; driver `drive.py` in the session scratchpad, guarded):
|
||||||
|
|
||||||
|
| session | calls | stat checks | re-reads before | re-reads after |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| OpenTitan `hw/ip`, 37 read calls (find/outline ×18, hierarchy) | 37 | 78 498 | 0 | 0 |
|
||||||
|
| copy of `hw/ip/uart`, 3 rounds of `format` then 8 reads | 33 | 1 120 | 120 | 120 |
|
||||||
|
| copy of `hw/ip/uart`, `chmod` every file, 8 calls at once, 3.5 s pause, 4 calls | 13 | 420 | 35 | **315** |
|
||||||
|
|
||||||
|
- Ordinary reads never re-read. An edit already makes the mtime fresh, so
|
||||||
|
it costs the same as before.
|
||||||
|
- The extra re-reads come only from a file whose ctime moved while its
|
||||||
|
mtime stayed old (`chmod`, `cp -p`, `touch -r`, rename-over). Each such
|
||||||
|
file is re-read on every call for 3 s, then never again.
|
||||||
|
- A re-read whose hash did not move re-indexes nothing.
|
||||||
|
|
||||||
|
*Checks, final tree.*
|
||||||
|
- macOS:
|
||||||
|
- `cargo fmt --all -- --check` exit 0.
|
||||||
|
- `cargo clippy --all-targets -- -D warnings` clean.
|
||||||
|
- `tools/guard.sh -- cargo test -p lucisv_mcp`: all pass, 388 tests, 4
|
||||||
|
of them new.
|
||||||
|
- `tools/gates.sh` **PASS** (`target/gates/20261119-114518/`): suites
|
||||||
|
521/435/743/376/672/119/151/2011/388, all with 0 failed; corpus 814/6;
|
||||||
|
node 37/0.
|
||||||
|
- Cross-check, the lead's command, for `-p lucisv -p lucisv_mcp`, on both
|
||||||
|
`x86_64-pc-windows-gnu` and `x86_64-unknown-linux-musl`, including
|
||||||
|
`lucisv_mcp`'s unit tests (`--profile test --bin lucisv-mcp`): clean, no
|
||||||
|
warning.
|
||||||
|
- `-p lucisv_server` fails on Windows at `state/incremental.rs:161`
|
||||||
|
(E0507, `dir_id` moved in a closure). That is the bug 0.65.7 fixed on
|
||||||
|
master, in a file this lane does not touch.
|
||||||
|
- `--all-targets` on Windows also fails in `tests/qa_m3.rs`, which uses
|
||||||
|
`std::os::unix` without a cfg. That predates this lane, and gates'
|
||||||
|
`cross` step does not build tests.
|
||||||
|
- Linux:
|
||||||
|
- the qa_m1 test alone: **0/300 failed as root and 0/300 as `--user`**
|
||||||
|
(before the fix: 39/300 and 12/150 as root).
|
||||||
|
- root: clippy exit 0; whole suite green **10 consecutive runs of 10**,
|
||||||
|
each 97 result lines, 5411 passed, 0 failed, 64 ignored. That is 5407
|
||||||
|
plus the 4 new unit tests.
|
||||||
|
- `--user`: clippy exit 0; green **10 of 10**, the same totals.
|
||||||
|
- The probe scripts are deleted from the tree again; copies are in the
|
||||||
|
session scratchpad.
|
||||||
|
|
||||||
|
*Changelog paragraph (for the lead):*
|
||||||
|
|
||||||
|
> **lucisv-mcp no longer serves stale contents after a same-size rewrite
|
||||||
|
> that restores an old mtime.** On Linux, ctime moves in 1 ms ticks. A
|
||||||
|
> file whose ctime had just moved (a rename-over, say), read by the server
|
||||||
|
> and then rewritten at the same size with its old mtime put back (`cp -p`,
|
||||||
|
> `rsync -t`, `touch -r`) inside the same tick, matched its stamp in every
|
||||||
|
> field. The server then answered from the old text until the file changed
|
||||||
|
> again. The "racy" rule now covers every timestamp the stamp trusts,
|
||||||
|
> ctime as well as mtime. Its window is 3 s (it was 2 s, too close to FAT's
|
||||||
|
> 2-second timestamps). A wall clock stepped back since a read now
|
||||||
|
> distrusts the stamp. Re-reads rise only for files whose metadata changed
|
||||||
|
> in the last 3 s. **Tests:** the suite is now stable on Linux.
|
||||||
|
> - Two stdin helpers tolerate a child that exits before reading.
|
||||||
|
> - The didOpen latency test measures its budget against a parse of the
|
||||||
|
> same buffer instead of a fixed 200 ms.
|
||||||
|
> - A macOS-only hang in an MCP concurrency test (a pipe inherited across
|
||||||
|
> threads) is fixed.
|
||||||
|
|
||||||
## QA log
|
## QA log
|
||||||
|
|
||||||
**2026-11-19 (QA, macOS arm64, 18 CPUs; tree = 948f8a0 + this lane).**
|
**2026-11-19 (QA, macOS arm64, 18 CPUs; tree = 948f8a0 + this lane).**
|
||||||
@@ -422,6 +813,200 @@ Nothing here has run on Linux since the 0.65.2/0.65.3 fast-forwards.
|
|||||||
*Fixed by QA:* finding 1 only. *Unverified:* everything on Linux, as
|
*Fixed by QA:* finding 1 only. *Unverified:* everything on Linux, as
|
||||||
above.
|
above.
|
||||||
|
|
||||||
|
### Round 2 QA
|
||||||
|
|
||||||
|
**2026-11-19 (QA, round 2; tree = 934d472 + f910554 in `lucisv-wt/70b`;
|
||||||
|
macOS arm64 18 CPUs, Linux = `tools/linux_check.sh` on luhpe).**
|
||||||
|
Verdict: **PASS WITH FINDINGS.** No stale read that the invariant claims to
|
||||||
|
prevent, no panic, no test that passes without testing, no Linux failure.
|
||||||
|
|
||||||
|
*Baseline (macOS).* `cargo fmt --all -- --check` exit 0. Guarded
|
||||||
|
`cargo test -p lucisv_mcp -p lucisv -p lucisv_server`: 24 result lines,
|
||||||
|
2569 passed, 0 failed, 53 ignored. Full `tools/gates.sh` **PASS** (fmt,
|
||||||
|
clippy, build, suites 521/435/743/376/672/119/151/2030/388, docs, corpus
|
||||||
|
814/6, node 37/0, cross). (`lucisv_server` is 2030 here, not the dev's 2011:
|
||||||
|
the dev measured on 0.65.6; 934d472 adds 19.) `#[test]` counts vs 934d472:
|
||||||
|
`cli.rs` 113→113, `e2e.rs` 109→109, `qa_m3.rs` 31→31, `qa_m8.rs` 6→6,
|
||||||
|
`project/tests.rs` 3→3, `files.rs` 3→7. The only removed assertion is
|
||||||
|
e2e's `best <= 200 ms`, replaced by the ratio. Cross, `--all-targets`, for
|
||||||
|
`lucisv_mcp`: linux-musl clean. Windows fails only in `tests/qa_m3.rs`
|
||||||
|
(12 errors, `std::os::unix` and `PermissionsExt` with no cfg). That is
|
||||||
|
pre-existing: the same 8 `std::os::unix` uses are at 934d472. Every other
|
||||||
|
target builds for Windows (`--bins --profile test` plus every `--test`
|
||||||
|
except `qa_m3`), including `files.rs`'s unit tests.
|
||||||
|
|
||||||
|
*PART 2: the stamp.*
|
||||||
|
- **Real files, the real binary.** A driver (`stale.py`, kept in the
|
||||||
|
session scratchpad) speaks MCP stdio to `lucisv-mcp` and asks `find` for
|
||||||
|
the new module name and then the old one. It covers 11 operations: in-place
|
||||||
|
same-size rewrite plus `utime(old)`; the same with `touch -r`;
|
||||||
|
rename-over of a same-size, old-mtime file; hard-link swap; `cp -p`-style
|
||||||
|
`O_TRUNC` rewrite plus `utime` plus `chmod`; truncate-and-rewrite plus
|
||||||
|
`utime`; mmap write plus msync, unmap and `utime`; vim-style
|
||||||
|
write-beside, rename and `utime`; replacing the file with a symlink to a
|
||||||
|
same-size file; `chmod` alone (expect the old content); and a directory
|
||||||
|
rename that brings in another same-size, old-mtime `c.sv`. It runs each at
|
||||||
|
delays of 0, 1 ms, 10 ms, 1 s, 2.9 s, 3.1 s and 10 s after the server's
|
||||||
|
read, with two preparations: stamp settled (ctime > 4 s old) and the
|
||||||
|
original hole (ctime made fresh by `utime(old)` just before the read).
|
||||||
|
That is 154 cases per run.
|
||||||
|
|
||||||
|
| platform / fs | cases | stale |
|
||||||
|
|---|---|---|
|
||||||
|
| macOS APFS | 154 | 0 |
|
||||||
|
| Linux root, overlayfs (`/w`) | 154 | 0 |
|
||||||
|
| Linux root, overlayfs `/tmp` | 154 | 0 |
|
||||||
|
| Linux root, tmpfs `/dev/shm` | 154 | 0 |
|
||||||
|
| Linux `--user`, the same three | 3 × 154 | 0 |
|
||||||
|
|
||||||
|
- **The exact hole, hit on purpose.** A sequential loop does
|
||||||
|
`utime(old)`, then `find` (the read), then a same-size rewrite plus
|
||||||
|
`utime(old)` immediately. It counts the runs whose stat after the write
|
||||||
|
equals the stat at the read: size, mtime, ctime and ino all identical.
|
||||||
|
|
||||||
|
| binary | fs | runs | stat-identical | stale |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| **934d472 (before)** | overlayfs | 300 | 65 | **65** |
|
||||||
|
| **934d472 (before)** | tmpfs | 300 | 87 | **87** |
|
||||||
|
| this lane, root | overlayfs | 300 | 65 | 0 |
|
||||||
|
| this lane, root | tmpfs | 300 | 125 | 0 |
|
||||||
|
| this lane, `--user` | overlayfs | 300 | 52 | 0 |
|
||||||
|
| this lane, `--user` | tmpfs | 300 | 106 | 0 |
|
||||||
|
| this lane, macOS | APFS | 100 | 0 | 0 |
|
||||||
|
|
||||||
|
So the driver does detect the bug. The old code is stale exactly when the
|
||||||
|
stat is identical, and the fix is fresh in every one of those runs.
|
||||||
|
- **Property test of `compare`.** I wrote my own xorshift generator and
|
||||||
|
included it temporarily in `files.rs` by `#[path]` from the scratchpad.
|
||||||
|
`files.rs` was restored from a copy and `cmp`-checked; `git status` is
|
||||||
|
clean. It ran **3 000 000 cases**: moved 970 519, racy 2 449 889, clock
|
||||||
|
step 677 250, and **232 760 cases where nothing doubted → all `Same`**
|
||||||
|
(no needless re-read). No `Same` was returned for any moved, racy or
|
||||||
|
stepped case. There was no panic, including at u64/i64 extremes, the
|
||||||
|
epoch, times before 1970, `RACY ± 1 ns`, `STEP_BACK ± 1 ns` and an
|
||||||
|
`Instant` behind the read. (Raw nsec ≥ 1e9 cannot be built as a
|
||||||
|
`SystemTime`. By reading `identity()`: `i64::MAX` s plus `i64::MAX` ns
|
||||||
|
fits a `Duration`, so the sum does not panic, and an out-of-range result
|
||||||
|
becomes `None`, which counts as racy.) Each of these mutations fails it:
|
||||||
|
ctime dropped, step check dropped, `>` → `>=`, identity ignored.
|
||||||
|
- **Clocks.** From the std 1.100 docs: `Instant` is `CLOCK_UPTIME_RAW` on
|
||||||
|
Darwin and `CLOCK_MONOTONIC` on Linux, both stopped in suspend; Windows
|
||||||
|
uses QPC. Through `compare` with injected clocks:
|
||||||
|
- 1 h suspend: `Same`, and also `Same` if `Instant` counts the suspend.
|
||||||
|
- 5 s backwards step: `Suspect`. After that one re-read: `Same`. A file
|
||||||
|
written 2 s before the step and read after it: `Suspect`.
|
||||||
|
- 5 s forwards step: `Same`, which is safe locally because the next
|
||||||
|
write is stamped after the step.
|
||||||
|
- Drift: 99 ms → `Same`, 115 ms → `Suspect`.
|
||||||
|
- On Linux NTP slews `CLOCK_MONOTONIC` along with the wall clock, so only
|
||||||
|
steps diverge. On macOS `UPTIME_RAW` is not slewed. Measured here, the
|
||||||
|
wall clock runs **ahead** of it by +6.37 ppm (stable over 300 s), so
|
||||||
|
the step rule never fires. A Mac drifting the other way at that rate
|
||||||
|
would distrust stamps older than ~4.4 h once: one re-read of each, with
|
||||||
|
no re-index. Benign.
|
||||||
|
- **TOCTOU.** The stat comes before `Clocks::now()`, which comes before the
|
||||||
|
read. A write between the stat and the read leaves an old stat with new
|
||||||
|
bytes, and the next stat differs, so this is safe. A write after the read
|
||||||
|
in the same tick is covered by the racy rule. `read_at` is earlier than
|
||||||
|
the read itself, which errs toward racy.
|
||||||
|
- **Skew tolerance** (by arithmetic). A later write can only carry the
|
||||||
|
stamp's timestamp if `RACY ≥ granularity + (local clock − file server
|
||||||
|
clock)`. That gives FAT (2 s) 1 s, 1 s filesystems (HFS+, ext3,
|
||||||
|
NFSv2/SMB1) 2 s, and ns filesystems ~3 s. Past that skew, an *ordinary*
|
||||||
|
same-size edit inside one server tick is invisible, not only an
|
||||||
|
mtime-restoring one. Not testable here (no FAT/NFS).
|
||||||
|
- **Audit of the other caches: confirmed.** The server's `file_view`
|
||||||
|
(`state/views.rs:74`) has no stamp. `index_cache.rs:226/298` is keyed by
|
||||||
|
`content_hash`. MCP `Records::take(path, hash)` (`cache.rs:110`) is too.
|
||||||
|
`Project::analysis` re-reads every call (`mod.rs:301`), so `read` and
|
||||||
|
`outline` were never exposed; only index answers (`find`, hierarchy,
|
||||||
|
names) were. The only other `metadata` uses outside tests are
|
||||||
|
`walk.rs:194` `(dev, ino)` for cycles and MCP temp-file aging.
|
||||||
|
Experiment: the CLI format cache with a formatted file, `--check` (from
|
||||||
|
cache), then a same-size unformatted rewrite with the mtime restored, then
|
||||||
|
`--check`. Result: "would reformat", exit 1. Correct.
|
||||||
|
|
||||||
|
*PART 1.*
|
||||||
|
- None of the four tests skips on macOS (`--nocapture`). My own mutations
|
||||||
|
(copies restored, `git status` clean):
|
||||||
|
|
||||||
|
| test | mutation | result |
|
||||||
|
|---|---|---|
|
||||||
|
| cli `stdin_and_lines…` | `args.rs:487` message reworded | FAILED cli.rs:1943 |
|
||||||
|
| qa_m8 `qa_argument_order…` | `main.rs:94` "unknown flag" | FAILED qa_m8.rs:345 |
|
||||||
|
| e2e didOpen | 100 ms sleep in the didOpen arm | FAILED 10.63x (142 ms; old 200 ms would pass) |
|
||||||
|
| qa_m3 CLI-while-formatting | CLI `--check` exits 3 instead of 1 | FAILED qa_m3.rs:743 |
|
||||||
|
|
||||||
|
- **BrokenPipe callers.** There are 22 `run_with_stdin(_raw)` callers. Each
|
||||||
|
asserts the exit code and/or output, except `cli.rs:2149-2150`, which
|
||||||
|
asserts only `stdout == ""` (finding 4). `qa_m8` `run` has 5 callers.
|
||||||
|
Each asserts the status or reads answers by id, so a server that died
|
||||||
|
leaves a missing answer and the test fails.
|
||||||
|
- **Ratio, 50× under load each.** macOS (36 busy loops): 0/50 failed,
|
||||||
|
2.40–3.09x. Linux root (8 busy loops, opens ~1 s): 0/50 failed,
|
||||||
|
**2.25–4.09x**. The worst is above the dev's 3.55; headroom to 6 is
|
||||||
|
1.47x. The blind spot of three extra parses is acceptable for a test named
|
||||||
|
for unbounded delay (see finding 5 for the machine dependence).
|
||||||
|
- **qa_m3.** The `lsof`/`sample` evidence fits the mechanism. On macOS std
|
||||||
|
creates pipes with `pipe()` and then sets `FD_CLOEXEC`. The fix removes
|
||||||
|
the only intra-test overlap: the main thread spawns nothing while the
|
||||||
|
checker runs. **100/100 green on macOS under 36 busy loops**, no hang.
|
||||||
|
Grep: `qa_m3.rs:721` is the only test thread that spawns children in a
|
||||||
|
loop; every other `thread::spawn` near a `Command` is a stdout pump.
|
||||||
|
Parallel *tests* in one binary can still inherit each other's pipes on
|
||||||
|
macOS, but the wait is bounded by the other test's lifetime, not a
|
||||||
|
deadlock.
|
||||||
|
|
||||||
|
*Linux, independently.*
|
||||||
|
- Root: clippy `--all-targets -D warnings` exit 0. Whole suite
|
||||||
|
`--no-fail-fast` **6/6 green**, each 97 result lines, 5430 passed,
|
||||||
|
0 failed, 65 ignored.
|
||||||
|
- `--user`: clippy exit 0. **6/6 green**, the same totals.
|
||||||
|
- `qa_m1` `qa_rework_a_rename_over…` alone, root: **0/300 failed**.
|
||||||
|
- No guard kill anywhere on macOS.
|
||||||
|
|
||||||
|
*Findings* (none is a FAIL):
|
||||||
|
1. (medium, documented-limit class) **A writable mmap kept open serves
|
||||||
|
stale contents indefinitely on Linux.** Map the file, store into it
|
||||||
|
(this sets mtime and ctime), wait 4 s, let the server read, then store
|
||||||
|
into the same already-dirty page. The stat is unchanged after the
|
||||||
|
store, after `msync` and after `munmap` (overlayfs and tmpfs, root and
|
||||||
|
`--user`), and `find` stays stale. On macOS it is stale until `msync`.
|
||||||
|
The kernel exposes nothing, so no stamp can see it (git has the same
|
||||||
|
limit). Repro: `stale.py BIN DIR mmap`. Suggest stating it in
|
||||||
|
Assumptions. Editors do not write through mmap.
|
||||||
|
2. (low, perf) **A future mtime makes a file racy forever**, so it is
|
||||||
|
re-read and re-hashed on every call (no re-index). Release binary,
|
||||||
|
macOS:
|
||||||
|
- 4 000 small files: 6.8 → **67.5 ms** median per `find`.
|
||||||
|
- A copy of OpenTitan `hw/`: 21 → **126 ms**.
|
||||||
|
- Fresh copy of `hw/` (every ctime new): burst median 58 ms against
|
||||||
|
33 ms settled, for ~3 s only.
|
||||||
|
|
||||||
|
Usable, but the cost lasts for as long as the clock stays behind. The
|
||||||
|
lead should decide whether a timestamp far in the future (> 1 day, say)
|
||||||
|
should stop counting as racy.
|
||||||
|
3. (low, docs) `docs/features/mcp-transport/README.md:53-58` still says
|
||||||
|
the 2 s window and mtime-only racy, and that identity is "0" elsewhere.
|
||||||
|
It is outside this lane's files: a Handshake request. The non-unix hole
|
||||||
|
is real: a same-size rewrite that restores the mtime ≥ 3 s after the
|
||||||
|
read is invisible, since std has no ctime and no stable `file_index`.
|
||||||
|
It is stated only in `files.rs` and this README, not where a Windows
|
||||||
|
user would see it (`docs/site/src/content/docs/guides/agents.md`).
|
||||||
|
macOS `setattrlist(ATTR_CMN_CHGTIME)` returns 0 but leaves ctime
|
||||||
|
unchanged, so an unprivileged ctime restore is not possible there.
|
||||||
|
4. (low, pre-existing) `crates/lucisv/tests/cli.rs:2149-2150` asserts only
|
||||||
|
that stdout is empty, so a child that crashes (before or after reading)
|
||||||
|
passes. The BrokenPipe tolerance does not materially widen this: the
|
||||||
|
inputs fit in the pipe buffer.
|
||||||
|
5. (info) The ratio test's sensitivity depends on the machine. A 100 ms
|
||||||
|
didOpen stall is 10.6x on this Mac but would be ~3–4x on the Linux
|
||||||
|
runner (parse 50–70 ms), which passes.
|
||||||
|
|
||||||
|
*Fixed by QA:* nothing. *Unverified:* FAT, NFS and SMB (skew arithmetic
|
||||||
|
only); Windows at run time (compile only); a real suspend or NTP step
|
||||||
|
(injected clocks only).
|
||||||
|
|
||||||
## Review
|
## Review
|
||||||
|
|
||||||
**Lead, 2026-11-19.** Accepted on macOS evidence; Linux line left open.
|
**Lead, 2026-11-19.** Accepted on macOS evidence; Linux line left open.
|
||||||
@@ -447,3 +1032,25 @@ above.
|
|||||||
unticked until that run happens; the Linux job is not added blind.
|
unticked until that run happens; the Linux job is not added blind.
|
||||||
- Open follow-up, recorded under Status: the references linear-time test
|
- Open follow-up, recorded under Status: the references linear-time test
|
||||||
times a copy of `Server::large_scan`'s loop, not the production code.
|
times a copy of `Server::large_scan`'s loop, not the production code.
|
||||||
|
|
||||||
|
**Lead, 2026-11-19 — Round 2.** Accepted for 0.65.9; §70 closed.
|
||||||
|
|
||||||
|
- Round 1 was accepted on macOS evidence with the Linux line open, and the
|
||||||
|
first Linux runs after ssh came back showed why that line mattered: clean
|
||||||
|
once, then 3 failing runs in 9. The dev's census (57 whole-suite runs,
|
||||||
|
2 090 loop iterations) is the right way to chase flakes — a ~10% flake does
|
||||||
|
not show in three runs.
|
||||||
|
- The dev stopped on the mtime test instead of loosening it, and it was a
|
||||||
|
real bug: `lucisv-mcp` could serve stale contents indefinitely. I extended
|
||||||
|
scope to fix it. QA reproduced the hole on purpose on the old binary
|
||||||
|
(65/65 and 87/87 stale when the stat was identical) and got 0 on the new
|
||||||
|
one across overlayfs, tmpfs and APFS, then property-tested `compare` with
|
||||||
|
three million cases under four mutations. That is the evidence.
|
||||||
|
- The `qa_m3` hang is the same test the guard killed in the 0.65.5 release
|
||||||
|
gates and in 71.7's QA; it now has a cause (a pipe inherited across
|
||||||
|
threads on macOS) and a fix, though no deterministic reproduction.
|
||||||
|
- `ci.yml` gains the `linux` job in this change, as §70 planned. It installs
|
||||||
|
Rust per job and builds cold — a few minutes; acceptable for now.
|
||||||
|
- Open, filed in TODO: future-mtime trees re-read on every call; the mmap
|
||||||
|
limit and the Windows gap are now written in `docs/features/mcp-transport`;
|
||||||
|
a weak assertion in `cli.rs`; `qa_m3.rs` does not compile for Windows.
|
||||||
@@ -50,13 +50,20 @@ arrived.
|
|||||||
a changed hash re-indexes it; a missing file is removed and triggers a
|
a changed hash re-indexes it; a missing file is removed and triggers a
|
||||||
re-walk; the roots are re-walked when the last walk is older than 5 s and
|
re-walk; the roots are re-walked when the last walk is older than 5 s and
|
||||||
on every `project_overview`, so new files appear. All changes go into the
|
on every `project_overview`, so new files appear. All changes go into the
|
||||||
index with one `absorb` (one merge). A file modified within 2 s of being
|
index with one `absorb` (one merge). A file any of whose trusted timestamps
|
||||||
read is re-read on every sweep until it settles — git's "racy clean" rule —
|
— its mtime, and on Unix its ctime — is within 3 s of the moment it was
|
||||||
so an edit that keeps a file's size inside one mtime tick is still seen.
|
read is re-read on every sweep until it settles — git's "racy clean" rule,
|
||||||
On Unix the stamp also holds the file's ctime and inode (the same
|
applied to every timestamp the stamp trusts since 0.65.9 (it covered the
|
||||||
|
mtime alone before, and a same-tick rewrite on Linux was served stale) —
|
||||||
|
so an edit that keeps a file's size inside one timestamp tick is still
|
||||||
|
seen. On Unix the stamp also holds the file's ctime and inode (the same
|
||||||
`stat`), so a same-size rewrite that puts the old mtime back (`cp -p`,
|
`stat`), so a same-size rewrite that puts the old mtime back (`cp -p`,
|
||||||
`rsync -t`, `touch -r`) is seen too; elsewhere they are 0 and size, mtime
|
`rsync -t`, `touch -r`) is seen too. Elsewhere (Windows) there is no ctime
|
||||||
and the racy rule are all there is. A by-name lookup that finds nothing
|
or inode: size, mtime and the racy rule are all there is, so a same-size
|
||||||
|
rewrite that restores the old mtime more than 3 s after a read is NOT
|
||||||
|
seen. Not seen anywhere: a store through a writable mmap that the kernel
|
||||||
|
has not yet reflected in the file's timestamps
|
||||||
|
(`docs/features/linux-test-portability`, Round 2). A by-name lookup that finds nothing
|
||||||
(`unit_interface`, `list_units` with a `glob`, `search_symbols`) walks
|
(`unit_interface`, `list_units` with a `glob`, `search_symbols`) walks
|
||||||
once more before it answers, unless this call already walked
|
once more before it answers, unless this call already walked
|
||||||
(`Project::ensure_walked_for_miss`) — so a file the agent wrote a moment
|
(`Project::ensure_walked_for_miss`) — so a file the agent wrote a moment
|
||||||
|
|||||||
@@ -5,6 +5,13 @@ for you. The extension and its bundled language server share one version
|
|||||||
number; the full engineering notes live in the
|
number; the full engineering notes live in the
|
||||||
[project changelog](https://git.luci.ooo/lucio/lucisv/src/branch/master/CHANGELOG.md).
|
[project changelog](https://git.luci.ooo/lucio/lucisv/src/branch/master/CHANGELOG.md).
|
||||||
|
|
||||||
|
## 0.65.9 — 2026-11-19
|
||||||
|
|
||||||
|
- **The bundled MCP server (`lucisv-mcp`) no longer answers from a file's old
|
||||||
|
contents** after a same-size rewrite that restores its old modification
|
||||||
|
time (`cp -p`, `rsync -t`) — a Linux timing hole in its change detection.
|
||||||
|
- Nothing changes in the editor itself.
|
||||||
|
|
||||||
## 0.65.8 — 2026-11-19
|
## 0.65.8 — 2026-11-19
|
||||||
|
|
||||||
- **Find All References works with the cursor just after a name** — after a
|
- **Find All References works with the cursor just after a name** — after a
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ Install **lucisv — Verilog/SystemVerilog** from the VS Code Extensions view,
|
|||||||
then open a Verilog or SystemVerilog file. There is no separate server or CLI
|
then open a Verilog or SystemVerilog file. There is no separate server or CLI
|
||||||
setup.
|
setup.
|
||||||
|
|
||||||
The current release is **0.65.8**. Its platform packages include
|
The current release is **0.65.9**. Its platform packages include
|
||||||
`lucisv-server`, the `lucisv` command-line tool and `lucisv-mcp` (see
|
`lucisv-server`, the `lucisv` command-line tool and `lucisv-mcp` (see
|
||||||
[Agents (MCP)](#agents-mcp)):
|
[Agents (MCP)](#agents-mcp)):
|
||||||
|
|
||||||
@@ -440,6 +440,12 @@ default):
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Release 0.65.9 highlights
|
||||||
|
|
||||||
|
Version 0.65.9 fixes the bundled MCP server answering from a file's old
|
||||||
|
contents after a same-size rewrite that restores its old modification time
|
||||||
|
on Linux; the editor features are unchanged.
|
||||||
|
|
||||||
## Release 0.65.8 highlights
|
## Release 0.65.8 highlights
|
||||||
|
|
||||||
Version 0.65.8 fixes Find All References (and definition, hover, rename)
|
Version 0.65.8 fixes Find All References (and definition, hover, rename)
|
||||||
|
|||||||
Generated
+2
-2
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "lucisv",
|
"name": "lucisv",
|
||||||
"version": "0.65.8",
|
"version": "0.65.9",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "lucisv",
|
"name": "lucisv",
|
||||||
"version": "0.65.8",
|
"version": "0.65.9",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vscode-languageclient": "9.0.1"
|
"vscode-languageclient": "9.0.1"
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "lucisv",
|
"name": "lucisv",
|
||||||
"displayName": "lucisv — Verilog/SystemVerilog",
|
"displayName": "lucisv — Verilog/SystemVerilog",
|
||||||
"description": "Fast Verilog/SystemVerilog formatting, linting, navigation, refactoring, semantic highlighting and RTL design intelligence.",
|
"description": "Fast Verilog/SystemVerilog formatting, linting, navigation, refactoring, semantic highlighting and RTL design intelligence.",
|
||||||
"version": "0.65.8",
|
"version": "0.65.9",
|
||||||
"publisher": "guoliangchen",
|
"publisher": "guoliangchen",
|
||||||
"author": "Guoliang Chen",
|
"author": "Guoliang Chen",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
|
|||||||
Reference in new issue
Block a user