MoonshotAI / MoonshotAI/kimi-code
Tool-call telemetry misclassifies Bash cancellation outcomes
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 7.5k
- Forks
- 1.2k
- Avg merge
- 11h 53m
- Merged PRs (30d)
- 350
Description
This was generated by AI during triage.
Summary
tool_call telemetry currently derives outcome from tool output text. This makes some cancellation paths show up as error, and can also make real errors show up as cancelled when their output happens to contain cancellation-related words.
I can help implement the fix, but I would like to discuss the preferred shape with maintainers first because the robust fix may involve structured metadata on internal tool.result handling, and possibly SDK-visible event contracts.
Affected code
packages/agent-core/src/agent/turn/index.ts:telemetryToolOutcomeclassifies by string matching against tool output.packages/agent-core/src/tools/builtin/shell/bash.ts: Bash abort and timeout paths return user-visible text such asInterrupted by userandCommand killed by timeout (...).packages/agent-core/src/loop/tool-call.ts:isUserCancellation(signal.reason)is available while settling aborted tool calls, but this structured signal is not preserved for telemetry.
What I observed
Current classification logic treats an error result as cancelled only when output contains one of:
abortedcancelledmanually interrupted
That means these cases are currently misclassified or fragile:
- Bash user abort returns
Interrupted by user, so telemetry recordsoutcome: errorinstead ofcancelled. - Bash timeout returns
Command killed by timeout (...), so it is also recorded aserror; whether timeout should remainerroror become a separate category seems worth deciding explicitly. - A real hook/tool error whose message or stack contains
aborted,cancelled, ormanually interruptedcan be recorded ascancelled, which also suppresses theerror_typefield becauseerror_typeis only attached whenoutcome === "error".
Expected behavior
Telemetry should not depend only on user-visible output strings. User-initiated cancellation should be classified consistently as cancelled; real tool or hook failures should remain error; timeout behavior should have an explicit agreed meaning, either a separate outcome or an error subtype.
Possible fix directions
- Minimal fix: add another string such as
interruptedtotelemetryToolOutcome. This covers the Bash user-abort text but keeps the false-positive problem and remains coupled to copy changes. - Preferred direction: preserve structured outcome or reason metadata when creating
tool.resultevents or internal telemetry inputs. The loop already has access toisUserCancellation(signal.reason)in cancellation paths, so telemetry can consume structured state instead of guessing fromoutput.
I am happy to help with the implementation after maintainers confirm which telemetry schema and event-surface tradeoff is preferred.
Additional notes
Impact appears limited to telemetry and the distribution of error_type; I did not find in-process retry, UI, or control-flow logic depending on this telemetry outcome field.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read telemetryToolOutcome in packages/agent-core/src/agent/turn/index.ts, then trace Bash cancellation and timeout results in packages/agent-core/src/tools/builtin/shell/bash.ts and cancellation settling in packages/agent-core/src/loop/tool-call.ts. Confirm the telemetry schema and event-surface choice with maintainers before implementing. Done means user cancellation is classified consistently, real failures remain errors with error_type, and timeout semantics are explicit.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- observability-sre
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100