{"record":{"id":"80a7841939977180","repo":"theonedev/onedev","slug":"timed-out-calling-tool-toolname","errorCode":null,"errorMessage":"Timed out calling tool: ${toolName}","messagePattern":"Timed out calling tool: (.+?)","errorType":"exception","errorClass":"ExplicitException","httpStatus":null,"severity":"warning","filePath":"server-core/src/main/java/io/onedev/server/ai/DefaultChatService.java","lineNumber":338,"sourceCode":"\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\tString toolName = toolRequest.name();\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tvar toolExecution = new AiToolExecution(toolName, ToolUtils.getToolArguments(toolRequest));\n\t\t\t\t\t\t\t\t\t\t\tconnection.sendMessage(toolExecution);\n\t\t\t\t\t\t\t\t\t\t\tvar toolExecutionFuture = toolExecution.getFuture();\n\t\t\t\t\t\t\t\t\t\t\tif (toolExecutionFuture == null)\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Tool not found: \" + toolName);\n\t\t\t\t\t\t\t\t\t\t\twhile (true) {\n\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\tvar toolExecutionResult = toolExecutionFuture.get(1, TimeUnit.SECONDS);\n\t\t\t\t\t\t\t\t\t\t\t\t\ttoolExecutionResult.addToMessages(langchain4jMessages, toolRequest);\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t\t} catch (TimeoutException e) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (responseFuture.isDone())\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t\t} catch (CancellationException e) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t// may get cancelled in DefaultManagedFutureService\n\t\t\t\t\t\t\t\t\t\t\t\t\tthrow new ExplicitException(\"Timed out calling tool: \" + toolName);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t} catch (Throwable t) {\n\t\t\t\t\t\t\t\t\t\t\tToolUtils.handleCallException(toolName, t);\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tif (responseFuture.isDone())\n\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tvar handler = newResponseHandler(SecurityUtils.getSubject());\n\t\t\t\t\t\t\t\t\tvar langchain4jChatRequest = ChatRequest.builder()\n\t\t\t\t\t\t\t\t\t\t\t.messages(new ArrayList<>(langchain4jMessages))\n\t\t\t\t\t\t\t\t\t\t\t.toolSpecifications(toolSpecifications)\n\t\t\t\t\t\t\t\t\t\t\t.build();\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t\tstreamingChatModel.chat(langchain4jChatRequest, handler);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\t// No tool calls. If the assistant produced text, use it","sourceCodeStart":320,"sourceCodeEnd":356,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/ai/DefaultChatService.java#L320-L356","documentation":"While waiting for the browser/client to execute a requested tool and return its result, the future can be cancelled (e.g. by DefaultManagedFutureService when the enclosing task is cancelled). The service converts this CancellationException into an ExplicitException reporting the tool call as timed out.","triggerScenarios":"During the toolExecutionFuture.get(1, SECONDS) retry loop, a CancellationException is thrown because the overall chat future was cancelled while awaiting the client tool result.","commonSituations":"User cancels the AI conversation while a tool call is pending; server-managed future cancelled due to task timeout or node shutdown; client takes too long executing the tool so the manager cancels the request.","solutions":["Avoid cancelling the conversation while a tool call is in progress, or expect this error as the outcome of cancellation","Check DefaultManagedFutureService timeout settings if tool executions legitimately take longer than the managed limit","Retry the conversation; the tool execution state is discarded on cancel","Ensure the client executes and returns tool results promptly"],"exampleFix":"// before: user cancels mid-tool-call -> 'Timed out calling tool: x'\n// after: disable the cancel button while a tool call is pending\nchatUi.setCancelEnabled(!chatState.isAwaitingToolResult());","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    chatService.chat(chatId, prompt);\n} catch (ExplicitException e) {\n    if (e.getMessage().startsWith(\"Timed out calling tool: \")) {\n        // treat as cancellation: clean up UI state and allow retry\n    }\n}","preventionTips":["Don't cancel conversations while a tool call is pending","Ensure the client executes tool results promptly","Review managed future timeout settings for long-running tools"],"tags":["ai-tools","timeout","cancellation"],"backgroundTag":"request-timeout","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}