Skip to content

fix: stop the agent's SQL on cancel, and name who asked - #893

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

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

Conversation

@EVWorth

@EVWorth EVWorth commented Oct 24, 2026

Copy link
Copy Markdown
Owner

This is the backend half of two agent-panel issues from the UX review. The UI half shipped in #886. The change was written by the implementer-rust subagent and reviewed here.

The shared problem

The in-app harness reaches the MCP endpoint with the same URL and token as an external client. Its statements ran on a route key minted per MCP session (agent-<uuid>). Nothing linked that key to the AgentSessions id the panel holds. The panel could neither stop "its" agent's SQL nor say which agent was asking.

Changes

  • Linking.
    • AgentSessions::start gives both harness configs (Claude and Copilot/ACP) the header X-SQLPilot-Session: <session id>, next to Authorization.
    • One call_tool override on the MCP server reads the header from the request (rmcp 3.5.1 stores http::request::Parts in the request extensions) before any tool runs.
    • Only a UUID is accepted, and the first owner wins.
    • The AppWorkspace then records its route key in a registry in McpState, and removes it when the workspace drops.
  • Agent panel Cancel doesn't stop the agent's running SQL #868: Cancel stops the agent's SQL.
    • New CancelScope::Agent(key) in the executor.
    • cancel_agent_turn first asks the harness to stop. It then cancels every route registered to that panel session, on every live connection, even if the harness didn't answer.
    • stop_agent_session does the same.
    • Failures are logged, not raised.
  • Name the requesting agent in the approval dialog #801: who asked.
    • ApprovalRequest / AgentAsk::Approve gain session (the in-app session id, or null for an external client) and client (the MCP initialize client name, cleaned and capped at 64 characters).
    • The dialog's "Asked by …" from feat: UX review fixes for admin, history and agent panel #886 now has data to show.
    • The mock's local stand-in type is removed.
  • Security reasoning (written up in the SESSION_HEADER doc comment):
    • Only a token holder gets this far.
    • A forged header can at worst make the panel's Stop also cancel the forger's own statements, or make the forger's prompt read as the panel's agent. Both need a live panel session UUID.
    • The prompt still shows the SQL, connection and row count and still needs the user's yes.
    • No grant, policy or approval decision reads the value.
  • Docs: docs/design/AI_INTEGRATION.md §2 and §6. This includes the remaining limit: staged writes and schema reads aren't tracked as in-flight, so cancel can't reach them yet.

Closes #868. Closes #801.

Test plan

  • cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings are clean at both commits.
  • cargo test -p mas-core -p mas-mcp -p mas-agent passes.
    • New executor scope tests.
    • Registry tests.
    • Header and client-name parsing tests.
    • Seven over-HTTP endpoint tests: binding once, external client unbound, non-UUID ignored, no rebinding, and approval naming.
  • cargo test -p sqlpilot --lib: 68 passed.
  • Live test an_agent_cancel_stops_only_that_agents_statements: agent "a"'s SLEEP(20) stops within 5 s; agent "b" and a tab session keep running. connection_lanes passes 11/11 on MySQL 8 and 11/11 on MariaDB 11.
  • Bindings regenerated and current. npm run test:unit: 170 files and 3,437 tests passed on the merged branch. Type check and dprint are clean.

Generated by Claude Code

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
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
@EVWorth
EVWorth merged commit 02adfee into main Oct 24, 2026
12 checks passed
@EVWorth
EVWorth deleted the claude/hopeful-bardeen-1k4d1h branch October 24, 2026 18:29
@github-actions github-actions Bot mentioned this pull request Nov 8, 2026
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.

Agent panel Cancel doesn't stop the agent's running SQL Name the requesting agent in the approval dialog

2 participants