Repository navigation
fix(desktop): Windows 进程台账改用系统接口,构建时不再闪出控制台窗口 - #2403
Merged
Merged
Conversation
进程台账每次登记进程都运行 ps 读取启动时间和命令名,结束残留进程时运行 kill。 Lithe 是没有控制台的 GUI 程序,PATH 上 Git for Windows、MSYS2 等提供的 ps 会自己 开一个控制台窗口,又因不支持 -o 立即退出,于是每次构建、运行、测试、调试都闪一下; 台账在 Windows 上也因此从未登记成功。 - processledger:平台差异拆到 processledger_unix.go(仍用 ps/kill)和 processledger_windows.go。Windows 通过进程句柄读创建时间(GetProcessTimes)和 程序路径(QueryFullProcessImageName),先用 WaitForSingleObject 排除已退出但句柄 未关的进程;结束用 TerminateProcess。不启动任何外部程序。 - localshell:Windows 的 ConPTY 终端 shell 登记进台账,退出后取消登记,与 macOS 一致。 - 删除只在 Windows 关闭台账时才有意义的 processledger.Supported 和设置窗口的 SweepsLeftovers 选项;“意外关闭后遗留的终端”设置两端都显示。 - 测试:Windows 用 PATH 最前面的记录型 ps.bat/kill.bat 断言台账从不调用它们,覆盖 登记、清扫、保留、PID 复用和已退出进程;ConPTY shell 的登记与取消登记。 - 更新子进程生命周期 Agent Note、统一子进程生命周期提案、两个功能矩阵条目和迁移表。
xiaoyumuxi
marked this pull request as ready for review
November 24, 2026 17:44
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
PR 类型 / Type
改动说明 / What changes
背景 / Why
Windows 上每次构建、运行、测试、调试,都会闪出一个控制台窗口并立刻关闭,非常影响体验。原因在进程台账:每次登记进程都运行
ps -o lstart= -o comm= -p <pid>读取启动时间和命令名,结束残留进程时运行kill,两者都不区分平台。Lithe 是没有控制台的 GUI 程序,Git for Windows 的usr\bin、MSYS2、Cygwin 等工具链放进 PATH 的ps.exe会自己开一个控制台窗口;这些ps不认识-o,打开就报错退出,所以看起来一闪而过。同一个原因也让台账在 Windows 上从来没有登记成功过(
ps要么找不到,要么报错),Lithe 崩溃后,下次启动时不会清扫残留进程。本 PR 保留台账,改为在 Windows 上通过进程句柄直接查询系统,不再启动任何外部程序。改动 / Changes
processledger:拆出平台实现processledger.go只保留记录、核对和清扫逻辑,两端共用一份。processledger_unix.go:把原来的identity(ps)和signal(kill)原样搬过来,macOS/Linux 行为不变。processledger_windows.go:identity用OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION|SYNCHRONIZE)打开进程。先用WaitForSingleObject(handle, 0)排除已退出、但还有句柄没关的进程。GetProcessTimes的创建时间(100 纳秒精度,十进制字符串),命令取QueryFullProcessImageName返回的完整路径。signal用TerminateProcess结束进程。Windows 没有能发给任意进程的停止请求(与buildprocess.StopsGracefully = false一致),所以 TERM 和 KILL 都是直接结束。uint32或不是正数时直接视为无效,因为从文件读回的记录可能是任何数字。localshell:Windows 的 ConPTY 终端 shell 启动后登记进台账(KindTerminal),WaitForSingleObject返回后取消登记,和backend_unix.go一致。ConPTY 的 shell 不在 Job Object 里,崩溃后的残留只能靠台账清扫。processledger.Supported:它的注释说 Windows 不登记,但Open从来没有检查它。SweepsLeftovers选项(controller.go、workbench/settings.go、visual_capture_test.go)。processledger_windows_test.go:在 PATH 最前面放两个记录调用的ps.bat、kill.bat,每个用例都断言台账从没调用它们。覆盖:Track和取消登记;shell_windows_test.go新增TestConPTYShellIsRecordedWhileItRuns:shell 运行期间在台账里,退出后记录被删除。implemented/bug-fix/2026-10-14-child-processes-end-with-the-ide.md新增“Windows:账本不启动外部程序”一节,写明原因、做法、覆盖面,以及“不要在客户端里启动ps、kill、tasklist、taskkill这类控制台程序,也不要为了不闪窗口关掉台账”。同时更新了未覆盖情况、验证和适用范围。proposed/architecture/2026-10-16-unified-child-process-lifecycle.md的迁移状态行:删除“Windows 账本不登记”,写明 Job Object 的实际范围。run-processes-end-with-ide.json、process-termination-policy.json:更新 notes,补充 Windows 证据路径,验证状态保持pending。docs/viva-migration.md:删除“启动清扫仅 macOS”。不在本 PR 范围内 / Out of scope
CREATE_NEW_CONSOLE),只在调试时出现,和构建闪窗无关,不在本 PR 处理。processledger仍手写临时文件再改名的写入方式,已有 [Feature] processledger 与 loginenv 仍手写固定 .tmp 文件改名写入,迁移到 atomicfile.Write #2376 跟踪。类型专属:fix
复现与根因
ps(例如加入 Git for Windows 的usr\bin),打开项目后执行构建、运行、测试或调试。实际:每次开始时闪出一个控制台窗口。期望:不出现任何额外窗口。0faecba49,desktop-v0.7.0)引入processledger时,identity/signal直接exec.Command("ps"…)、exec.Command("kill"…),没有区分平台。buildprocess.Track在每次启动进程时都会调用它们。processledger_unix.go,行为不变。检查项
desktop/internal/processledger/processledger_windows_test.go(所有用例都用withRecordingProcessTools)。本机没有 Windows 虚拟机,修复前后都没有实际运行。按代码推断,修复前identity会调用ps.bat,它没有标准输出,于是不登记任何记录:recorded()因为台账为空而失败,Cleanup 也会报calls.txt里有ps -o lstart= -o comm= -p <pid>。这一项要等 Windows CI 或 Windows 实机确认。identity/signal只在processledger包内使用;Supported/SweepsLeftovers已无引用;Track/Open/Add的调用方(buildprocess、localshell两端、pluginservice、workbench/app.go)都和平台无关。ps/kill不会弹窗;macOS 的终端 shell 本来就登记了。Supported/SweepsLeftovers是因为本次修复让它们变成了无用代码;ConPTY shell 登记是台账在 Windows 生效后补齐的同一个登记点。没有发现新的既有问题,原子写入已有 [Feature] processledger 与 loginenv 仍手写固定 .tmp 文件改名写入,迁移到 atomicfile.Write #2376。.agents/notes/implemented/bug-fix/记录范围检查 / Scope checks
功能矩阵 / Feature matrix
shared/platform-feature-matrix/features/<id>.json:更新了run-processes-end-with-ide、process-termination-policy的 notes 和 Windows 证据,验证状态保持pending./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh;改了平台实现路径的,还运行了./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD.artifacts/下生成的矩阵视图插件归属 / Plugin ownership
develop-lithe第三节“插件归属与宿主零依赖”的自查命令,结果为空shared/i18n/;插件的构建步骤、资源路径和补丁没有写进docs/ci-builds.md、Agent Note 或 SkillUI 验证 / UI evidence
TestVisualSettings原来就固定显示这张卡片,已随settingswindow测试通过统一日志系统 / Structured logging
N/A:没有新增或改动生命周期里程碑、终态或失败路径的日志;台账原来就不记日志。
界面文案 / i18n
N/A:没有新增或修改用户可见文字,Windows 上新显示的卡片复用现有词条。
逻辑归属 / Logic placement
processLifecycle.resolve决定;本 PR 只改了读取进程身份、结束进程这两项平台 I/O性能与内存 / Performance and memory
设置 / Settings
插件契约 / Plugin contract
N/A:不涉及插件契约、能力版本、插件函数协议或宿主方法。
发行包与资源 / Bundle and resources
N/A:台账文件位置不变(应用偏好目录下的
process-ledger.json),没有新增运行时资源或构建步骤。无用代码与重构 / Dead code and refactoring
processledger.Supported、设置窗口的SweepsLeftoversrefactor标签的 Issue:没有发现新的;台账写入方式已有 [Feature] processledger 与 loginenv 仍手写固定 .tmp 文件改名写入,迁移到 atomicfile.Write #2376验证 / Verification
./scripts/desktop/desktop-go.sh test ./..../scripts/desktop/desktop-go.sh test -race -count=1 ./internal/processledger/ ./internal/localshell/ ./internal/settingswindow/test-stability-macos.sh --package ./internal/processledger/ --package ./internal/localshell/verify-test-stability.sh、verify-test-stability.sh --base origin/mainGOOS=windows GOARCH=amd64/arm64 go vet ./internal/processledger/,GOOS=windows GOARCH=amd64 go vet ./internal/localshell/./scripts/platform-feature-matrix/verify-platform-feature-matrix.sh./scripts/platform-feature-matrix/verify-platform-feature-matrix-change.sh origin/main HEAD./scripts/agent-notes/verify-agent-notes.shrg未能执行的检查和原因:
processledger_windows_test.go、TestConPTYShellIsRecordedWhileItRuns都没有运行:本机 Parallels 只有 Fedora、Ubuntu 虚拟机,没有 Windows 来宾;按debug-windows-on-parallelsSkill,也不改用云主机。要等 Windows CI(标记 ready 后)或 Windows 实机。usr\bin的机器上构建、运行、测试、调试、打开终端,确认不再闪窗口;再强制结束 Lithe 后重新启动,确认启动清扫列出了残留的终端和运行进程。workbench、settingswindow)不能在 macOS 上交叉 vet 到 Windows,Windows 编译要靠 CI。提交前确认 / Final checks
main创建;目标分支:feat、fix、docs 为main,release 以发布流程要求为准.build/、target/、dist/、.artifacts/等产物,没有凭据、个人路径和未脱敏的日志或截图