Final telemetry flush races the Substrate checkpoint: "flush telemetry after task settlement" fails with EOF on ~25% of turns

未关闭
#3,758 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@xixi-box 已经在做这个了。

开始于 2026年11月22日。

  • #3765 来自 @xixi-box —— 未关闭

评估

难度
5/5
预计耗时
一周以上
新手友好度
22/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
go, kubernetes

调研方向

Start by finding the runtime code that emits the flush telemetry after task settlement export and the worker path that logs Actor checkpointing, then look at the ordering between them; the related issues #2176, #2909 and the LoggerProvider races #2759/#2772 show where earlier flushes were hooked in. Reproduce with the steps above (short SendMessage turns against an OTLP/HTTP collector) and compare collector-received spans against the checkpoint timestamps. Done means the final flush completes before checkpointing starts, or unsent spans survive restore, verified on repeated short turns rather than one run. This is a design choice between three options in the issue, so expect discussion before a patch.

由索引模型根据 Issue 内容生成。

描述

Disclosure: an AI agent (Claude) wrote this issue while debugging telemetry on a homelab kagent install. A human reviewed it before filing.

Summary

The flush that runs after task settlement races the Substrate checkpoint. Substrate starts checkpointing the actor as soon as the task settles. The runtime's flush telemetry after task settlement export starts a few milliseconds later, and the frozen sandbox cuts it off with EOF. Whatever was still buffered in that last batch is lost.

On one node, 283 of 1,110 checkpoints (25%) in 24 hours logged this error.

Environment

  • kagent chart and controller 1.0.0
  • Substrate worker pools kagent-default and kagent-trusted (gVisor, one replica each, one node)
  • Traces configured on the Harness with standard OTEL variables:
    • OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://<collector>:4318/v1/traces
    • OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf
  • Seen on kagent-engine (adk-go) Agents and on Claude-harness Agents

Timeline of one turn

All lines are from the worker pod log for one actor (session-01a1fe27-…, a kagent-engine Agent):

Time (UTC) Source Event
12:48:58.247 runtime execute (task starts)
12:49:01.701 runtime tool execution completed
12:49:03.637 egress last trace POST from this actor returns 200
12:49:03.645 worker Actor checkpointing
12:49:03.657 runtime ERROR flush telemetry after task settlement … error="traces export: Post \"http://<collector>:4318/v1/traces\": EOF"
12:49:03.760 worker Actor checkpointed

The flush starts 12 ms after checkpointing begins, and its POST ends in EOF. The egress proxy logs the same request with no HTTP status, followed by Reset { error_code: CANCEL } on the actor's connection.

Frequency

These counts come from Loki over 24 hours on one node:

sum(count_over_time({k8s_namespace_name="kagent"} |= "\"message\":\"Actor checkpointing\"" [24h]))     -> 1110
sum by (target) (count_over_time({k8s_namespace_name="kagent"} |= "flush telemetry after task settlement"
  | regexp "(?P<target>otel-collector\\.[a-z-]+|otel-gateway)" [24h]))
    agentevals collector   275
    usage collector          7
    monitoring gateway       1    (a metrics export)

By agent type, over the same 24 hours:

Agents Checkpoints Final flush failed
Claude-harness eval candidates 695 275 (40%)
Claude-harness production agents ~85 7
kagent-engine agents with trace export 18 1

The eval candidates fail most often. Their turns are short and run back to back, and each turn ends in a checkpoint.

Steps to reproduce

  1. Configure an Agent's Harness to export traces to an OTLP/HTTP collector (OTEL_EXPORTER_OTLP_TRACES_ENDPOINT, OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf).
  2. Send several short blocking SendMessage turns to the Agent, each one tool call and two model calls.
  3. Search the worker pod log for flush telemetry after task settlement. For each hit, compare its timestamp with that actor's Actor checkpointing line. The flush starts after the checkpoint has started.
  4. Compare the spans the collector received for that turn with the spans the turn should produce. The spans still buffered at settlement are expected to be missing. These include the A2A request span, invoke_agent and the task-store RPCs, plus any span that ended less than one batch delay earlier. I have confirmed the failed export, but not which spans it carried.

Impact

  • Incomplete traces for evaluation. Trace-based scoring (agentevals) gets turns without their closing spans. That is 275 of the 283 failures here.
  • Lost GenAI telemetry. Any span or log record still in the final batch is dropped. With the default 5 s batch delay, that can include the anthropic.messages.create span of a turn's last model call, so token and cost accounting built on traces would undercount.
  • Silent loss. The error is logged only inside the actor, and nothing retries the export after the actor resumes.

Expected

The final flush finishes before Substrate starts the checkpoint. One of these would do it:

  • run the flush before the task is settled and reported as complete, or
  • have Substrate wait for a runtime "quiescent" signal sent after the flush, or
  • keep unsent telemetry in the snapshot and export it after restore, instead of dropping it.

Related

  • #2176: added the pre-response flush. Here the flush does run, but too late.
  • #2759 and #2772: the same checkpoint race for the LoggerProvider.
  • #2909: removed KAGENT_PRE_RESPONSE_TRACE_FLUSH. The flush is now always on, so this affects every install that exports telemetry.

Workaround

OTEL_BSP_SCHEDULE_DELAY=200 on the Harness exports spans during the turn instead of at the end. That shrinks the final batch, but it can't remove it.

主要语言
Go
星标
4.5k
派生
937
平均合并
1 天 10 小时
30 天内合并 PR
150

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

kagent-dev/kagent 的其他 Issue

查看 kagent-dev/kagent 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。