Skip to content

fix(query): keep results and run state per editor tab - #866

Merged
EVWorth merged 19 commits into
mainfrom
claude/hopeful-bardeen-1k4d1h
Oct 23, 2026
Merged

EVWorth merged 19 commits into
mainfrom
claude/hopeful-bardeen-1k4d1h

Conversation

@EVWorth

@EVWorth EVWorth commented Oct 23, 2026

Copy link
Copy Markdown
Owner

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

  • One copy per tab. Each tab keeps its own results, run state, errors, paging and plan. The top-level fields in the result store hold the shown tab's copy, and the other tabs' copies wait in parked until their tab is shown again. Components that read the store needed no change.
  • Synchronous tab switching. The result store subscribes to the editor store and follows the active tab synchronously, in the same tick. So a run started right after a tab opens is filed under the new tab, not the one shown before. Show DDL for events and statistics also runs on the new tab's own session.
  • Session-less runs. Runs without a session (from the schema tree, the designer or the routine viewer) go to the last query tab shown, never to a designer or admin tab that has no results pane.
  • Per-tab cancel. Cancel is tracked per tab, so a run in one tab no longer throws away another tab's response. Cancel stops only the shown tab's query, and the update guard checks every tab for a running query.
  • Run outcome. executeQuery returns how its own run ended: succeeded, failed, awaiting-confirmation or cancelled. TableDesigner and RoutineViewer act on that instead of reading the store's error, which after a tab switch could be another tab's.
  • History. A run is recorded even if its tab was closed while it ran. A cancelled run's interrupt error stays out.
  • Fresh grid per tab. ResultsGrid is keyed by tab, so pending edits and Edit Mode can't carry from one tab's grid to another's.
  • Results from another connection. They are dropped when the shown tab's own connection doesn't match where they were read. This is checked when a tab is shown and when its connection changes, and the plan is cleared along with the grid.

Not in this PR

Checks

  • tsc --noEmit, ESLint (0 errors, no new warnings) and dprint are clean.
  • Vitest: 158 files, 3165 tests.
  • Browser suite: all 10 files, 344 tests.

Generated by Claude Code

claude added 13 commits October 23, 2026 05:19
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
@EVWorth
EVWorth merged commit d1f55c1 into main Oct 23, 2026
12 checks passed
@EVWorth
EVWorth deleted the claude/hopeful-bardeen-1k4d1h branch October 23, 2026 11:25
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]>
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.

Keep results and run state per editor tab

2 participants