Skip to content

Fix SQL notebook IntelliSense loss on save and reconnect (#22124) - #22525

Merged
kburtram merged 2 commits into
mainfrom
dev/karlb/notebook
Jul 27, 2026
Merged

Fix SQL notebook IntelliSense loss on save and reconnect (#22124)#22525
kburtram merged 2 commits into
mainfrom
dev/karlb/notebook

Conversation

@kburtram

Copy link
Copy Markdown
Member

Cell IntelliSense registrations now wait for the real connection/complete result instead of trusting the connect request acknowledgement, so failed cell binds are retried instead of silently memoized (saved notebooks previously ended up with keyword-only completions). Cell connects also use the live execution-connection credentials so they carry refreshed auth tokens and the actual database.

Saving an untitled notebook replaces its NotebookDocument, which previously disposed the notebook's connection mid-save. The connection manager is now parked when a connected untitled notebook closes and adopted by the file-based notebook that replaces it (matched by cell content within the save-transition window, guarded by tab presence and open recency), covering close-then-open, open-then-close, and lingering-document event orderings. Adoption re-registers the new cell URIs with STS and refreshes UI state.

Additional fixes from review: per-cell STS connections are released on notebook disconnect/close instead of leaking one server session per cell; stale cell connects that complete after a connection change are disconnected; completion expectations are identity-guarded against cross-cancellation between overlapping registrations; re-parking a reused untitled URI no longer leaks the superseded manager.

Description

Provide a clear, concise summary of the changes in this PR. What problem does it solve? Why is it needed? Link any related issues using issue closing keywords.

Code Changes Checklist

  • New or updated unit tests added
  • All existing tests pass (npm run test)
  • Code follows contributing guidelines
  • Telemetry/logging updated if relevant
  • No regressions or UX breakage

Reviewers: Please read our reviewer guidelines

Cell IntelliSense registrations now wait for the real connection/complete
result instead of trusting the connect request acknowledgement, so failed
cell binds are retried instead of silently memoized (saved notebooks
previously ended up with keyword-only completions). Cell connects also use
the live execution-connection credentials so they carry refreshed auth
tokens and the actual database.

Saving an untitled notebook replaces its NotebookDocument, which previously
disposed the notebook's connection mid-save. The connection manager is now
parked when a connected untitled notebook closes and adopted by the
file-based notebook that replaces it (matched by cell content within the
save-transition window, guarded by tab presence and open recency), covering
close-then-open, open-then-close, and lingering-document event orderings.
Adoption re-registers the new cell URIs with STS and refreshes UI state.

Additional fixes from review: per-cell STS connections are released on
notebook disconnect/close instead of leaking one server session per cell;
stale cell connects that complete after a connection change are
disconnected; completion expectations are identity-guarded against
cross-cancellation between overlapping registrations; re-parking a reused
untitled URI no longer leaks the superseded manager.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@kburtram

Copy link
Copy Markdown
Member Author

This is a proposed fix for #22124

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.

Pull request overview

This PR hardens SQL notebook IntelliSense connection handling around save/reconnect flows by (1) waiting for real connection/complete outcomes for per-cell registrations, and (2) transferring/adopting notebook connection managers when untitled notebooks are saved and VS Code replaces the NotebookDocument.

Changes:

  • Add untitled→file save adoption/transfer logic in SqlNotebookController, including re-registering cell URIs and handling close/open event ordering.
  • Update NotebookConnectionManager cell IntelliSense registration to await connection/complete, release/disconnect per-cell STS connections, and handle stale completions across connection changes.
  • Add/extend unit tests covering save URI transfer, adoption flows, late cell document registration, and per-cell registration retry/release scenarios.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
extensions/mssql/test/unit/notebooks/sqlNotebookController.test.ts Adds unit tests for save URI transfer/adoption and late cell document registration.
extensions/mssql/test/unit/notebooks/notebookConnectionManager.test.ts Adds unit tests for connection/complete-based registration, retry on failure/timeout, and releaseCellRegistrations.
extensions/mssql/src/notebooks/sqlNotebookController.ts Implements manager parking/adoption across untitled save replacement; re-registers cell URIs; registers opened cell docs for IntelliSense.
extensions/mssql/src/notebooks/notebookConnectionManager.ts Awaits connection/complete, prefers live execution-connection credentials for cell binds, and disconnects released cell URIs from STS.
extensions/mssql/src/controllers/connectionManager.ts Exposes expectConnectionComplete + cancellation to observe real connect outcomes for direct connection/connect callers.

Comment thread extensions/mssql/src/notebooks/sqlNotebookController.ts Outdated
Comment thread extensions/mssql/src/notebooks/sqlNotebookController.ts
Comment thread extensions/mssql/src/notebooks/notebookConnectionManager.ts
- Locate a cell's owning notebook via path-prefiltered lookup (verified
  membership, full-scan fallback) instead of scanning every cell of every
  notebook per cell-open event.
- Build the notebook content signature incrementally so large notebooks
  no longer materialize their full concatenated cell text for a capped
  signature.
- Best-effort disconnect a cell URI whose connect times out, so a
  late-completing STS connection doesn't linger untracked after the cell
  was deregistered.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 22, 2026 21:14

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.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Comment thread extensions/mssql/test/unit/notebooks/sqlNotebookController.test.ts
Comment thread extensions/mssql/test/unit/notebooks/sqlNotebookController.test.ts
Comment thread extensions/mssql/test/unit/notebooks/sqlNotebookController.test.ts
Comment thread extensions/mssql/test/unit/notebooks/sqlNotebookController.test.ts
Comment thread extensions/mssql/test/unit/notebooks/sqlNotebookController.test.ts
@github-actions

Copy link
Copy Markdown

PR Changes

Category Target Branch PR Branch Difference
vscode-mssql VSIX 79289 KB 79290 KB ⚪ 1 KB ( 0% )
sql-database-projects VSIX 2945 KB 2945 KB ⚪ 0 KB ( 0% )
data-workspace VSIX 188 KB 188 KB ⚪ 0 KB ( 0% )
keymap VSIX 7 KB 7 KB ⚪ 0 KB ( 0% )

@codecov-commenter

codecov-commenter commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.58590% with 41 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.89%. Comparing base (9e4c7c5) to head (61e635c).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...sions/mssql/src/notebooks/sqlNotebookController.ts 93.80% 23 Missing ⚠️
...ensions/mssql/src/controllers/connectionManager.ts 53.84% 18 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (9e4c7c5) and HEAD (61e635c). Click for more details.

HEAD has 6 uploads less than BASE
Flag BASE (9e4c7c5) HEAD (61e635c)
mssql 3 1
sqlproj 3 1
data-workspace 3 1
Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main   #22525       +/-   ##
===========================================
- Coverage   88.24%   75.89%   -12.35%     
===========================================
  Files         415      407        -8     
  Lines      131028   131070       +42     
  Branches     8394     8447       +53     
===========================================
- Hits       115622    99476    -16146     
- Misses      15406    31594    +16188     
Flag Coverage Δ
data-workspace 78.37% <ø> (ø)
mssql 75.56% <92.58%> (-13.74%) ⬇️
sqlproj 78.87% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...s/mssql/src/notebooks/notebookConnectionManager.ts 97.71% <100.00%> (-2.29%) ⬇️
...ensions/mssql/src/controllers/connectionManager.ts 63.63% <53.84%> (-8.33%) ⬇️
...sions/mssql/src/notebooks/sqlNotebookController.ts 77.95% <93.80%> (-14.15%) ⬇️

... and 201 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kburtram

Copy link
Copy Markdown
Member Author

This fixes the issue where saved notebooks don't get intellisense; but it doesn't resolve the issue where saving an untitled notebook loses the active connection. I'll fix that as a separate PR so that I can take this one, which fixes the core bug reported in the issue. The "auto-reconnect" issue can be worked-around by manually reconnecting after "save as".

@kburtram
kburtram merged commit 562458c into main Jul 27, 2026
9 of 11 checks passed
@kburtram
kburtram deleted the dev/karlb/notebook branch July 27, 2026 16:56
kburtram added a commit that referenced this pull request Jul 27, 2026
…2525) (#22553)

* Fix SQL notebook IntelliSense loss on save and reconnect (#22124)

Cell IntelliSense registrations now wait for the real connection/complete
result instead of trusting the connect request acknowledgement, so failed
cell binds are retried instead of silently memoized (saved notebooks
previously ended up with keyword-only completions). Cell connects also use
the live execution-connection credentials so they carry refreshed auth
tokens and the actual database.

Saving an untitled notebook replaces its NotebookDocument, which previously
disposed the notebook's connection mid-save. The connection manager is now
parked when a connected untitled notebook closes and adopted by the
file-based notebook that replaces it (matched by cell content within the
save-transition window, guarded by tab presence and open recency), covering
close-then-open, open-then-close, and lingering-document event orderings.
Adoption re-registers the new cell URIs with STS and refreshes UI state.

Additional fixes from review: per-cell STS connections are released on
notebook disconnect/close instead of leaking one server session per cell;
stale cell connects that complete after a connection change are
disconnected; completion expectations are identity-guarded against
cross-cancellation between overlapping registrations; re-parking a reused
untitled URI no longer leaks the superseded manager.



* Address Copilot review feedback on notebook adoption paths

- Locate a cell's owning notebook via path-prefiltered lookup (verified
  membership, full-scan fallback) instead of scanning every cell of every
  notebook per cell-open event.
- Build the notebook content signature incrementally so large notebooks
  no longer materialize their full concatenated cell text for a capped
  signature.
- Best-effort disconnect a cell URI whose connect times out, so a
  late-completing STS connection doesn't linger untracked after the cell
  was deregistered.



---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

5 participants