Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
3c9b6f0
Move memory-lifetime rules into the spec; delete the finished leak pl…
MelbourneDeveloper Nov 20, 2026
8165bcb
Profile loopback server: concurrent first registrations share one server
MelbourneDeveloper Nov 20, 2026
335f32a
Makefile: profiler-ui targets run under Windows PowerShell (no && cha…
MelbourneDeveloper Nov 20, 2026
ac1751c
live::watcher docs: drop the exclusion rules it never had
MelbourneDeveloper Nov 20, 2026
4dd0da2
Live scheduler: one waiting trigger per busy consumer, bounded backlog
MelbourneDeveloper Nov 20, 2026
be3b82e
CPU sessions: an ended recording no longer blocks its PID; atomic PID…
MelbourneDeveloper Nov 20, 2026
ad77f7d
Consumer kit: ship dotnet/Directory.Build.props so its fixtures build…
MelbourneDeveloper Nov 20, 2026
9c39086
Dispatch: remove the unguarded CancellationHandle::register
MelbourneDeveloper Nov 20, 2026
07eca7b
lspkit::vfs text primitives and lspkit_server::hover_markdown (#2)
MelbourneDeveloper Nov 20, 2026
cd4e731
memory/start: a failed start stops and releases the session it opened
MelbourneDeveloper Nov 20, 2026
e807e0a
Retention graph: sharp on Retina, labels never overlap (#4)
MelbourneDeveloper Nov 20, 2026
b4f4ae1
CPU sessions measure duration from the sampler's start, not registration
MelbourneDeveloper Nov 20, 2026
997e043
lsp-profiler-dotnet tests: poll observed events instead of sleeping
MelbourneDeveloper Nov 20, 2026
9716976
Profiler spec: link lspkit's memory lifetime rules without a foreign …
MelbourneDeveloper Nov 20, 2026
5a01304
lsp-profiler-dotnet tests: keep session ids out of poll-timeout panic…
MelbourneDeveloper Nov 20, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,7 @@ jobs:
# here keeps a broken script from surfacing only at release time.
# [REL-CONSUMER-ASSETS]
- name: Release consumer assets (linux-x64)
run: |
set -eu
sh scripts/release-assets.sh ci "${RUNNER_TEMP}/assets" linux-x64
tar -tzf "${RUNNER_TEMP}/assets/lsp-profiler-dotnet-engine-ci-linux-x64.tar.gz" | grep -qx './lsp-profiler-dotnet-engine'
kit=$(tar -tzf "${RUNNER_TEMP}/assets/lspkit-consumer-kit-ci.tar.gz")
for want in dotnet/fixtures/HotLeakApp/Program.cs docs/specs/LSP-PROFILER-SPEC.md docs/specs/LSP-PULL-SPEC.md test-support/state.rs scripts/typediagram/run-cli.mjs; do
printf '%s\n' "$kit" | grep -qx "lspkit-consumer-kit-ci/$want"
done
if printf '%s\n' "$kit" | grep -q '/bin/\|/obj/'; then echo "kit ships build output"; exit 1; fi
run: sh scripts/consumer-kit-check.sh "${RUNNER_TEMP}/assets" linux-x64

- name: Upload build artifacts
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Reusable Rust components for building language servers, plus the shared CPU and

## Memory lifetimes 🛑

Language servers run for days, so a retained allocation is a production bug. These rules come from the leaks fixed under `[MEM-FIX-SCOPE]` ([plan](docs/plans/memory-leak-fixes.md)); review every change against them.
Language servers run for days, so a retained allocation is a production bug. These rules come from the leaks fixed under `[MEM-LIFETIME]` ([spec](docs/specs/lspkit-spec.md#mem-lifetime-memory-lifetimes)); review every change against them.

- **No ownership cycles.** A handler, callback or spawned task never captures an owner of the registry that stores it (`Server`, `Dispatcher`, correlator). Capture an `Arc` of only the data it needs; back-references are `Weak` and get upgraded per call.
- **Every registration has an RAII owner.** Pending-response entries, cancellation controls, watcher tasks and subscriptions are removed by a guard's `Drop`. That includes error, rejection, cancellation and abandoned-future paths. Never rely on a later sweep or count call.
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ lsp-types = "0.97"
# Document / state
dashmap = "6"
ropey = "1"
unicode-ident = "1.0.24"

# Filesystem
notify = "8"
Expand Down
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,12 @@ doc:
## that `cargo build` generates).
profiler-ui:
cargo build -p lsp-profiler --locked
cd packages/lsp-profiler-ui && npm ci && npm run build
npm ci --prefix packages/lsp-profiler-ui
npm run build --prefix packages/lsp-profiler-ui

## profiler-ui-test: Test the UI library against a mock language server.
profiler-ui-test: profiler-ui
cd packages/lsp-profiler-ui && npm test
npm test --prefix packages/lsp-profiler-ui

# [WEB-CONTENT] Share dependency setup; npm owns the build and dev commands.
_website_setup:
Expand Down
94 changes: 70 additions & 24 deletions crates/lsp-profiler-dotnet/tests/dotnet_e2e.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ mod graph_retention;
mod support;

use std::path::PathBuf;
use std::time::Duration;

use lsp_profiler::wire::methods;
use lsp_profiler::ProfilerService;
use serde_json::{json, Value};
use support::{assert_only_busy_threads_count, call, completed, engine, service, Fixture};
use support::{
assert_only_busy_threads_count, call, completed, cpu_samples_exceed, cpu_session_ended, engine,
memory_count_exceed, service, Fixture,
};

const FIXTURE: &str = "HotLeakApp";
const FIXTURE_TYPE: &str = "HotLeakApp.LeakedPayload";
Expand All @@ -37,6 +39,11 @@ const HOT_FUNCTION: &str = "HotLeakApp.Hot.Spin";
const ENTRY_POINT: &str = "HotLeakApp.Program.Main(";
/// `LeakCache.Items`: one small object, outside any top-twenty summary.
const LEAK_LIST: &str = "System.Collections.Generic.List`1[HotLeakApp.LeakedPayload]";
/// Payloads whose burst a 1 MB capture buffer cannot hold ([PROF-DOTNET-HEAP-CAPTURE]):
/// 256 MB lost events past about six million objects, about 45 event bytes per
/// object, and each payload is at least three objects (the record, its 1 KiB
/// `Data` and its `Label`), so 20 000 payloads is a burst of roughly 2.7 MB.
const HEAP_BURST_PAYLOADS: i64 = 20_000;

#[tokio::test(flavor = "multi_thread")]
async fn the_fixture_is_recognised_as_an_attachable_dotnet_process() {
Expand Down Expand Up @@ -78,7 +85,9 @@ async fn cpu_profiling_finds_the_hot_function_and_its_lines() {
.expect("session_id")
.to_owned();
assert_eq!(started["runtime"], "dotnet");
tokio::time::sleep(Duration::from_secs(3)).await;
// The hot function needs samples on record before the report can name it:
// watch the live session until the count the report asserts exists.
cpu_samples_exceed(&service, &session_id, 100).await;
let report = call(
&service,
methods::CPU_STOP,
Expand Down Expand Up @@ -175,7 +184,10 @@ async fn memory_profiling_sees_the_leak_its_root_and_the_collection() {
> 0
);

tokio::time::sleep(Duration::from_secs(2)).await;
// The diff needs the leak to have grown since `first`: the fixture never
// stops allocating, so watch its count through the service until it has.
let first_count = site["count"].as_i64().unwrap_or(0);
memory_count_exceed(&service, &session, FIXTURE_TYPE, first_count).await;
let diff = call(&service, methods::MEMORY_DIFF, session.clone()).await;
let grown = completed(&diff)["outcome"]["diff"]["grown"]
.as_array()
Expand Down Expand Up @@ -219,6 +231,11 @@ async fn memory_profiling_sees_the_leak_its_root_and_the_collection() {
service.shutdown().await;
}

/// The engine's refusal when the target has no diagnostics endpoint. Only the
/// pre-connect check reports it; a failed connection reports the runtime's own
/// error ([PROF-DOTNET-ENGINE-ENDPOINT]).
const NO_ENDPOINT: &str = "has no .NET diagnostics endpoint";

async fn error_code(service: &ProfilerService, method: &str, params: Value) -> i64 {
match service.handle(method, params).await {
Ok(value) => panic!("{method} must be refused, got {value}"),
Expand Down Expand Up @@ -250,9 +267,8 @@ async fn a_pid_that_names_no_process_is_process_not_found_everywhere() {
}

/// A live process no runtime recognises (this test binary) is `UNSUPPORTED_RUNTIME`
/// for every PID-taking command, answered well under the engine's connect timeout:
/// the engine decides "no .NET diagnostics endpoint" up front ([PROF-ERRORS],
/// [PROF-DOTNET-ENGINE-ENDPOINT]). Kill refuses it — kill can never reach a
/// for every PID-taking command ([PROF-ERRORS]); the engine-level test below proves
/// the refusal comes before any connection ([PROF-DOTNET-ENGINE-ENDPOINT]). Kill refuses it — kill can never reach a
/// process outside the profiler's reach.
#[tokio::test(flavor = "multi_thread")]
async fn a_live_process_no_runtime_recognises_is_unsupported_and_never_killed() {
Expand All @@ -267,37 +283,31 @@ async fn a_live_process_no_runtime_recognises_is_unsupported_and_never_killed()
error_code(&service, methods::MEMORY_START, own.clone()).await,
-32002
);
let started = tokio::time::Instant::now();
assert_eq!(error_code(&service, methods::CPU_START, own).await, -32002);
assert!(
started.elapsed() < Duration::from_secs(5),
"the engine answers without waiting for a connect timeout: {:?}",
started.elapsed()
);
service.shutdown().await;
}

/// The engine itself refuses a live process with no .NET diagnostics endpoint as
/// `UnsupportedRuntime` immediately, before any connection attempt
/// `UnsupportedRuntime` before any connection attempt
/// ([PROF-DOTNET-ENGINE-ENDPOINT]). Drives the engine binary directly so the
/// endpoint decision is proven at the engine boundary, not through the service.
#[tokio::test(flavor = "multi_thread")]
async fn the_engine_refuses_a_process_without_a_dotnet_endpoint_immediately() {
let started = std::time::Instant::now();
async fn the_engine_refuses_a_process_without_a_dotnet_endpoint_before_connecting() {
let output = std::process::Command::new(engine())
.args(["cpu", "--pid", &std::process::id().to_string()])
.output()
.expect("run the engine");
let elapsed = started.elapsed();
let stdout = String::from_utf8_lossy(&output.stdout);
let last: Value = serde_json::from_str(stdout.lines().last().unwrap_or_default())
.unwrap_or_else(|error| panic!("one protocol line expected ({error}): {stdout}"));
assert_eq!(output.status.code(), Some(1), "{stdout}");
assert_eq!(last["kind"], "failure", "{last}");
assert_eq!(last["error_kind"], "UnsupportedRuntime", "{last}");
assert!(
elapsed < Duration::from_secs(5),
"the engine answers without waiting for a connect timeout: {elapsed:?}"
last["message"]
.as_str()
.is_some_and(|m| m.contains(NO_ENDPOINT)),
"decided before any connection attempt: {last}"
);
}

Expand Down Expand Up @@ -361,10 +371,22 @@ async fn a_target_that_exits_mid_session_keeps_its_samples() {
let dir = tempfile::tempdir().expect("tempdir");
let service = service(dir.path().to_path_buf());
let started = call(&service, methods::CPU_START, json!({ "pid": fixture.pid })).await;
tokio::time::sleep(Duration::from_secs(2)).await;
// Samples must exist before the exit for the kept report to hold any.
cpu_samples_exceed(
&service,
started["session_id"].as_str().expect("session_id"),
0,
)
.await;
let _ = fixture.child.kill();
let _ = fixture.child.wait();
tokio::time::sleep(Duration::from_millis(500)).await;
// The session ends itself once the engine notices the exit; only a session
// that ended keeps its recording for the stop below ([PROF-CPU-SESSIONS]).
cpu_session_ended(
&service,
started["session_id"].as_str().expect("session_id"),
)
.await;
let report = call(
&service,
methods::CPU_STOP,
Expand Down Expand Up @@ -421,8 +443,12 @@ async fn a_duration_caps_the_recorded_time() {
json!({ "pid": fixture.pid, "duration_secs": 1.0 }),
)
.await;
tokio::time::sleep(Duration::from_secs(3)).await;
// [PROF-CPU-SESSIONS] the duration ended the session: it is no longer active.
cpu_session_ended(
&service,
started["session_id"].as_str().expect("session_id"),
)
.await;
let listed = call(&service, methods::CPU_LIST, json!({})).await;
assert!(
!listed["sessions"]
Expand Down Expand Up @@ -461,7 +487,13 @@ async fn a_mid_session_snapshot_reports_the_samples_so_far() {
let service = service(dir.path().to_path_buf());
let started = call(&service, methods::CPU_START, json!({ "pid": fixture.pid })).await;
let session = json!({ "session_id": started["session_id"] });
tokio::time::sleep(Duration::from_secs(2)).await;
// The snapshot the test asserts on needs samples on record first.
cpu_samples_exceed(
&service,
session["session_id"].as_str().expect("session_id"),
0,
)
.await;
let snapshot = call(&service, methods::CPU_SNAPSHOT, session.clone()).await;
let _ = call(&service, methods::CPU_STOP, session).await;
assert!(
Expand All @@ -478,7 +510,21 @@ async fn a_mid_session_snapshot_reports_the_samples_so_far() {
#[tokio::test(flavor = "multi_thread")]
async fn a_snapshot_that_loses_events_fails_instead_of_misreporting_the_heap() {
let fixture = Fixture::start(FIXTURE);
tokio::time::sleep(Duration::from_secs(2)).await;
// The burst must overflow the 1 MB buffer: the fixture never stops growing,
// so watch its heap through the service until it holds more payloads than
// such a buffer can capture, then ask the engine for exactly that capture.
let poll_dir = tempfile::tempdir().expect("tempdir");
let service = service(poll_dir.path().to_path_buf());
let started = call(
&service,
methods::MEMORY_START,
json!({ "pid": fixture.pid }),
)
.await;
let session = json!({ "memory_session_id": started["memory_session_id"] });
memory_count_exceed(&service, &session, FIXTURE_TYPE, HEAP_BURST_PAYLOADS).await;
let _ = call(&service, methods::MEMORY_STOP, session).await;
service.shutdown().await;
let dir = tempfile::tempdir().expect("tempdir");
let graph = dir.path().join("snapshot.heapgraph.json");
let output = std::process::Command::new(engine())
Expand Down
30 changes: 24 additions & 6 deletions crates/lsp-profiler-dotnet/tests/dotnet_fsharp_e2e/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
//! Process recognition, CPU profiling and CPU session steps on the F# fixture.

use std::time::Duration;

use lsp_profiler::wire::methods;
use serde_json::{json, Value};

Expand All @@ -10,7 +8,7 @@ use crate::harness::{
CLASSIFY_COUNT, ENTRY_POINT, FIXTURE, HOT_FUNCTION, MATCHING_FS, MATCH_FUNCTION, MATCH_LINES,
ORDER_TYPE,
};
use crate::support::{assert_only_busy_threads_count, call, service, Fixture};
use crate::support::{assert_only_busy_threads_count, call, cpu_samples_exceed, service, Fixture};

#[tokio::test(flavor = "multi_thread")]
async fn the_fsharp_fixture_is_recognised_as_an_attachable_dotnet_process() {
Expand Down Expand Up @@ -52,7 +50,14 @@ async fn cpu_profiling_finds_the_fsharp_hot_function_and_its_lines() {
let service = service(dir.path().to_path_buf());
let started = call(&service, methods::CPU_START, json!({ "pid": fixture.pid })).await;
assert_eq!(started["runtime"], "dotnet");
tokio::time::sleep(Duration::from_secs(3)).await;
// The hot function needs samples on record before the report can name it:
// watch the live session until the count the report asserts exists.
cpu_samples_exceed(
&service,
started["session_id"].as_str().expect("session_id"),
100,
)
.await;
let report = call(
&service,
methods::CPU_STOP,
Expand Down Expand Up @@ -203,7 +208,13 @@ async fn cpu_sessions_list_snapshot_and_refuse_a_second_attach() {
Some(1),
"the refusal stacks nothing"
);
tokio::time::sleep(Duration::from_secs(2)).await;
// The snapshot the test asserts on needs samples on record first.
cpu_samples_exceed(
&service,
started["session_id"].as_str().expect("session_id"),
0,
)
.await;
let snapshot = call(&service, methods::CPU_SNAPSHOT, session.clone()).await;
assert!(
snapshot["total_samples"].as_i64().unwrap_or(0) > 0,
Expand Down Expand Up @@ -321,7 +332,14 @@ async fn heap_snapshots_during_a_cpu_session_name_every_type() {
json!({ "pid": h.fixture.pid }),
)
.await;
tokio::time::sleep(Duration::from_secs(1)).await;
// The CPU session must demonstrably record before the memory session starts:
// samples on record prove its EventPipe session is live in the runtime.
cpu_samples_exceed(
&h.service,
cpu["session_id"].as_str().expect("session_id"),
0,
)
.await;
let session = start(&h).await;
for orders in [100, 200] {
let grown = h.fixture.send("grow 100");
Expand Down
Loading
Loading