Repository navigation
Fix #2, #4, #23, #42; memory-lifetime leaks and CPU session bugs - #64
Merged
Merged
Conversation
…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]
…s (CodeQL cleartext-logging)
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.
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
lspkit::vfs::text([VFS-TEXT]) (Provide generic position-aware text primitives (word-at-position, whole-word occurrences) + a hover MarkupContent builder #2): language-agnostic, encoding-aware text primitives. They areword_at,occurrences,prefix_to,measureandchar_width, with identifier classification by UnicodeXID_Continue. Adds theunicode-identdependency.lspkit_server::hover_markdown([LSP-HOVER-MARKDOWN]) (Provide generic position-aware text primitives (word-at-position, whole-word occurrences) + a hover MarkupContent builder #2): builds a markdown hover reply ornull.ref-graph-layout.tsandcanvas-hidpi.ts(Profiler: remaining discovery and memory-dashboard defects from production filming #4): the retention graph is now laid out with no overlapping labels and drawn at device-pixel resolution, so it is sharp on Retina displays.scripts/consumer-kit-check.sh(Publish the .NET profiler engine, fixtures and test-support so consumers need no source checkout #42): packages the release assets and asserts their contents. CI calls this script instead of an inline step.Changed
dotnet/Directory.Build.props, so its fixtures build from the kit alone.Makefileprofiler-ui targets (make ci fails under Windows PowerShell before tests and coverage #23): usenpm --prefixinstead ofcd … &&, 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.SamplerHandle.started_at), not from registration.MAX_PENDING_EVENTS, then collapse toRescan. Before, the backlog was unbounded.CancellationHandle::register.queueand itsQueuedRequestguard are now the only way to register a request.sleepis replaced by polling for the observed event: sample counts, heap growth, or the session ending.POLL_GUARDis only a failure timeout.Deleted
docs/plans/memory-leak-*.md. Their rules now live inlspkit-spec.mdunder[MEM-LIFETIME], andAGENTS.mdpoints there.How Do The Automated Tests Prove It Works?
crates/lspkit/tests/vfs_text.rsandvfs_text_scan.rscoverword_at,occurrencesandprefix_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.rschecks the markdown andnullreply shapes.crates/lsp-profiler/src/service/memory_start_lifetime_tests.rssends 8 refusedmemory/startrequests. It asserts that every start reaches the backend'sstopand that the runtimeArccount returns to its baseline. Both checks failed before the fix.session_lifetime_tests.rschecks that an ended CPU session frees its PID for a new recording.live_scheduler.rschecks that a stalled consumer sees one bounded, merged trigger and that an overflowing burst becomesRescan.dispatch_heap_leak.rsanddispatch_memory_retention.rsdrive requests that are rejected, cancelled or abandoned before preparation. Exact allocator bytes andWeakcounts must return to zero.packages/lsp-profiler-ui:profile-server.test.tschecks that concurrent first registrations reuse one server.ref-graph-layout.test.tschecks that no two node labels overlap and that layers are ordered.webview-contract-memory.tschecks the HiDPI canvas backing size.crates/lsp-profiler-dotnetsuites (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, includingdotnet/Directory.Build.props, and that nobin/orobj/is shipped.Spec / doc changes
lspkit-spec.mdadds[MEM-LIFETIME]with its sub-rules,[VFS-TEXT]and[LSP-HOVER-MARKDOWN].LSP-PROFILER-SPEC.mdandLSP-PULL-SPEC.mdlink to the lifetime rules.AGENTS.mdcites the spec instead of the deleted plan.Breaking changes
lspkit_server::dispatch::CancellationHandle::registeris removed. UseCancellationHandle::queue, which returns aQueuedRequestguard.live::spawn_schedulernow returns a bounded receiver.🤖 Generated with Claude Code