Repository navigation
fix(query): keep results and run state per editor tab - #866
Merged
Merged
Conversation
The result store held one set of results, run state and explain state for the whole app, and one cancel generation, so a tab showed another tab's grid and spinner, and a run in one tab dropped the response another tab was waiting for (never shown, never recorded in history). Each editor tab now has its own slice. The top-level fields hold the active tab's, other tabs' are parked until shown, and cancel generations and in-flight executions are tracked per tab. The results pane follows the active tab, drops closed tabs' results, and clears a grid read on another connection when the selection changes. The update guard checks every tab for a running query. Fixes #842. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
The grid's edit state lived in the component, which stayed mounted across a tab switch, so pending edits and Edit Mode made on one tab's result were saved against another tab's rows and table. The results panel is now keyed by the editor tab. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
The results pane followed the active tab from an effect after render, so a run started right after opening a tab (Show DDL, re-run from history) landed in the tab shown before. The result store now follows the editor store synchronously, Show DDL runs on the new tab's session, and a run with no session goes to the last query tab shown rather than to a designer or admin tab with no results pane. A confirmed statement keeps the tab it was asked in. executeQuery returns how the run ended, so callers need not read the shown tab's error afterwards. A statement is recorded in history even when its tab closed or moved on while it ran; only a cancelled run's interrupt error is left out. Results and plans read on another connection are cleared by comparing them with the shown tab's own connection, when the tab is shown and when that connection changes, rather than with the selected one. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
The table designer and the routine viewer read the store's error after awaiting the statement. That is the shown tab's, so after a tab switch mid-run they reported another tab's failure as their own, or missed their own. They now act on the outcome executeQuery returns, and a cancelled save is no longer claimed as a success. Fixes #842. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
A run that names no session was counted under the generation and cancel slot of the tab it is filed into, so a designer's ALTER discarded that tab's own SELECT still in flight and Ctrl+. there cancelled the ALTER instead. Each such run now has a key of its own and shows its response only if nothing started in the tab since. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
The refresh after a grid save named no session for a schema-tree or SQLite result, so its tab was picked by runTabId after the awaits on the confirmation and the save. Switching tabs meanwhile replaced the other tab's results. The tab is now captured before the awaits and passed to executeQuery, which takes an optional target tab. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
With every tab closed, runs were filed under no tab. Opening a tab adopted the spinner but the response went to parked[""], so it never stopped. Showing a tab now moves those runs onto it. With no query tab open, session-less runs are kept under no tab, for the next query tab, rather than filed under a designer tab nobody sees. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
forgetTabs dropped a closed tab's execution while its statement was still on the server, so anyTabExecuting said nothing was running and an app update could restart mid-statement. The execution now stays listed, marked orphaned, until it settles, and anyTabExecuting counts every execution in flight. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
Approving Explain Analyze on production read the format back from the store, which is the shown tab's, and dropped the one passed in. The format now rides in the confirmation dialog state. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
The module-level subscription to the editor store was never removed, so every hot reload of resultStore in dev stacked another listener. It is now handed to import.meta.hot.dispose. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
Editor tabs now run concurrently, each on its own server session, but QueryExecutor::cancel sent KILL QUERY to every thread in flight on the connection. Cancelling one tab therefore interrupted every other tab's query on that connection, which came back "Query execution was interrupted" and was logged as a failure. cancel_query and QueryExecutor::cancel take an optional session. With one, only threads registered under that tab's Route::Session are killed; without one, everything on the connection is killed as before, which session-less callers (schema tree, admin, agents) rely on. The selection is a pure function with unit tests. api.cancelQuery takes an optional session, and the mock backend filters by session the same way. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
Remounting the results grid per tab stopped edits leaking across tabs, but it dropped unsaved edits, Edit Mode, sort and column widths on every tab switch. The grid now parks them per tab on unmount and takes them back when that tab's grid mounts again, as long as the tab still shows the same results. Closed tabs' state is dropped. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
Ctrl+. told the server to stop every statement on the connection, so cancelling one tab also interrupted another tab's query there. It now passes the session the run used: the tab's id for an editor run, nothing for a run on the shared pool. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
When no tab had been shown yet, the first tab shown took the runs in flight and the results on screen even if it was a designer, so they never reached a query tab. The same path ignored results parked under no tab, which then attached to a later tab after all tabs had closed. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
Closing the shown tab forgot its grid memory before React unmounted the grid, and the grid's unmount cleanup then wrote the closed tab's entry back, holding on to its results. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
The grid kept its pending edits when its tab re-ran while it stayed mounted, and on unmount kept them for the new results as if they had been made on them. Edits are by row index, so a save would change the wrong rows. Now new results drop the pending edits and undo history, leave Edit Mode and show a toast with the number of edits dropped. A refresh after a save has nothing pending and stays in Edit Mode. This discards without asking first, so the confirmation #865 asks for is still open. Refs #865. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
A cancel without a session (a designer ALTER, a schema-tree query, a grid refresh or paging) still killed every thread on the connection, including other tabs' sessions and agents. QueryExecutor::cancel now takes a CancelScope: All, Interactive or Session. The cancel_query command maps a session to Session and no session to Interactive, so a user's Cancel only stops the run they are looking at. All stays for internal callers. The mock backend matches. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
keepGrid with no value still created an empty entry, and a recall on results that had changed left the stale entry in place. Both held on to a results array that would never be handed back. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
This was referenced Oct 23, 2026
Merged
EVWorth
pushed a commit
that referenced
this pull request
Oct 24, 2026
The agent panel's Stop only asked the harness to end its turn. Since the editor's Cancel was scoped per tab (#866), nothing reachable from the UI stopped a statement the agent already had running on its own lane. The in-app harness now sends X-SQLPilot-Session with SQLPilot's id for the session. The MCP server reads it on each tool call and binds the MCP session's workspace to that owner once, which records its Route::Agent key in McpState. cancel_agent_turn and stop_agent_session then cancel every statement on those lanes with the new CancelScope::Agent, leaving tabs, the shared pool and other agents running. The header is a label from a client that already holds the token: only UUIDs are accepted, the first owner wins, and no policy decision reads it. Closes #868. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g
EVWorth
added a commit
that referenced
this pull request
Oct 24, 2026
* fix: stop an agent's running SQL on cancel The agent panel's Stop only asked the harness to end its turn. Since the editor's Cancel was scoped per tab (#866), nothing reachable from the UI stopped a statement the agent already had running on its own lane. The in-app harness now sends X-SQLPilot-Session with SQLPilot's id for the session. The MCP server reads it on each tool call and binds the MCP session's workspace to that owner once, which records its Route::Agent key in McpState. cancel_agent_turn and stop_agent_session then cancel every statement on those lanes with the new CancelScope::Agent, leaving tabs, the shared pool and other agents running. The header is a label from a client that already holds the token: only UUIDs are accepted, the first owner wins, and no policy decision reads it. Closes #868. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g * feat: say who asked in an agent approval The approval dialog could not say which agent wanted the change: the request carried no session or client. ApprovalRequest and AgentAsk::Approve now carry `session`, SQLPilot's id for the in-app session (from the X-SQLPilot-Session header its harness sends), and `client`, the name the client gave in the MCP handshake, trimmed of control characters and capped at 64 characters. Both are labels from a client that already holds the token; a forged session id still has to match a session running in the panel to read as the panel's agent, and the prompt still needs the user's yes. The mock's approval requests fill both, so the dialog's requester line can be seen in the browser preview. Closes #801. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g * chore: drop the mock's Requester stand-in The generated AgentAsk now carries session and client. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01WTypK4RjzzdjoFxd3qk14g --------- Co-authored-by: Claude <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #842.
Before this, every editor tab shared one results pane. Running a query in tab B replaced tab A's results, and a slow query finishing in A could overwrite what B showed. This was held back from #856 because a review found blocking bugs in the first version; this PR is that version plus the fixes.
How it works
parkeduntil their tab is shown again. Components that read the store needed no change.executeQueryreturns how its own run ended:succeeded,failed,awaiting-confirmationorcancelled. TableDesigner and RoutineViewer act on that instead of reading the store'serror, which after a tab switch could be another tab's.ResultsGridis keyed by tab, so pending edits and Edit Mode can't carry from one tab's grid to another's.Not in this PR
Checks
tsc --noEmit, ESLint (0 errors, no new warnings) and dprint are clean.Generated by Claude Code