Skip to content

regen: sync SDK with corrected monit + a2a specs#31

Merged
ysyneu merged 6 commits into
feat/api-review-auto-fixfrom
fix/monit-contract-sync
Jul 20, 2026
Merged

regen: sync SDK with corrected monit + a2a specs#31
ysyneu merged 6 commits into
feat/api-review-auto-fixfrom
fix/monit-contract-sync

Conversation

@ysyneu

@ysyneu ysyneu commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

依赖 flashduty-docs #190(先合那个,再合这个)。

为什么

monit-webapi d0d1ef4(2026-07-20 15:53)把 tools/invoke 改成稀疏字段并拍平了单工具结果。生成的 ToolInvokeResponseResultsItem 从来就没有 Summary / Params / Truncated 字段——摘要根本没有地方可以解码进去,所以 fduty monit-agent invoke 在每一次成功调用上都静默把它丢掉。

用 v1.3.26(嵌进 runner、发到全部沙箱与 BYOC 的那个版本)从 tag 编译后实测确认,缺陷此刻活在整个 fleet 上。

本 PR 是什么

三个提交,都是纯重新生成(make sync-spec + make generate),spec 来自 docs #190。

端到端验证——基于本分支重建 flashduty-cli 后打真实 dev API:

之前: [agent_elapsed_ms data e2e_elapsed_ms error(伪造) tool tool_version]
之后: [agent_elapsed_ms data e2e_elapsed_ms params summary tool tool_version]

找回的摘要:os.overview cpu=33.50% mem=74.47% swap=not_configured oom_kill_since_boot=2 load1=3.84。成功时不再出现 error / truncated 键——输出与 webapi 裸线形态逐键一致。

其他变化:

  • diagnose 证据类型现在来自 docs spec,而非手工编辑的 vendored 副本——以后 make sync-spec 不会再把它抹掉
  • 新增服务 LicensesSessionReplay:docs spec 自本分支上次同步(07-14)以来的新接口。没有任何服务丢失,生成的服务集是原来的严格超集

关于被删掉的 en.go

未修复的 docs spec 生成会产出一个假的 EnService彻底丢失 A2aAgents,因为 7 个 /safari/a2a-agent/* 操作的 tag 是裸的 "en"/"zh" 而非 "AI SRE/A2A agents"。docs #190 已修复该问题,这里删除对应的残留生成物。

这很可能解释了为什么已发布的 CLI 固定在一个未合入 main 的 SDK 伪版本上——那条分支的 vendored spec 被手工修过。

验证

  • go build ./... 通过
  • go test ./... 全绿,含 TestSpecExamplesRoundTrip(它抓出了 diagnose 示例把 RFC 3339 时间写成 unix 整数的问题,已在 docs 侧修正)
  • 服务集与集成分支比对:无缺失,仅新增
  • flashduty-cli 对本分支编译通过并成功调用线上 API

第二个提交:稀疏字段不再被物化成零值

原先的判断是「根因在生成器策略、另案处理」,这个判断是错的。生成器早就支持 x-flashduty-preserve-absenceinternal/cmd/gen/main.go)——只是 monit 那几个字段在 spec 里没标。docs #190 补上标记后,本次重新生成的结果:

Summary     *string                                 `json:"summary,omitempty"`
Error       *ToolInvokeResponseResultsItemError      `json:"error,omitempty"`
Truncated   *ToolInvokeResponseResultsItemTruncated  `json:"truncated,omitempty"`
ToolVersion *string                                  `json:"tool_version,omitempty"`
Data        *map[string]any                          `json:"data,omitempty"`

改 spec 而不动生成器默认策略,是因为「响应值类型不加 omitempty」对其余 583 个 schema 是对的(enabled=false 必须忠实渲染)。影响面精确限于标记过的 10 个字段models_gen.go 的 diff 是 10 增 10 删,零附带变化。

ParamsTool 和两个 elapsed 计数器保持值类型——webapi 总会发它们。

遗留(未包含在本 PR)

  • zz_generated_response_help.goDiagnostics.TargetsListdata 记成顶层数组,实际是 {items,total}——存量错误,与 monit 契约无关,另案

第三个提交:target_kinds

审查发现第二个提交漏了一个字段:标记加在父级 error 对象上,但生成器只认字段自身的标记。TargetKinds 因此仍是 []string 无 omitempty,CLI 在每个错误响应上凭空补出 "target_kinds": null

现为 *[]string + omitempty。真实 dev 复验:target_unavailable 路径下 CLI 输出与 webapi 裸线逐键一致。

ysyneu added 6 commits July 20, 2026 01:59
Regenerated from flashduty-docs after the monit contract sync and the a2a
tag repair (flashduty-docs PR #190).

What changes for consumers:

  ToolInvokeResponseResultsItem gains Summary, Params and Truncated.
  These have been missing since the type was first generated, so
  `fduty monit-agent invoke` silently dropped the per-tool summary on
  every successful call — the field simply had nowhere to decode into.
  Verified against the live dev API: rebuilding the CLI on this SDK turns

    [agent_elapsed_ms data e2e_elapsed_ms error tool tool_version]
  into
    [agent_elapsed_ms data e2e_elapsed_ms error params summary tool
     tool_version truncated]

  with a real summary line ("os.overview cpu=30.69% mem=74.53% ...").

  Diagnose evidence types now come from the docs spec rather than a
  hand-edited vendored copy, so `make sync-spec` no longer erases them.

  New services Licenses and SessionReplay appear because the docs spec has
  moved on since this branch last synced. No service is lost — the
  generated service set is a strict superset of the previous one.

Note on `en.go`: regenerating against the *unfixed* docs spec produced a
bogus `EnService` and dropped `A2aAgents` entirely, because seven
/safari/a2a-agent/* operations carried a bare "en"/"zh" tag instead of
"AI SRE/A2A agents". That is fixed on the docs side in the same PR; the
stale generated file is removed here.

Still outstanding: response structs decode absent optional objects into
zero values, so the CLI re-serializes `error:{"code":"","message":""}` and
`truncated:{"reason":""}` even though the API omits both. That needs a
generator change (optional nested structs in response types should emit as
pointers with omitempty) and is deliberately not bundled into this regen.
…ving spec

Picks up flashduty-docs' x-flashduty-preserve-absence markers on the sparse
tool-invoke / tool-catalog response fields. The generator already honours the
extension (internal/cmd/gen/main.go), so this is a pure spec-driven regen:
10 fields move from value types to *T + omitempty, matching monit-webapi's
omit-when-empty wire contract.

Closes the second half of the monit contract drift: consumers no longer
materialise a fabricated error:{"code":"","message":""} / truncated:{"reason":""}
on successful calls. params, tool, and the two elapsed counters stay value
types — webapi always emits them.
Spec-driven regen from flashduty-docs. `ToolInvokeResponseError.TargetKinds`
and `ToolCatalogResponseError.TargetKinds` become `*[]string` + omitempty,
matching webapi's `json:"target_kinds,omitempty"`.

Verified on live dev: a CLI built from this SDK now returns a bare
{"error":{"code","message"},"tools":[]} on the target_unavailable path,
byte-shape-identical to the webapi response. Previously it appended
"target_kinds": null.
Example-only change; models_gen.go is byte-identical. TestSpecExamplesRoundTrip
green against the live-captured failure entry.
@ysyneu
ysyneu merged commit 4d5816a into feat/api-review-auto-fix Jul 20, 2026
4 checks passed
@ysyneu
ysyneu deleted the fix/monit-contract-sync branch July 20, 2026 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant