Skip to content

feat: add created at post request for ch cluster - #1738

Merged
SAKURA-CAT merged 9 commits into
mainfrom
feat/openapi-with-createtat
Aug 19, 2026
Merged

feat: add created at post request for ch cluster#1738
SAKURA-CAT merged 9 commits into
mainfrom
feat/openapi-with-createtat

Conversation

@Nexisato

@Nexisato Nexisato commented Aug 18, 2026

Copy link
Copy Markdown
Collaborator

Description

House 指标查询接口现在要求必须携带实验的 createdAt(10 位 Unix 秒时间戳),并以 createdAt >= toDateTime(<createdAt>) 作为 ClickHouse 数据入库时间的包含式单边下界,用于裁剪扫描范围、避免每次查询重复扫描冷层数据。

Changes

新增工具模块 swanlab/utils/time(查询 API lane 与运行时 SDK lane 共用):

  • parse_timestamp_s():将 ISO 8601 字符串(含/不含时区)、秒级(10 位)/毫秒级(13 位)时间戳统一归一化为 10 位 Unix 秒
  • None / 空串 / 无法解析 / 非正数 / 越界时抛出 ValueError不做默认值回退,避免 House 退化为全历史扫描(慢查询)

查询 lane(swanlab/api/**swanlab/cli/api/**

  • Metric / Metrics / Summary / Key / Column / Columns 构造参数 created_at 必传(无默认值)
  • 所有 House 查询 payload(scalar / media / f_media / log / summaries / scalar/export / log/export)无条件携带 createdAt
  • Series 构造时校验每个 experiment ref 必须携带非零 createdAt,缺失即抛错

运行时 lane(swanlab/sdk/internal/core_python/**

  • create_or_resume_experiment() 确保 createdAt 总是被填充:
    • 201(新建实验):直接复用请求中的本地值,零额外请求
    • 200(已存在)且 POST 响应已携带 createdAt:直接使用(对接 SwanHubX/SwanLab-Server#1090)
    • 200 且响应未携带(旧后端):回退一次 GET /runs/{cuid} 获取
    • GET 仍无法获取:抛出 ValueError(提示升级 swanlab-server)
  • resume / sync 时 get_experiment_summary()createdAt 作为查询下界

Notes

  • SDK 端 createdAt 为强制携带:后端未返回该字段时显式报错,而非静默降级为无下界查询
  • 服务端在 POST 响应中补充 createdAt 后可消除 resume 场景的额外 GET:SwanHubX/SwanLab-Server#1090

@Nexisato Nexisato self-assigned this Aug 18, 2026
@Nexisato Nexisato added the 🔌 api SwanLab OpenAPI label Aug 18, 2026
Comment thread swanlab/api/column.py Outdated
Comment thread swanlab/api/utils.py Outdated
SAKURA-CAT
SAKURA-CAT previously approved these changes Aug 18, 2026
@SAKURA-CAT
SAKURA-CAT force-pushed the feat/openapi-with-createtat branch from def5e94 to a04865e Compare August 18, 2026 16:22
The backend does not return `createdAt` when creating a new experiment,
so use the client-provided timestamp. When resuming an existing
experiment, fetch the actual creation time from the run endpoint. Update
type signatures accordingly.
Use consistent createdAt formatting across responses
```

@SAKURA-CAT SAKURA-CAT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

审核结论: 评论

上一轮阻塞项已全部解决,剩余为非阻塞 finding;建议 CI 转绿、PR 描述修正后再合并。

本次 PR 解决的问题

House 指标查询接口新增必填 createdAt(10 位 Unix 秒)作为 ClickHouse 数据入库时间的包含式下界,裁剪扫描范围避免慢查询;新增共享工具 parse_timestamp_s() 统一归一化秒/毫秒时间戳与 ISO 8601 字符串。

审核范围

  • 公共 API 与类型兼容: ApiExperimentType.createdAt(optional)、InitExperimentType.createdAt(required),无顶层 API 变更
  • Run 生命周期与运行时组件: resume/sync lane 的 summary 查询接入
  • Record、Core 与传输: core.py / sync.py 仅透传 createdAt,不改批次与重试逻辑
  • 配置、认证与 HTTP 客户端: create_or_resume_experiment 的 GET 回退走既有 client,无凭据暴露
  • Public API 与 CLI: swanlab/api/**swanlab/cli/api/** 全部查询 lane 注入 createdAt
  • 媒体、集成与插件: 无变更
  • Protobuf、构建与依赖: 无变更
  • 安全、性能与跨平台兼容: Py3.9 兼容(datetime.fromisoformat 未用 Z 直解),无敏感数据泄露;resume 额外 GET 已缓解
  • 测试与验证: 新增 TestCreatedAtTestParseTimestampS;sync fixture 已修复

未挂行发现

建议: PR 描述与实现不符——描述称“None/空串/无法解析时返回 0”、“House 未更新时 createdAt 被静默丢弃无影响”,实际 parse_timestamp_sValueError(测试 test_payload_raises_when_created_at_missing 锁定硬失败设计);描述提到的 swanlab/api/utils.py 不存在(实际 swanlab/utils/time/__init__.py)。建议合并前修正描述,避免误导后续维护者。

说明: 查询 lane 在未返回 createdAt 的旧自部署后端上会使 metrics()/summary()/logs() 等抛错;PR Notes 已声明“House 更新则必须更新 SDK”,视为有意决策。resume 额外 GET 的长期方案已由 SwanHubX/SwanLab-Server#1090 跟踪。

验证

  • uv run pytest tests/unit: 1627 passed / 21 skipped(head f72868d
  • uv run ruff check .: 通过
  • uv run basedpyright: 0 errors
  • PR Actions: 新 head 的 Type check 运行中(旧 run 对 afd1620 fail,测试矩阵 skipped),合并前需确认转绿

Comment thread swanlab/sdk/internal/core_python/api/experiment.py
Comment thread swanlab/api/series.py Outdated
@SAKURA-CAT
SAKURA-CAT merged commit 4d78fea into main Aug 19, 2026
19 checks passed
@SAKURA-CAT
SAKURA-CAT deleted the feat/openapi-with-createtat branch August 19, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔌 api SwanLab OpenAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants