Repository navigation
Conversation
SAKURA-CAT
force-pushed
the
feature/core
branch
from
September 22, 2026 08:01
2d33d99 to
e2d1da0
Compare
Nexisato
force-pushed
the
feat/gateway-starter
branch
from
September 22, 2026 08:25
5d35dc1 to
c933966
Compare
Nexisato
marked this pull request as ready for review
September 23, 2026 07:16
Nexisato
force-pushed
the
feat/gateway-starter
branch
from
October 27, 2026 02:27
5b01a65 to
e066548
Compare
Nexisato
marked this pull request as draft
October 27, 2026 05:58
Nexisato
force-pushed
the
feat/gateway-starter
branch
from
October 27, 2026 06:46
2885114 to
f26a9b5
Compare
Nexisato
force-pushed
the
feat/gateway-starter
branch
from
October 27, 2026 06:50
f26a9b5 to
6960fb3
Compare
* feat: add python client skeleton * feat(core-go): add protocol errors and port-file discovery - add fixed handshake constants shared by client modules - add CoreGoError with stage/reason and gRPC status-name mapping - parse port-file v1 with Go portinfo parity - validate pid and unix/tcp endpoint ownership * feat(core-go): manage runtime, spawn and reap core process - create private 0700 runtime dirs under the system temp root - spawn swanlab-core with port-file/parent-pid only and sanitized env - poll endpoint, classify early exit codes and validate ownership - reap with wait -> terminate -> kill and keep bounded stderr * feat(core-go): add grpc channel and CoreService rpc wrapper - lazily import grpcio and wait for channel readiness - map gRPC statuses once and preserve UNIMPLEMENTED details - attach session_id to every run-level request - convert success=false responses into protocol errors * fix(core-go): use absolute imports and shared rpc channel type - add RpcChannelType Protocol under swanlab.sdk.typings.core_go - switch core_go modules to absolute imports and drop the rpc re-export - report missing grpcio as GRPC_UNAVAILABLE instead of leaking ImportError - skip POSIX mode/uid checks on Windows runtime dirs * feat(core-go): own core process lifecycle in launcher - add CoreLauncher as the sole owner of runtime, process and channel - validate binary before creating runtime and clean up on any start failure - make close/abort idempotent and guard fork children via pkg.fork - reuse validate_core_binary and cover launcher orchestration with unit tests * feat(core-go): bind run session in CoreGo - add CoreGo state machine and single session_id binding - start via launcher, SpinupService and DeliverRunStart - forward upserts and surface UNIMPLEMENTED once without fallback - map finish/stats/confirm and keep close/abort idempotent - return a NullCoreProtocol-based detached stub for fork children * fix(test): fork error on win32 platform * fix(core-go): resolve binary path Resolve core binary paths before launching from the runtime directory, and use safe.block to contain cleanup failures during teardown and channel close. Add a regression test for relative binary paths.
Nexisato
marked this pull request as ready for review
October 28, 2026 05:28
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.
概述
实现 swanlab-core(Go)的进程启动与生命周期框架,以及 Python SDK 侧的握手客户端:
session_id)Go core 功能点
启动与端点回报
Python SDK 通过
subprocess.Popen启动swanlab-core。未指定--listen时按平台自选端点:POSIX 使用 runtime 目录内的 UDS,listen 失败记录 warning 后回退127.0.0.1:0;Windows 使用回环 TCP。listen 与 gRPC server 初始化成功后原子写入 port-file(同目录临时文件 + chmod 0600 + rename),Python 轮询该文件完成握手。显式--listen视为调用方指定端点,失败报错;tcp://限定回环地址,unix://要求绝对路径或抽象地址。端点被占用时先判定占用者,再决定下一步:
port-file 为最小协议,承担临时 endpoint discovery,不携带鉴权或身份字段:
信任模型
POSIX 使用 UDS(socket 文件位于 owner-only 私有 runtime 目录),port-file 以 0600 权限发布;loopback TCP 回退不隔离本机用户,能连接端口的本机进程可调用全部 RPC。
生命周期与会话路由
NOT_READY → READY → STOPPING → CLOSED:SpinupService幂等置 READY,READY 前 run 级 RPC 返回FAILED_PRECONDITION;DeliverRunStart创建 UUIDv7 形式的session_id(可按创建时间排序)存入并发安全 registry,run 级 RPC 按session_id路由;session_id只标识会话:每次调用创建独立会话,不按run_id去重。同一实验可能由多个进程上报(多 rank、resume复用实验),各会话的缓冲与上传状态互不影响;run_id由 Python SDK 生成后透传,core 不补写;ConfirmRunFinish在对应会话的DeliverRunFinish交付后原子释放(提前调用返回FAILED_PRECONDITION,会话保留),不关闭 gRPC Server;TeardownService在独立 goroutine 执行 GracefulStop,避免 handler 内自等待;pid字段判定归属,路径被后启动实例覆盖时不误删。父进程监控
Linux 使用 PDEATHSIG 快路径,另有进程级兜底:先使用 pidfd,不可用时低频轮询 PID/PPID,覆盖从非主线程 spawn、spawn 线程先退出的场景;监控通知 controller,不在监控 goroutine 中执行关闭。
日志
--log-dir可选开启debug-core.log,为空时只写 stderr。轮转、stderr 合并与skip_store分流在后续提交接入。detached 预留
--detach与--idle-timeout为 detached 模式预留,当前版本接受传值但作为 no-op 忽略并记录 warning,core 仍以 Owner Mode 运行,当前实现暂不添加 detached 运行逻辑。协议调整
core.proto新增 Spinup/Teardown RPC;DeliverRunStart响应返回session_id,upsert/finish/stats/confirm 等 run 级请求携带该字段。原run_handle统一更名为session_id,字段号保持不变;Python/Go stub 重新生成。退出码
Go core 启动流程
Python SDK 客户端(CoreGo)
由 #1803 合入。
握手与关闭
行为与边界
NEW → STARTING → RUNNING → FINISHED → CLOSED,启动失败走ABORTING;close()/abort()幂等。UNIMPLEMENTED:客户端只记一次 warning,不重试、不改写、不回退CorePython。CoreGo当前只实现online;local/offline返回MODE_UNSUPPORTED,disabled为 no-op。CorePython的四种模式不变。create_core()未改动,生产路径仍走CorePython;CoreEnum.CORE→CoreGo的切换在后续切片。core.fork()返回 no-op 的_DetachedCoreGo(继承NullCoreProtocol),不持有父进程资源;仅覆盖显式os.fork(),macOS 默认spawn需在子进程重新swanlab.init()。测试
tests/unit/sdk/internal/core_go/覆盖发现、进程、RPC、launcher 与错误映射,110 passed;全量pytest tests/unit2139 passed / 21 skipped,ruff/basedpyright通过。UNIMPLEMENTED、重复 close。风险提示
Go core 以
CGO_ENABLED=0静态编译,二进制无动态链接依赖,不要求宿主机的 glibc 版本。发行版暂不支持 alpine,是 Python 侧grpcio需要 glibc,与 core 二进制无关。