Repository navigation
fix(desktop): panic、窗口循环错误和致命崩溃全部接入统一日志 - #1955
Merged
Merged
Conversation
- logstore:新增 Store.RecordPanic,无锁 panicQueue 暂存恢复的 panic(最多 8 条,超出计入丢弃), Close 途中记录的也写进最后一次排空;事件 app.runtime.panic_interrupted。 - logstore:新增 Store.CaptureCrashes,用 debug.SetCrashOutput 把致命崩溃写进默认日志目录的 .crash/<会话名>;下次启动认领旧文件,记 app.session.previous_interrupted 或 close_missing, 失败记 app.session.crash_capture_failed。macOS 用 flock,Windows 用独占打开加 DELETE_ON_CLOSE。 - core:WatchCoreEvents 增加 recovered 回调;日志唤醒回调和请求事件观察者 recover 后交给写入器, 不再静默丢弃。新增 log_text.go(LogText、LogFirstLine、LogToken、LogPanicStack), LogErrorFields 共用截断。 - workbench:Run 在窗口循环期间安装 Viva fault handler,记为 viva:<位置>;窗口循环错误记 app.window.loop_failed,已由恢复的 panic 造成时不重复记录。 - cmd/lithe:ObserveCoreFacts 之后调用 CaptureCrashes。 - PINNED_CORE_REVISION 升到 Core fix/panic-logging 的 f4f3e93(事件声明与 Core panic hook)。 - develop-lithe 日志参考页补上 panic 与致命崩溃的记录入口。
…ging # Conflicts: # scripts/desktop/build-desktop-core.sh
This was referenced Nov 15, 2026
xiaoyumuxi
marked this pull request as ready for review
November 15, 2026 05:42
This was referenced Nov 15, 2026
2 tasks done
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.
关联 Issue / Linked issue
52c54e0)PR 类型 / Type
改动说明 / What changes
背景 / Why
#1949:新建项目对话框选中 Maven 后卡死(卡死本身已由 #1952 修复),但日志里什么也没有。排查发现,桌面端所有 panic 和崩溃路径都不经过统一日志:
main退出前写 stderr,打包后的应用没有 stderr。fatal error(例如并发写 map)只写 stderr,打包应用里完全丢失;被强制退出的会话也看不出来。改动 / Changes
恢复的 panic →
app.runtime.panic_interrupted(ERROR)logstore/panics.go(新增):Store.RecordPanic(boundary, value, stack)。panic 可能发生在持有写入器锁的线程上(ObserveCoreFacts持有s.mu时调用WatchCoreEvents),所以它不加锁:用无锁栈panicQueue暂存,最多 8 条,超出的计入丢弃数。Close开始后记录的 panic 也会写进最后一次排空。drain把它们和普通事件按时间合并后写入。boundary(token)、panic(文本,空值记<empty>)、stack(只保留 panic 调用之后的帧,每帧写成“函数 文件基名:行”)。core/log_text.go(新增):LogText、LogFirstLine、LogToken、LogPanicStack,限长并去掉不可见字符;LogErrorFields改用同一套截断。core/log_waker.go:WatchCoreEvents(wake, recovered)多了recovered回调。唤醒回调拆出wakeLogWatch,recover 后交给当前 watch,边界为core:log-waker。currentLogWatch是 Core 唯一唤醒回调背后的那一次注册,不是第二个写入器或日志单例;stop后清空,此后的 panic 被丢弃。core/events_bridge.go:请求事件观察者 recover 后交给当前 watch,边界为core:events-observer,不再静默丢弃。workbench/app.go:Run在窗口循环期间用app.SetFaultHandler安装faultRecorder,把 Viva 报告的每个 fault 记成viva:<位置>(例如viva:darwin:appkit-callback);窗口循环结束时移除。写入器经panicSink接口取得,和diagnosticsWatchSink、pluginFileSink的写法一样。窗口循环错误 →
app.window.loop_failed(ERROR)workbench/app.go:windowLoopEnded在RunApplication返回后、会话清理之前记录。循环期间 Viva 恢复过 panic 时,返回的错误就是那次 panic 造成的,已经记过,按“同一次失败已经记录过”豁免。致命崩溃和强制退出 →
app.session.previous_interrupted/app.session.close_missinglogstore/crash.go(新增):Store.CaptureCrashes()用debug.SetCrashOutput让 Go 运行时把致命崩溃报告写进<默认日志目录>/.crash/<会话名>。Close时删除。下次启动认领上一次留下的文件:有内容记previous_interrupted(ERROR,字段为报告首行panic和栈帧stack);空文件说明进程被强制结束或在 Go 运行时之外崩溃,记close_missing(WARN)。每次启动最多认领 8 个,剩下的留给下次。flock(crash_unix.go,先以隐藏的.tmp名创建并加锁再改名);Windows 用共享模式加FILE_FLAG_DELETE_ON_CLOSE独占打开(crash_windows.go)。app.session.crash_capture_failed(WARN),stage为create、claim、release;应用照常运行,只是没有崩溃捕获。.crash在写入器已经拥有的平台可写日志目录(DefaultDir)下,不在 app bundle 或安装目录里,不影响代码签名和 Sparkle 增量包。目录是隐藏的,日志清单、保留策略和“清除日志”都不处理它。cmd/lithe/main.go:ObserveCoreFacts()之后调用logs.CaptureCrashes()。其他
scripts/desktop/build-desktop-core.sh:PINNED_CORE_REVISION升到 Core main 的52c54e0(w3多终端 #49 合入),其中包含上述 6 个事件的声明和 Core 自己的 panic hook。.agents/skills/develop-lithe/references/logging.md:“写入器与记录入口”补上 panic 和致命崩溃两类入口,并规定新增的recover()边界必须交给 panic 入口,不能恢复后不记录。不在本 PR 范围内 / Out of scope
sample,所以本 PR 只写 Refs。崩溃捕获让被强制退出的卡死会话在下次启动时留下一条close_missing,以后再遇到能看出发生过。recover()已逐个核对,只有reopen_darwin.go没有调用platform.ReportFault,那里的 panic 到不了 fault handler。修复在 fix(darwin): reopen 处理函数的 panic 交给 fault handler Lithe-IDEA/Lithe-viva#20(基于 fork main),同一提交的上游 PR 是 fix(darwin): report a panicking reopen handler to the fault handler vivaui/viva#288。其余 recover 要么已经交给ReportFault,要么不是应用故障:窗口释放后迟到的回调、web 平台把 JS 异常作为 error 返回、诊断流和 fault 路径自身的保护、cmd/viva命令行工具。go.mod固定版本由维护团队升级,本 PR 不加绕过代码。crash_windows.go只在 macOS 上做了GOOS=windows类型检查(amd64、arm64),还没有在 Windows 虚拟机上实际运行。类型专属:fix
复现与根因
events_bridge.go的 recover 一直是静默丢弃。检查项
core/log_waker_test.go(TestObserverPanicIsReportedToTheWatch、TestWakerPanicIsReportedToTheWatch),logstore/panics_test.go、logstore/crash_test.go,workbench/fault_test.go。修复前这些入口都不存在,测试无法编译;观察者 panic 在修复前被静默丢弃,没有任何记录。Run里安装 fault handler 的那一步在无头环境跑不了,用faultRecorder和windowLoopEnded的单元测试覆盖。WatchCoreEvents只有logstore调用,测试替身wakingKernel已同步;recover()在桌面端非测试代码里只剩这三处,全部接入。TestProviderDebugStartsTheNamedAdapter偶发 TempDir 清理失败);Viva reopen 的缺口已在 fix(darwin): reopen 处理函数的 panic 交给 fault handler Lithe-IDEA/Lithe-viva#20 / fix(darwin): report a panicking reopen handler to the fault handler vivaui/viva#288 修复,见上。.agents/notes/implemented/bug-fix/记录:约束已写进develop-lithe的日志参考页和 Core 的rust/logging/README.md,没有另写 Note。范围检查 / Scope checks
功能矩阵 / Feature matrix
N/A:没有新增宿主能力,也没有改变跨平台行为;只是把已有的失败路径接进日志。
插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空shared/i18n/;插件的构建步骤、资源路径和补丁没有写进scripts/resources/、docs/ci-builds.md、Agent Note 或 SkillUI 验证 / UI evidence
N/A:没有界面变化;新记录在日志窗口里按现有方式显示。
统一日志系统 / Structured logging
rust/logging/events/app.json声明,固定版本已升级;事件 ID、级别和字段键都是常量,由TestEveryLoggedEventIsAcceptedByTheKernel逐条校验;没有写 stderrtext限长,栈只保留函数名、文件基名和行号,不含完整路径界面文案 / i18n
N/A:没有新增界面文案;事件消息是 Core 目录里的英文事实。i18n 两项检查照常运行并通过。
逻辑归属 / Logic placement
debug.SetCrashOutput、文件锁),Core 替代不了性能与内存 / Performance and memory
CaptureCrashes在main打开窗口之前运行,只创建一个空文件、读取.crash目录,不在窗口循环里mkdir、readdir和一个空文件的创建,没有单独测基线设置 / Settings
N/A:没有设置改动。
插件契约 / Plugin contract
N/A:没有改插件契约、能力版本或宿主方法;
PINNED_CORE_REVISION的升级只为了日志事件目录。发行包与资源 / Bundle and resources
.crash在平台可写的默认日志目录下,生命周期、所有权和可写位置写在logstore/crash.go的注释里;已运行verify-runtime-bundle-immutability.sh.crash是运行时日志文件,不是构建资源,不跨 worktree 复用无用代码与重构 / Dead code and refactoring
logging.go里原有的截断逻辑合并进log_text.go验证 / Verification
desktop-go.sh test ./internal/core ./internal/logwindow ./cmd/lithe(含目录门禁TestEveryLoggedEventIsAcceptedByTheKernel),LITHE_CORE_RUST_DIR指向 Core52c54e0(与f4f3e93的日志目录和 panic hook 无差异)desktop-go.sh test -race ./internal/logstoredesktop-go.sh test ./internal/workbench(合入 preview 含 1954 之后,链接 Core52c54e0)TestProviderDebugStartsTheNamedAdapter一次 TempDir 清理失败外全部通过;它单独重跑 10 次均通过,与本 PR 无关,已建 #1956test-stability-macos.sh跑新增测试(单测试计时)GOOS=windows GOARCH=amd64/arm64 CGO_ENABLED=0 go build,用 overlay 类型检查crash_windows.gogofmt -l desktop/internal desktop/cmdnode scripts/i18n/verify-app-language-localization.mjs、node scripts/i18n/generate-i18n.mjs --checkscripts/desktop/verify/verify-runtime-bundle-immutability.shnode scripts/logging/generate-log-events.mjs --check、cargo test -p lithe-diagnostics、cargo test -p lithe-core未能执行的检查和原因:
close_missing)还没在打包应用上做。提交前确认 / Final checks
preview(061aecfe5)创建;目标分支preview