Skip to content

Conversation

@coinmoles
Copy link

Remove the std::mem::take from OperationProcessor::collect_completed_results

Motivation and Context

std::mem::take would clear OperationProcessor::completed_results, causing completed tasks to be dropped. This made tasks/get and tasks/result to fail for subsequent requests.

How Has This Been Tested?

  • All existing tests passed
  • Tested with a custom task server/client implementation (Will add this to examples if requested)

Breaking Changes

This is technically a breaking change that changes the return type of OperationProcessor::collect_completed_results from Vec<TaskResult> to (). However, I doubt there was anyone calling the method directly without using the #[tool_handler] macro.

I did this to avoid introducing an unnecessary clone call. If this is a problem, I can change the method so it returns either:

  • self.completed_results.clone()
  • An owned vector of newly collected items, which I think was the intended return value in the first place.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

Fixes #638

@github-actions github-actions bot added T-test Testing related changes T-core Core library changes labels Feb 2, 2026

/// Collect completed results from running tasks and remove them from the running tasks map.
pub fn collect_completed_results(&mut self) -> Vec<TaskResult> {
pub fn collect_completed_results(&mut self) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thoughts on this being pub in the first place?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right now, the function has to be public because it is called from the output of #[task_handler] macro.

However, it would make sense to make this private and have OperationProcessor::peek_completed and OperationProcessor::take_completed_result call this before returning. Do you think that would be better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, something like that makes sense to me. Can you make the change?

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

Labels

T-core Core library changes T-test Testing related changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Completed tasks are erased from OperationProcessor

2 participants