mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-08-01 20:44:53 +00:00
* feat: attach KFC trace_id to telemetry events Capture the x-trace-id response header in both kimi providers (kosong and agent-core-v2 llmProtocol) via the openai SDK withResponse(), and thread it through the request result chain into telemetry so events can be joined with server-side request logs by trace id instead of session_id + time window. - kosong / llmProtocol: StreamedMessage/GenerateResult.traceId, GenerateOptions.onTraceId early capture (available mid-stream), APIStatusError.traceId on the error path - v1 (agent-core): per-turn traceIdByTurn on TurnFlow; attach trace_id to turn_ended/turn_interrupted/api_error/cancel/tool_call(+dedup, repeat)/permission_approval_result/question_*/compaction_* - v2 (agent-core-v2): AgentTelemetryContext carries turn_id/trace_id updated by llmRequester; registry gains trace_id on 13 events plus turn_id on turn_* and turn_id/step_no on api_error * fix: attribute trace_id to the failed request on error paths Review follow-ups for trace_id attribution on failure paths: - v1: chatWithRetry feeds a failed attempt's APIStatusError trace id into the turn's traceIdByTurn before the loop dispatches turn.interrupted, so turn_ended/turn_interrupted on error turns attribute to the failed request instead of the previous successful step. - v2: llmRequester keeps the onTraceId-captured trace in per-request state and trackApiError prefers it over error extraction, so failures after response headers arrived (empty response, mid-stream decode errors) no longer clear the ambient trace_id. - v2: compaction_failed falls back to the ambient trace_id once a summarizer request actually hit the wire, covering mid-stream failures whose error carries no trace. - kosong: parseTraceId filters empty x-trace-id headers and both kimi providers read the header through it. - v2 test harness forwards onTraceId to GenerateFn so tests can simulate the early header capture. * fix: attribute v1 api_error to the in-flight request on post-headers failures - v1: a failure after response headers arrived (mid-stream decode error, empty response) carries no trace on the error itself, so api_error lost the trace the client had already captured via onTraceId. Add a per-step in-flight capture (written by onTraceId, cleared at step begin/end) and fall back to it when the error carries no trace, aligning with v2's per-request requestTraceId. Failures before any response headers (network errors, local aborts) still report no trace rather than leaking a previous request's. - v2: document that ambient trace_id distribution assumes serialized LLM requests per agent, naming the two supported paths that break it (after-step compaction below the block ratio; inject-path turns during a manual compaction). * fix: isolate telemetry trace attribution * fix: isolate telemetry trace by request * fix: declare @moonshot-ai/protocol dependency of agent-core-v2 The trace-by-request refactor imports types from @moonshot-ai/protocol in toolContract and toolExecutorService, but the package was not declared, failing clean CI installs (TS2307). Also drop three type imports that are unused after the merge with main. |
||
|---|---|---|
| .. | ||
| src | ||
| test | ||
| CHANGELOG.md | ||
| package.json | ||
| README.md | ||
| tsconfig.json | ||
| tsconfig.type-negative.json | ||
| tsdown.config.ts | ||
| vitest.config.ts | ||