Repository navigation
Emit DCP session termination when stopping resources - #19125
Adam Ratzman (adamint) merged 24 commits into
Conversation
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 19125Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 19125" |
There was a problem hiding this comment.
Pull request overview
Adds reliable DCP run-session termination when dashboard-controlled resources stop.
Changes:
- Tracks run lifecycle and ownership by execution ID.
- Deduplicates terminal notifications and late adapter events.
- Adds extensive lifecycle, ownership, telemetry, and adapter tests.
Show a summary per file
| File | Description |
|---|---|
extension/src/dcp/AspireDcpServer.ts |
Implements lifecycle, ownership, teardown, and notification handling. |
extension/src/dcp/types.ts |
Makes termination exit codes optional. |
extension/src/debugger/adapterTracker.ts |
Routes callbacks through run-scoped handlers. |
extension/src/test/aspireDcpServer.test.ts |
Tests DCP lifecycle and ownership scenarios. |
extension/src/test/adapterTracker.test.ts |
Tests run-scoped adapter notifications. |
Review details
- Files reviewed: 5/5 changed files
- Comments generated: 1
- Review effort level: Balanced
`SessionTerminatedNotification.exit_code` is now optional, so the run telemetry summary can no longer assume a number is present. Treat an absent exit code as its own `unknown` bucket instead of letting it fall into `nonzero`, and omit the `exit_code` measurement entirely rather than emitting a fabricated value. This mirrors the bucket logic in microsoft#19125 verbatim so the two branches compose without conflict. Co-authored-by: Copilot <[email protected]> Copilot-Session: 0caf8437-4c5f-47a5-82da-9ecefb06e2fc
There was a problem hiding this comment.
Review details
Suppressed comments (1)
extension/src/dcp/AspireDcpServer.ts:819
- If the adapter reports
sessionTerminatedwithout an exit code after a DELETE, this cancels the fallback timer and records the run asunknown, even thoughrun.lifecycleproves it was a requested stop. The telemetry bucket therefore depends on whether the adapter's no-code callback arrives before the timeout. Preserve the omitted wire field, but record-1for this requested-stop completion so it is consistently classified as canceled.
this._recordRunSessionCompletion(run, sessionTerminated.exit_code);
- Files reviewed: 5/5 changed files
- Comments generated: 0 new
- Review effort level: Balanced
There was a problem hiding this comment.
Review details
Suppressed comments (1)
extension/src/dcp/RunSessionRegistry.ts:202
undefineddoes not uniquely mean a requested stop:adapterTracker.onExit(undefined)now intentionally emits a naturalsessionTerminatedwithoutexit_code. This branch therefore marks that natural adapter exit asstopRequested, waits for retention, and records it as canceled (-1) instead of completing it with an unknown exit code. Distinguish the stop source (for example, by checking the lifecycle set byrequestStop) and add an integration test for an adapter termination with no exit code.
if (exitCode === undefined && record.terminationTrigger.kind === 'adapterExit') {
// A requested stop on an adapter-backed run. The notification stream is terminal
// immediately, but telemetry is deferred: the adapter's later exit reports the
// process's real exit code, and the retention deadline records a cancellation if
// no exit ever arrives.
record.lifecycle = 'stopRequested';
this._scheduleRetention(record);
return;
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Balanced
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
|
Retrying the failed CI jobs for this pull request from the CI run attempt. The rerun is being tracked in the rerun attempt. |
There was a problem hiding this comment.
Review details
Suppressed comments (3)
extension/src/dcp/RunSessionRegistry.ts:215
- A natural adapter exit now records completion and evicts the run after five seconds without ever invoking
stopSession(). That method is also the per-run cleanup path (AspireDebugSession.ts:596-608); for example, Azure Functions registerskillFuncProcessthere explicitly for every session end (languages/azureFunctions.ts:107-109). The DELETE handler also skips teardown forcompletedrecords, and after eviction it returns 204, so an absent or delayed follow-up DELETE leaves auxiliary processes and cleanup registrations alive until the whole Aspire debug session is disposed. Trigger the memoized teardown/cleanup when an adapter-backed run completes, while retaining only the protocol record for idempotent DELETEs.
if (record.terminationTrigger.kind === 'adapterExit') {
// DCP usually follows a natural exit with its own DELETE. Retention keeps the
// record addressable so that DELETE is still answered 200 rather than 204 for
// the most common shutdown ordering.
this._scheduleRetention(record);
extension/src/test/aspireDcpServer.test.ts:587
- Repository comments should describe the current behavior without depending on within-PR review history. This discussion URL becomes stale context after merge and is not needed to understand the scenario; state the reconnect sequence directly instead.
// Sequence from https://github.com/microsoft/aspire/pull/19125#discussion_r3735627366:
// the first instance stops the run while its socket is unavailable, then a replacement
// instance retries the DELETE and is answered 200 without a second notification.
extension/src/dcp/RunSessionRegistry.ts:22
- This comment describes the implementation change rather than the current contract. Repository comments should remain valid without branch history; explain only that callers declare the termination model at registration.
* This replaces per-call-site booleans: a caller declares the run's termination model once
* at registration instead of each termination path re-deciding whether to send and dedupe.
- Files reviewed: 7/7 changed files
- Comments generated: 1
- Review effort level: Balanced
Co-authored-by: Copilot <[email protected]> Copilot-Session: ffeff87e-f284-434d-87d3-843e21a7aebb
Copilot-Session: ffeff87e-f284-434d-87d3-843e21a7aebb Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]> Copilot-Session: ffeff87e-f284-434d-87d3-843e21a7aebb
Co-authored-by: Copilot <[email protected]> Copilot-Session: ffeff87e-f284-434d-87d3-843e21a7aebb
Keep resource notifications run-scoped through bounded retention, preserve compatible DELETE routing and status semantics, replace stale sockets, and finalize telemetry during cleanup and disposal. Co-authored-by: Copilot <[email protected]> Copilot-Session: ffeff87e-f284-434d-87d3-843e21a7aebb
Omit the wire exit code when startup fails before a process exit is available, while retaining -1 only for canceled telemetry. Co-authored-by: Copilot <[email protected]> Copilot-Session: ffeff87e-f284-434d-87d3-843e21a7aebb
Co-authored-by: Copilot <[email protected]> Copilot-Session: ffeff87e-f284-434d-87d3-843e21a7aebb
Co-authored-by: Copilot <[email protected]> Copilot-Session: ffeff87e-f284-434d-87d3-843e21a7aebb
A `sessionTerminated` queued for the exact owner while its WebSocket was already gone stayed under that owner's DCP instance ID. The pending queue is only drained by a WebSocket upgrade for that exact ID, and a replaced DCP execution never reconnects under it, so the notification was dropped for good. When an open same-prefix replacement then retried DELETE, ownership moved but the queue did not: the run was already `stopRequested` with `terminalNotificationSent` set, so the replacement got a bare 200 and never learned the session had ended — the original symptom of issue microsoft#15426. Hand the run's queued notifications to the new owner during ownership transfer, before the terminal-state early return. Only this run's notifications move; other runs still owned by the previous instance keep their place in the queue and transfer with their own DELETE. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]> Copilot-Session: c235246b-d021-4d8e-b041-cc4984674ebe
There was a problem hiding this comment.
Review details
Suppressed comments (3)
extension/src/dcp/AspireDcpServer.ts:592
- A DELETE can set this record to
stopRequestedwhileprepareDebugSession(or another awaited startup step) is pending. If that operation then rejects before retention expires, the record still exists, so this guard misclassifies the acknowledged cancellation aslaunch_failedand returns 500; after retention expires the same race returns 409. Check that the lifecycle is stillstarting, not merely that the record exists.
if (!runSessions.get(runId)) {
extension/src/dcp/AspireDcpServer.ts:551
- If DELETE arrives while
startAndGetDebugSessionis pending and startup then resolvesundefined, this path reportsdebugger_did_not_start/500 instead of the cancellation 409 used for a late successful start. If the retention timer has already evicted the run, it also emits a second run-session end event after the canceled completion. Recheck the lifecycle before emitting failure telemetry.
runTelemetryById.delete(runId);
emitRunSessionFailureEnd('debugger_did_not_start');
runSessions.terminate(runId, -1);
extension/src/dcp/AspireDcpServer.ts:680
- This early return skips debugger teardown when the run already became terminal through a natural adapter exit.
stopSessionis also the path that invokescleanupRun, so resource-specific cleanup handlers remain registered (and processes such as Azure Functions can remain reachable) until the parent session is disposed. Schedule the memoized teardown for every known owned adapter run;teardownStartedalready prevents duplicate stops.
if (!runSessions.requestStop(runId)) {
res.status(200).end();
return;
- Files reviewed: 7/7 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Co-authored-by: Copilot <[email protected]> Copilot-Session: 3253974d-4f18-486f-863c-281a607656d4
There was a problem hiding this comment.
Review details
Suppressed comments (2)
extension/src/test/aspireDcpServer.test.ts:640
- This reconnect test connects the replacement socket before issuing DELETE, so it never exercises the pending-notification queue. A regression that keyed
pendingNotificationQueueByDcpIdby the old full instance ID would still pass even though a terminal queued while disconnected would be stranded. Add a case that closes the original socket, issues DELETE with no socket connected, then connects a same-prefix replacement and verifies the queued terminal is delivered exactly once.
test('DELETE accepts a reconnected DCP instance with the same stable prefix', async () => {
const originalClient = await openNotificationClient(harness);
const stopSession = sinon.stub().resolves();
const runId = await createRun(harness, 'node', stopSession);
const reconnectedDcpId = 'aspire-extension-run-test-reconnected';
const reconnectedClient = await openNotificationClient(harness, reconnectedDcpId);
extension/src/dcp/AspireDcpServer.ts:170
- Pending-start cancellations now complete through this callback, but they never pass through either aggregate increment at the successful-start path or
emitRunSessionFailureEnd. Consequentlydebug/apphost/endomits these accepted runs fromtotal_child_sessionsanddistinct_resource_typeseven though a paireddebug/runsession/start/endis emitted. Record the aggregate membership once when the run is accepted (and remove the later duplicate increments), or track whether it has already been recorded.
const recordRunSessionCompletion = (runId: string, exitCode: number): void => {
const entry = runTelemetryById.get(runId);
if (!entry) {
return;
}
- Files reviewed: 7/7 changed files
- Comments generated: 0 new
- Review effort level: Balanced
Record aggregate membership when a run session is accepted and cover queued terminal delivery after a disconnected DELETE. Co-authored-by: Copilot <[email protected]> Copilot-Session: 3253974d-4f18-486f-863c-281a607656d4
Ella Hathaway (ellahathaway)
left a comment
There was a problem hiding this comment.
I reviewed the DCP run-session lifecycle end to end, including startup and DELETE races, terminal-notification ordering, debugger teardown and retry behavior, reconnect routing, retention and telemetry, disposal, and the new unit coverage.
I found one wire-contract regression in the handling of unavailable exit codes.
Co-authored-by: Copilot <[email protected]> Copilot-Session: 3e0243ed-7347-4ac1-848c-db9440abb139
|
The CI build failed due to test failure(s) that appear unrelated to the PR changes. These may be flaky tests. Suspected flaky test(s):
Suggested actions:
You can re-run the failed jobs from the workflow run page. |
Description
Keeps DCP run-session lifecycle consistent when a VS Code-controlled resource is stopped from the Aspire dashboard.
debugger_did_not_start.Fixes #15426
Security considerations
The existing authenticated DCP channel remains the trust boundary. Run control is limited to the stable owning DCP session prefix; this change adds no listener, credential flow, or network surface.
Validation
AspireDcpServertestsChecklist