Skip to content

[Perf] Release discarded draft session state - #348922

Merged
roblourens merged 3 commits into
mainfrom
roblourens-discarded-draft-cleanup
Nov 17, 2026
Merged

roblourens merged 3 commits into
mainfrom
roblourens-discarded-draft-cleanup

Conversation

@roblourens

@roblourens roblourens commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Fixes #347907.

Release state retained after new-session drafts are discarded or replaced:

  • Remove canvas owners through the existing cleanup path, closing inputs before presentation changes can reopen them.
  • Weakly cache approval observables so unused entries can be collected while active consumers retain observable identity.
  • Release connection-qualified advertised host mappings after session-removal notification delivery, preserving removal deltas, identities registered again before cleanup, and owner-held aliases until their owners release them.

Preserves accepted/reused session identity and leaves the existing PR-review-state repair unchanged.

Focused regression cases exercise repeated draft creation/removal, forced-GC approval collection, canvas close/dismissal behavior, opaque backend identities, alias survival through unpublication/republication, and multiple session-list consumers. Claude Opus 5.5 reviewed the change in two initial rounds and a focused follow-up; the notification-ordering and alias-lifetime findings are fixed, with no remaining findings. A shared canvas working-set test mock now supplies the draft-discard event used by the real service.

Completed local checks:

pnpm run build-fast --client-only
  Passed.

./scripts/test.sh --isolate \
  --run src/vs/platform/agentHost/test/browser/agentHostConnectionsService.test.ts \
  --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentSessionApprovalModel.test.ts \
  --run src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasService.test.ts \
  --run src/vs/workbench/contrib/canvases/test/electron-browser/canvasService.test.ts \
  --run src/vs/sessions/services/sessions/test/browser/sessionsManagementService.test.ts \
  --run src/vs/sessions/contrib/codeReview/test/browser/codeReviewService.test.ts \
  --run src/vs/sessions/contrib/providers/agentHost/test/browser/localAgentHostSessionsProvider.test.ts \
  --run src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostSessionsProvider.test.ts \
  --run src/vs/workbench/contrib/sessions/providers/remoteAgentHost/test/browser/cloudSandboxAgentHostContribution.test.ts \
  --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts \
  --run src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/editorCloudSandboxContribution.test.ts \
  --js-flags=--expose-gc --reporter dot
  Passed after merging current main: 3,119 tests; 13 pending. All 11 suites passed independently.

./scripts/test.sh --isolate \
  --run src/vs/platform/agentHost/test/browser/agentHostConnectionsService.test.ts \
  --run src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostSessionsProvider.test.ts \
  --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts \
  --run src/vs/workbench/contrib/chat/test/browser/remoteAgentHost/editorCloudSandboxContribution.test.ts \
  --js-flags=--expose-gc --reporter dot
  Passed after the alias-lifetime correction: 1,659 tests across four isolated suites.

./scripts/test.sh --run src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasWorkingSet.test.ts --reporter dot
  Passed after the shared test-mock correction: 20 tests.

pnpm run typecheck-client
  Passed, including the alias-lifetime correction.

pnpm run oxlint \
  src/vs/platform/agentHost/browser/agentHostConnectionsService.ts \
  src/vs/platform/agentHost/test/browser/agentHostConnectionsService.test.ts \
  src/vs/sessions/contrib/canvases/electron-browser/sessionCanvasService.ts \
  src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasService.test.ts \
  src/vs/workbench/contrib/canvases/electron-browser/canvasService.ts \
  src/vs/workbench/contrib/chat/browser/agentSessions/agentSessionApprovalModel.ts \
  src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostChatContribution.test.ts \
  src/vs/workbench/contrib/chat/test/browser/agentSessions/agentSessionApprovalModel.test.ts
  Passed.

pnpm run oxlint \
  src/vs/platform/agentHost/browser/agentHostConnectionsService.ts \
  src/vs/platform/agentHost/common/agentHostConnectionsService.ts \
  src/vs/platform/agentHost/test/browser/agentHostConnectionsService.test.ts
  Passed after the alias-lifetime correction.

pnpm run oxlint src/vs/sessions/contrib/layout/test/browser/layoutControllerTestUtils.ts
  Passed after the shared test-mock correction.

git diff origin/main --check
  Passed.

The reported Linux/mock-CAPI composer-return scenario and whole-application forced-GC heap slope were not rerun; these checks establish the individual retention mechanisms rather than a measured application-wide heap improvement.

(Written by Copilot)

Clean up canvas ownership, weakly retain approval observables, and release host identities after removal notification delivery while preserving accepted sessions.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings November 17, 2026 20:02
Preserve the upstream resource-URI mapper test harness alongside draft-removal notification coverage.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Removal cleanup discards aliases that are not restored on backend re-publication, leaving existing cloud-task URIs without backend routing.

1 open issue
What changed in this PR

Addresses #347907 by releasing state retained by discarded or replaced new-session drafts in the Agents window, while preserving accepted and reused session identities.

Changes:

  • Connects draft lifecycle events to canvas-owner cleanup and closes inputs before presentation changes.
  • Weakly caches approval observables so unused entries can be collected.
  • Defers host identity cleanup until removal notifications are delivered, with regression tests for retention and lifecycle behavior.
File Description
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentSessionApprovalModel.test.ts Tests observable identity preservation and garbage collection.
src/​vs/​workbench/​contrib/​chat/​test/​browser/​agentSessions/​agentHostChatContribution.test.ts Tests removal delivery across multiple list controllers.
src/​vs/​workbench/​contrib/​chat/​browser/​agentSessions/​agentSessionApprovalModel.ts Replaces strong approval caching with weak references.
src/​vs/​workbench/​contrib/​canvases/​electron-browser/​canvasService.ts Starts input closure before removing presentations.
src/​vs/​sessions/​contrib/​canvases/​test/​electron-browser/​sessionCanvasService.test.ts Tests draft cleanup, dismissal reset, and reused identities.
src/​vs/​sessions/​contrib/​canvases/​electron-browser/​sessionCanvasService.ts Removes canvas owners when drafts are discarded or replaced.
src/​vs/​platform/​agentHost/​test/​browser/​agentHostConnectionsService.test.ts Tests connection-scoped cleanup and re-registration.
src/​vs/​platform/​agentHost/​browser/​agentHostConnectionsService.ts Adds deferred cleanup of removed backend mappings and aliases.

Review effort: Balanced

@vs-code-engineering

This comment has been minimized.

…tten by Copilot)

Keep catalog aliases bound until their owner releases them, avoid restoring removed canonical mappings, and provide the draft-discard event in the canvas working-set test harness.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@vs-code-engineering

vs-code-engineering Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

No demo for 6b8b1d9. Releases retained draft-session state and caches without changing the visible interface. Workflow run

@roblourens
roblourens marked this pull request as ready for review November 17, 2026 20:35
@roblourens
roblourens enabled auto-merge November 17, 2026 20:35
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

Ulugbek Abdullaev (@ulugbekna)

Matched files:

  • src/vs/sessions/contrib/canvases/electron-browser/sessionCanvasService.ts
  • src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasService.test.ts
  • src/vs/workbench/contrib/canvases/electron-browser/canvasService.ts

Joaquín Ruales (@jruales)

Matched files:

  • src/vs/sessions/contrib/canvases/electron-browser/sessionCanvasService.ts
  • src/vs/sessions/contrib/canvases/test/electron-browser/sessionCanvasService.test.ts
  • src/vs/workbench/contrib/canvases/electron-browser/canvasService.ts

@roblourens
roblourens added this pull request to the merge queue Nov 17, 2026
Merged via the queue into main with commit 4fa0c32 Nov 17, 2026
37 of 38 checks passed
@roblourens
roblourens deleted the roblourens-discarded-draft-cleanup branch November 17, 2026 20:52
@vs-code-engineering vs-code-engineering Bot added this to the 1.148.0 milestone Nov 17, 2026
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.

Agents window: discarded new-session drafts leave per-session state behind (PR review, canvas owners, approvals, agent host maps)

4 participants