修复 worker 线程 OOM 拖垮整个应用的崩溃(git 输出无上限撑爆 V8 地址笼)#94
Open
siyuan-123 wants to merge 9 commits into
Open
Conversation
… versioning checks
崩溃取证(三次同点崩溃 chrome.dll OOM 自杀,系统内存充足)锁定根因: git/diff worker 线程执行 review-summary 等任务时,git 命令输出无上限 (如 ls-files 枚举超大目录的全部未跟踪文件),几百 MB 巨型字符串涌入 V8 堆,撑爆多 isolate 共享的 4GB 指针压缩地址笼,进程主动 OOM 崩溃。 新增三层防线补丁(均已加入 patch-all 常驻): - patch-git-output-cap.js:git 执行器输出兜底上限 32MB,覆盖 worker.js 与共享库副本,超限走现成的错误处理路径,任务报错但应用不死 - patch-diff-limits.js:单条 diff 输出上限 32MB 收紧到 8MB,超大 diff 走已有 diff-too-large 分支 - patch-worker-limits.js:worker 线程加 resourceLimits 老生代 1024MB 优雅上限,失控时 worker 自行 OOM 退出并被自动重建 取证增强(定位真凶的关键手段,保留用于后续诊断): - patch-crash-forensics.js 升级 V3:主进程内存水位快照、进程矩阵、 截图活动追踪、自适应采样 - patch-worker-forensics.js 升级 V3:worker 线程内存自采样、V8 堆 空间分布、RPC 任务归因(内存暴涨时日志直接给出正在执行的任务名) 实测:同款 review 重负载下老包 2 分钟内崩溃,新包 36 分钟稳定运行, 超大输出被截停后内存即时回收。 Co-authored-by: Cursor <cursoragent@cursor.com>
Reviewer's GuideAdds multi-layer protections and forensics around worker/main-process memory to prevent V8 OOM in git/diff workers, hardens build/sync pipelines and packaging, and introduces several targeted behavior patches (fast mode gating, workspace roots, Sentry scope, CDP screenshots, etc.) across scripts and CI. Sequence diagram for review-summary worker with git output cap and worker limitssequenceDiagram
actor User
participant MainProcess as main-*.js
participant WorkerManager as ensureWorker
participant Worker as worker.js
participant Git as git
participant Forensics as __codexWorkerForensics
User->>MainProcess: Trigger review-summary
MainProcess->>WorkerManager: ensureWorker()
WorkerManager->>Worker: new Worker(worker.js,{...,resourceLimits})
WorkerManager-->>MainProcess: worker ready
MainProcess->>Worker: {type:worker-request, method:review-summary}
Worker->>Forensics: track in-flight task
Worker->>Git: $(cmd, {maxOutputBytes:l=33554432})
alt git output <= 32MB & diff <= 8MB
Git-->>Worker: stdout (<=32MB)
Worker-->>MainProcess: {type:worker-response, result}
Forensics-->>Forensics: sample wmem#, heapUsedMB
else git output > 32MB or diff > 8MB
Git-->>Worker: outputLimitExceeded
Worker-->>MainProcess: diff-too-large / outputLimitExceeded
Forensics-->>Forensics: WORKER-HIGH wmem#, WORKER-HEAP-SPACES
end
alt Worker heap > 1024MB old_space
Worker--xWorker: ERR_WORKER_OUT_OF_MEMORY (resourceLimits)
WorkerManager->>WorkerManager: worker exit handler
WorkerManager->>WorkerManager: ensureWorker() (auto-recreate)
Forensics-->>Forensics: log last tasks & heap spaces
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Fixed security issues:
- Command injection from untrusted input passed to child_process commands (link)
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
Windows 版长时间使用中反复出现整个应用崩溃(进程直接消失)。对三次崩溃的 minidump 与自建取证日志分析后确认为同一根因:
chrome.dll同一条指令,属于 Chromium/V8 主动 OOM 崩溃(分配失败后写空指针自杀),且崩溃时系统内存充足(物理剩余 13GB、commit 剩余 22GB),进程自身 commit 仅 1.7~3GB;worker.js(git/diff worker 线程):执行review-summary等任务时,git 命令输出没有大小上限——例如git ls-files --others在超大目录(用户授权扫描 C 盘一类场景)会把几十万个文件路径拼成几百 MB 的单条 stdout 巨型字符串读进 JS;large_object_space破 1GB),最终撑爆同进程全部 isolate 共享的 4GB 指针压缩地址笼(pointer compression cage),进程整体崩溃。崩溃前最后的取证采样(任务归因直接点名):
修复(三层防线)
patch-git-output-cap.jsmaxOutputBytes解构加兜底默认值 32MB(覆盖worker.js与src-*.js共享库副本各一处)ls-files)超限即截停,走现成的outputLimitExceeded错误路径;正常仓库输出仅几 MB 无感patch-diff-limits.jsA1从 32MB 收紧到 8MBdiff-too-large分支被跳过/提示,不再全量入内存patch-worker-limits.jsresourceLimits(老生代 1024MB)三个补丁均:锚点唯一校验、注入前 acorn 语法校验、幂等可重复执行,并已加入
patch-all.js。附带:取证基础设施升级(定位本问题的关键手段)
patch-crash-forensics.jsV3:主进程内存水位快照(2.2GB/2.8GB 双水位)、全进程矩阵、截图活动追踪、自适应采样频率;patch-worker-forensics.jsV3:worker 线程内存自采样、V8 堆空间分布、RPC 任务归因——每条采样带task=[任务名(运行秒数)],高水位时补最近完成任务列表,内存暴涨瞬间即可从日志锁定肇事任务。纯观测设计(额外 message listener +
postMessage透传包装),不改变业务行为;日志按天滚动,重负载一天约 700KB,开销可忽略。验证
review-summary并行 + 超大目录):修复前 1~10 分钟内必崩;修复后 36 分钟稳定运行,日志可见超大输出被截停(任务取消、外部缓冲 510MB 峰值 5 秒内回收),单个任务从卡死 60 秒变为数百毫秒返回;Summary by Sourcery
Harden Codex Desktop against worker-thread OOM crashes, add rich crash/forensics tooling, and improve build/CI workflows and packaging behavior across platforms.
New Features:
Bug Fixes:
Enhancements:
Build:
CI:
Deployment:
Documentation:
Chores: