Skip to content

Shell commands silently fail (exit code 1, no output) when skills contain node_modules #3289

@kevinjqy

Description

@kevinjqy

What happened?

Bug 描述

Shell 命令(如 !pwd!ls)静默失败,返回 exit code 1 且无任何输出。但命令实际已执行(例如写文件操作可以成功),只是 stdout/stderr 未被捕获。

根因

packages/core/src/skills/skill-manager.ts 中的 updateWatchersFromCache() 方法调用 chokidar watch()未设置 ignored 选项

const watcher = watchFs(watchPath, {
  ignoreInitial: true,
  // ❌ 没有 `ignored` 选项 —— chokidar 会递归监听所有子目录,包括 node_modules
})

当 skill 目录(如 ~/.agents/skills/~/.qwen/skills/)中包含 node_modules 时,chokidar 会递归监听其中的所有文件,导致大量 FD(文件描述符)泄漏:

$ lsof -p <qwen-code-pid> | wc -l
15256   # 远超 ulimit -n(通常为 4096)

$ lsof -p <qwen-code-pid> | grep REG | awk '{print $9}' | sort | uniq -c | sort -rn | head -5
  438  .../node_modules/.../electron/dist/Electron.app/...
  12   .../node_modules/color-name/package.json
  12   .../node_modules/color-name/index.js
  ...

FD 耗尽后,node-pty.spawn() 可以成功创建进程,但 onData/onExit 回调永远不会被触发。进程最终超时,返回 exitCode: 1 且输出为空。

What did you expect to happen?

shell-command 正常执行

Client information

复现步骤

  1. 安装一个包含大型 node_modules 的 skill(例如依赖了 electron 的 skill)

  2. 启动 qwen-code

  3. 执行任意 shell 命令:

    > !pwd
    
  4. 期望结果:正常输出当前目录路径

  5. 实际结果Command exited with code 1. (Command produced no output)

Login information

No response

Anything else we need to know?

No response

Metadata

Metadata

Assignees

Labels

status/needs-triageIssue needs to be triaged and labeledtype/bugSomething isn't working as expected

Type

No type
No fields configured for issues without a type.

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions