Skip to content

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

Merged
aviadshiber merged 2 commits into
mainfrom
fix/v0142-followups
Sep 30, 2026
Merged

aviadshiber merged 2 commits into
mainfrom
fix/v0142-followups

Conversation

@aviadshiber

Copy link
Copy Markdown
Owner

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_gcs2kafka run (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_modules armed). STOP(jdtls-busy) fired at t=101.98s — that's 11.97 + ROUND_TIMEOUT_SEC(90.0) = 101.97s, an almost exact match. For comparison, the much smaller t1_delta group (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 .claudeignore blocks reading ~/.cache/jdtls-data/** (including the read-only jdtls workspace .log for data dir 8c3ad2231ce5 that the task named), and the harness's messages.jsonl doesn't capture jdtls-internal language/progressReport traffic (only what crosses the harness↔proxy boundary). The fix below is robust to either cause, since it just keeps waiting for BuildIdle to 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 as BuildIdle next 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 final jdtls-busy STOP (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 SaveManager reporting an incomplete .snap write from the previous run — i.e. the workspace was killed before its save-on-exit finished. jdtls's exit notification triggers this save; proxy.stop() previously gave the JVM only _STOP_GRACE_SEC (1.0s) after exit, 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-exit save-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 in jdt.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_publish and test_note_progress_raising_does_not_break_the_next_progress in test_shutdown.py: each makes the corresponding dependency_modules hook raise, feeds one message, and asserts the diagnostics cache/BuildIdle state 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's imported_gas() regex was updated to match.

5. Fixed-sleep synchronization

Investigated tests/test_diagnostics_freshness.py's _past_debounce/_past_min_age helpers and every other fixed asyncio.sleep in tests/. 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 in tests/; nothing to change here.

Tests

  • test_busy_beyond_one_round_timeout_resumes_when_idle_returns (new): a build that stays busy past one round_timeout but goes idle within the busy budget completes the round instead of stopping. Uses only Timing fields that exist on v0.14.1, so it doubles as the fail-before reproduction: run against a detached origin/main worktree, it fails (assert [] == [['g:mid'], ['g:owner']], i.e. STOP_BUSY fired at once). Ablation on this branch (temporarily reverting _wait_idle calls back to the bare idle.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 acks shutdown immediately but sleeps 1.5s before exiting on exit now exits with code 0 and is never SIGTERMed. Verified failing against origin/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.
  • Full suite: 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-data shows no orphaned processes from these runs, and ~/git/products is untouched (git status --porcelain empty before and after).

What the products gate will check

The gate should re-run t2_gcs2kafka (and ideally t2b/t2c) to confirm the service/boot group now reaches a clean or budget/rounds stop instead of jdtls-busy at ~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

  • Real-jdtls measurement of mid-import exit duration to tune _EXIT_GRACE_SEC precisely (item 2).
  • Startup-time detection/WARN when an open in-scope file lands in jdt.ls-java-project (item 2, lower value than the save-grace fix, deferred with reasoning above).

🤖 Generated with Claude Code

aviadsTaboola and others added 2 commits September 30, 2026 14:24
…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
aviadshiber marked this pull request as ready for review September 30, 2026 20:07
@aviadshiber
aviadshiber merged commit 9f1da7a into main Sep 30, 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