Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix: Isolate query execution state per editor instance to prevent shared SPID issues#20407

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
Copilot wants to merge5 commits intomain
base:main
Choose a base branch
Loading
fromcopilot/fix-running-in-transaction-issue

Conversation

Copy link
Contributor

CopilotAI commentedNov 3, 2025
edited
Loading

When multiple editors view the same SQL file (split views or tabs), they share a single QueryRunner instance and SQL Server session (SPID). This causes UI state synchronization issues: if Tab 1 starts a transaction, Tab 2's completed query incorrectly shows "executing..." until Tab 1 commits.

Changes

Key generation for editor instances

  • AddedgetEditorInstanceKey() to generate unique keys per editor using URI + viewColumn (e.g.,"file:///test.sql::2")
  • AddedgetDocumentUriFromEditorKey() to extract document URI from instance keys

Execution state isolation

  • SqlOutputContentProvider: Keys QueryRunner instances by editor instance key instead of document URI
  • QueryRunner: Tracks both document URI (for SQL Tools Service/connection lookup) and editor instance key (for StatusView/UI state)
  • MainController: Uses editor instance keys for query execution while connections remain keyed by document URI (shared)

Document lifecycle handling

  • onDidCloseTextDocument(): Cleans up all editor instances for closed document (handles keys matchingdocumentUri ordocumentUri::*)
  • onUntitledFileSaved() /updateQueryRunnerUri(): Remaps all editor instances when document is saved/renamed

Architecture

// Before: All editors shared same QueryRunner_queryResultsMap["file:///test.sql"]=QueryRunnerState// After: Each editor gets its own QueryRunner_queryResultsMap["file:///test.sql::1"]=QueryRunnerState// Tab 1_queryResultsMap["file:///test.sql::2"]=QueryRunnerState// Tab 2// QueryRunner internalsconstructor(documentUri,// "file:///test.sql" - for SQL Tools ServiceeditorInstanceKey// "file:///test.sql::2" - for UI state)

Connections remain keyed by document URI (shared), while execution state and SPIDs are isolated per editor instance.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • update.code.visualstudio.com
    • Triggering command:/usr/local/bin/node ./out/test/unit/runTest.js --grep Editor Instance Key (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Keeps running while in transaction</issue_title>
<issue_description>
Type:Bug

begin tran
delete command
exec sp
select
while committing (or even on previous commands), the editor keep "executing query"

Extension version: 1.30.0
VS Code version: Code 1.99.2 (4949701c880d4bdb949e3c0e6b400288da7f474b, 2025-04-10T01:21:25.295Z)
OS version: Windows_NT x64 10.0.26100
Modes:

System Info
ItemValue
CPUs12th Gen Intel(R) Core(TM) i7-1255U (12 x 2611)
GPU Status2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg)undefined
Memory (System)15.68GB (2.06GB free)
Process Argv--crash-reporter-id be4b83fa-1a15-441d-a95b-0802ecbe4b43
Screen Readerno
VM0%
A/B Experiments
vsliv368:30146709vspor879:30202332vspor708:30202333vspor363:30204092vscod805cf:30301675binariesv615:30325510c4g48928:30535728azure-dev_surveyone:30548225a9j8j154:30646983962ge761:309597992e7ec940:31000449pythontbext0:30879054cppperfnew:31000557dwnewjupyter:31046869pythonrstrctxt:31112756nativeloc1:311922155fd0e150:31155592dwcopilot:311700136074i472:31201624dwoutputs:31242946customenabled:31248079hdaa2157:31222309copilot_t_ci:31222730e5gg6876:31282496pythoneinst12cf:31262606bgtreat:312685684gafe986:3127182631787653:312621863e8i5726:3127174749da9784:31282606useunpkgapi:31280918747dc170:31275177aj496949:31278748aj953862:31281341

<agent_instructions>Problem Statement
When a user opens the same SQL file in multiple editor instances (tabs, split views, or windows), all editors share the same query execution state and SQL Server session (SPID). This causes critical UI state synchronization issues:

Primary Issue - Shared Execution State:
When multiple tabs/editors are open for the same file and they share the same SPID:

Tab 1 executes a query that starts a transaction (e.g., BEGIN TRANSACTION; UPDATE table SET column = value;)
Tab 2 executes a different query (e.g., SELECT * FROM another_table;)
Problem: Tab 2's query completes successfully and returns results, BUT the UI shows the query as still "executing" indefinitely because Tab 1's transaction hasn't been committed
The execution state is shared between both tabs, so Tab 1's active transaction causes Tab 2's UI to remain in "executing" state even though Tab 2's query finished
Secondary Issue - Session Sharing:
Both editors use the same SQL Server session (SPID), which means:

Any transaction state from one editor affects the other
Query execution contexts are not isolated
Users cannot work independently in different tabs of the same file
Reproduction Steps:

Open a SQL file (e.g., test.sql)
Split the editor or open the same file in a second tab
In Tab 1: Execute BEGIN TRANSACTION; UPDATE table SET column = value; (leaves transaction open)
In Tab 2: Execute SELECT * FROM another_table; (different query, no locks needed)
Result: Tab 2 gets query results successfully, but the UI shows "executing..." indefinitely until Tab 1 commits the transaction
Root Cause
The extension currently keys all connection state, query runners, and execution state tracking by document URI only. When multiple editors view the same document, they all share:

The same QueryRunner instance
The same execution state tracking in SqlOutputContentProvider
The same SQL Server session (SPID)
The same status bar state in StatusView
This means UI updates and execution state from one editor instance overwrite or interfere with another editor's state.

Required Solution
Implement per-editor-instance isolation for query execution state and SQL Server sessions while maintaining shared connection profiles:

Generate unique editor instance keys using both document URI and VS Code's viewColumn property (e.g., "file:///path/to/file.sql::1", "file:///path/to/file.sql::2")

Separate connection sharing from execution context: Connection credentials can be shared, but each editor instance must get:

Its own QueryRunner with independent execution state tracking
Its own SQL Server session (SPID) for query execution
Its own status bar state showing query execution status
Update state management across these components:

ConnectionManager: Track execution contexts per editor instance while sharing connection profiles
SqlOutputContentProvider: Key query runners by editor instance, not just document URI - each editor needs its own QueryRunnerState
QueryRunner: Us...


✨ Let Copilot coding agentset things up for you — coding agent works faster and does higher quality work when set up for your repo.

CopilotAIand others added4 commitsNovember 3, 2025 23:38
- Add getEditorInstanceKey() helper to generate unique keys per editor (URI + viewColumn)- Update VscodeWrapper to provide activeTextEditorInstanceKey property- Update MainController to use editor instance keys for query execution- Update SqlOutputContentProvider to key QueryRunner instances by editor instance- Update QueryRunner to track both document URI (for SQL Tools Service) and editor instance key (for UI state)- Update StatusView calls to use editor instance key for per-editor status trackingThis ensures each editor viewing the same document has independent query execution state.Co-authored-by: allancascante <755488+allancascante@users.noreply.github.com>
- Update onDidCloseTextDocument to clean up all editor instances- Update onUntitledFileSaved to remap all editor instances- Update updateQueryRunnerUri to migrate all editor instances to new URI- Ensure proper cleanup of actual plan statuses per editor instanceThis ensures editor instances are properly managed during document lifecycle events.Co-authored-by: allancascante <755488+allancascante@users.noreply.github.com>
- Test getEditorInstanceKey generates unique keys per editor- Test getDocumentUriFromEditorKey extracts URI correctly- Verify different view columns generate different keys- Verify same view column generates same key- Test edge cases (undefined editor, missing view column)Co-authored-by: allancascante <755488+allancascante@users.noreply.github.com>
The function can return undefined, so update the return type from 'string' to 'string | undefined' to match the actual behavior.Co-authored-by: allancascante <755488+allancascante@users.noreply.github.com>
CopilotAI changed the title[WIP] Fix editor executing query during transactionFix: Isolate query execution state per editor instance to prevent shared SPID issuesNov 3, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@allancascanteallancascanteAwaiting requested review from allancascanteallancascante is a code owner

@kburtramkburtramAwaiting requested review from kburtramkburtram will be requested when the pull request is marked ready for reviewkburtram is a code owner

@aasimkhan30aasimkhan30Awaiting requested review from aasimkhan30aasimkhan30 will be requested when the pull request is marked ready for reviewaasimkhan30 is a code owner

@caohaicaohaiAwaiting requested review from caohaicaohai will be requested when the pull request is marked ready for reviewcaohai is a code owner

@laurenastrid1laurenastrid1Awaiting requested review from laurenastrid1laurenastrid1 will be requested when the pull request is marked ready for reviewlaurenastrid1 is a code owner

@lewis-sanchezlewis-sanchezAwaiting requested review from lewis-sanchezlewis-sanchez will be requested when the pull request is marked ready for reviewlewis-sanchez is a code owner

@BenjinBenjinAwaiting requested review from BenjinBenjin will be requested when the pull request is marked ready for reviewBenjin is a code owner

@ssreeramassreeramaAwaiting requested review from ssreeramassreerama will be requested when the pull request is marked ready for reviewssreerama is a code owner

@manujoseph85manujoseph85Awaiting requested review from manujoseph85manujoseph85 will be requested when the pull request is marked ready for reviewmanujoseph85 is a code owner

At least 1 approving review is required to merge this pull request.

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Keeps running while in transaction

2 participants

@allancascante

[8]ページ先頭

©2009-2025 Movatter.jp