hx-lens: rust-analyzer can report already-fixed errors under load #66

Open
opened 2026-09-30 21:31:11 +00:00 by hermes · 1 comment
Collaborator

Under heavy parallel cargo load, after a file is fixed and saved, rust-analyzer sometimes runs a flycheck that publishes the old error with the new document version. The lens then reports an error that no longer exists.

Observed: tests::rust_analyzer_turn_end fails ~1 in 4 runs while cargo test --workspace runs concurrently; passes reliably alone. Debug trace: synced v=2, flycheck begin, publish v=2 n=1 (stale E0308), flycheck end.

Tried (not enough): wait for flycheck started after our save; wait for a publish after flycheck end (up to 10s); 15s grace for flycheck start; sleeping 1.1s before the fix write (mtime granularity).

Workaround: tests/all.sh runs that test alone.

Ideas: re-run diagnostics once when an error persists across a content change on the same line; compare the reported range text with current file content; trigger rust-analyzer/runFlycheck explicitly after save.

Done when: rust_analyzer_turn_end passes 20/20 with concurrent workspace tests and the all.sh special case is removed.

Context: #58

Under heavy parallel cargo load, after a file is fixed and saved, rust-analyzer sometimes runs a flycheck that publishes the *old* error with the *new* document version. The lens then reports an error that no longer exists. Observed: `tests::rust_analyzer_turn_end` fails ~1 in 4 runs while `cargo test --workspace` runs concurrently; passes reliably alone. Debug trace: `synced v=2`, flycheck begin, `publish v=2 n=1` (stale E0308), flycheck end. Tried (not enough): wait for flycheck started after our save; wait for a publish after flycheck end (up to 10s); 15s grace for flycheck start; sleeping 1.1s before the fix write (mtime granularity). Workaround: `tests/all.sh` runs that test alone. Ideas: re-run diagnostics once when an error persists across a content change on the same line; compare the reported range text with current file content; trigger `rust-analyzer/runFlycheck` explicitly after save. Done when: `rust_analyzer_turn_end` passes 20/20 with concurrent workspace tests and the all.sh special case is removed. Context: #58
Author
Collaborator

Investigation (not fixed):

Root cause, from an LSP trace of a failing run. The stale error is rust-analyzer's native diagnostic (source rust-analyzer, E0308), not cargo's. After the fix is written and sent as v2 (didChange + didSave), rust-analyzer publishes v=2 with the old E0308 error; its native analysis was computed from the previous content. The following flycheck ends without republishing, so the stale native diagnostic stays.

publish v=2  rust-analyzer E0308 expected u32, found &'static str   <- stale, content already fixed
progress flycheck report "t (lib)" / end

Tried, all still failing under concurrent cargo test --workspace load:

  1. Wait for a publish after flycheck end (up to 10s): about 1 in 4 fail.
  2. On errors after an edit, send didSave again and wait for that flycheck: 1 in 8 fail (the flycheck finishes without a new publish).
  3. On errors after an edit, resend the full content as a new version v3 (didChange + didSave): 2 in 6 fail, and runs take over 100s.

Not yet tried:

  • Pull diagnostics (textDocument/diagnostic, if the server supports it) for the native part, instead of relying on push.
  • Filter native rust-analyzer diagnostics once a newer flycheck has run, and trust rustc results.
  • Compare the flagged range's text with current file content, and drop the diagnostic if that range changed.

Workaround still in place: tests/all.sh runs rust_analyzer_turn_end alone (even alone it flakes rarely on a loaded box).

Investigation (not fixed): **Root cause, from an LSP trace of a failing run.** The stale error is rust-analyzer's *native* diagnostic (source `rust-analyzer`, E0308), not cargo's. After the fix is written and sent as v2 (didChange + didSave), rust-analyzer publishes `v=2` with the old E0308 error; its native analysis was computed from the previous content. The following flycheck ends without republishing, so the stale native diagnostic stays. ``` publish v=2 rust-analyzer E0308 expected u32, found &'static str <- stale, content already fixed progress flycheck report "t (lib)" / end ``` **Tried, all still failing under concurrent `cargo test --workspace` load:** 1. Wait for a publish after flycheck end (up to 10s): about 1 in 4 fail. 2. On errors after an edit, send didSave again and wait for that flycheck: 1 in 8 fail (the flycheck finishes without a new publish). 3. On errors after an edit, resend the full content as a new version v3 (didChange + didSave): 2 in 6 fail, and runs take over 100s. **Not yet tried:** - Pull diagnostics (`textDocument/diagnostic`, if the server supports it) for the native part, instead of relying on push. - Filter native `rust-analyzer` diagnostics once a newer flycheck has run, and trust `rustc` results. - Compare the flagged range's text with current file content, and drop the diagnostic if that range changed. Workaround still in place: `tests/all.sh` runs `rust_analyzer_turn_end` alone (even alone it flakes rarely on a loaded box).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: johannes/hx#66