Skip to content

feat: add go core with console logging and parent process monitoring - #1737

Merged
SAKURA-CAT merged 10 commits into
mainfrom
feat/core-basic
Aug 13, 2026
Merged

SAKURA-CAT merged 10 commits into
mainfrom
feat/core-basic

Conversation

@SAKURA-CAT

@SAKURA-CAT SAKURA-CAT commented Aug 12, 2026 •

Copy link
Copy Markdown
Member

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 三平台测试)。
  • Makefile 新增 core-lint / core-fmt / core-test / core-build / core-tidy 目标,pre-commit 新增 golangci-lint 与 go mod tidy hooks。
  • 顺手将三个 CI workflow 用到的 GitHub Actions 升级到最新大版本。

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 版本升级(见下)

CI Actions 升级

Workflow Action 升级前 升级后
test-core-pr.yml actions/checkout v4 v7
test-core-pr.yml actions/setup-go v5 v7
test-core-pr.yml golangci/golangci-lint-action v6 v9
test-python-pr.yml actions/checkout v4 v7
test-python-pr.yml astral-sh/setup-uv v7 v10.0.0
publish-to-pypi.yml actions/checkout v4 v7
publish-to-pypi.yml astral-sh/setup-uv v7 v10.0.0
publish-to-pypi.yml softprops/action-gh-release v2 v3

注:astral-sh/setup-uv 自 v8 起不再发布浮动大版本标签(供应链安全),因此钉到完整版本号 @v10.0.0。

Testing

  • 已运行 go test ./...(core/ 目录),全部通过
  • 已运行 golangci-lint run(core/ 目录),0 issues
  • CI workflow 仅改动 action 版本号,未运行 workflow 本身

Notes

  • process 包仅负责检测父进程退出并关闭通知 channel,不直接终止进程或执行业务清理,退出编排由调用方决定。
  • 本 PR 只引入 core 的基础设施与两个基础包,尚未接入 gRPC 服务或 Python SDK 调用侧。
  • softprops/action-gh-release v3 与 setup-go v6+/golangci-lint-action v9 均迁移到 Node 24 runtime,GitHub-hosted runner 满足要求。

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.
@SAKURA-CAT SAKURA-CAT added the 💪 enhancement New feature or request label Aug 12, 2026
@SAKURA-CAT SAKURA-CAT self-assigned this Aug 12, 2026
@SAKURA-CAT
SAKURA-CAT requested a review from Nexisato August 12, 2026 17:58
@SAKURA-CAT

Copy link
Copy Markdown
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 SAKURA-CAT left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

审核结论: 通过

本次 PR 解决的问题

为 SwanLab 引入 Go core 基础设施与两个基础包:console(终端输出 + 诊断日志持久化)与 process(跨平台父进程退出监控),并配套 Go 工具链、CI 与工程配置。

审核范围

  • 平台与进程生命周期: process 三平台实现(Linux prctl(PR_SET_PDEATHSIG)、Windows OpenProcess+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.yml version: "2" 与 CI golangci-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.Cleanup LIFO;三级进程树集成测试真实验证三平台父进程退出;断言含实际值。

未挂行发现

建议: 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 测试矩阵)

@SAKURA-CAT SAKURA-CAT changed the title feat: add Go core with console logging and parent process monitoring feat: add go core with console logging and parent process monitoring Aug 13, 2026
@SAKURA-CAT
SAKURA-CAT merged commit 6d50bc3 into main Aug 13, 2026
23 checks passed
@SAKURA-CAT
SAKURA-CAT deleted the feat/core-basic branch August 13, 2026 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💪 enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant