Skip to content

Fix #2, #4, #23, #42; memory-lifetime leaks and CPU session bugs - #64

Merged
MelbourneDeveloper merged 15 commits into
mainfrom
fix/open-issues-2-4
Nov 20, 2026
Merged

MelbourneDeveloper merged 15 commits into
mainfrom
fix/open-issues-2-4

Conversation

@MelbourneDeveloper

Copy link
Copy Markdown
Collaborator

TLDR

Fixes the open bugs in #2, #4, #23 and #42, plus a set of memory-lifetime leaks and CPU-session bugs, and moves the memory-lifetime rules into the spec as [MEM-LIFETIME].

Details

Added

Changed

  • Consumer kit (Publish the .NET profiler engine, fixtures and test-support so consumers need no source checkout #42): now ships dotnet/Directory.Build.props, so its fixtures build from the kit alone.
  • Makefile profiler-ui targets (make ci fails under Windows PowerShell before tests and coverage #23): use npm --prefix instead of cd … &&, so they run under Windows PowerShell.
  • memory/start ([PROF-MEMORY-START]): a backend start that fails now stops and releases the session it opened. Before, it leaked one session for each failed start.
  • CPU sessions:
    • An ended recording no longer blocks its PID.
    • The per-PID check is atomic.
    • Duration is measured from the sampler's start (SamplerHandle.started_at), not from registration.
  • Live scheduler ([MEM-LIFETIME-SCHEDULER-BACKLOG]): at most one trigger waits for a busy consumer. Later bursts merge into it, up to MAX_PENDING_EVENTS, then collapse to Rescan. Before, the backlog was unbounded.
  • Dispatch ([MEM-LIFETIME-QUEUED-REQUEST]): removed the unguarded CancellationHandle::register. queue and its QueuedRequest guard are now the only way to register a request.
  • Profile loopback server: concurrent first registrations share one server instead of each starting their own.
  • .NET e2e tests: every sleep is replaced by polling for the observed event: sample counts, heap growth, or the session ending. POLL_GUARD is only a failure timeout.

Deleted

  • The finished memory-leak plans in docs/plans/memory-leak-*.md. Their rules now live in lspkit-spec.md under [MEM-LIFETIME], and AGENTS.md points there.

How Do The Automated Tests Prove It Works?

  • crates/lspkit/tests/vfs_text.rs and vfs_text_scan.rs cover word_at, occurrences and prefix_to. They run each case in UTF-8, UTF-16 and UTF-32, on astral and combining characters, at line boundaries and with out-of-range columns.
  • crates/lspkit-server/tests/hover.rs checks the markdown and null reply shapes.
  • crates/lsp-profiler/src/service/memory_start_lifetime_tests.rs sends 8 refused memory/start requests. It asserts that every start reaches the backend's stop and that the runtime Arc count returns to its baseline. Both checks failed before the fix.
  • session_lifetime_tests.rs checks that an ended CPU session frees its PID for a new recording.
  • live_scheduler.rs checks that a stalled consumer sees one bounded, merged trigger and that an overflowing burst becomes Rescan.
  • dispatch_heap_leak.rs and dispatch_memory_retention.rs drive requests that are rejected, cancelled or abandoned before preparation. Exact allocator bytes and Weak counts must return to zero.
  • packages/lsp-profiler-ui:
    • profile-server.test.ts checks that concurrent first registrations reuse one server.
    • ref-graph-layout.test.ts checks that no two node labels overlap and that layers are ordered.
    • webview-contract-memory.ts checks the HiDPI canvas backing size.
  • crates/lsp-profiler-dotnet suites (16 + 18 + 3, all passing) prove the new CPU duration and the sleep-free polling against the real .NET engine.
  • scripts/consumer-kit-check.sh (run in CI) checks the engine binary and every kit file, including dotnet/Directory.Build.props, and that no bin/ or obj/ is shipped.

Spec / doc changes

  • lspkit-spec.md adds [MEM-LIFETIME] with its sub-rules, [VFS-TEXT] and [LSP-HOVER-MARKDOWN].
  • LSP-PROFILER-SPEC.md and LSP-PULL-SPEC.md link to the lifetime rules.
  • AGENTS.md cites the spec instead of the deleted plan.

Breaking changes

  • lspkit_server::dispatch::CancellationHandle::register is removed. Use CancellationHandle::queue, which returns a QueuedRequest guard.
  • live::spawn_scheduler now returns a bounded receiver.

🤖 Generated with Claude Code

…ans; drop timing asserts from .NET endpoint tests

The leak plans' checklists were complete. Their durable rules and IDs now live in
lspkit-spec.md [MEM-LIFETIME] (MEM-FIX/MEM-AUDIT/MEM-060 citations renamed). The
engine endpoint test proves the pre-connect refusal by its message instead of
elapsed < 5s.
Each concurrent first call created its own http.Server and the last one won, so
the others listened until the extension host exited and dispose never closed
them. One pending start is shared; a start superseded by dispose closes its
server. [PROF-UI-LIFETIME]
The trigger channel was unbounded: a slow analyzer under sustained churn queued
one Trigger (with every event path) per quiet window, without limit. Now at
most one trigger waits; later bursts merge into it, and past MAX_PENDING_EVENTS
it becomes one Rescan. spawn_scheduler returns a bounded mpsc::Receiver.
[MEM-LIFETIME-SCHEDULER-BACKLOG]
… check

ensure_free counted ended recordings (kept only so stop can return them), so a
timed-out session refused every new session on its process until eviction. The
check also ran under a separate lock from the insert, so two concurrent starts
on one PID could both succeed. Now only recording sessions hold a PID, and the
check and insert share one lock. [PROF-CPU-SESSIONS]
… alone (#42)

The v0.10.1 kit's HotLeakApp failed to build outside the repo (CS0246: List<>)
because ImplicitUsings and the rest of the shared settings live in
dotnet/Directory.Build.props, which the kit omitted. CI's kit check only listed
files; scripts/consumer-kit-check.sh now also builds every fixture from a fresh
extraction of the kit. [REL-CONSUMER-ASSETS]
A request registered with register() and never prepared (rejected by the
consumer, peer gone, loop stuck) kept its control and interest strings until
the Dispatcher dropped: 32 abandoned 64 KiB registrations stayed in_flight.
queue() and its QueuedRequest guard are now the only pre-dispatch
registration. [MEM-LIFETIME-QUEUED-REQUEST] [LSP-PULL-CANCELLATION]
word_at (identifier run under a cursor), occurrences (whole-word matches),
char_width / measure / prefix_to, all in the negotiated PositionEncoding.
Identifier characters are Unicode XID_Continue (unicode-ident), so combining
marks stay inside their word. hover_markdown builds the markdown hover result
or null. Table tests permute UTF-8/16/32 across ASCII, CJK, emoji and
combining marks. [VFS-TEXT] [LSP-HOVER-MARKDOWN]
memory_start opened the session before backend.start; when the start (or its
first step) failed, the session stayed in the manager and the backend's state
was never stopped, while the client never received the id to stop it. The
failed start now runs backend.stop and closes the session. Regression drives
the real service handle with a refusing backend and checks the runtime's
strong count while the service lives. [PROF-MEMORY-SESSION]
The retention canvas sized its backing store in CSS pixels, so it blurred at
devicePixelRatio 2, and long type names overlapped. One devicePixelRatio helper
(canvas-hidpi.ts) now sizes the retention graph, memory timeline and flame
graph; the layout is a pure, unit-tested function that fits each label to its
node's share of the row. Contract regressions: backing store 2x at dpr 2, and no
two drawn label boxes overlap. [PROF-UI-REFGRAPH]
A .NET session's duration timer starts in the producer right after attach, but
the session clock started at adopt, after the process-table version lookup
(~0.3-0.4 s later). A session that ended by its duration and was stopped at
once reported ~0.68 s for a 1 s request; the test's 3 s sleep had hidden it.
SamplerHandle records when its channel opened and the session counts from
there. [PROF-CPU-SESSIONS]
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