matplotlib hook初始化90秒+导致环境频繁超时卡死

灵犀claw环境卡死bug反馈.md

【Bug反馈】Python sandbox 中 matplotlib hook 初始化极慢(60-96秒),导致环境频繁超时卡死

环境信息

  • 灵犀Claw版本:v1.1.23

  • 操作系统:Windows Server

  • 系统内存:24GB(可用9.7GB,不存在内存不足)

  • 问题时间:2026年5月中旬至今持续发生

问题描述

每次新会话或代码执行时,Python sandbox 冷启动后 matplotlib hook 初始化极慢(60-96秒),期间触发心跳超时 → 中断无效 → 进程强杀 → 重试 → 再次卡死 → 连续超时,最终导致整个执行环境"卡死"。大量正常任务因此被 600 秒总超时强杀。

复现步骤

  1. 发起任意需要执行 Python 代码的对话(尤其是涉及 openpyxl/pandas 等常规库的操作)

  1. sandbox 冷启动 Python 执行器

  1. matplotlib hook 开始初始化(扫描系统字体、注册 290 个字体)

  1. 等待 60-96 秒 → 心跳超时 → 强杀 → 环境卡死

日志证据

1. matplotlib hook 初始化耗时分布(2026-06-01 当天)

指标

数值

初始化总次数

58次

最快

0.7秒

中位数

12.8秒

最慢

96.4秒

超过 30秒

13次

超过 60秒

11次

超过 90秒

10次

2. 典型卡死链条(日志原文)

06:52:27 [Executor-py] plotly hook 已安装 (610ms)
06:53:27 [Executor-py] hooks 初始化超时(60s),继续执行,部分功能(matplotlib/plotly等)可能不可用
06:53:57 [Executor] 心跳超时 (90s),触发中断
06:54:03 [Executor-py] 已注册 290 个系统字体到 matplotlib
06:54:04 [Executor-py] matplotlib CJK 字体回退已配置
06:54:04 [Executor-py] matplotlib hook 已安装
06:54:04 [Executor-py] hook matplotlib 完成 (96375ms)    ← 单次96秒
06:54:13 [Executor-py] 已安装 281 个包 (105828ms)          ← 全部hook初始化105秒
06:54:13 [Executor-py] 全部 hook 初始化完成 (105828ms)
06:54:27 [Executor] 心跳超时 (90s),触发中断                ← 又触发超时

3. 近期每日超时统计

日期

hooks超时(60s)

matplotlib慢(>10s)

600s执行超时被杀

执行失败总数

05-17

0

0

0

108

05-19

0

26

23

21

05-20

0

46

83

71

05-21

15

0

52

94

05-24

12

0

46

46

05-25

8

0

33

28

05-26

16

6

56

51

05-28

4

28

11

76

05-29

8

35

32

142

05-30

8

29

20

154

05-31

2

21

8

29

06-01

11

32

38

119

影响范围

  • 系统资源充足(24GB内存、9.7GB可用),排除资源不足原因

  • 卡死与具体用户代码无关,纯 hook 初始化阶段阻塞

  • 中断信号无法打断字体扫描(阻塞操作),只能强杀进程

  • 连续超时后 sandbox 进入"连续2次超时"惩罚模式,限制更严

初步判断

matplotlib hook 在注册 290 个系统字体时耗时过长,大概率与字体扫描逻辑有关(可能是逐字体枚举而非缓存命中)。建议研发关注 hook matplotlib 完成已注册 X 个系统字体到 matplotlib 这两个日志点。

期望修复

  1. matplotlib hook 初始化时间降至正常水平(< 2秒)

  1. 或提供字体缓存持久化机制,避免每次冷启动重新扫描

  1. 心跳超时机制应对 hook 初始化阶段做豁免,避免误杀


日志来源:C:\Users\Administrator\AppData\Roaming\WPS 灵犀\logs\sandbox_*.log
辽宁省
浏览 34
收藏
2
分享
2 +1
1
+1
全部评论 1
 
千钰
他现在这个内置的Python 确实容易卡死 目前只有退出重进 之前还能在任务管理器关闭Python进程解决 现在不行了
· 河南省
回复