[Bug] ZCode 3.7.7 macOS:打开含数十 GB 媒体的工作区后 zcode-host-local-1 因 RangeError: Failed to allocate memory 崩溃;settingService 读失败后把默认值写回,清空 recentProjects / provider
Nobody has claimed this yet.
- 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/coding,k3-256k)+ 内置 BigModel coding-plan - 数据目录:
~/.zcode/(未删除)。tasks-index.sqlite/cli/db/db.sqlite的PRAGMA integrity_check均为ok
现象
- 窗口还在,但聊天 / 工作区空白,看起来像「记录全没了」。
- 实际数据还在。是
zcode-host-local-1(Electronnode.mojom.NodeServiceutility)反复崩掉,主窗口变成空壳。 - 崩溃当天
~/.zcode/v2/logs/2026-08-17.log:host process (local-1) exited:12 次Failed to allocate memory:134 次settingService read failed, returning defaults:75 次
- 机器并不是 OOM。崩溃时
heapUsed约 50 MB,rss约 400–900 MB;process.memoryUsage().external稳定在 ~8.0 GiB(例如8605331842)。setting.json本身只有约 2 KB。 - 更严重的副作用:
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 相同,再加上设置保护:
- 文件读取 / 工具输出做体积上限与二进制检测,禁止把整文件缓冲进 host 堆。
- 解压流、
allocUnsafe失败要 catch,不要变成未处理异常把 host 打死。 settingService读失败时禁止把 defaults 写回磁盘。 应保留原文件,只在内存里降级,并打明确错误。- 启动恢复多个工作区时,对超大目录做延迟 / 只读元数据,避免一启动就扫几十 GB。
复现步骤 · Steps to reproduce
- 工作区目录内有大量二进制(本机是媒体 / 模型,打开前约 37 GB:mp4、whisper 权重、torch
.dylib等)。 - ZCode 已开着多个项目 tab(本机
lastWorkspaceSession恢复 7 个工作区)。 - 新开该大目录为项目,并拉起 agent(本机是 Kimi
k3-256k)。 - 约 400 ms 内
settingService读 2 KB 的setting.json失败(Buffer.allocUnsafeSlow),随后 hostexited with code 6。 - 之后每次启动都会把该工作区放回
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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