Skip to content

Stale diagnostics lag behind edits (imports/signature changes report false errors until recompile) #109

Closed

Description

@aviadshiber

Summary

During rapid multi-edit sessions (Claude Code with ENABLE_LSP_TOOL, edits applied programmatically rather than by a human typing), the Java compile diagnostics — the ones with "source": "Java" that jdtls produces (X cannot be resolved to a type, The constructor/method is undefined, not applicable for the arguments) — lag behind the current file state by one or two edits. They reflect the file as it was one or two edits ago, then clear only after a later unrelated edit or a full recompile.

The custom "source": "java-functional-lsp" rules (tree-sitter based) update in lockstep with edits and are not affected. Only the jdtls-sourced compile diagnostics lag.

Net effect: the compile diagnostics are eventually-consistent but noticeably stale mid-session, so they can't be trusted right after an edit.

Component

Stale diagnostics come from Eclipse jdtls (the compile-error/import-resolution engine), surfaced through this wrapper. Versions in the affected setup:

  • java-functional-lsp 0.12.0 (installed via Homebrew tap)
  • jdtls 1.61.0
  • JDK 21 runtime for jdtls; Java 17 source level
  • OS: macOS (Apple Silicon)
  • Editor/host: Claude Code with ENABLE_LSP_TOOL=1, server registered via lspServers (.java → java)

Filed here because the stale-compose logic lives in this wrapper's server.py, so the wrapper can likely mitigate it even though jdtls's async builder is the upstream latency source.

Steps to reproduce

Using generic placeholder code (real names redacted):

  1. Open MyClass.java, which references Bar without importing it. jdtls reports Bar cannot be resolved to a type. Correct.
  2. Add import com.example.Bar; as the fix.
  3. Make one or two further edits elsewhere in the file (or in a caller).
  4. Observe: the LSP still reports Bar cannot be resolved to a type for the next one or two edits, even though the import is present and a real compile of the same file succeeds.
  5. The stale error clears only after a further unrelated edit or a full external recompile.

Signature-change variant:

  1. Foo has a 2-arg constructor; a call site new Foo(a, b) is clean.
  2. Add a third parameter to Foo's constructor and update the call site to new Foo(a, b, c) in the same session.
  3. The LSP keeps reporting the OLD arity at the already-updated call site (The constructor Foo(...) is undefined / not applicable for the arguments) for one or two subsequent edits.

In both cases an actual command-line compile of the same files succeeds, confirming the diagnostics are stale/false, not real.

Hypothesis / code pointers

Not asserting a root cause — just where I think the relevant logic sits, for the maintainer to judge:

  • On didChange, the edit is forwarded to jdtls and a re-analysis is scheduled. When that re-analysis runs, it merges freshly computed custom diagnostics with the last cached jdtls diagnostics (JdtlsProxy.get_cached_diagnostics(uri) in proxy.py, consumed by _run_analysis in server.py). jdtls recomputes compile diagnostics asynchronously via the Eclipse JDT incremental builder, which lands well after the edit-triggered re-analysis — so the edit-triggered publish carries current custom diagnostics but a previous build's jdtls compile diagnostics.
  • jdtls's own async publish is wired back (_on_jdtls_diagnostics → _analyze_and_publish), so it should self-heal when jdtls finishes. But for an agent host that reads diagnostics right after each tool operation (rather than reacting to server pushes), the observed set is whatever was last published at edit time — the stale one — until the next edit triggers a fresh publish, which is exactly the "clears only on a later edit" symptom.
  • jdtls publishDiagnostics notifications don't carry the textDocument version, so there's no obvious signal in the proxy to tell "this cached jdtls set is older than the current document" and withhold or invalidate it.

Possible mitigation directions (for discussion): tag/track document versions and drop cached jdtls diagnostics known to be older than the current edit; or don't re-emit cached jdtls compile diagnostics from an edit-triggered analysis, and rely solely on jdtls's own async publish; or invalidate the per-URI jdtls cache on didChange until the next fresh jdtls publish arrives.

Log evidence

Logs were found at the wrapper's stderr log (/tmp/java-functional-lsp.log, rotating). They confirm the two diagnostic sources on the same file — "source": "Java" (jdtls compile) alongside "source": "java-functional-lsp" (custom rules) — in a single publishDiagnostics. The raw excerpt contains private project paths and code, so here is a synthetic, structurally faithful line instead:

{"method": "textDocument/publishDiagnostics", "params": {
  "uri": "file:///path/to/project/src/main/java/com/example/MyClass.java",
  "diagnostics": [
    {"range": {"start": {"line": 12, "character": 4}, "end": {"line": 12, "character": 7}},
     "message": "Bar cannot be resolved to a type", "severity": 1, "source": "Java"},
    {"range": {"start": {"line": 20, "character": 24}, "end": {"line": 20, "character": 28}},
     "message": "Avoid passing null as argument. Use Option.none() ...",
     "severity": 2, "code": "null-literal-arg", "source": "java-functional-lsp"}
  ]}}

The "source": "Java" entry is the one that goes stale; the "source": "java-functional-lsp" entry tracks edits correctly.

Environment

  • java-functional-lsp: 0.12.0
  • jdtls: 1.61.0
  • OS: macOS (Apple Silicon)
  • Editor: Claude Code (ENABLE_LSP_TOOL=1), programmatic edits
  • Java: source level 17, jdtls runtime JDK 21

Activity

  1. self-assigned this
    on Sep 28, 2026
  2. aviadshiber commented on Sep 29, 2026

    @aviadshiber
    OwnerAuthor

    Fixed in v0.13.0.

    • fix: hold edit-triggered publishes until jdtls re-validates (#109) #111: edit-triggered jdtls publishes are held until jdtls re-validates the edited content, so a publish for an older version no longer overwrites fresh results. Claude Code gets custom diagnostics first; IDEs get one merged publish.
    • feat: fresh jdtls diagnostics in Claude Code's own tool result (#109 part B) #112: after a Claude Code edit the server sends didSave (only when the buffer matches disk) so jdtls also re-checks dependent files, and it writes a per-file freshness marker when it publishes final diagnostics. The deeperdive-java-linter plugin's PostToolUse hook waits for that marker (default at most 3s, JAVA_FUNCTIONAL_LSP_HOOK_WAIT, 0 disables), so the edit's jdtls errors land in that edit's tool result instead of one tool call later.

    Verified with headless Claude Code (2.1.282, jdtls 1.61.0): type error from an Edit attached ~0.9s after the edit, before the agent's reply, 4/4 runs; without the hook, 0/4.

    Upgrade: brew upgrade java-functional-lsp (or restart Claude Code with the plugin, which upgrades daily).

    The non-project / cross-module false errors are a different bug, tracked in #110.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions