Skip to content

fix(agent-core): classify user-cancelled tool telemetry correctly#630

Open
Cyning12 wants to merge 1 commit into
MoonshotAI:mainfrom
Cyning12:feature/fix-583-telemetry-cancel
Open

fix(agent-core): classify user-cancelled tool telemetry correctly#630
Cyning12 wants to merge 1 commit into
MoonshotAI:mainfrom
Cyning12:feature/fix-583-telemetry-cancel

Conversation

@Cyning12

Copy link
Copy Markdown
Contributor

Related Issue

Fixes #583

Problem

tool_call telemetry inferred outcome from tool output text. Bash user interrupts (Interrupted by user) were recorded as error instead of cancelled, while some real errors containing words like aborted or cancelled could be misclassified as cancelled.

What changed

  • Add telemetry-only cancelledByUser?: true on ExecutableToolErrorResult, set on user abort paths in tool-call.ts and bash.ts via isUserCancellation.
  • Extract telemetryToolOutcome / telemetryToolErrorType to tool-telemetry.ts; classify cancelled outcomes from the structured flag instead of string heuristics.
  • Add vitest coverage for R3 scenarios (user cancel, timeout, false positives, approval cancel, programmatic abort, grace timeout).
  • Changeset: patch for @moonshot-ai/agent-core and @moonshot-ai/kimi-code.

Checklist

  • I have read the CONTRIBUTING document.
  • I have linked a related issue, or explained the problem above.
  • I have added tests that prove my feature works.
  • Ran gen-changesets skill, or this PR needs no changeset.
  • Ran gen-docs skill, or this PR needs no doc update.

Test plan

  • pnpm exec tsc -p tsconfig.json --noEmit (packages/agent-core)
  • pnpm exec vitest run test/agent/turn.test.ts test/loop/tool-call.e2e.test.ts test/tools/bash.test.ts test/tools/shell-cancel.test.ts (119 passed)
  • pnpm lint (0 errors)
  • Manual dev TUI: Bash sleep 30 + Stop → telemetry outcome: cancelled

Made with Cursor

Use cancelledByUser on tool results instead of guessing outcome from
output text, fixing Bash user interrupts misreported as errors.

Fixes MoonshotAI#583

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 679db40

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@moonshot-ai/agent-core Patch
@moonshot-ai/kimi-code Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 679db4069d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines +25 to +26
if (result.cancelledByUser === true) return 'cancelled';
return 'error';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve cancelled telemetry for Agent tool cancels

When a user stops a foreground Agent tool call, the tool handles isUserCancellation(signal.reason) itself and returns { output: ..., isError: true } with the “manually interrupted this subagent” message (checked packages/agent-core/src/tools/builtin/collaboration/agent.ts lines 283-303 and 309-318), but it does not set cancelledByUser. Because this new classifier now treats every unflagged error as error, those user-cancelled Agent calls regress from the old string heuristic’s cancelled outcome to error; either propagate the new flag from that tool path or keep a safe fallback for known internal cancellation outputs.

Useful? React with 👍 / 👎.

Cyning12 pushed a commit to Cyning12/kimi-code that referenced this pull request Jun 11, 2026


Update task self-check, invoke 30 snapshot, and README link.

Co-authored-by: Cursor <cursoragent@cursor.com>
Cyning12 pushed a commit to Cyning12/kimi-code that referenced this pull request Jun 11, 2026
…onshotAI#630

Mark C2关账、勾选验收项,invoke README 链 PR;PROMPT 路径改 done/。

Co-authored-by: Cursor <cursoragent@cursor.com>
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.

Tool-call telemetry misclassifies Bash cancellation outcomes

2 participants