Skip to content

fix: pass tool_call_timeout to shell.exec for configurable shell timeout#7310

Draft
sunnyyangyangyang wants to merge 1 commit intoAstrBotDevs:masterfrom
sunnyyangyangyang:fix-shell-timeout
Draft

fix: pass tool_call_timeout to shell.exec for configurable shell timeout#7310
sunnyyangyangyang wants to merge 1 commit intoAstrBotDevs:masterfrom
sunnyyangyangyang:fix-shell-timeout

Conversation

@sunnyyangyangyang
Copy link
Copy Markdown

@sunnyyangyangyang sunnyyangyangyang commented Apr 2, 2026

PR 描述(Draft)


Modifications / 改动点

修复了 astrbot_execute_shell 工具的超时时间配置功能,使得用户可以通过管理面板中的"工具调用超时时间(秒)"设置来控制 shell 执行的超时时间。

问题描述

  • 之前 ExecuteShellTool 调用 shell.exec() 时,没有传递 timeout 参数,导致始终使用接口默认的 30 秒超时
  • 用户即使将 tool_call_timeout 设置为 600 秒,shell 执行仍然是 30 秒就超时

修复方案

  • context.tool_call_timeout 获取配置的超时时间
  • tool_call_timeout 传递给 shell.exec()timeout 参数

修改文件

  • astrbot/core/computer/tools/shell.py
--- a/astrbot/core/computer/tools/shell.py
+++ b/astrbot/core/computer/tools/shell.py
@@ -58,7 +58,11 @@ class ExecuteShellTool(FunctionTool):
                 context.context.event.unified_msg_origin,
             )
         try:
-            result = await sb.shell.exec(command, background=background, env=env)
+            # 从上下文获取工具调用超时时间配置,传递给 shell.exec
+            timeout = context.tool_call_timeout
+            result = await sb.shell.exec(
+                command, background=background, env=env, timeout=timeout
+            )
             return json.dumps(result)
         except Exception as e:
             return f"Error executing command: {str(e)}"
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

注意:这是一个 Draft PR,目前代码尚未经过实际测试。

测试步骤建议:

  1. 在管理面板中设置 tool_call_timeout 为较大值(如 600)
  2. 使用 astrbot_execute_shell 工具执行一个耗时较长的命令
  3. 验证 shell 执行是否能在 30 秒后继续运行,直到达到配置的超时时间

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 My changes do not introduce malicious code.

状态:Draft PR - 待测试

Summary by Sourcery

Bug Fixes:

  • Ensure astrbot_execute_shell uses the context-provided tool_call_timeout value when invoking shell.exec so long-running commands respect the configured timeout.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the shell tool to incorporate a configurable timeout for command execution by passing context.tool_call_timeout to the sb.shell.exec method. The review feedback suggests simplifying the implementation by removing the intermediate variable and the Chinese comment to improve code clarity and maintain style consistency.

Comment on lines +61 to +65
# 从上下文获取工具调用超时时间配置,传递给 shell.exec
timeout = context.tool_call_timeout
result = await sb.shell.exec(
command, background=background, env=env, timeout=timeout
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

建议移除冗余的中间变量和中文注释,直接将 context.tool_call_timeout 传递给 sb.shell.exec。根据 Google Python 风格指南,代码注释应使用英文以保持一致性,且此处代码逻辑已足够清晰,无需额外注释。

            result = await sb.shell.exec(
                command, background=background, env=env, timeout=context.tool_call_timeout
            )
References
  1. Google Python Style Guide 建议所有注释都应使用英文,以保持代码库的一致性。 (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant