Skip to content

[Bug]: event_loop_delay 高延迟问题 — pdf-tool 同步初始化阻塞 Event Loop #76644

Closed

Description

@shmshz03

Bug type

Regression (worked before, now fails)

Beta release blocker

No

Summary

event_loop_delay 高延迟问题 — pdf-tool 同步初始化阻塞 Event Loop

环境

  • OpenClaw 版本: 2026.5.2
  • Node 版本
  • 操作系统: Linux (arm64, 4核)
  • ** Channel**: wecom

问题描述

每次收到请求时,core-plugin-tools 阶段耗时 13–18 秒,其中 pdf-tool(document-extract 插件)固定占用 10–12 秒,且以同步阻塞方式运行,导致 Node.js Event Loop 长时间卡住,触发 liveness warning: reasons=event_loop_delay。

Steps to reproduce

  1. 启动 OpenClaw 2026.5.2,连接企业微信 channel
  2. 发送任意文字消息
  3. 观察 Gateway 日志,出现大量 liveness warning: reasons=event_loop_delay

Expected behavior

pdf-tool 的初始化或文件提取操作能改为异步执行,或者提供配置项将其延迟加载/缓存,避免每次请求都同步阻塞 10+ 秒。

参考 tools.media.asyncCompletion 已支持视频异步完成,可否为 pdf-tool 提供类似的异步模式?

Actual behavior

每次收到请求时,core-plugin-tools 阶段耗时 13–18 秒,其中 pdf-tool(document-extract 插件)固定占用 10–12 秒,且以同步阻塞方式运行,导致 Node.js Event Loop 长时间卡住,触发 liveness warning: reasons=event_loop_delay。

OpenClaw version

2026.5.2

Operating system

Linux (arm64, 4核)

Install method

NODE 版本 v24.14.0

Model

Minimax

Provider / routing chain

openclaw

Additional provider/model setup details

No response

Logs, screenshots, and evidence

**典型 trace 数据:**

| 请求时刻 | core-plugin-tools 总耗时 | 其中 pdf-tool | eventLoopDelayMax |
|---------|------------------------|--------------|------------------|
| 10:28:10 | 18,747 ms | 11,760 ms | — |
| 10:32:36 | 15,936 ms | 11,760 ms | — |
| 10:54:33 | 13,032 ms | 10,746 ms | 13 s |
| 11:06:41 | 13,682 ms | 11,338 ms | 13 s |

即使没有实际使用 PDF 工具,每次请求都会经历完整的 `pdf-tool` 初始化链路,`eventLoopUtilization` 冲到 0.9–1.0,但 `cpuCoreRatio` 仅 0.5–1.1(说明瓶颈在 I/O 等待而非 CPU 计算)。

Impact and severity

受影响: 2026.5.2
严重程度: 启动耗时

Additional information

No response

Activity

  1. added
    bug
    on May 3, 2026
  2. clawsweeper commented on May 3, 2026

    @clawsweeper
    Contributor

    Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve.

    Summary
    Keep open. Current main still builds the PDF tool during the core tool-prep hot path, and the reported release has identical code, so the per-request stall is plausible; the exact 10-12s root cause still needs live validation because current source only imports pdfjs-dist during actual PDF extraction.

    Reproducibility: unclear. there is not yet a high-confidence live reproduction of the reported 10-12s WeCom/Linux arm64 stall. Source inspection does show the PDF tool is rebuilt on the request hot path and performs immediate model/auth resolution, so the performance bug is source-reproducible enough to keep open.

    Next step
    This is a focused performance repair candidate, but not an automatic high-confidence bugfix because the live 10-12s stall was not reproduced in the review environment.

    Review details

    Best possible solution:

    Make PDF tool registration cheap on every agent turn by caching scoped availability/model/auth resolution or deferring expensive discovery, while keeping pdfjs-dist and canvas loading confined to actual PDF execution.

    Do we have a high-confidence way to reproduce the issue?

    Unclear: there is not yet a high-confidence live reproduction of the reported 10-12s WeCom/Linux arm64 stall. Source inspection does show the PDF tool is rebuilt on the request hot path and performs immediate model/auth resolution, so the performance bug is source-reproducible enough to keep open.

    Is this the best way to solve the issue?

    Unclear: adding a video-style async PDF completion mode or new config knob is not the narrowest first fix. The better first solution is to make PDF tool prep lazy/cached without changing PDF execution semantics.

    Acceptance criteria:

    • pnpm test src/agents/openclaw-tools.pdf-registration.test.ts src/agents/tools/pdf-tool.model-config.test.ts src/agents/tools/pdf-tool.test.ts src/media/document-extractors.runtime.test.ts src/plugins/document-extractors.runtime.test.ts
    • pnpm exec oxfmt --check --threads=1 src/agents/openclaw-tools.ts src/agents/tools/pdf-tool.ts src/agents/tools/pdf-tool.model-config.ts src/media/document-extractors.runtime.ts src/plugins/document-extractors.runtime.ts extensions/document-extract/document-extractor.ts
    • pnpm check:changed in Testbox before handoff if production code changes

    What I checked:

    • PDF tool is built on the agent-turn tool-prep path: createOpenClawTools calls createPdfTool(...) before marking openclaw-tools:pdf-tool, so that trace stage includes synchronous PDF tool construction on each tool build. (src/agents/openclaw-tools.ts:408, a92e2b13b8b8)
    • PDF tool construction performs model resolution immediately: createPdfTool calls resolvePdfModelConfigForTool before returning a tool object, so availability/model probing is on the hot path even when no PDF is used. (src/agents/tools/pdf-tool.ts:262, a92e2b13b8b8)
    • PDF model resolution probes provider/auth candidates: The resolver checks Google/default-provider auth and enumerates native/generic image candidates, which is the likely source area for repeated request-time cost. (src/agents/tools/pdf-tool.model-config.ts:76, a92e2b13b8b8)
    • Document extraction dependency load is deferred to extraction: The document-extract plugin caches pdfjs-dist behind loadPdfJsModule() and calls it from extractPdfContent, which is reached during actual PDF extraction rather than PDF tool registration. (extensions/document-extract/document-extractor.ts:67, a92e2b13b8b8)
    • Reported release and current main match on the relevant files: The relevant PDF tool/document-extract blobs are identical between v2026.5.2 and current HEAD, and git diff v2026.5.2..HEAD is empty for those paths. (8b2a6e57fef6)
    • Liveness warning threshold is consistent with the report: Diagnostics classify event_loop_delay when p99 or max event-loop delay reaches the configured 1000ms threshold; the reporter's 10-13s samples exceed that threshold substantially. (src/logging/diagnostic.ts:58, a92e2b13b8b8)

    Likely related people:

    • buyitsydney: Current-main blame for the PDF tool registration, createPdfTool, PDF model resolver, and document-extractor runtime points to commit 2ffdb5d248, which adds the relevant files in this checkout. (role: current-main path owner; confidence: medium; commits: 2ffdb5d248a1; files: src/agents/openclaw-tools.ts, src/agents/tools/pdf-tool.ts, src/agents/tools/pdf-tool.model-config.ts)
    • Peter Steinberger: The reported v2026.5.2 tag is commit 8b2a6e57fe, authored by Peter Steinberger, and that tag first ships identical blobs for the relevant PDF/document-extract paths in this checkout. (role: release introducer/maintainer; confidence: medium; commits: 8b2a6e57fef6; files: src/agents/openclaw-tools.ts, src/agents/tools/pdf-tool.ts, src/agents/tools/pdf-tool.model-config.ts)

    Remaining risk / open question:

    • No live WeCom/Linux arm64/Node 24 reproduction was run, so the reported 10-12s latency remains reporter-observed rather than locally measured.
    • The report attributes the stall to document-extract/pdfjs-dist, but source inspection shows pdfjs-dist is loaded only during actual PDF extraction; a fix should measure the expensive prep-time call before changing plugin APIs.

    Codex review notes: model gpt-5.5, reasoning high; reviewed against a92e2b13b8b8.

  3. mkdev5 commented on May 3, 2026

    @mkdev5
    Contributor

    @steipete Is this issue intended to be solved by #73039, or would you accept a narrower PDF-only PR that avoids repeated PDF model/auth resolution during createOpenClawTools?

  4. added a commit that references this issue on May 3, 2026
    02b1075
  5. added a commit that references this issue on May 6, 2026
    062e3f3
  6. locked as resolved and limited conversation to collaborators on May 6, 2026
  7. added a commit that references this issue on May 24, 2026
    cb295be
  8. added a commit that references this issue on Jun 2, 2026
    62b3414
  9. added a commit that references this issue on Jun 10, 2026
    a4642f2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions