Skip to content

feat: fresh jdtls diagnostics in Claude Code's own tool result (#109 part B) - #112

Merged
aviadshiber merged 4 commits into
mainfrom
fix/109-part-b-didsave-hook-wait
Sep 28, 2026
Merged

aviadshiber merged 4 commits into
mainfrom
fix/109-part-b-didsave-hook-wait

Conversation

@aviadshiber

Copy link
Copy Markdown
Owner

Part B of #109: get fresh jdtls diagnostics into the tool result of the edit that caused them, and fix the cross-file variant. Stacked on #111 (base branch fix/109-stale-jdtls-diagnostics); merge #111 first.

Why

  • Claude Code records LSP diagnostics right after its PostToolUse hooks finish, without waiting for the server (141/141 attachments in local transcripts came after all hooks). jdtls needs 0.4-2.4s, so even with fix: hold edit-triggered publishes until jdtls re-validates (#109) #111 the fresh result showed up one tool call later.
  • Cross-file (Foo gains a constructor parameter, Caller updated, both written to disk): without a didSave, jdtls's only post-edit publish for Caller kept the old-arity error in ~2/5 runs and was never corrected; with didSave, 5/5 clean.

Change

  • Freshness marker: on each final publish (fresh jdtls results merged in) of a file opened or edited since its last marker, the server writes <pid> <sha256 of the analyzed content> to $TMPDIR/java-functional-lsp-<user>/fresh/<hash of path> (0700 dirs, 0600 file, symlink/ownership checks). didOpen writes a placeholder so the hook waits for jdtls's first result.
  • Hook: hooks/post_tool_lint.py waits until the marker's hash matches the file on disk, at most JAVA_FUNCTIONAL_LSP_HOOK_WAIT seconds (default 3, max 4, always under the hook's 5s cap). No marker or a dead server pid: no wait. The hook reads markers with O_NOFOLLOW from private owned dirs; a marker problem never suppresses the lint output.
  • didSave: after a Claude Code didChange whose buffer matches the file on disk (regular files only), the server forwards a didSave to jdtls. jdtls's handleSaved only reloads the working copy from disk, which equals the buffer. Kill switch: JAVA_FUNCTIONAL_LSP_AGENT_DIDSAVE=off.
  • Only for clients named Claude Code; other editors are unchanged. Version 0.13.0, plugin 0.4.4. README updated.

Testing

  • uv run pytest: 856 passed, 1 skipped (opt-in measurement), jdtls 1.61.0 locally.
  • E2E through the real server + jdtls: when the hook returns, the client already has jdtls's new error for the edit (fails with JAVA_FUNCTIONAL_LSP_HOOK_WAIT=0); three cross-file arity cycles converge without a client didSave. The cross-file e2e is a smoke test: with the didSave switched off it failed only in some runs, because the stale case is nondeterministic; the didSave effect is measured in tests/test_e2e_cross_file.py.
  • /review-ensemble (5 reviewers + claim verifier): 3 APPROVE / 1 CHANGES / 1 DISCUSS, 34 findings; all high and medium ones addressed in the later commits (content-hash markers with pid, hardened hook reads, final-publish rules, didSave fixes, tests). The claim verifier confirmed the jdtls handleSaved, O_NOFOLLOW and kill(pid, 0) assumptions.

Known limits

  • On projects where jdtls takes longer than the hook's wait (4s max), the hook still returns before the fresh result; raise JAVA_FUNCTIONAL_LSP_HOOK_WAIT up to 4.
  • Each Java edit in Claude Code now takes longer, by up to the jdtls latency (typically 0.5-2.5s).

Refs #109

🤖 Generated with Claude Code

aviadsTaboola and others added 3 commits September 28, 2026 09:08
…part B)

Claude Code attaches LSP diagnostics right after its PostToolUse hooks finish
(measured: 141/141 attachments), without waiting for the server, so jdtls's
result for an edit only showed up one tool call later.

- The server stamps a per-file marker (timestamp only, private per-user temp
  dir, path hashed, symlink-safe) whenever it publishes final diagnostics for
  a Claude Code client; hooks/post_tool_lint.py waits until the stamp is newer
  than the edit (JAVA_FUNCTIONAL_LSP_HOOK_WAIT, default 3s, max 4s, bounded by
  the hook's own 5s cap).
- After a Claude Code edit whose buffer matches the file on disk the server
  forwards a didSave to jdtls. Without it jdtls re-checked dependents against
  the old file and left them stale (~2/5 runs; cross-file constructor arity).
- E2E through the real server + jdtls: the hook returns only after jdtls's
  new error is published (fails with HOOK_WAIT=0), and three arity cycles
  converge without a client didSave (fails on the first cycle without it).
- Version 0.13.0, plugin 0.4.4.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Markers carry the server pid and a hash of the analyzed content instead of a
  time: a publish for an older version (late jdtls result, coarse mtime) can no
  longer release the hook, and the hook skips waiting when the server is gone.
- Stamp only final publishes of files opened or edited since the last marker;
  off-mode debounce publishes and background republishes no longer stamp.
  didOpen writes a placeholder so the hook waits for jdtls's first result.
- Hook reads markers safely: private owned dirs (no group/other bits), no
  symlinks (O_NOFOLLOW), regular file, bounded read; a marker problem never
  suppresses the lint output. Named wait constants.
- Server: permissions tightened on existing marker dirs, 0600 temp file with
  O_NOFOLLOW, directory checks cached, getpass fallback to the uid.
- didSave check: regular files only, never raises (runs after the hold task is
  scheduled), debug log on content mismatch, JAVA_FUNCTIONAL_LSP_AGENT_DIDSAVE=off
  kill switch; jdtls's handleSaved only reloads from disk (comment).
- _AGENT_HOST_CLIENTS / _is_agent_host replace the hold-mode constant reuse.
- Tests: in-process hook wait tests (budget, dead pid, placeholder, malformed
  and symlinked markers), agent-host marker rules, didSave edge cases, e2e with
  private TMPDIR, pinned modes, hold-all cross-file smoke test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kill(0, 0) and kill(-n, 0) signal process groups and usually succeed, so such a
marker would look like a live server and make the hook wait its full budget.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aviadshiber
aviadshiber marked this pull request as ready for review September 28, 2026 11:56
@aviadshiber
aviadshiber changed the base branch from fix/109-stale-jdtls-diagnostics to main September 28, 2026 11:58
@aviadshiber
aviadshiber merged commit 925c410 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