Skip to content

fix: hold edit-triggered publishes until jdtls re-validates (#109) - #111

Merged
aviadshiber merged 4 commits into
mainfrom
fix/109-stale-jdtls-diagnostics
Sep 28, 2026
Merged

aviadshiber merged 4 commits into
mainfrom
fix/109-stale-jdtls-diagnostics

Conversation

@aviadshiber

@aviadshiber aviadshiber commented Sep 28, 2026 •

Copy link
Copy Markdown
Owner

Fixes the stale-diagnostics lag from #109 (Part A of the design).

Problem

After an edit the wrapper republished jdtls's diagnostics from the previous version: 150ms after didChange, and immediately on didSave. jdtls needs 0.4-2.4s to re-validate (one debounced validation job shared by all files, reset by any didChange) and its publishes carry no document version. Claude Code attaches diagnostics right after the edit, so the agent saw the old compile errors ("X cannot be resolved", old constructor arity) as current. Evidence: the local wrapper log shows 19 of 23 edit-triggered publishes followed by a jdtls correction on the same file; Claude Code transcripts show diagnostics attached after the PostToolUse hooks, within ~40ms of the tool result.

Change

  • Per-file "waiting for jdtls" state after a forwarded didChange. It is released by a jdtls publish that arrives at least 400ms (jdtls's minimum debounce) after the last change to any file; earlier publishes belong to an older snapshot and keep the hold.
  • Deadline: 3s after the last change, stretched to 2x the observed jdtls latency, capped at 10s from the first edit. On timeout the last known jdtls set is used (previous behavior).
  • Modes: custom-first for Claude Code (custom diagnostics publish at once without the stale jdtls set, full set when jdtls is fresh), hold-all for other editors (no flicker), off via JAVA_FUNCTIONAL_LSP_DIAG_HOLD=off for the old behavior.
  • Not held: modules still importing, files matched by java.diagnostic.filter, files outside the opened set, jdtls unavailable/starting/skipped.
  • didSave while waiting no longer publishes the stale set; re-initialize and jdtls stop release all holds; jdtls stop clears the cache.
  • jdtls cache keyed by normalized URI; jdtls-triggered publishes go out under the client's URI string.
  • Observability: JAVA_FUNCTIONAL_LSP_LOG_LEVEL, a jdtls freshness: summary line (released / too_early / timeout / late_correction / ineligible), jdtls version at startup, a log line per dropped jdtls-to-client request method. Two log lines no longer print full paths.
  • README section "Fresh jdtls diagnostics after edits" + troubleshooting row. Version 0.12.1.

Cross-file variant (Part B, in #112)

New e2e test with a real jdtls and a two-file Maven project (Foo gains a ctor parameter, Caller updated, both written to disk):

  • with didSave: Caller converges, 5/5 runs
  • without didSave: jdtls's only post-edit publish for Caller still has the old-arity error in ~2/5 runs and is never corrected (non-strict xfail)

So the follow-up is to make sure jdtls sees a didSave after agent edits, not the dependent-revalidation nudge from the design.

Testing

  • uv run pytest: 804 passed, 1 skipped (opt-in measurement), including jdtls e2e locally (jdtls 1.61.0 via Homebrew).
  • New e2e through the real server with default constants (tests/test_e2e_hold.py): fixing a missing import never re-publishes "Bar cannot be resolved" with the hold, and does with JAVA_FUNCTIONAL_LSP_DIAG_HOLD=off, so the Stale diagnostics lag behind edits (imports/signature changes report false errors until recompile) #109 symptom is reproduced and fixed end to end.
  • Reviews: two correctness + test rounds (round 1's critical finding, the e2e wait passing on pre-edit state, is fixed), then /review-ensemble (5 reviewers + claim verifier): 4 APPROVE / 1 CHANGES, 30 findings; the medium and high ones are addressed in the last commit (per-file freshness timing, package-scoped log level, didOpen/didClose handling, caching on the hot paths, server-level e2e).

Follow-up

#112 (stacked on this PR) gets the fresh result into the edit's own tool result via the plugin hook and fixes the cross-file variant with a didSave.

Before merge

Run the missing-import and signature-change repros in Claude Code on a large Maven repo with JAVA_FUNCTIONAL_LSP_DIAG_HOLD=custom-first vs off and JAVA_FUNCTIONAL_LSP_LOG_LEVEL=DEBUG, and check that no attachment after the fixing edit carries the resolved error.

Trade-off

In hold-all (IDEs) custom diagnostics after typing now appear when jdtls answers (~0.5-2s, max 10s) instead of 150ms.

Refs #109

🤖 Generated with Claude Code

aviadsTaboola and others added 4 commits September 28, 2026 07:47
After an edit the wrapper re-published jdtls's diagnostics for the previous
version 150ms later (and immediately on save), while jdtls needs 0.4-2.4s to
re-validate. Agent hosts that attach diagnostics right after the edit showed
those stale compile errors as current.

- Track per-file "waiting for jdtls" state; release it only on a jdtls publish
  that arrives after jdtls's minimum debounce since the last forwarded change,
  with an adaptive deadline (3s floor, 10s ceiling) falling back to the cache.
- custom-first mode (Claude Code): publish custom diagnostics at once without
  the stale jdtls set; hold-all (other editors): publish nothing until fresh.
  JAVA_FUNCTIONAL_LSP_DIAG_HOLD=off restores the old behavior.
- Skip the hold for modules not yet imported and java.diagnostic.filter files.
- Key the jdtls cache by normalized URI and publish under the client's URI.
- Clear cached diagnostics and release holds when jdtls stops.
- JAVA_FUNCTIONAL_LSP_LOG_LEVEL, freshness summary counters, jdtls version
  and dropped jdtls->client request logging; redact paths in two log lines.
- E2E test for the cross-file arity variant: converges with didSave, stays
  stale without it (xfail, Part B).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Keep the too-early floor fixed at jdtls's 400ms debounce; the adaptive floor
  ratcheted up after one slow publish and rejected normal ones for the rest of
  the session. The latency EWMA now only stretches the deadline.
- Re-initialize wakes held files like a jdtls stop does.
- A failing custom-first publish no longer leaves the file pending with no
  hold task; a superseded hold task never publishes.
- Only hold files in the opened set, since jdtls publishes for other files are
  gated out and could never release the hold.
- Tests: long deadlines in the wiring fixture with polling instead of fixed
  sleeps, autouse isolation of hold state, and cases for custom-first timeout,
  cross-file holds, save then release, late correction, didOpen while pending,
  re-initialize and encoded URIs. The e2e test now judges only post-edit
  publishes after jdtls goes quiet (it previously passed on pre-edit state).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Guard the superseded-hold-task race (its cleanup no longer removes the live
task's event or pending state) and pin it with a test; make the close test
wait past a short deadline, drop the last wall-clock upper bound in the
timeout test, and let the e2e readiness wait see a publish that landed while
the files were opening.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Judge freshness by the file's own last edit: another file's change no longer
  pushes a fresh publish into the timeout path. The deadline still follows the
  last change to any file; the ceiling now counts from the file's last edit.
- JAVA_FUNCTIONAL_LSP_LOG_LEVEL applies only to this package's loggers (root
  DEBUG also enabled pygls payload and jdtls stderr logging); README wording
  corrected. Exception messages with paths are logged as type names.
- didOpen while a file waits for jdtls publishes without the stale jdtls set;
  didClose drops the file's hold event; on_stopped fires once per jdtls death.
- Cache _normalize_uri and the per-file module lookup (per-publish and
  per-keystroke costs on large workspaces); hash diagnostics only when needed.
- Typed hold outcomes, constructor timing knobs, a clearer late-correction path,
  bounded/escaped dropped-request method names, jdtls source permalink.
- New real-jdtls e2e through the server with default constants: fixing a
  missing import never re-publishes the resolved error with the hold, and does
  with DIAG_HOLD=off. No-didSave cross-file measurement is now opt-in; global
  pytest timeout.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aviadshiber
aviadshiber marked this pull request as ready for review September 28, 2026 11:28
@aviadshiber
aviadshiber merged commit 64b184c into main Sep 28, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants