You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tasks SEP-1686 missing important operation "wait"/"await" to prevent excessive polling #1955
We implemented a very similar design earlier this year and noticed without a wait/wait_for_tasks command agents tend to excessively poll burning tokens and context when they don't have anything else to do on the main thread (or get fixated on waiting for the task)
Our implementation included
async task -> returns id, status, head of result
list async tasks -> returns set of id, status, head of result
get async task -> gets the result of an async task
cancel async task -> cancels an async task
wait for async tasks -> this prevents the agent from getting into a polling loop which resulted in many cases in consuming the whole context (this is equivalent to await or join multiple async tasks as a barrier)
The tasks/get will return the status asap, just the tasks/result may be blocked.
The LLM maybe a problem if it not been trained for that, maybe an instructions of mcp server can help in this case.
@kajogo777 Can you share your design here, thanks.
exactly, the LLM misbehaving is the cause of the problem, what we observed is that it will keep generating the "get" tool call repeatedly, even the smartest Claude model at the time
we were not able to fix it with prompting nor a more verbose tool call description
MCP is also used by less intelligent models
the solution that worked for us, and what I propose here is a wait([task_id]), that acts as a barrier and blocks on a set of task_ids, until they either fail, succeed, or timeout
this will give the LLM an explicit tool to use when it wants to block on async tasks
I added a link to our implementation of the async tool calls pattern above, it's Apache 2.0, and would love to discuss this more or document it in a diagram if you're interested
I don't think tasks should get directly exposed to the model as you seem to be doing. In my implementation, tasks are used behind the scenes but the model just sees a single blocking or resumable e.g. tool call. It doesn't get direct control over protocol mechanics.
In the current implementation, there's a statusMessage. Could you try including information in the statusMessage that instructs the AI to check again later? @kajogo777
I don't think tasks should get directly exposed to the model as you seem to be doing. In my implementation, tasks are used behind the scenes but the model just sees a single blocking or resumable e.g. tool call. It doesn't get direct control over protocol mechanics.
@connor4312 how does the model see the single blocking / resumable tool call? how do you notify it that the task is finished so it can get access to the result?
this has to fit within the tool calling scheme the model uses and/or message schema it expects
The point of tasks/get is to have a way to deterministically allow the application or framework to do polling instead of making the model do it - the problem being described is exactly what we're avoiding. A naive implementation can just block until the task is complete (e.g. don't yield back to the model until polling is done and a result is available), but a more sophisticated implementation can provide an immediate placeholder result to the model to satisfy the requirement that every tool request is followed by its result, and then push a message to the conversation when the full result is available.
The point of tasks/get is to have a way to deterministically allow the application or framework to do polling instead of making the model do it - the problem being described is exactly what we're avoiding. A naive implementation can just block until the task is complete (e.g. don't yield back to the model until polling is done and a result is available), but a more sophisticated implementation can provide an immediate placeholder result to the model to satisfy the requirement that every tool request is followed by its result, and then push a message to the conversation when the full result is available.
then the proposal leaves out how the client returns the intermediate task placeholder, and the result return out of the spec
this means people implementing this in clients will have to figure out how to tell the model something is running in the background, and how to inject the results
I don't think this solves the issue, just push it up the stack to the MCP client implementation
then the proposal leaves out how the client returns the intermediate task placeholder, and the result return out of the spec
this means people implementing this in clients will have to figure out how to tell the model something is running in the background, and how to inject the results
This is correct, how host applications integrate with MCP clients has always been left unspecified, though we do have recommendations.
I don't think this solves the issue, just push it up the stack to the MCP client implementation
It solves model polling - if the client can deterministically poll, the model doesn't need to anymore, and there is also a protocol-mediated way to know when there are results available to inject the final results. It maps (almost) directly to e.g. background tasks in Claude Code, with the exception that there's not yet any form of explicit model polling to read an output stream.
While for now I'm getting this implemented into frameworks/applications via a blocking shim (because that's trivial and enables the most basic level of support), the next step is to expand from blocking to injecting "task has started etc." and "task has completed etc." messages into the conversation.
One thing that pushing all polling onto the client loses is the ability for agents to wait for specific conditions. For example, I have a tool that runs Gradle tasks in the background. My current "status" tool has the ability to wait for a particular sub-task to complete, for a regex match appearing in the output, and/or a certain timeout. This does not seem possible to implement with the current SEP.
Additionally, Tasks have now been graduated to an official extension, so any changes should be tracked in the extension repo rather than the core spec.
Activity
He-Pin commentedon Dec 10, 2025
pollInterval.kajogo777 commentedon Dec 10, 2025
how is
pollIntervalenforced, will the get command just block forpollInterval?because the LLM can just decide to ignore it and keep calling get
edit: also note the wait example I mentioned above can wait for multiple tasks like a barrier
He-Pin commentedon Dec 10, 2025
The
tasks/getwill return the status asap, just thetasks/resultmay be blocked.The LLM maybe a problem if it not been trained for that, maybe an instructions of mcp server can help in this case.
@kajogo777 Can you share your design here, thanks.
kajogo777 commentedon Dec 10, 2025
exactly, the LLM misbehaving is the cause of the problem, what we observed is that it will keep generating the "get" tool call repeatedly, even the smartest Claude model at the time
we were not able to fix it with prompting nor a more verbose tool call description
MCP is also used by less intelligent models
the solution that worked for us, and what I propose here is a wait([task_id]), that acts as a barrier and blocks on a set of task_ids, until they either fail, succeed, or timeout
this will give the LLM an explicit tool to use when it wants to block on async tasks
I added a link to our implementation of the async tool calls pattern above, it's Apache 2.0, and would love to discuss this more or document it in a diagram if you're interested
connor4312 commentedon Dec 10, 2025
I don't think tasks should get directly exposed to the model as you seem to be doing. In my implementation, tasks are used behind the scenes but the model just sees a single blocking or resumable e.g. tool call. It doesn't get direct control over protocol mechanics.
He-Pin commentedon Dec 10, 2025
In our implementation, we are using a fire-and-forget way to handle it. The agent will only get notified once the task is terminated.
He-Pin commentedon Dec 10, 2025
In the current implementation, there's a
statusMessage. Could you try including information in thestatusMessagethat instructs the AI to check again later?@kajogo777
kajogo777 commentedon Dec 11, 2025
@connor4312 how does the model see the single blocking / resumable tool call? how do you notify it that the task is finished so it can get access to the result?
this has to fit within the tool calling scheme the model uses and/or message schema it expects
maybe I misunderstood the spec
LucaButBoring commentedon Dec 12, 2025
The point of
tasks/getis to have a way to deterministically allow the application or framework to do polling instead of making the model do it - the problem being described is exactly what we're avoiding. A naive implementation can just block until the task is complete (e.g. don't yield back to the model until polling is done and a result is available), but a more sophisticated implementation can provide an immediate placeholder result to the model to satisfy the requirement that every tool request is followed by its result, and then push a message to the conversation when the full result is available.kajogo777 commentedon Dec 22, 2025
then the proposal leaves out how the client returns the intermediate task placeholder, and the result return out of the spec
this means people implementing this in clients will have to figure out how to tell the model something is running in the background, and how to inject the results
I don't think this solves the issue, just push it up the stack to the MCP client implementation
LucaButBoring commentedon Jan 20, 2026
This is correct, how host applications integrate with MCP clients has always been left unspecified, though we do have recommendations.
It solves model polling - if the client can deterministically poll, the model doesn't need to anymore, and there is also a protocol-mediated way to know when there are results available to inject the final results. It maps (almost) directly to e.g. background tasks in Claude Code, with the exception that there's not yet any form of explicit model polling to read an output stream.
While for now I'm getting this implemented into frameworks/applications via a blocking shim (because that's trivial and enables the most basic level of support), the next step is to expand from blocking to injecting "task has started etc." and "task has completed etc." messages into the conversation.
rnett commentedon Mar 24, 2026
One thing that pushing all polling onto the client loses is the ability for agents to wait for specific conditions. For example, I have a tool that runs Gradle tasks in the background. My current "status" tool has the ability to wait for a particular sub-task to complete, for a regex match appearing in the output, and/or a certain timeout. This does not seem possible to implement with the current SEP.
localden commentedon Jun 24, 2026
@kajogo777 closing this as SEPs have since moved to pull requests. If this is still a relevant project to pursue, feel free to create a new SEP PR and build support in our contributor Discord.
Additionally, Tasks have now been graduated to an official extension, so any changes should be tracked in the extension repo rather than the core spec.
kajogo777 commentedon Jun 24, 2026
@localden I was willing to work on it 6 months ago when I opened this, when it was still a spec