Repository navigation
fix: stop the agent's SQL on cancel, and name who asked - #893
Merged
Merged
Conversation
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
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
71 tasks
Merged
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.
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-rustsubagent 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 theAgentSessionsid the panel holds. The panel could neither stop "its" agent's SQL nor say which agent was asking.Changes
AgentSessions::startgives both harness configs (Claude and Copilot/ACP) the headerX-SQLPilot-Session: <session id>, next toAuthorization.call_tooloverride on the MCP server reads the header from the request (rmcp 3.5.1 storeshttp::request::Partsin the request extensions) before any tool runs.AppWorkspacethen records its route key in a registry inMcpState, and removes it when the workspace drops.CancelScope::Agent(key)in the executor.cancel_agent_turnfirst 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_sessiondoes the same.ApprovalRequest/AgentAsk::Approvegainsession(the in-app session id, ornullfor an external client) andclient(the MCPinitializeclient name, cleaned and capped at 64 characters).SESSION_HEADERdoc comment):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 --allandcargo clippy --workspace --all-targets --all-features -- -D warningsare clean at both commits.cargo test -p mas-core -p mas-mcp -p mas-agentpasses.cargo test -p sqlpilot --lib: 68 passed.an_agent_cancel_stops_only_that_agents_statements: agent "a"'sSLEEP(20)stops within 5 s; agent "b" and a tab session keep running.connection_lanespasses 11/11 on MySQL 8 and 11/11 on MariaDB 11.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