feat(engine): 运行日志落盘 + 崩溃可见性 - #47
Open
AmberCXX wants to merge 1 commit into
Open
Conversation
engine 的 log() 此前只写 stderr,而 MCP 宿主通常只在连接建立那一刻捕获 stderr——启动之后打印的任何东西都不再被记录。进程一旦异常退出,线索为零。 实测(2026-09-03):engine 在 00:00-03:00 之间消失,宿主日志无断开记录、 系统无崩溃报告、无内存压力事件,调度静默停摆 10 小时 31 分、漏跑 12 个任务, 事后无从判断死因。 改动: - log()/logError() 同时追加到 <DATA_DIR>/engine.log,超 2MB 转存 .log.1 - 新增 logFatal(),带完整堆栈落盘 - 注册 uncaughtException / unhandledRejection:记录后 stopScheduler() 释放 PID 锁并 exit(1) 两处取舍写在注释里: - 抓到异常后退出而非续跑——状态可能已损坏,错误的推送比没有推送更坏 - 不做自动重起——多实例 + 自动重起 + 抢 PID 锁是本项目已踩过的坑; 恢复由外部检测触发人工重连,engine 自己不做进程管理 验证:tsc --noEmit 通过 · bun test 19 pass · 临时 DATA_DIR 实测日志落盘、 FATAL 带堆栈、2MB 轮转生效 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EWhZ8wD8Ne5yiYaCdL6cjf
AmberCXX
added a commit
to AmberCXX/forge-hub
that referenced
this pull request
Sep 7, 2026
同上:本地 main 收敛为唯一运行版本。PR LinekForge#47 仍挂上游等合并。
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.
动机
engine 的
log()此前只写 stderr,而 MCP 宿主通常只在连接建立那一刻捕获 stderr —— 启动之后打印的任何东西都不再被记录。进程一旦异常退出,线索为零。实测(2026-09-03):engine 在 00:00–03:00 之间消失,宿主日志无断开记录、系统无崩溃报告、无内存压力事件,调度静默停摆 10 小时 31 分、漏跑 12 个任务,事后无从判断死因。
改动概要
log()/logError()同时追加到<DATA_DIR>/engine.log,超 2MB 转存.log.1(只留一份)logFatal(),带完整堆栈落盘uncaughtException/unhandledRejection:记录后stopScheduler()释放 PID 锁并exit(1)两处取舍(注释里写了理由)
抓到异常后退出而非续跑 —— 调度器状态可能已损坏,而状态损坏的调度器发出的推送比不推送更坏。
不做自动重起 —— 多实例 + 自动重起 + 抢 PID 锁是本项目已经踩过的坑(
cleanOrphans与一次性acquirePidLock的组合)。恢复由外部检测触发人工重连,engine 自己不做进程管理。影响范围
只加不改:日志多一个落盘目标,新增两个 process 事件监听,既有行为零变更。
DATA_DIR沿用FORGE_ENGINE_DATA环境变量,未引入新配置项。Self-test
bunx tsc --noEmit -p tsconfig.json→ 退出码 0bun test→ 19 pass / 0 failFORGE_ENGINE_DATA实测:日志落盘 ✅ · FATAL 带完整堆栈 ✅ · 2MB 轮转生效(原文件转.log.1,新文件重开)✅🤖 Generated with Claude Code