Why do agents request sleep terminal commands

When the agent runs my unit tests it is willing to wait exactly 2 minutes, and then the tests havent finished yet because it takes a bit longer, then i get this sleep 30 or sleep 15. the moment i cancel or skip this the agent immidiatly tries to kill the tests, but why is it doing that in the first place, it knows how long it took the last 1000 times it ran these tests, right?

I think letting it sleep with a terminal command is very weird, the agent can wait without sleeping in the terminal. like it did during the initial running of the tests.

1 Like

I was also encountering this error. Here’s a possibly related post:

The agent shouldn’t get it’s execution back until the command finishes. But sometimes it seems like it gets it back slightly before the command output is available, or for whatever reason it can’t see that the command has actual finished. So it sleeps for some amount of time, based on how long the command took to process. It’s an intermittent error that I haven’t seen in a while.

In all the times I had this issue, as soon as the sleep finishes or I cancel it, it recognizes the commands finished and continues doing what it should be doing. But your situation might be a little different, because it sounds like your commands actually have not finished, and the agent even tries to cancel them.

Sorry I couldn’t be much help; I’m hoping someone else comes along with a better answer.

For me it really feels like there is a 2 minute race between the script running and the agent waiting to process the output, by 2 minutes I mean exactly 120 seconds, no more. After that the agent reads the output file and determines the tests are still running, now at this point I would expect it to just idle for a while and check again. However what happens instead is it asks me to run the sleep command in my terminal.

I might have walked away from my pc to grab a coffee, I return and see its waiting for me to accept a sleep 15 but it had been sitting there waiting for me to click run, so i click cancel, it already waiting that much and probably more, now because i canceled the agent starts thinking along the lines of “the user canceled the sleep, so the tests must be done or something else might have triggered the user to cancel the sleep” its causing confusion without any reason, it could read the current time and see time has already passed or something.

Spawning another terminal to wait without any verification of time actually passing is not the right thing to do imo.

For example this screenshot, why is it doing this?

1 Like

Everyone needs their sleep but sleeping on the job is outrageous. :wink:

Hey, thanks for the report. I can see the screenshots. This is a known issue with how the Agent handles long-running terminal commands.

What’s happening: the Agent has an internal timeout for foreground commands. When it hits that timeout, the Agent loses context that the command is still running and tries to “wait” by running sleep in a new terminal. Yeah, that’s not logical, and your point that the Agent should just wait without extra commands is totally fair.

There’s a workaround. You can add a project rule telling the Agent to use a higher block_until_ms value when running terminal commands. Some users use this successfully for tests that run 15+ minutes. More details here: Timeout setting on terminal/shell Agent tool

You can also try adding a rule to run tests as a background command. In that case, the timeout doesn’t apply.

The team is aware of this category of terminal timeout issues.

A couple questions:

  • What OS are you on, and what Cursor version?
  • What shell are you using?

Let me know if the block_until_ms workaround helps.