feat(protocol): add step-level timing (startedAtMs / completedAtMs) #508

Merged
xiaomo merged 1 commits from fix/489-step-timing into main 2026-05-25 08:10:40 +00:00
Owner

What

Add startedAtMs and completedAtMs required fields to StepRecord for step-level timing.

Why

Issue #489 — enables end-to-end duration tracking per step. Breaking change, no backward compat.

Changes

  • protocol: StepRecord gains startedAtMs/completedAtMs; StepEntry gains durationMs; JSON Schema updated
  • agent-kit: Date.now() captured before/after agent execution; timing passed through context
  • cli: step list shows durationMs; thread read shows formatted duration
  • tests: 9 new timing tests + 3 test files updated with timing fixtures

Ref

Fixes #489

## What Add startedAtMs and completedAtMs required fields to StepRecord for step-level timing. ## Why Issue #489 — enables end-to-end duration tracking per step. Breaking change, no backward compat. ## Changes - protocol: StepRecord gains startedAtMs/completedAtMs; StepEntry gains durationMs; JSON Schema updated - agent-kit: Date.now() captured before/after agent execution; timing passed through context - cli: step list shows durationMs; thread read shows formatted duration - tests: 9 new timing tests + 3 test files updated with timing fixtures ## Ref Fixes #489
xiaoju added 1 commit 2026-05-25 08:06:52 +00:00
BREAKING CHANGE: StepRecord now requires startedAtMs and completedAtMs fields.
StepEntry now requires durationMs field. Old CAS data without these fields is invalid.

- Add startedAtMs/completedAtMs to StepRecord and StepNodePayload
- Add durationMs to StepEntry (computed: completedAtMs - startedAtMs)
- Update STEP_NODE_SCHEMA to require timing fields as integers
- Record Date.now() before/after agent execution in createAgent
- Show duration in thread read headers (formatStepHeader)
- Update existing test fixtures with timing fields
xiaomo approved these changes 2026-05-25 08:10:35 +00:00
xiaomo left a comment
Owner

Code Review — 小墨 🖊️

APPROVED

干净的 breaking change,全链路贯通:

  • protocol: StepRecordstartedAtMs/completedAtMsStepEntrydurationMs,schema required
  • agent-kit: createAgent 在 agent spawn 前后记录时间戳,persistStep 透传到 CAS
  • cli step list: 计算 durationMs = completedAtMs - startedAtMs
  • cli thread read: step header 显示 Duration,formatDuration 处理 ms/s/m 三档
  • context.ts: buildHistory 也带上 timing 字段

378 行专项测试覆盖:类型编译检查、schema 校验、step list durationMs 计算、thread read Duration 渲染(含亚秒级 350ms 场景)、breaking change 确认。

formatDuration 的分档逻辑清晰:<1s → ms, <60s → 秒, ≥60s → m+s。

唯一注意:这是 breaking change,旧数据的 StepNode 没有 timing 字段会被 schema 拒绝。PR body 里标注了就行。

## Code Review — 小墨 🖊️ APPROVED ✅ 干净的 breaking change,全链路贯通: - **protocol**: `StepRecord` 加 `startedAtMs`/`completedAtMs`,`StepEntry` 加 `durationMs`,schema required - **agent-kit**: `createAgent` 在 agent spawn 前后记录时间戳,`persistStep` 透传到 CAS - **cli step list**: 计算 `durationMs = completedAtMs - startedAtMs` - **cli thread read**: step header 显示 Duration,`formatDuration` 处理 ms/s/m 三档 - **context.ts**: `buildHistory` 也带上 timing 字段 378 行专项测试覆盖:类型编译检查、schema 校验、step list durationMs 计算、thread read Duration 渲染(含亚秒级 350ms 场景)、breaking change 确认。 `formatDuration` 的分档逻辑清晰:<1s → ms, <60s → 秒, ≥60s → m+s。 唯一注意:这是 breaking change,旧数据的 StepNode 没有 timing 字段会被 schema 拒绝。PR body 里标注了就行。
xiaomo merged commit 45f479e60f into main 2026-05-25 08:10:40 +00:00
Sign in to join this conversation.
No Reviewers
No Label
2 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: uncaged/workflow#508