Skip to content

Tasks SEP-1686 missing important operation "wait"/"await" to prevent excessive polling #1955

Closed

Description

@kajogo777

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)

related to #1686 and #1732 @LucaButBoring @felixweinberger @He-Pin I would have loved to share this earlier but just noticed the SEP

Activity

  1. He-Pin commented on Dec 10, 2025

    @He-Pin
    Contributor
    1. The server can control the polling interval via pollInterval.
    2. Fire-and-forget functionality can be achieved through an additional side channel, for example, using a lite topic from Apache RocketMQ.
    3. wait async task === waiting for a pollInterval and check again
  2. kajogo777 commented on Dec 10, 2025

    @kajogo777
    Author
    1. The server can control the polling interval via pollInterval.
    1. wait async task === waiting for a pollInterval and check again

    how is pollInterval enforced, will the get command just block for pollInterval?

    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

  3. He-Pin commented on Dec 10, 2025

    @He-Pin
    Contributor

    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.

  4. kajogo777 commented on Dec 10, 2025

    @kajogo777
    Author

    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

  5. connor4312 commented on Dec 10, 2025

    @connor4312
    Contributor

    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.

  6. He-Pin commented on Dec 10, 2025

    @He-Pin
    Contributor

    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.

  7. He-Pin commented on Dec 10, 2025

    @He-Pin
    Contributor

    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

  8. kajogo777 commented on Dec 11, 2025

    @kajogo777
    Author

    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

    maybe I misunderstood the spec

  9. LucaButBoring commented on Dec 12, 2025

    @LucaButBoring
    Contributor

    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.

  10. kajogo777 commented on Dec 22, 2025

    @kajogo777
    Author

    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

  11. LucaButBoring commented on Jan 20, 2026

    @LucaButBoring
    Contributor

    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.

  12. rnett commented on Mar 24, 2026

    @rnett

    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.

  13. localden commented on Jun 24, 2026

    @localden
    Contributor

    @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.

  14. kajogo777 commented on Jun 24, 2026

    @kajogo777
    Author

    @localden I was willing to work on it 6 months ago when I opened this, when it was still a spec

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