Reapply "修复菜单插件超时拖慢主链路问题"

This reverts commit 34adefa931.
This commit is contained in:
Liu
2026-05-01 12:45:29 +08:00
parent 994f452b99
commit 47d623e4a4
5 changed files with 51 additions and 11 deletions

View File

@@ -87,6 +87,18 @@ class RobotMenuPlugin(MessagePluginInterface):
self.image_render_retries = int(
self._config.get("RobotMenu", {}).get("image_render_retries", 1)
)
# 菜单命令属于强交互型消息:
# 1. 用户输入“菜单”后,不能允许单次渲染长期霸占消息处理协程;
# 2. 因此这里单独定义“主链路同步等待预算”,超出后立即由渲染工具降级;
# 3. 该预算默认比底层图片渲染超时短很多,优先保障机器人整体吞吐稳定。
self.sync_send_timeout_seconds = int(
self._config.get("RobotMenu", {}).get("sync_send_timeout_seconds", 18)
)
# 对外层插件保护显式声明一个更合适的总超时:
# 1. 内层菜单发送会在 sync_send_timeout_seconds 内决定“成功发图 / 回退文本 / 返回失败提示”;
# 2. 外层 wait_for 必须比内层稍长,给降级发送文本留出缓冲;
# 3. 这样可以避免过去“内外层都卡在 55 秒”时,外层先打断,导致降级逻辑来不及执行。
self.plugin_process_timeout_seconds = max(12, self.sync_send_timeout_seconds + 8)
# 菜单图片模板文件路径(相对仓库根目录):
# 调整样式和布局时只改模板,不改 Python 逻辑。
self.image_template_path = str(
@@ -101,6 +113,7 @@ class RobotMenuPlugin(MessagePluginInterface):
image_fallback_to_text=self.image_fallback_to_text,
image_render_timeout_seconds=self.image_render_timeout_seconds,
image_render_retries=self.image_render_retries,
sync_send_timeout_seconds=self.sync_send_timeout_seconds,
image_template_path=self.image_template_path,
log=self.LOG,
)