Repository navigation
fix: resume a busy dependency-module round and give jdtls time to save on stop (v0.14.2) - #117
Merged
Merged
Conversation
…e 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>
_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>
aviadshiber
marked this pull request as ready for review
September 30, 2026 20:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-ups from the v0.14.1 products-gate evidence (PR #115). Five items were investigated with evidence before any fix; here's what each turned up and what changed.
1. Large-group jdtls-busy stall (main item)
Investigation. In the gate's
t2_gcs2kafkarun (service/boot group, 95 modules / 127 jdtls projects), the file was opened at t≈2s and its first demand-bearing publish arrived at t≈11.97s (stderr.log:11.97,dependency_modulesarmed).STOP(jdtls-busy)fired at t=101.98s — that's11.97 + ROUND_TIMEOUT_SEC(90.0) = 101.97s, an almost exact match. For comparison, the much smallert1_deltagroup (kfc-services, 5 imported modules) completed 3 rounds cleanly with each round well under 90s (16.6s / 25.4s / 59.2s). This points at "the build genuinely takes longer than one 90s round timeout for a 127-project group," not an obviously leaked progress id — though I could not fully rule out the latter: the sandbox's.claudeignoreblocks reading~/.cache/jdtls-data/**(including the read-only jdtls workspace.logfor data dir8c3ad2231ce5that the task named), and the harness'smessages.jsonldoesn't capture jdtls-internallanguage/progressReporttraffic (only what crosses the harness↔proxy boundary). The fix below is robust to either cause, since it just keeps waiting forBuildIdleto actually report idle rather than assuming a fixed 90s always suffices.Fix.
DependencyModules._wait_idle()retries the build-idle wait within a bounded busy budget (up to 6 attempts / 10 minutes) instead of failing at the first 90s timeout. A busy round no longer stops and un-arms its modules at once — it resumes as soon asBuildIdlenext reports idle. The existing budget/rounds/wall-clock limits are still checked between attempts, so a long-busy build still can't outlive the session limits. A finaljdtls-busySTOP (which still un-arms the module, so the next demand publish tries again) only fires once the busy budget itself is exhausted. README's stop-reasons table and knobs section are updated.2. Mid-import shutdown → workspace recovery
Research (Eclipse bug 272648 and related Eclipse Platform/JDT-LS shutdown discussions): "The workspace exited with unsaved changes in the previous session; refreshing workspace to recover changes" is Eclipse's
SaveManagerreporting an incomplete.snapwrite from the previous run — i.e. the workspace was killed before its save-on-exit finished. jdtls'sexitnotification triggers this save;proxy.stop()previously gave the JVM only_STOP_GRACE_SEC(1.0s) afterexit, and that budget was shared with the shutdown-request reply wait, so a slow shutdown reply could leave near-zero time for the save.Fix. A dedicated
_EXIT_GRACE_SEC(3.0s) now bounds the JVM's own post-exitsave-and-exit, decoupled from the shutdown-reply timeout. New worst-case stop bound: shutdown reply (≤1s) + exit grace (≤3s) + SIGTERM wait (≤1s) + SIGKILL wait (≤1s) ≈ 6s; the cooperative path (the common case) is unaffected, well under 1s. I did not measure a real jdtls's actual mid-import exit duration (spinning up cold jdtls per the README's 60-120s startup was too costly for this change) — the 3s budget is a reasoned estimate, documented in the code comment as unverified, and flagged here for a follow-up measurement. The startup-side "open file landed injdt.ls-java-project" WARN hint is deferred (see below).3. Missing proxy exception-resilience test
Added
test_note_publish_raising_does_not_break_the_next_publishandtest_note_progress_raising_does_not_break_the_next_progressintest_shutdown.py: each makes the correspondingdependency_moduleshook raise, feeds one message, and asserts the diagnostics cache/BuildIdlestate still updated correctly and the warning was logged, then un-patches and asserts the next message of that kind is handled normally.4. Round-log wording
The line now reads
dependency round N: imported X dependency module(s) (...) -> build idle (round took Ys) -> refresh <result>, ...instead of the old... round took Ys, refresh <result>, ... importing X ..., which read as if the import happened after refreshing.tests/e2e_maven.py'simported_gas()regex was updated to match.5. Fixed-sleep synchronization
Investigated
tests/test_diagnostics_freshness.py's_past_debounce/_past_min_agehelpers and every other fixedasyncio.sleepintests/. Every debounce/min-age wait in that file is already followed by the bounded_until()poll (the prior CI-flake fix — "poll for the failed custom-first analysis instead of a fixed 30ms sleep" — already covers the pattern this item describes). No further fixed-sleep-then-assert-on-async-side-effect instances were found in that file or elsewhere intests/; nothing to change here.Tests
test_busy_beyond_one_round_timeout_resumes_when_idle_returns(new): a build that stays busy past oneround_timeoutbut goes idle within the busy budget completes the round instead of stopping. Uses onlyTimingfields that exist on v0.14.1, so it doubles as the fail-before reproduction: run against a detachedorigin/mainworktree, it fails (assert [] == [['g:mid'], ['g:owner']], i.e.STOP_BUSYfired at once). Ablation on this branch (temporarily reverting_wait_idlecalls back to the bareidle.wait) reproduces the same failure, confirming the fix is load-bearing.test_jdtls_slow_to_save_still_exits_on_its_own(new,test_shutdown.py): a fake jdtls that acksshutdownimmediately but sleeps 1.5s before exiting onexitnow exits with code 0 and is never SIGTERMed. Verified failing againstorigin/main(returncode == -15, i.e. SIGTERMed mid-"save").test_deaf_jdtls_gets_sigterm/test_stubborn_jdtls_gets_sigkill(renamed from..._within_three_seconds): bounds widened to match the new, larger (but still single-digit-second) worst-case stop budget.uv run ruff check .,uv run ruff format --check .,uv run mypy src,uv run pytest -q(including real-jdtls e2e) all pass — 1084 passed, 1 skipped, 89.67% coverage.pgrep -fl jdtls-datashows no orphaned processes from these runs, and~/git/productsis untouched (git status --porcelainempty before and after).What the products gate will check
The gate should re-run
t2_gcs2kafka(and ideallyt2b/t2c) to confirm the service/boot group now reaches a clean or budget/rounds stop instead ofjdtls-busyat ~102s, and that a SIGTERM sent mid-import no longer produces "workspace exited with unsaved changes" on the next start for that data dir.Deferred
_EXIT_GRACE_SECprecisely (item 2).jdt.ls-java-project(item 2, lower value than the save-grace fix, deferred with reasoning above).🤖 Generated with Claude Code