Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions apps/staged/src-tauri/src/project_mcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ impl ProjectToolsHandler {
async fn start_repo_session(
&self,
Parameters(p): Parameters<StartRepoSessionParams>,
request_ct: CancellationToken,
) -> String {
log::debug!(
"[project_mcp] start_repo_session called: repo={:?} subpath={:?} expected_outcome={:?} return_info={:?} provider={:?} instructions={:?}",
Expand Down Expand Up @@ -448,8 +449,9 @@ impl ProjectToolsHandler {
}

// Poll until the session reaches a terminal state.
// Also watch the parent project session's cancellation token so we
// don't loop forever if the project session is cancelled while waiting.
// Watch both the parent project session's cancellation token and the
// per-request cancellation token (fired by rmcp when the MCP client
// sends a CancelledNotification, e.g. on Goose's 5-minute timeout).
loop {
tokio::select! {
_ = tokio::time::sleep(Duration::from_secs(2)) => {}
Expand All @@ -463,6 +465,20 @@ impl ProjectToolsHandler {
})
.to_string();
}
_ = request_ct.cancelled() => {
// The MCP client cancelled this specific tool call (e.g.
// Goose's per-tool timeout fired). Cancel the child session
// so it doesn't continue running as an orphan.
log::info!(
"[project_mcp] per-request cancellation received for session {session_id}"
);
self.registry.cancel(&session_id);
return serde_json::json!({
"outcome": "cancelled",
"output": "",
})
.to_string();
}
}
match self.store.get_session(&session_id) {
Ok(Some(s)) if s.status != SessionStatus::Running => {
Expand Down