Skip to content

Completed tasks are erased from OperationProcessor #638

Description

@coinmoles

Describe the bug
The completed tasks are erased from OperationProcessor

To Reproduce
Steps to reproduce the behavior:

  1. tasks/get request returns task: None after task completion.
  2. tasks/result request returns error after task completion.

Expected behavior

  1. tasks/get request should return a Task object with status: "completed".
  2. tasks/result request should return the task result.

Additional context
I am using the latest commit (32a68aa) because the published version 0.14.0 does not include the enum-variant reordering fix.

rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", features = ["macros", "client", "rmcp/transport-streamable-http-client-reqwest"] }

Fix

This is caused by std::mem::take from the OperationProcessor::collect_completed_results, which clears OperationProcessor::completed_results.

/// Collect completed results from running tasks and remove them from the running tasks map.
pub fn collect_completed_results(&mut self) -> Vec<TaskResult> {
if let Some(receiver) = &mut self.task_result_receiver {
while let Ok(result) = receiver.try_recv() {
self.running_tasks.remove(&result.descriptor.operation_id);
self.completed_results.push(result);
}
}
std::mem::take(&mut self.completed_results)
}

The solution would be simply to not return anything from this function. While this would be a breaking change, this method is only used in a single test code, and I doubt anyone was calling this method directly without using the #[tool_handler] macro.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions