Skip to content

fix: retrieve stored result from tasks/result for failed tasks#1930

Open
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/issue-1922
Open

fix: retrieve stored result from tasks/result for failed tasks#1930
Christian-Sidak wants to merge 1 commit intomodelcontextprotocol:mainfrom
Christian-Sidak:fix/issue-1922

Conversation

@Christian-Sidak
Copy link
Copy Markdown

Summary

When a task-augmented request reaches failed terminal status, TaskManager.requestStream was yielding a hardcoded ProtocolError(InternalError, "Task <id> failed") instead of calling tasks/result to retrieve the actual stored result. This meant whatever the handler stored (e.g. { isError: true, content: [...] }) was unreachable by the client.

The fix mirrors the completed case: call this.getTaskResult(...) and yield { type: 'result', result }, matching the spec requirement that tasks/result must return exactly what the underlying request would have returned.

Root cause (packages/core/src/shared/taskManager.ts:310-312):

// Before (wrong)
case 'failed': {
    yield { type: 'error', error: new ProtocolError(ProtocolErrorCode.InternalError, `Task ${taskId} failed`) };
    break;
}

// After (correct, mirrors 'completed' branch)
case 'failed': {
    const result = await this.getTaskResult({ taskId }, resultSchema, options);
    yield { type: 'result', result };
    break;
}

Test plan

  • Added integration test in test/integration/test/taskLifecycle.test.ts that:
    • Calls callToolStream on a tool registered with shouldFail: true
    • Asserts the terminal stream event is { type: 'result' } (not { type: 'error' })
    • Asserts result.isError === true and result.content matches the stored failure text
  • All 489 core unit tests pass
  • All integration task lifecycle tests pass

Fixes #1922

When a task-augmented request reaches 'failed' status, requestStream
now calls tasks/result to retrieve and yield the actual stored result
(same as the 'completed' branch), instead of yielding a hardcoded
ProtocolError('Task <id> failed'). This matches the spec requirement
that tasks/result must return exactly what the underlying request
would have returned.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@Christian-Sidak Christian-Sidak requested a review from a team as a code owner April 19, 2026 06:52
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 19, 2026

🦋 Changeset detected

Latest commit: 1e82e88

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 19, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1930

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1930

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1930

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1930

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1930

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1930

commit: 1e82e88

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.

Client sees "Task <id> failed" instead of the real error/result on failed tasks

1 participant