Repository navigation
feat: add go core with console logging and parent process monitoring - #1737
Merged
Merged
Conversation
Set up the core Go module with golangci-lint configuration and implement the console logging package (mirroring the Python SDK's console module) with loguru-style terminal output, file-based diagnostic logging with rotation, and parent process exit detection across Linux, Windows, and other platforms.
Add a GitHub Actions workflow that runs Go linting and cross-platform tests when changes to the `core/` directory are made. The workflow uses golangci-lint v2.12.2 and tests on Ubuntu, Windows, and macOS, skipping generated protobuf code that has no tests.
Member
Author
|
console、process的代码仅为短暂测试,具体代码质量还需判断 |
Introduce a dedicated `pr-review-core` skill for reviewing SwanLab Go core PRs, covering platform lifecycle, console logging, protobuf contracts, toolchain, and cross-cutting quality. Add cross-reference checks so `pr-review-lab` and `pr-review-core` delegate to each other for mixed-language PRs. Update the Makefile skill-linking targets to map all skills under `docs/skills/` instead of a hardcoded single skill, and bump Go toolchain and dependencies in `core/go.mod`/`go.sum` to Go 1.26.5 with updated grpc, protobuf, and x/sys versions.
SAKURA-CAT
commented
Aug 13, 2026
SAKURA-CAT
left a comment
Member
Author
There was a problem hiding this comment.
审核结论: 通过
本次 PR 解决的问题
为 SwanLab 引入 Go core 基础设施与两个基础包:console(终端输出 + 诊断日志持久化)与 process(跨平台父进程退出监控),并配套 Go 工具链、CI 与工程配置。
审核范围
- 平台与进程生命周期:
process三平台实现(Linuxprctl(PR_SET_PDEATHSIG)、WindowsOpenProcess+WaitForSingleObject、兜底轮询)构建标签互斥且无遗漏;NotifyOnParentExit+checkParent+ 二次 PID 确认齐备;channel 单次关闭,goroutine 均有终止路径(signal.Stop/CloseHandle/ticker.Stop)。 - 控制台与诊断日志: 与 Python
swanlab/sdk/internal/pkg/console逐级对照一致;warning/error/trace无条件写文件、debug/info按SWANLAB_DEBUG门控;log 子包 0600 权限、轮转、内存缓冲上限、Init/Reset对称。 - Protobuf 与生成代码: 本 PR 未改 proto;新增
go.mod纳入既有生成代码,go build ./...(含core/proto)通过。 - Go 模块、工具链与构建:
.go-version与go.mod(均 1.26.5)一致;.golangci.ymlversion: "2"与 CIgolangci-lint-action@v9/v2.12.2一致;modules-download-mode: readonly下go.sum完整;core-*target 与 CI 行为一致。 - Go core 横切质量与代码规范: 错误显式处理;
_ =仅限尽力而为清理;导出 API 均有文档注释;internal/不外泄;无调试残留或死代码。 - 安全、性能与跨平台兼容: 日志文件强制 0600;缓冲有上限;轮询 1s 无忙等;三平台 CI 全绿。
- 测试与验证: 表驱动 +
t.TempDir/t.CleanupLIFO;三级进程树集成测试真实验证三平台父进程退出;断言含实际值。
未挂行发现
建议: core/Makefile 为空文件(0 字节),无任何目标。根 Makefile 已含全部 core-* target,空文件易误导维护者;建议删除,或将 core 目标下沉到 core/Makefile 使 make -C core test 可用。
说明: publish-to-pypi.yml 的 action 升级(checkout@v7、setup-uv@v10.0.0、action-gh-release@v3)仅 tag push 触发,PR CI 无法验证,需下次发版时确认。
验证
- go test -race(
go list ./... | grep -v /proto/)→ console / console/log / process 全绿 - golangci-lint run → 0 issues
- go build ./... → 通过
- PR Actions 已通过(core 三平台 + Python type-check / 3×6 测试矩阵)
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.
Summary
为 SwanLab 引入 Go 语言 core 的基础设施与两个基础包:
core/Go 模块(go.mod/go.sum/.go-version/.golangci.yml),作为 core 的起点。console终端输出包,镜像 Python SDK 的 console 模块(loguru 风格日志,SWANLAB_DEBUG=true时输出 debug 并同步到诊断日志文件)。console/log,带轮转)。process):Linux 走prctl(PR_SET_PDEATHSIG),Windows 走进程句柄等待,其他平台回退为轮询,避免 core 成为孤儿进程。core/**变更触发的 GitHub Actions CI(golangci-lint + Ubuntu/Windows/macOS 三平台测试)。core-lint/core-fmt/core-test/core-build/core-tidy目标,pre-commit 新增 golangci-lint 与 go mod tidy hooks。Changes
core/internal/pkg/console/:终端输出 + loguru 风格日志(info/debug/warning/error/trace)core/internal/pkg/console/log/:诊断日志文件持久化(带轮转)core/internal/pkg/process/:父进程退出监控(Linux / Windows / 其他平台三套实现).github/workflows/test-core-pr.yml:Go lint + 跨平台测试Makefile/.pre-commit-config.yaml/.gitignore:工具链与工程配置CI Actions 升级
Testing
go test ./...(core/目录),全部通过golangci-lint run(core/目录),0 issuesNotes
process包仅负责检测父进程退出并关闭通知 channel,不直接终止进程或执行业务清理,退出编排由调用方决定。softprops/action-gh-releasev3 与setup-gov6+/golangci-lint-actionv9 均迁移到 Node 24 runtime,GitHub-hosted runner 满足要求。