zai-org / zai-org/feedback

[Bug] ZCode 3.7.7 macOS:打开含数十 GB 媒体的工作区后 zcode-host-local-1 因 RangeError: Failed to allocate memory 崩溃;settingService 读失败后把默认值写回,清空 recentProjects / provider

Open
#292 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

priority: P2 status: 待评估 type: Bug
Dominant language
No language data
Stars
22
Forks
1
PR merge metrics
No merged PRs in 30d

Description

提交前确认 · Pre-submission checklist
  • 我已搜索过现有 issue,确认这不是重复 / I searched existing issues and confirmed this isn't a duplicate.
  • 我已阅读 CONTRIBUTING.md / I've read CONTRIBUTING.md.
问题类别 · Category

稳定性 / 崩溃 · Stability / Crash

涉及的 Agent 框架 · Agent framework

ZCode Agent(自研)

严重程度 · Severity

阻塞使用 · Blocking (无法使用核心功能 / core function unusable)

复现频率 · Reproducibility

必现 · Always

问题描述 · Description

Related: https://github.com/zai-org/feedback/issues/183

环境

  • OS: macOS 26.6.1 (25G76), Apple M5 Pro, arm64, 24 GB RAM
  • ZCode: 3.7.7 (3.7.7.4926),安装于 2026-08-14
  • Electron: 41.0.3 (Chrome/146.0.7680.80)
  • Host 内置 Node: v24.14.0(与 #183 相同)
  • 模型:自定义 Kimi Coding(https://api.kimi.com/codingk3-256k)+ 内置 BigModel coding-plan
  • 数据目录:~/.zcode/(未删除)。tasks-index.sqlite / cli/db/db.sqlitePRAGMA integrity_check 均为 ok

现象

  1. 窗口还在,但聊天 / 工作区空白,看起来像「记录全没了」。
  2. 实际数据还在。是 zcode-host-local-1(Electron node.mojom.NodeService utility)反复崩掉,主窗口变成空壳。
  3. 崩溃当天 ~/.zcode/v2/logs/2026-08-17.log
    • host process (local-1) exited12 次
    • Failed to allocate memory134 次
    • settingService read failed, returning defaults75 次
  4. 机器并不是 OOM。崩溃时 heapUsed 约 50 MB,rss 约 400–900 MB;process.memoryUsage().external 稳定在 ~8.0 GiB(例如 8605331842)。setting.json 本身只有约 2 KB。
  5. 更严重的副作用settingService 读失败后返回默认值,并立刻 write~/.zcode/v2/setting.json。日志里能看到 recentProjects 被写成 []modelProviderFamilyModes / modelProviderFamilySelectedKeys 被清空,providerFamilyDomainMigrated 被打成 false。UI 随后出现未配置 / providerCount: 0。这是真实的设置覆盖,不是单纯崩溃。

复现步骤

时间线(均为 2026-08-17,东八区):

时间 事件
09:19 同一主进程(从 08-14 一直开着)仍正常,subscribeSessionsIndexV4 OK
10:27:29.505 打开含大文件的工作区,agent pid 拉起
10:27:29.894 首次 RangeError: Failed to allocate memory(读 setting.json
10:27:29.896 把默认设置写回磁盘(recentProjects: []
10:27:35.617 zcode-host-local-1 exit 6;child-process-gone
10:31–14:19 至少 12 次新 spawn,多数秒崩
14:35 左右 从该工作区删掉那几十 GB 媒体目录(目录剩约 5 GB 模型/venv)
14:28 起的 host 之后连续 setting.update OK / resyncConversationV4 OK,未再出现该 RangeError

缓解(已验证)

从该工作区删掉那几十 GB 媒体后,当前 host 恢复正常(setting.update OK)。没有删除 ~/.zcode,也没有按 #183 那样 UPDATE tasks SET deleted=1
仍建议:不要把媒体 / 模型 / .venv 放进 ZCode 工作区;lastWorkspaceSession 不要一次恢复多个含大文件的项目。

建议修复

与 #183 相同,再加上设置保护:

  1. 文件读取 / 工具输出做体积上限与二进制检测,禁止把整文件缓冲进 host 堆。
  2. 解压流、allocUnsafe 失败要 catch,不要变成未处理异常把 host 打死。
  3. settingService 读失败时禁止把 defaults 写回磁盘。 应保留原文件,只在内存里降级,并打明确错误。
  4. 启动恢复多个工作区时,对超大目录做延迟 / 只读元数据,避免一启动就扫几十 GB。
复现步骤 · Steps to reproduce
  1. 工作区目录内有大量二进制(本机是媒体 / 模型,打开前约 37 GB:mp4、whisper 权重、torch .dylib 等)。
  2. ZCode 已开着多个项目 tab(本机 lastWorkspaceSession 恢复 7 个工作区)。
  3. 新开该大目录为项目,并拉起 agent(本机是 Kimi k3-256k)。
  4. 约 400 ms 内 settingService 读 2 KB 的 setting.json 失败(Buffer.allocUnsafeSlow),随后 host exited with code 6
  5. 之后每次启动都会把该工作区放回 lastWorkspaceSession 第一项,host 多数在 1–5 秒内再崩。重启 / 关机再开都一样。回退到 3.7.5 无意义(同一 Electron 41.0.3)。
期望表现 · Expected behavior
  • Agent / 索引不应把工作区里的大二进制整段读进 host 的 V8 堆。
  • 单次分配失败不应杀死整个 zcode-host-local-1,更不应把默认设置写回覆盖用户配置。
  • 聊天 / 工作区面板在 host 重启期间应保留或明确报错,而不是空白到像数据被删。
实际表现 · Actual behavior

Host 堆被耗尽后,连读 2 KB 设置、构造 Brotli 解压器都失败;窗口变空壳;设置被默认值覆盖。sqlite 完好,用户会误以为记录丢了。

ZCode 版本 · ZCode version

v3.7.7

设备 / 系统 / 浏览器 · Device / OS / Browser

macOS 26.6.1 (25G76)

截图 / 录屏 / 日志 · Screenshots / Recordings / Logs

第一次失败(打开大工作区后约 400 ms,读 2 KB 设置):
RangeError: Failed to allocate memory at createUnsafeBuffer (node:internal/buffer:1095:25) at Buffer.allocUnsafeSlow (node:buffer:447:10) at readFileHandle (node:internal/fs/promises:540:23) at async readSettingsWithMeta (.../app.asar/out/host/index.js:57:5837) at async readSettings (.../app.asar/out/host/index.js:57:6624) at async runUpdate (.../app.asar/out/host/index.js:57:7802)

随后立即把默认值写回:
[settingService] read failed, returning defaults. [settingService] writing settings to: ~/.zcode/v2/setting.json {"recentProjects":[],"modelProviderFamilyModes":{},"modelProviderFamilySelectedKeys":{}, ...}

后续 HTTPS(Brotli)路径,与 #183 同栈:
RangeError: Failed to allocate memory at createUnsafeBuffer (node:internal/buffer:1095:25) at Buffer.allocUnsafe / allocate at BrotliDecompress.ZlibBase ... at Object.onHeaders (node:internal/deps/undici/undici) code: ERR_MEMORY_ALLOCATION_FAILED

host 记账(不是系统 OOM):
contained host allocation failure from native TLS callback {"arrayBuffers":0,"external":8605331842,"heapUsed":50862976,"message":"Failed to allocate memory","origin":"uncaughtException","rss":493715456}

进程退出:
host process (local-1) exited with code 6 child-process-gone: {"type":"Utility","reason":"crashed","exitCode":6,"serviceName":"node.mojom.NodeService","name":"zcode-host-local-1"}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ~/.zcode/v2/logs/2026-08-17.log and the stack traces for readSettingsWithMeta, readSettings, runUpdate, and settingService; the reported bundle path is app.asar/out/host/index.js. Reproduce with a workspace containing large binary files and multiple restored projects. Done means the host no longer crashes during this flow and a settings read failure does not overwrite setting.json with defaults.

Written by the indexing model from the issue text.

Assessment

Tech stack
electron, node.js
Domain
backend, desktop
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.