Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
23 changes: 23 additions & 0 deletions .github/skills/error-translation/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ for, and errors that are already obsolete by the time they appear.
Anything with a side effect belongs at the call site, which alone knows whether the user is
watching, whether the operation was a read or a write, and which surface is right.

## Connection-lifecycle errors

The lifecycle uses four typed error families. Preserve their classes and original `cause`; C-2
types are contracts, not prose to infer from a message:

| Error | Meaning |
| --------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `EntraSignInRequiredError` | Silent acquisition returned no session or the configured authentication provider changed; `reason` is `noSession` or `providerChanged`. |
| `EntraIdentityMismatchError` | Interactive acquisition returned a different Microsoft account from the pinned one. |
| `TokenCallbackError` | Any other OIDC callback throw for Microsoft Entra ID or managed identity. Its bounded `authMethod` records which one, and `cause` retains the original failure. |
| `ConnectionUnavailableError { reason }` | A bound client cannot be used. The reason is `signInRequired`, `credentialsRejected`, `credentialsMissing`, `credentialsUpdating`, `credentialsChanged`, `identityChanged`, `userDisconnected`, `connectionRemoved`, or `unreachable`. |

Register `EntraSignInRequiredErrorExplainer` with provider id `entraSignInRequired` before the
general Entra explainer because the first explanation wins. That provider follows cyclic-safe
`cause` links and `MongoServerSelectionError.reason.servers[*].error`, and recognizes only the
typed sign-in-required and identity-mismatch errors. It explains those failures without exposing
private causes and asks the user to sign in with the original account when identities differ.

Do not translate `ConnectionUnavailableError` through an infrastructure provider. The call site
knows whether the right response is a tree recovery action, a disabled webview dialog, or bounded
shell or playground output. Preserve the `reason`; webviews map it to **Retry** or **Close view**.

## Adding a provider

Implement `ErrorExplanationProvider` and register it in
Expand Down Expand Up @@ -193,5 +215,6 @@ l10n.t('The container was removed outside VS Code.')

- [errorExplanationService.ts](../../../src/services/errorExplanationService.ts)
- [connectionReachabilityService.ts](../../../src/services/connectionReachabilityService.ts) prepares a connection _before_ connecting; this service explains a failure _afterwards_
- [EntraSignInRequiredErrorExplainer.ts](../../../src/documentdb/auth/entraErrors/EntraSignInRequiredErrorExplainer.ts)
- [tree-cluster-architecture](../tree-cluster-architecture/SKILL.md) for `clusterId` versus `treeId`
- [telemetry-instrumentation](../telemetry-instrumentation/SKILL.md)
30 changes: 29 additions & 1 deletion .github/skills/tree-cluster-architecture/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,21 @@ Rules:
- Never assume a stable ID is also a tree path unless the provider explicitly guarantees `clusterId === treeId`.
- Never change tree construction without checking reverse lookup from `clusterId`.

## Connection Binding Contract

A long-lived surface binds to `{ clusterId, fingerprint, generation }`, not to a `ClustersClient`
instance. Resolve the client for every operation through the binding with
`ClustersClient.resolveBoundClient()` or `runWithClient()`. Never retain a `ClustersClient` in view,
router, shell, playground, task, or clipboard state.

- A new generation with the same fingerprint is a transparent same-connection replacement.
- A different fingerprint is an identity or settings change. Never rebind an existing surface.
- Check latches and the binding again at operation and async-reply boundaries.
- An operation may hold the resolved client only for the duration of that operation. A stale reply
must not mutate the new connection or replay a failed write.
- Shell and playground workers may keep their own connection, but pin the originating identity and
obey the same fingerprint and epoch checks when they respawn.

## Design Rendering and Lookup Together

When adding a cluster hierarchy or a tree/list mode, specify these four functions before coding:
Expand Down Expand Up @@ -194,10 +209,19 @@ actions such as "Update credentials…" via `errorRecoveryActions`

Keep a fixed relative order: configuration/targeted repairs, diagnosis/inspection, shell,
destructive recovery, and **Retry always last** (including "Retry setup…").
Providers prepend repairs; Update connection string precedes Update credentials when both exist.
Providers prepend repairs; **Update connection string** precedes **Update credentials** when both
exist. Then `ClusterItemBase` renders **Retry sign-in** when a verified Entra identity can recover,
followed by **Diagnose connection…** and **Open shell**. **Retry** is last. When **Retry sign-in** or
the stored-credential rejection action replaces Retry, do not add an ordinary Retry row too.
Failure classification changes availability, never ordering. When healthy resources coexist with
recovery actions, render the healthy resources first and the recovery block last.

A connected cluster's `TreeItem.contextValue` includes the `connected` tag while a client exists
and no lifecycle latch blocks it. Preserve the base context value and use this tag to gate
Disconnect. A user-disconnected cluster renders its single **Reconnect** action instead of database
children; Remove and rejected credentials use their own states and must not be exposed as
user-disconnected.

Do not add a child whose purpose is to show a message (an error label, a "sign-in required" row,
a tooltip-only info node), even with an icon. Better wording belongs in the modal and in the
Diagnose connection panel, not in the tree.
Expand All @@ -210,10 +234,14 @@ Before approving a cluster tree change, answer yes to all:
- [ ] Base cluster context tag is preserved.
- [ ] `clusterId`, `treeId`, and `viewId` have documented owners.
- [ ] Credentials and clients use `clusterId` only.
- [ ] Long-lived surfaces retain bindings, not `ClustersClient` instances.
- [ ] Per-operation resolution checks the fingerprint and generation.
- [ ] Every rendered layout has a reverse lookup strategy.
- [ ] Cluster and collection lookup share one resolver.
- [ ] Synthetic ownership is exact and isolated from stored lookup.
- [ ] IDs are collision-safe beyond display names.
- [ ] A real render-to-lookup round-trip test covers every layout.
- [ ] Standard cluster commands work or are explicitly gated off.
- [ ] Failures show a modal; tree children are recovery actions only, never error or info rows.
- [ ] Recovery actions keep provider repairs first, diagnosis and shell next, and Retry last.
- [ ] The `connected` context tag gates Disconnect and disappears while a lifecycle latch applies.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Change Log

## 1.2.0 (Unreleased)

> Draft entries for an unpublished release. They may change before the release is finalized.

### New Features & Improvements

- **Resilient Connections**: Renews Microsoft Entra ID tokens silently, refreshes Azure discovery credentials, and replaces closed or transient failed clients with the same binding on a later foreground operation. [#990](https://github.com/microsoft/vscode-documentdb/issues/990), [#1102](https://github.com/microsoft/vscode-documentdb/issues/1102)
- **Explicit Connection Teardown**: Adds Disconnect and Reconnect, a shared disconnect and deletion flow, a Close all or Keep open (disabled) choice, and protection for active copy, export, or import work. [#566](https://github.com/microsoft/vscode-documentdb/issues/566), [#1059](https://github.com/microsoft/vscode-documentdb/issues/1059)
- **Identity-Bound Open Views**: Keeps open views and editor state tied to the connection that created them. Expired sign-in or unavailable connections receive bounded recovery, while changed saved settings require a new view instead of changing identity behind it. [#1102](https://github.com/microsoft/vscode-documentdb/issues/1102)

## 1.1.0

### New Features
Expand Down
36 changes: 35 additions & 1 deletion docs/ai-and-plans/features/connection-lifecycle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,20 @@ created: 2026-11-19
code:
- src/documentdb/ClustersClient.ts
- src/documentdb/ClusterSession.ts
- src/documentdb/runWithClient.ts
- src/documentdb/connectionTeardown.ts
- src/documentdb/auth/MicrosoftEntraIDAuthHandler.ts
- src/documentdb/auth/entraErrors/EntraSignInRequiredErrorExplainer.ts
- src/documentdb/shell/ShellSessionManager.ts
- src/documentdb/playground/PlaygroundEvaluator.ts
- src/tree/documentdb/ClusterItemBase.ts
- src/webviews/components/DisconnectedOverlay.tsx
---

# Connection lifecycle

**Status:** planned (iteration 1) · **Issues:**
**Status:** implemented in the feature branch; documentation draft ready; release and final
integration pending · **Issues:**

- [#1102](https://github.com/microsoft/vscode-documentdb/issues/1102)
- [#1059](https://github.com/microsoft/vscode-documentdb/issues/1059)
Expand Down Expand Up @@ -41,6 +48,28 @@ defects:

Evidence, telemetry and source pointers: [research-findings.md](./research-findings.md).

## Code map

| Area | Primary implementation |
| -------------------------------- | --------------------------------------------------------------------------------------------- |
| Client and binding lifecycle | `ClustersClient`, `ClusterSession`, `runWithClient` |
| Entra token renewal and errors | `MicrosoftEntraIDAuthHandler`, `entraSession`, `entraErrors/*`, `entraTokenFailures` |
| Shell and playground token relay | `ShellSessionManager`, `PlaygroundEvaluator`, `WorkerSessionManager`, `playgroundWorker` |
| Disconnect and removal | `connectionTeardown`, Disconnect command, connection and folder removal callers |
| Bound webviews and stale replies | `connectionSurfaces`, `DisconnectedOverlay`, bound-view routers and controllers |
| Tree recovery | `ClusterItemBase`, provider `errorRecoveryActions`, `showClusterConnectFailure` |
| Dashboard lifecycle polling | Cluster Dashboard controller, router and sampler |
| Measurement | established-connection lifecycle telemetry; the pending WI-9 operator volume/dashboard review |

## WI-10 documentation choice

The lifecycle manual stays in
[connecting-to-databases.md](../../../user-manual/connecting-to-databases.md) rather than adding a
separate page. The existing page already owns failed-connection recovery, so the continuation is
discoverable without another navigation level. The three requested workflow pages link to that
section. The operator chose no screenshots; no placeholders were added. Release notes and changelog
entries are unpublished drafts and do not represent a shipped release.

## Intent

- **Recover database connections silently** from token expiry and idle drops. For database
Expand Down Expand Up @@ -103,6 +132,7 @@ See [decisions.md](./decisions.md):
- 0017 limit unavailable webview recovery to Retry and Close view.
- 0018 saved connection edits permanently lock existing views.
- 0019 require a fresh Dashboard delete after Disconnect and retain tree-only Paste.
- 0020 defer the late-failure comparison across releases and retain descriptive telemetry.

## Timeline

Expand All @@ -111,3 +141,7 @@ See [decisions.md](./decisions.md):
| 2026-11-18 | Investigation: code read, telemetry attribution, vscode-cosmosdb comparison |
| 2026-11-19 | Operator decisions 0001–0005; implementation plan (iteration 1) |
| 2026-11-19 | Decision 0006: delivery model (feature branch, sub-PRs, one release) |
| 2026-11-23 | WI-1 through WI-5 implement renewal, Azure auth, bindings and recovery |
| 2026-11-24 | WI-6 through WI-8 implement bound views, teardown and Dashboard behavior |
| 2026-11-25 | WI-2 review fixes and WI-9 lifecycle measurements |
| 2026-11-26 | WI-10 documentation draft, skill updates and unpublished 1.2.0 notes |
19 changes: 17 additions & 2 deletions docs/ai-and-plans/features/connection-lifecycle/decisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ created: 2026-11-19
| 0004 | Disconnect lets the user choose: close all affected tabs, or keep them open and disabled | Accepted | Operator position; the default is still open (Q2) | 2026-11-19 | — |
| 0005 | Fix stale ARM credentials by upgrading azureauth to v6 (#990), not with a local shim | Accepted | Operator: open to updating dependencies | 2026-11-19 | — |
| 0006 | Deliver through `feature/connection-lifecycle` with stacked sub-PRs, ship once | Accepted (amended) | Operator removed the intermediate merge wait | 2026-11-19 | — |
| 0007 | The Disconnect choice is a VS Code modal with nothing remembered; a setting can set the default | Accepted | Operator: modal cannot pre-select; no remembering | 2026-11-19 | — |
| 0007 | The Disconnect choice is a VS Code modal with nothing remembered; a setting can set the default | Accepted (modified by 0018) | Operator: modal cannot pre-select; saved edits are close-only | 2026-11-19 | — |
| 0008 | Upgrade the azext stack as high as viable without breaking workflows, using Azure Resources as reference | Accepted | Operator: replaces the "minimal versions" proposal | 2026-11-19 | — |
| 0009 | Kubernetes tunnel recovery, cluster ID case handling and wider network-resilience testing move to #1105 | Accepted | Operator: keep 1.2.0 focused; schedule after release | 2026-11-19 | — |
| 0010 | Rely on the server to reject expired tokens; replacing a client for the same identity is transparent | Accepted | Operator: no rotation, no out-of-date notices | 2026-11-19 | — |
Expand All @@ -30,6 +30,8 @@ created: 2026-11-19
| 0016 | Keep disconnected webviews open under a full-view overlay | Accepted (modified by 0017) | Operator chose a simple disabled state with explicit actions | 2026-11-24 | Yes; replaces the inline banner and single-action layout |
| 0017 | Limit unavailable webview recovery to Retry and Close view | Accepted (modified by 0018) | Operator wants credential repair in the tree and no extra recovery workflow in a tab | 2026-11-24 | Yes; removes in-view credential repair |
| 0018 | Saved connection edits permanently lock existing views | Accepted | Operator prefers simple reconnect for unchanged settings over recovery after edits | 2026-11-24 | Yes; removes same-identity recovery after a saved edit |
| 0019 | Require a fresh Dashboard delete after Disconnect and keep Paste Collection in the tree | Accepted | Operator: a lifecycle change cancels the pending delete and never replays it | 2026-11-24 | — |
| 0020 | Defer the cross-release comparison of late failures | Accepted | Operator: keep descriptive telemetry and defer the comparison | 2026-11-26 | Yes; removes the WI-9 before/after comparison for 1.2.0 |

> Entries below are **semantically** immutable: append new entries rather than rewriting old ones,
> and record reversals as a new entry plus a status change above. Heading text is frozen once
Expand Down Expand Up @@ -199,7 +201,9 @@ operator input on the dev plan's provisional answer A2.
- The choice is **not remembered** between uses.
- A setting lets users pick a default: `ask` (the default) shows the modal; `closeAll` or
`keepOpenDisabled` skips it. The setting never skips the unsaved-edits confirmation.
- The choice applies to Disconnect, Remove Connection and credential updates that change identity.
- The choice applies to Disconnect and Remove Connection. Decision 0018 makes a saved identity or
settings edit close-only instead: existing views keep their contents but are not moved to the
new connection.

Rejected:

Expand Down Expand Up @@ -487,3 +491,14 @@ in the tree only. Copy stores a tree reference, not a snapshot of the data or
credentials. The later tree Paste uses the current connection; it does not resume
a Dashboard operation. Binding the whole clipboard and index-copy flow was not
part of this change.

## 0020. Defer the cross-release comparison of late failures

The operator chose to keep descriptive telemetry and defer the WI-9 before/after comparison
for 1.2.0. Auth and closed-client unavailability can now be returned as normal RPC responses,
which the SDK records as successes without a failure signature. An apparent drop across releases
could be a reporting change rather than improved recovery.

Keep renewal, client age and entry generation, and ARM challenge queries for a single version.
Do not add an instrumentation path or keep a socket-only comparison in this release. CP-5 still
checks pre-release ingestion and records that the late-failure trend is unmeasured.
Loading
Loading