Skip to content

Add a Disconnect action for clusters that ends live sessions and clears per-cluster state #1059

Open

Description

Problem

There is no way to end a live connection to a cluster without closing every shell, playground
document and view, or reloading the VS Code window.

This matters more after #1050. Under decision D12 (sovereign-clouds feature), Update Credentials
no longer touches open sessions
. An open shell keeps the credentials and token audience it started
with until it is closed, and a modal tells the user that new credentials apply to new connections.
Users need an explicit way to force fresh sessions. That way is Disconnect.

Proposal

Add a Disconnect action for a connected cluster in the Connections, Azure Resources and Discovery
views. After Disconnect, the cluster behaves as if this window had never connected to it. The next
expand, shell, playground run or view opens a new connection using the current saved or
discovered credentials and the current settings, including the sovereign-cloud environment and
documentDB.customEnvironment.

Once Disconnect exists, the Update Credentials modal (D12) should offer it as a button.

Relationship to #566: #566 covers stale surfaces after Remove Connection. Both commands should share
one teardown implementation: Remove = Disconnect, then delete the saved connection and clear the
cluster's schema data. Do not build two teardown paths.

Teardown checklist

Everything is keyed by the stable clusterId, never treeId. Cluster IDs can differ only in case,
so match them case-insensitively, the same way CredentialCache does.

Connections and sessions

  • Main-thread client: ClustersClient.deleteClient(clusterId). This closes the MongoClient
    and drops its cached collection lists.
  • Interactive shells: every shell terminal for the cluster (getRegisteredShellTerminals()).
    Stop the worker, print a clear "Disconnected" line instead of an error, and drop the session's
    pinned token audience (D12).
  • Query playground: shutdownEvaluator(clusterId). Move the playground documents bound to the
    cluster to the disconnected state in PlaygroundService, so the next run does not fail with
    "No credentials found".
  • Webviews: Collection View, Document View and the Cluster Dashboard show a disconnected state
    or reconnect on their next action. They must not keep using a stale client.
  • Running tasks (copy and paste, import and export, schema scans): cancel them or ask first.
    Never replay an operation automatically after reconnecting.
  • In-flight token requests: a token request that completes after Disconnect must not post to
    a replacement worker or write the Entra failure registry. See finding E4 in
    docs/ai-and-plans/features/sovereign-clouds/iterations/02-copilot-feedback-and-edge-case-review.md.

Per-cluster caches

  • CredentialCache: drop the entry, so the next connection re-reads saved credentials. For
    Azure and Discovery nodes, credentials are re-fetched from the provider.
  • Entra failure registry: clearEntraTokenFailure(clusterId).
  • SchemaStore: decide. The proposal is to keep schema data on Disconnect, because it is
    knowledge about the data, not connection state, and to clear it on Remove, as removeConnection
    does today.

Process-wide state: must NOT be touched

  • VS Code authentication sessions. They are shared with other extensions. Disconnect must never
    sign the user out of their Microsoft account or remove a session.
  • Managed identity token cache and the ARM metadata cache. These are per process, not per
    cluster.

Tree and UI

  • Return the node to its not-connected state (collapse it and clear any error state). Show the
    Disconnect action only for connected clusters. A context key that stands alone in package.json
    must not have the name.ext shape; use dashes (see the copilot instructions).
  • Failures show actions in the tree, not error rows (tree-cluster-architecture skill).
  • Localize all strings with vscode.l10n.t() and announce the state change for screen readers.

Open design questions

  1. Tree failure eviction. Today, about 10 tree items call CredentialCache.deleteCredentials when a
    connection fails. Should they keep the credentials, separating "drop the client" from "forget the
    credentials"? Deferred here from the Support Entra ID sign-in in sovereign clouds and explain sign-in failures #1050 review (finding C3, option 3).
  2. Playground init. PlaygroundEvaluator.buildInitMessage reads CredentialCache on every run,
    even when it reuses a live worker. This predates Support Entra ID sign-in in sovereign clouds and explain sign-in failures #1050. Fix it as part of this work.
  3. Notification vs explicit calls. Use an event from a connection manager (as Unified disconnect/remove connection experience across all views #566 suggests) or
    explicit calls from one teardown service.
  4. Scope. Disconnect affects the current window only.

Telemetry

Record one event with the activation source (inline tree action, context menu or the Update Credentials
modal) and how many shells, playground workers, views and tasks were torn down. Include no cluster
identifiers, host names or connection strings. See the telemetry-instrumentation skill.

Tests

  • Teardown of each surface listed above, including clusters whose IDs differ only in case.
  • Disconnect while a token request is pending: the late result is ignored (E4).
  • Reconnecting after Disconnect uses the current saved credentials and the current cloud settings,
    with no pinned audience carried over.
  • Disconnect never calls VS Code's authentication APIs in a way that signs the user out.
  • Remove Connection reuses the same teardown (Unified disconnect/remove connection experience across all views #566).

Docs

User manual: a Disconnect section, plus the Update Credentials note about open sessions. Release notes.

Context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions