Repository navigation
feat: add McpTask for long-running Tools - #8631
lloydrichards wants to merge 32 commits into
Conversation
🦋 Changeset detectedLatest commit: 851fad3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 40 packages
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 |
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
00c9f73 to
e7302a7
Compare
e7302a7 to
c17e3df
Compare
c17e3df to
ffc7e78
Compare
ffc7e78 to
ef68ef5
Compare
ef68ef5 to
e3e2e97
Compare
ca21d3a to
d648ca4
Compare
d648ca4 to
130581b
Compare
130581b to
880f9b5
Compare
There was a problem hiding this comment.
Reviewed the task execution layers, protocol integration, ownership checks, and added coverage. Reported one blocking dispatch issue affecting replacement of task tools with inline tools. Validation was by source inspection; no tests were run.
Reviewed at 880f9b5: 1 blocking, 0 nits.
Disagree? Reply in the finding's thread, or a maintainer can comment /janitor to re-run or dismiss this review.
Fold the client task tests into McpClient.test.ts, cut the server suite to the negotiation, lifecycle, input, cancellation, ownership and execution cases, keep two SQL reconstruction cases, and trim the typetests. Drop the Toolkit withHandlers typetests and the unrelated McpServer test changes.
Replace the task binding with a Task outcome on core tool registrations
and task routes in McpCore, mirror the Skills layout for the tasks/*
methods, and rebuild the Workflow backend on keyed snapshot writes.
Simplify the public API: McpTasks.toolkit(tools, { owner }),
TaskContext.setStatusMessage(message), and extensions.tasks as a boolean
or polling options. Move toolkit registration helpers out of McpServer,
drop Toolkit.withHandlers and McpTasks.workflowRace, and update MCP.md.
…outing Move to setStatusMessage(message) and extensions.tasks: true. Cover withdrawal of a lost durable race input and late answers, Workflow cancellation of waiting and running tasks, and mismatched Mcp-Name headers on task methods.
Cover task handles surviving replacement by another task tool, status set in a cached durable race arm, a __proto__ input key in the Workflow backend, and the Tasks capability check for task notification subscriptions. These fail until the implementation is fixed. Give the SQL reconstruction stages wall-clock budgets so a stall names its stage, and report stage timings when a test runs slowly.
…acement and replay Route task handles by tool registration generation so a replacing task toolkit does not take over existing handles. Take a status set in work a replay skipped from the durable log. Build outstanding inputs with a null-prototype record. Require the Tasks capability when a subscription requests task notifications.
…ssages Extend the durable race regression with a second race whose pending branch replays while the other appends, and with a status message that is reused after an earlier setter is skipped by replay.
Record input requests, withdrawals, status messages and completion as changes that readers fold, instead of full snapshots written from a run's partially replayed state. Identify input changes by key, match status messages against the recorded status changes after the last match, and withdraw recorded inputs a suspending run no longer waits for.
Extend the durable race regression with a reused message as the first setter after skipped setters, and add cases for concurrent setters that replay reorders and for a lost race input when the task next waits on a durable clock. These fail until the implementation is fixed.
Restore TaskContext.setStatusMessage(key, message). Status changes are recorded once per key, so replay that skips or reorders work no longer changes the reported status. Keys must be unique per task in both backends. Withdraw recorded inputs a Workflow run no longer waits for whenever the run suspends, including on clocks and deferreds.
…nd tidy task docs
|
At the rate that PRs are being made and the amount of time I spend now on just fixing merge conflicts for these open prs, I'm gonne just say I'm marking this as |
Goal
Add long-running MCP tools that clients can poll, answer and cancel, using the Tasks extension (
io.modelcontextprotocol/tasks, protocol 2026-07-28).Server
McpTasks.toolkit(tools, { owner })registers task tools. A call returns a task handle instead of an immediate result. AnMcpTasks.Executionservice runs the tasks. You can provide it in three ways:McpTasks.layerWorkflow(tools, handlers, { name }): durable. Tasks survive runner restarts and support Workflow Activities and compensation. A tool failure is recorded as a Workflow failure, so it triggers compensation.McpTasks.layerMemory(tools, handlers): in-process. State is lost on restart.Executionbacked by your own job service.Handlers use
McpTasks.TaskContext:Keys identify steps, like the names of Workflow Activities. Each
requestInputcall and eachsetStatusMessagecall needs a key that is unique for the life of the task, and reusing a key is a defect. When a Workflow replay runs the same keyed step again, it is not recorded twice. That keeps the status and the outstanding inputs correct when replay skips or reorders work. When a durable race resolves, inputs requested by the losing branches are withdrawn. If replay resolves the race without running those branches, the inputs are withdrawn the next time the task suspends.Task handles stay valid when a task tool is replaced. Tasks are advertised only while at least one task tool is registered. Without one, the
tasks/*methods return method-not-found.Client
extensions.tasksistrueor{ pollInterval, requestTimeout }. It is available inmake,layerHttpandlayerStdio, next toextensions.skills.callToolreturns the final result, whether the server answers immediately or creates a task.startToolreturns aToolExecutionwithtaskId,awaitResultandcancel. Several waiters on the same task share one polling worker.inputhandlers answer the roots, sampling and elicitation requests that a task makes.Scope
cancelacknowledges that cancellation was requested. Later reads report what actually happened to the task.Validation
At
653859c:vitest run packages/effect/test/ai: 1779 passed, 50 skipped.pnpm test-typesfortypetest/ai: 250 of 250 pass on both TypeScript targets.pnpm check,pnpm lint,pnpm circular,pnpm jsdocsandpnpm codegenpass with no changes.This PR also shrinks the fixture in the
McpClientdiscoveryLimitErrortest from 150,000 prompts to 11, withmaxItems: 10. The large fixture blocked the event loop for 1–2 s. Under load, that made the 2026-07-28McpClient.toolkittest time out. That timeout also happens onmain.Known intermittent failures (not diagnosed)
These failures are not explained by the passing runs above. They are listed separately so they are not mistaken for resolved issues.
McpTasksWorkflow.test.tsreconstruction tests timed out during development. They have not timed out since, across many sequential and parallel runs. Each step now runs through astagehelper with an 8 s budget. A stalled step fails with its name and the timings of the earlier steps, and any test slower than 4 s writes its stage timings to stderr.McpServer/Workerd.test.tscases (GET-first and warm-up-POST-first) failed withrequest stalled. Both passed when run alone and in a full rerun, with no code change. The cause is unknown.Closes #6834
Closes EFF-3417