Skip to content

fix: bound dependency-module imports to what the open file needs (v0.14.1) - #115

Merged
aviadshiber merged 6 commits into
mainfrom
fix/dependency-module-cascade
Sep 30, 2026
Merged

aviadshiber merged 6 commits into
mainfrom
fix/dependency-module-cascade

Conversation

@aviadshiber

Copy link
Copy Markdown
Owner

Why

v0.14.0 (#110, #114) imported every in-repo GA that m2e reported missing on any pom. Each import exposed the next layer of the transitive closure. On products (delta-product-config-report), the import cascaded to the 60-module budget (viper-*, spark-*, trs-*, ...):

  • peak RSS went from 1.68 GB to 3.13 GB;
  • once the budget was reached, every LSP request (definition, hover, documentSymbol) timed out at 30 s;
  • the proxy logged 60 refreshDiagnostics timeouts, because ClasspathRefresher refreshed after every ClasspathUpdated event into a busy jdtls.

Experiment S2 showed the file needs 4 modules, each proven necessary by ablation: taz-kfc-core, mario-hdfs-connector, traffic-analyzer-backend and frontend-data-consumer-core. It also showed that jdtls never re-publishes an open file after an import, so a refresh after build-idle is required.

Design: java-functional-lsp-dependency-module-cascade.md, "Final design v2.1" as amended by "v2.2". Items deferred to v0.15 are not in this PR.

Change

Demand-driven rounds (dependency_modules.py):

  • Demand: an open .java file with False 'cannot be resolved' / 'hierarchy is inconsistent' for inherited symbols when a module is treated as a non-project file #110-class errors. The problem ids are checked first, with a bounded message fallback. Build-path markers (0, 964) and non-project files (16) are excluded.
  • Fresh-demand gate: the gate owns its state and does not depend on the Stale diagnostics lag behind edits (imports/signature changes report false errors until recompile) #109 marker, so non-agent clients work too.
    • It waits for build-idle: language/progressReport via extendedClientCapabilities.progressReportProvider=true, no open non-indexing task, and 10 s without a progress event. There is a single timer, and "Searching…"/indexing tasks are ignored.
    • It then sends java.project.refreshDiagnostics for the round's demand files: most recently opened first, at most 3, one in flight, a 20 s timeout and one retry.
    • Only the last publish between the send and the response counts. The response hook runs in wire order. The publish must also match the current document digest.
  • Frontier: the in-repo compile/provided/runtime <dependencies> of the demand module and of every imported module, including the in-repo parent chain. For a src/test file, the demand module's test and test-jar edges are added. Deferred candidates carry forward.
  • Candidates: the frontier ∩ m2e "Missing artifact" markers. Markers keep type and classifier, so a test-jar edge only matches a test-jar/tests marker. They are ordered by declaration, hubs last. At most 8 go into one didChangeWorkspaceFolders per round.
  • Markers: before round k, the server waits until the modules imported in round k−1 have published their pom, for at most 30 s.
  • STOP: a fixed enum: clean, no-candidates(none|markers-pending|owner-has-jar), budget, rounds, wall-clock, jdtls-busy, no-fresh-diagnostics. Each STOP is logged, and sent once via window/logMessage. A new module re-arms the process unless a session limit was hit.
  • Limits:
    • budget 30 and rounds 6. The repo config can only lower them; JAVA_FUNCTIONAL_LSP_DEPENDENCY_MODULES and the new JAVA_FUNCTIONAL_LSP_DEPENDENCY_ROUNDS can raise them up to 200 and 20;
    • a 5-minute import wall clock per session. It counts import phases only, so refresh time and idle gaps between phases are excluded.
  • The per-ClasspathUpdated refresh is removed in the same change as the post-idle refresh that replaces it.
  • Logging: one INFO line per round, a line per STOP, and a session summary. Pom churn for modules without an open file is logged at DEBUG.

Reactor index (reactor.py): dependency edges (scope, test-jar), ${project.groupId}/${project.parent.groupId} substitution, and the parent GA of each module. A GA→dir map (aggregators included) serves parent lookups, with a visited set and a depth bound. The index also records fan-in. The hardened parser rules are unchanged, and dependencyManagement is ignored.

Hygiene (proxy.py, server.py):

Testing

Pre-checks (real jdtls 1.61):

  1. Two modules were added via didChangeWorkspaceFolders, then jdtls was shut down and restarted on the same data dir. java.project.getAll after build-idle listed only groupB/it, and all 4 import errors were back. The folders do not persist, so the record resets at start.
  2. S2's language/progressReport shape matches the design (id, task, subTask, status, workDone, totalWork, complete). Every id completes in runs A–G, and "Searching..." is the dominant indexing task. In runs B, C, E, F and G the refresh publish arrives just before the null response.

New e2e tests (real jdtls, isolated primed repository, never ~/.m2):

  • (a) test_parent_inherited_chain_stops_when_clean. App → mid; mid's parent pom declares owner; owner → deeper, which the file does not need.
  • (b) test_cross_group_dependency_resolves. The post-idle refresh must run and see the clean set.
  • (c) test_sigterm_leaves_no_jdtls. SIGTERM the server, then check the JVM pid.
origin/main (51177db) this PR
(a) chain FAIL: imported mid, owner, deeper (the cascade) PASS: round 1 {mid}, round 2 {owner} (inherited via the parent), STOP clean, 2/30 modules, deeper never imported
(b) refresh FAIL, but only because the round/STOP log lines do not exist on main (its per-event refresh does make the file clean) PASS: 1 round, 2 refreshes, STOP clean
(c) SIGTERM FAIL: jdtls JVM survived PASS: "received SIGTERM: stopping jdtls", the JVM is gone

The behavioral evidence for the post-idle refresh is an ablation: with the round refresh disabled, both (a) and (b) fail. In (a) the file keeps "The import com.example.mid cannot be resolved" because jdtls does not re-publish it after round 1. In (b) the STOP line shows refreshes 1.

Unit tests cover:

  • edge parsing with parent inheritance, placeholders, scopes and the test-jar classifier; marker type/classifier;
  • frontier union and carry-forward; marker ∩ frontier; ordering (hubs last); test-jar matching;
  • every STOP reason, including all three no-candidates details;
  • the stale in-flight publish, a publish after the response, the last publish in the window, URI spelling, an edit during a refresh, and an unsolicited publish never deciding a round;
  • a non-agent client;
  • the build-idle state machine (single timer, indexing ignored, timeout leading to jdtls-busy);
  • the refresh caps (3 per round and 20 per session), one refresh in flight, and one retry;
  • the budget taken from the proxy's own record;
  • knob clamping;
  • wall clock: import phases only, excluding refresh time;
  • the ws2 key, and the progressReportProvider merge;
  • stop() against real child processes: a cooperative one under 1 s, SIGTERM, SIGKILL in under 3.5 s, and idempotence;
  • the EXIT/SHUTDOWN/signal handlers.

Gates: ruff check, ruff format --check, mypy src and pytest -q all pass: 1062 passed, 1 skipped (the pre-existing measurement-only test), 89.45% coverage. All real-jdtls e2e tests ran.

Not in this PR / notes:

  • The products manual gate (A/B harness plus claude -p on delta-product-config-report) was not run here.
  • "Supertype owner first" ordering needs the FQN→module symbol index, which is deferred to v0.15. Without it the owner is never known, so the order is declaration order with hubs last.
  • disabled is in the STOP enum, but a disabled budget is logged once at start and never runs a round.
  • The e2e chain module is named app, not target: jdtls excludes **/target/** from the import.

🤖 Generated with Claude Code

aviadsTaboola and others added 6 commits September 30, 2026 01:12
…14.1)

v0.14.0 imported every in-repo GA that any pom reported missing. Each
import surfaced the next layer of the transitive closure (60 modules,
3.1 GB RSS and 30 s timeouts on products), and ClasspathRefresher sent
refreshDiagnostics after every ClasspathUpdated event into a busy jdtls.

Imports now run in bounded rounds that only fresh demand can start:
- demand = an open .java file with #110-class errors (problem ids, with
  a bounded message fallback), confirmed by a refreshDiagnostics publish
  that lands between the send and the response and matches the document
  digest, sent after build-idle (language/progressReport, 10 s quiet,
  indexing tasks ignored);
- candidates = frontier (in-repo <dependencies> of the demand module and
  of imported modules, with the in-repo parent chain; test/test-jar
  edges only for src/test demand) intersected with m2e Missing-artifact
  markers; declaration order, hubs last; at most 8 per round, sent as
  one didChangeWorkspaceFolders;
- fixed STOP reasons (clean, no-candidates(none|markers-pending|
  owner-has-jar), budget, rounds, wall-clock, jdtls-busy,
  no-fresh-diagnostics), logged and sent once via window/logMessage;
- budget 30 and 6 rounds (repo config can only lower, env can raise to
  200/20), a 5-minute wall clock from the round-1 import, and 3
  refreshes per round, one in flight, with one retry.

The per-ClasspathUpdated refresh is removed in the same change. The
reactor index gains dependency edges, the parent chain and fan-in, and
markers keep type/classifier (test-jar). The data-dir key is tagged
ws2, and the proxy keeps its own record of imported modules. jdtls 1.61
drops added folders on restart, so the record resets.

Shutdown: real SHUTDOWN/EXIT handlers and SIGTERM/SIGHUP handlers stop
jdtls within ~3 s (shutdown reply read first, SIGTERM after 1 s, SIGKILL
after 2 s) and end the process with os._exit, so no JVM outlives the
server (#107). pygls>=2.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A round now refreshes the files that had fresh demand in that round
(still open, most recent first, at most 3), instead of whichever open
files looked like demand from their latest publish. When jdtls
re-validated a file on its own mid-build, the round was otherwise
decided without a refresh. The e2e test asserts that the post-idle
refresh ran and saw the clean set. With the refresh disabled, both
dependency e2e tests fail.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The 5-minute cap started at the session's first import and never reset.
A module armed 20 minutes after the first one stopped clean was cut off
with wall-clock as soon as it had candidates. Now only import phases
count (round-1 import to STOP, minus refreshes after that import), and
the total carries across re-arms.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- reactor: parse truncated "Missing artifact g:a:jar" markers without raising;
  proxy guards the dependency-module bookkeeping so it cannot kill the reader loop
- refresh cap: a terminal refresh-cap STOP (not no-fresh-diagnostics), and a
  default cap of 3 x (rounds + 1) x 2 so the rounds limit fires first
- probe-time jdtls-busy / no-fresh-diagnostics and failing phases un-arm their
  modules; a failing phase no longer drops queued modules; a repeated warning
  stop is logged at DEBUG only; nothing stays armed when no runner is scheduled
- one phase per reactor root; refresh time on the STOP and summary lines
- remove the unused "disabled" stop reason
- signal watchdog exits without logging.shutdown(); record temp file via
  NamedTemporaryFile; capped repo-config log value and open progress ids
- tests: budget cut-off inside a round, demand during a phase, the extra quiet
  window, failing phases, JSON-RPC error and cancelled requests, real server
  process shutdown/exit codes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… ms sleep

The test flaked on the macOS / Python 3.11 CI runner: the debounced analysis
could run after the patch context exited, so the file was still pending.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aviadshiber
aviadshiber marked this pull request as ready for review September 30, 2026 08:00
@aviadshiber
aviadshiber merged commit f619c77 into main Sep 30, 2026
14 checks passed
aviadshiber added a commit that referenced this pull request Sep 30, 2026
…n its own (v0.14.2) (#117)

* fix: resume a busy dependency-module round and give jdtls time to save on stop (v0.14.2)

Follow-ups from the v0.14.1 products-gate evidence (#115):

1. A large module group's jdtls build routinely outlasts the fixed 90 s
   round timeout (measured: a 95-module/127-project service/boot group
   never went idle within 90 s across three gate runs, t2/t2b/t2c). The old
   code treated a busy timeout as a dead end: it stopped with jdtls-busy
   and un-armed the module, so only a new demand publish (which jdtls
   never sends without a fresh classpath change) could try again.
   _wait_idle() now retries the wait for build-idle within a bounded busy
   budget (up to 6 attempts, 10 minutes) instead of failing at the first
   90 s timeout, so the round resumes as soon as jdtls next reports idle.
   The session's existing budget/rounds/wall-clock limits are still
   checked between attempts, and a final jdtls-busy STOP (which still
   un-arms the module) only fires once the busy budget itself is
   exhausted.

2. Mid-import shutdown: stop() gave the JVM only ~1 s after the exit
   notification before SIGTERM, shared with the shutdown-request timeout.
   Research (Eclipse bug 272648 and related Eclipse Platform/JDT-LS
   reports) confirms "the workspace exited with unsaved changes" comes
   from an incomplete ResourcesPlugin SaveManager .snap write, which
   SIGTERM mid-save can produce. A dedicated exit-grace constant now
   bounds the JVM's own post-exit save-and-exit (3 seconds), decoupled
   from the shutdown reply timeout. Total worst-case stop bound: about
   6 seconds (shutdown reply + exit grace + SIGTERM wait + SIGKILL
   wait); the cooperative path is unaffected (well under 1 second). The
   exact real-jdtls mid-import exit duration was not measured (too
   costly for this change, deferred); the exit-grace budget is a
   reasoned estimate, stated in the code comment.

3. Added the missing proxy test: note_publish and idle.note_progress
   raising is caught and logged, and the next message of each kind is
   still handled (diagnostics cache updated / BuildIdle updated).

4. The round-log line now states the order explicitly (imported, then
   idle, then refresh), instead of reading as if the import happened
   after going clean.

5. Investigated tests/test_diagnostics_freshness.py's fixed-sleep
   helpers (_past_debounce, _past_min_age): every use is already
   followed by the bounded _until() poll (the prior CI-flake fix
   already covers this); no further fixed-sleep-then-assert instances
   were found there or elsewhere in tests/.

Fail-before: the busy-round-resume test and the slow-to-save shutdown
test were both run against a detached origin/main worktree and shown to
fail there (a final busy stop, and a SIGTERM mid-save respectively),
then the scratch worktree was removed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

* fix: latch the real session-limit reason through a busy retry (PR #117)

_wait_idle's busy-retry loop returned a bare busy timeout even when a
session limit (budget/rounds/wall-clock) had already been reached
mid-retry, instead of latching self._session.terminal like _select
does. Since the generic jdtls-busy reason is retryable, the module was
un-armed and its next demand re-entered the same limited session and
busy-waited again, repeating indefinitely on a persistently busy jdtls
-- exactly the large-module-group scenario this PR targets.

_wait_idle now returns the real STOP reason (or None on idle) and
latches it onto the session before the busy-retry exhaustion check, so
a terminal limit is never masked as jdtls-busy even on the final
retry attempt, and _process/_round log and report the true reason.

Adds two tests covering previously-untested _wait_idle paths (the
busy_wait_budget deadline, and a session limit reached mid-retry) plus
a third for the limit-vs-exhaustion race on the final attempt; each
was verified to fail against a hand-mutated pre-fix reproduction.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

---------

Co-authored-by: Aviad Shiber <aviad.s@taboola.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
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