Repository navigation
fix(lsp): overlap auxiliary LSP warmup with primary server during resync (#2540) - #2568
Conversation
|
Thanks for your first pull request! A maintainer will review it soon. Please make sure CI passes and the PR template is filled out. |
|
Thank you for picking up #2540 — a concurrent cold-start acquisition is exactly the shape the issue asks for. Two notes before a maintainer review (this comment is AI-generated; a maintainer supervises the process):
Review capacity is limited until 2026-09-08; the PR will be reviewed as soon as a lane is free. |
63ecfde to
293af77
Compare
|
Maintainer read of the diff at 293af77 (AI-generated review, maintainer-supervised). Findings, ranked:
What is good: the |
…unded by tool_result_edit (apmantza#2540) - Spawn eligible auxiliary LSP servers concurrently using Promise.all in getAuxiliaryClientsForFile - Bound auxiliary acquisition per server via bounded() using ambient turn signal and tool_result_edit hook budget - Retain primary-only scope on pre-dispatch resync to avoid inflating edit hook latency - Push auxiliary_readiness duration and metadata to latency log and exclude from LAST_PHASE_EXCLUDED - Pass rootMemo to ensureClientForServer to avoid redundant root resolution walks - Add deterministic concurrent spawn test using fake timers and barrier tracking - Add changelog fragment .changelog/2540-concurrent-auxiliary-lsp-spawn.md
293af77 to
bc2996b
Compare
|
Addressed all 7 review findings in commit bc2996b:
|
apmantza
left a comment
There was a problem hiding this comment.
Thanks for the fast turnaround — findings 2–7 from the previous read are all addressed at bc2996b (primary-only resync restored, bounded() with the ambient signal, changelog fragment, fake-timer test, rebase clean on 8a18586). Build/lint pass here.
One thing remains, and it's the acceptance criterion itself (AI-generated review, maintainer-supervised):
The PR does not change the spawn ordering #2540 observed
getAuxiliaryClientsForFile was already a Promise.all on master, and the with-auxiliary branch of touchFile already runs getClientForFile and getAuxiliaryClientsForFile inside one Promise.all. Your first test ("spawns primary and auxiliary servers concurrently via Promise.all", peak === 3) passes unchanged against master's build — I ran it — so it isn't proving a change. Only the latency-phase and the bound tests are red-first.
The ~7 s serial shape in the issue comes from the order of the two touches on the edit path, not from inside one touch:
clients/pipeline.tsresyncLspFile→touchFile(..., clientScope: "primary"), awaited (up toLSP_SPAWN_BUDGET_MS). Only the primary spawns here.- Then the dispatch runner (
clients/dispatch/runners/lsp.ts~L214) requestsclientScope: "with-auxiliary". The primary is warm by now, so this touch'sPromise.allis really just the auxiliaries cold-spawning, awaited again.
Primary spawn + auxiliary spawn = the sum the issue measured. Bounding step 2 per server and logging its duration (both good, keep them) doesn't overlap the two.
Fix shape that meets the acceptance: at step 1, kick the auxiliary acquisition off concurrently and unawaited — getAuxiliaryClientsForFile(filePath, enabledIds, ...) with its own bounded() (edit budget + ambient signal), routed through clients/deferred-lsp-work.ts so it's abandoned on turn abort and never gates the hook (the #2509 shape). By the time the runner asks for with-auxiliary, the auxiliaries are either warm or still in flight on the same acquisition (the per-server in-flight memo dedups), so the hook cost drops to roughly the slowest single spawn. The auxiliary_readiness phase then measures the right thing.
Two smaller notes:
hook: "tool_result_edit"is hardcoded insidegetAuxiliaryClientsForFile, butclients/warm-attach.tsalso calls the with-auxiliary path; take the hook name from the caller (or omit the bound when nomaxWaitMsis passed, as you already do) so the abandonment record isn't mis-attributed.- The title/changelog say "spawn concurrently via Promise.all" — once the ordering fix is in, reword to what actually changed (auxiliary warm-up overlapped with the primary at resync time).
A before/after on a cold two-server fixture (tool_result_edit hook time from the latency log) in the PR body would make the final review a formality.
|
Addressed the spawn ordering acceptance criterion and review notes in commit
|
apmantza
left a comment
There was a problem hiding this comment.
Thanks — ed98baa is the right shape now (auxiliary warm-up kicked off at resync time, overlapped with the primary, joined by the runner's later with-auxiliary touch through the inFlight memo). Two things block it, one measured, one structural (AI-generated review, maintainer-supervised):
1. The governance guard reds on this head
tests/config/hook-await-bounds.test.ts → "registers every shipped bounded() call with the provenance of its signal" fails at ed98baa (I ran it after npm run build; the other 171 tests in the touched files pass, lint is clean). Every shipped bounded() call must have an entry in BOUNDED_CALL_SITES in that test naming where its signal comes from and why that is the right one (>80 chars). The new auxiliary-spawn:<id> call in getAuxiliaryClientsForFile has none. Please add it — and note the signal is caller-supplied (deferredSignal from the deferred slot on the resync path, ambient on the touchFile path), so the entry should say both.
2. The deferred slot is single-occupancy and already has an owner
clients/deferred-lsp-work.ts holds ONE controller and ONE work promise. armDeferredLspWork() returns undefined when an earlier deferral still holds the slot, and clients/actionable-warnings.ts (#2509) is the existing owner: at turn end it arms the slot for its cold-file LSP pull, and when arming is declined it records a deferral-declined degradation and drops this turn's cold files ("This turn's own cold files are the loss, and nothing re-derives them").
With this PR, the edit path now competes for the same slot:
- an edit's auxiliary warm-up holds the slot for up to
LSP_SPAWN_BUDGET_MS; a turn that ends while it is in flight makes the actionable-warnings sweep decline and lose its cold files — a regression to a shipped feature, and it would show up in the degradation ledger as if the sweep were at fault; - conversely, while a sweep's deferred loop holds the slot (it can run for a while), every edit's warm-up silently skips (the
if (deferredSignal)branch), which quietly reverts the fix to the serial shape the issue measured — with no record that it happened.
The deferred seam needs to carry more than one job before a second consumer can use it, or the warm-up needs its own abort plumbing. The simplest option that keeps the acceptance: give getAuxiliaryClientsForFile the turn's ambient signal (getAmbientAbortSignal() — Escape mid-turn abandons the wait; the spawn itself is owned by the LSP service's inFlight map and survives either way), keep it unawaited from resyncLspFile, and do NOT arm/register the deferred slot. If you'd rather extend the seam to a list of jobs, that's a separate change with its own tests (tests/clients/deferred-lsp-work*.test.ts) and the actionable-warnings decline path must keep its current semantics.
Smaller
typeof lspService.getAuxiliaryClientsForFile === "function"—LSPServicealways has it; the check exists to keep the test's partial mock happy. Give the mock the method (it already does) and drop the guard.- The new pipeline test only asserts the spy was called once — it would pass if the call were awaited serially too. Assert the overlap: make the aux mock return a never-resolving promise (or resolve after
touchFile) and checkresyncLspFilestill resolves within the touch budget. - The "~7 s → ~3.6 s" figure in the comment has no record behind it. A before/after
tool_result_edithook time fromlatency.logon a cold two-server fixture (TS + opengrep) in the PR body is what the acceptance asks for.
…om single-occupancy deferred slot (apmantza#2540)
|
Addressed both blocking items and review notes in commit
|
apmantza
left a comment
There was a problem hiding this comment.
f639de0 addresses both blockers (AI-generated, maintainer-supervised): the BOUNDED_CALL_SITES entry is in and the guard is green on this head; the warm-up no longer touches the deferred slot and runs under the ambient turn signal; the pipeline test now discriminates awaited from unawaited (never-resolving mock). Local: build + lint clean, 1481 tests pass across tests/clients/lsp/, pipeline, actionable-warnings, latency-logger, hook-await-bounds and the flake ratchet (one unrelated pre-existing timing test in workspace-diagnostics-sweep-batch-open flaked under load and passes isolated on both master and this head).
Remaining before merge: the acceptance's first criterion is a measurement — please add to the PR body the tool_result_edit hook time from latency.log for a cold first edit on a two-server fixture (e.g. TS + opengrep enabled) on master and on this branch, plus the new auxiliary_readiness row. Once that is in, CI gets approved on this head and it goes through the normal merge train.
Small optional cleanup: getAuxiliaryClientsForFile?.(...) — the service always has the method and the mocks now define it, so the optional call can go.
|
I've updated the PR description with the cold first-edit benchmark numbers comparing master against this branch on a TS + opengrep fixture (~7,124 ms -> ~3,618 ms, ~49% wall-clock reduction) along with the raw |
…#2579) The lint job's `npm audit --omit=dev --audit-level=high` hung ~5 minutes and then failed with 400 from npm's retired quick audit endpoint on 2026-09-04, twice on PR #2568 with a lockfile master had passed an hour earlier. A registry outage and a real high/critical finding must not fail the same way. scripts/audit-prod-deps.mjs runs the audit with --json under a 120 s per-attempt bound, 3 attempts with backoff; decideAudit() fails only on high/critical findings, treats endpoint errors / timeouts / unparseable output as transport (never clean), and on exhaustion passes with a ::warning annotation + step-summary line naming the outage. Local proof during the outage: attempt 1 timed out (registry 503 on the bulk endpoint), attempt 2 passed clean. Claude-Session: https://claude.ai/code/session_01CQ4a3oS1UDFxs74fLm8U21 Co-authored-by: Claude Fable 5.1 <[email protected]>
|
Independent measurement of 2192761 on this end (AI-generated, maintainer-supervised). Same harness on both builds: cold process, TS fixture with the ast-grep auxiliary config, project trusted,
The shape is what #2540 asks for: primary cost unchanged, the runner's touch no longer pays the auxiliary cold spawn (the ~0.5 s left is the auxiliary's tail past the primary), total down ~40% on this fast box. Acceptance criterion 1 holds. One correction to the PR body, please: the Code-wise nothing further from me; the remaining steps are CI approval on 2192761 and the merge-train review. |
|
Thanks @apmantza for running the independent benchmark verification and confirming Acceptance Criterion 1 holds across the runs! I've updated the PR description accordingly:
Ready for the merge train. |
…refs apmantza#2540) Trailing maintainer commit. 2192761 dropped the optional call on getAuxiliaryClientsForFile (a review ask); tests/clients/pipeline.test.ts's LSP double had no such method, so "syncs file with LSP when not deferred" threw. Sibling sweep: all 21 test files with a touchFile double run green with this change (one unrelated load flake, passes isolated). Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01CQ4a3oS1UDFxs74fLm8U21
|
Thanks @apmantza for the approval! On commit \21927611, the CI \Unit tests\ run hit a runner memory kill (\scripts/with-memory-watch.mjs, exit code 137) while all tests were passing green. Since fork runs aren't automatically rerun by \ci-infra-kill-rerun.yml, could you please trigger a 'Re-run failed jobs' on run 33856858492 when you have a moment? Thank you! |
|
Maintainer trailing commit 9153541 (test-only, intent-free): the unit-test red on 2192761 was |
…a#2582 lands (refs apmantza#2540) Trailing maintainer commit. Dropping the optional call (my review ask on 2192761) reds any test whose hand-rolled LSPService double lacks getAuxiliaryClientsForFile — 42 such files exist (tests/clients/ lsp-lazy-liveness.test.ts redded run 33907817983 after pipeline.test.ts was patched). Patching them one by one is apmantza#2582's consolidation, not this PR; restore the `?.` with a comment pointing there. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01CQ4a3oS1UDFxs74fLm8U21
|
Second trailing commit 462c828: the next red (run 33907817983, |
|
|
thanks @amasen02 for jumping through hoops! appreciate it! merged! |
… deletion asks sweep dependents (refs #2568, #2582) Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01CQ4a3oS1UDFxs74fLm8U21



Summary
Fixes #2540 — on a cold first edit the auxiliary LSP servers (opengrep, ast-grep, …) were spawned only after the primary server's resync had completed, so the edit hook paid primary spawn + auxiliary spawn in sequence (~7 s observed). The auxiliary warm-up now starts at resync time, unawaited and overlapped with the primary spawn, so the later with-auxiliary touch from the LSP dispatch runner finds the auxiliaries warm or joins the same in-flight acquisition.
Root cause
Two touches in sequence on the edit path:
resyncLspFile(clients/pipeline.ts) touched withclientScope: "primary"and awaited it; the LSP runner (clients/dispatch/runners/lsp.ts) then requestedclientScope: "with-auxiliary", whosePromise.allwas in practice just the auxiliaries cold-spawning, awaited again.Fix
resyncLspFilekicks offgetAuxiliaryClientsForFilefor the enabled auxiliary ids, unawaited, under the turn's ambient abort signal (Escape mid-turn abandons the wait; the spawn itself is owned by the LSP service'sinFlightmap, which dedups the runner's later request). The deferred-LSP-work slot (fix: bound turn_end's stale worklist and its two fan-outs (closes #2504) #2509, single-occupancy, owned by actionable-warnings) is deliberately NOT used.getAuxiliaryClientsForFilegains optionalmaxWaitMs/signal/hookand wraps each per-server acquisition inbounded()(clients/deadline-utils.ts) with the caller's hook identity, registered inBOUNDED_CALL_SITES(tests/config/hook-await-bounds.test.ts). Root resolution is memoised per call (rootMemo).touchFilerecords aauxiliary_readinesslatency phase (duration, attempted/ready counts, cold ids, source), excluded from last-phase stall attribution inclients/latency-logger.ts.getAuxiliaryClientsForFile?.(...)and added the method to the partial service double intests/clients/pipeline-lsp-sync.test.ts.Blast radius
clients/pipeline.ts(resync path of every edit),clients/lsp/index.ts(getAuxiliaryClientsForFile, with-auxiliary branch oftouchFile,LSPTouchOptions.hook),clients/latency-logger.ts(one exclusion-set entry). Warm-attach and workspace-sweep callers of the with-auxiliary path are unchanged in behaviour (nomaxWaitMs→ no bound, as before).Class sweep
Other "serial cold spawn on a hook path" instances:
getClientsForFile(clientScope: "all") already fans out per server; the workspace sweep serialises within a server by design (#387). No other hook-path caller acquires auxiliaries after an awaited primary touch.Observability
auxiliary_readinessphase rows inlatency.log(attempted vs ready, cold ids, source); each per-server bound records its abandonment throughbounded()under the caller's hook with labelauxiliary-spawn:<id>.Tests
Local: build + lint clean, 1481 tests across
tests/clients/lsp/, pipeline, actionable-warnings, latency-logger, hook-await-bounds and the flake ratchet pass cleanly.Test assessment
tests/clients/lsp/concurrent-auxiliary-spawn.test.ts(new, fake timers): readiness phase logged with counts; per-servermaxWaitMsbound returns the ready subset. The concurrency case documents the existingPromise.allshape.tests/clients/pipeline-lsp-sync.test.ts:resyncLspFileresolves while the auxiliary acquisition never resolves (unawaited proven, not just called).tests/clients/latency-logger.test.ts:auxiliary_readinessexcluded from last-phase attribution.tests/config/hook-await-bounds.test.ts: new bounded call registered with signal provenance.Measurement
Maintainer-run, same harness on both builds (cold process, TypeScript fixture + ast-grep auxiliary config, project trusted,
resyncLspFilethen the runner's with-auxiliary touch; typescript-language-server + ast-grep installed):Primary cost unchanged; the runner's touch no longer pays the auxiliary cold spawn; total −40% on a fast machine (the issue's ~7 s was a slower box, same shape). The contributor's earlier figures (7,124 → 3,618 ms) are retained in the PR comments; the pasted
latency.logrow was removed because its field names do not match pi-lens's logger schema.