Daily Usage Issues

MCP Server - WaitForEngineWorkCompleted times out

Started by arkiaconsulting on 22 views

Hi,

whatever the engine is busy or not, the AI agent call to `WaitForEngineWorkCompleted` times out.

This happens either from within VS 2026 IDE integration, either from the console tool.


System.Exception: An exception was thrown in the remote environment: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> nCrunch.Common.UserException: Timed out while waiting for NCrunch engine work to complete. Last state: Running, tasks in progress: 2, unprocessed tasks: 74
at nCrunch.Client.MCP.McpToolReflector.CallTool(Object controlSurface, String name, JObject arguments)
at nCrunch.Client.MCP.McpIpcEndpoint.CallToolJson(String name, String argumentsJson)
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.processCallMethodMessage(CallMethodMessage callMethodMessage)
at nCrunch.TaskRunner.Ipc.IpcMessageProcessor.ProcessMessageReturningResult(Byte[] data)
at nCrunch.TaskRunner.Ipc.RemoteProxyCommunicator.readMessage(Byte[] returnedData)
at nCrunch.TaskRunner.Ipc.RemoteProxyCommunicator.Invoke(String methodName, Object[] args)
at nCrunch.Client.MCP.McpIpcEndpointProxy.CallToolJson(String name, String argumentsJson)
at NCrunch.MCP.McpSessionHost.CallTool(String name, JObject arguments)
at NCrunch.MCP.McpJsonRpcServer.HandleLine(String line)


nCrunch version: 5.23.0.1
nCrunch Console: 5.23.0.1

UPDATE: It does not happen all the time. Cannot figure out what's the discriminant.

Edited

Hi, thanks for sharing this issue.

Most likely you have tasks that are hanging and not completing. Unfortunately the agent doesn't have a way to directly get the list of tests attached to a task that is hanging, but they are able to pull up a list of tests that are in a running state. If you have tests that intermittently take a long time to run and have a generous timeout value (or the timeout is failing to activate due to the state of the test), WaitForEngineWorkCompleted can fail.

When this happens, try getting your agent to find which tests are running and inspect them for potential hanging. The agent does have the ability to forcefully terminate tasks, but that probably isn't a long term solution.

Something I will also add is that I've found that agents tend to be quite eager with their calls to WaitForEngineWorkCompleted by supplying very short timeout values. When working with large codebases I had to specifically tell the agent what a normal test cycle time was so that it wouldn't get stuck calling this function in a timeout loop and wasting tokens.

Edited

I think that I found the reason. When working with the console MCP, when the agent starts a new session, all the tests are launched which in my case is a long running task as I also have integration tests.

So I changed the console tool configuration file adding the flag
<TestsToExecuteAutomatically>False</TestsToExecuteAutomatically>


Now the session no longer hangs when started.

Edited

Post a reply

Log in to reply.