-
Notifications
You must be signed in to change notification settings - Fork 259
fix(agent-core): classify user-cancelled tool telemetry correctly #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Cyning12
wants to merge
1
commit into
MoonshotAI:main
Choose a base branch
from
Cyning12:feature/fix-583-telemetry-cancel
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@moonshot-ai/agent-core": patch | ||
| "@moonshot-ai/kimi-code": patch | ||
| --- | ||
|
|
||
| Fix tool_call telemetry misclassifying user-cancelled Bash runs as errors. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import type { ContentPart } from '@moonshot-ai/kosong'; | ||
|
|
||
| import type { ExecutableToolResult } from '../../loop/types'; | ||
|
|
||
| export type ToolTelemetryResult = ExecutableToolResult; | ||
|
|
||
| function toolOutputText(output: ExecutableToolResult['output']): string { | ||
| if (typeof output === 'string') return output; | ||
| return output | ||
| .filter((part): part is Extract<ContentPart, { type: 'text' }> => { | ||
| return typeof part === 'object' && part !== null && part.type === 'text'; | ||
| }) | ||
| .map((part) => part.text) | ||
| .join(''); | ||
| } | ||
|
|
||
| function toolResultText(result: ToolTelemetryResult): string { | ||
| return toolOutputText(result.output); | ||
| } | ||
|
|
||
| export function telemetryToolOutcome( | ||
| result: ToolTelemetryResult, | ||
| ): 'success' | 'error' | 'cancelled' { | ||
| if (result.isError !== true) return 'success'; | ||
| if (result.cancelledByUser === true) return 'cancelled'; | ||
| return 'error'; | ||
| } | ||
|
|
||
| export function telemetryToolErrorType(result: ToolTelemetryResult): string { | ||
| const text = toolResultText(result); | ||
| if (text.startsWith('Tool "') && text.includes('" not found')) return 'ToolNotFound'; | ||
| if (text.startsWith('Invalid args for tool "')) return 'ToolInputError'; | ||
| if (text.includes('prepareToolExecution hook failed')) return 'HookError'; | ||
| if (text.includes('finalizeToolResult hook failed')) return 'HookError'; | ||
| if (text.includes('blocked')) return 'ToolBlocked'; | ||
| return 'ToolError'; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a user stops a foreground
Agenttool call, the tool handlesisUserCancellation(signal.reason)itself and returns{ output: ..., isError: true }with the “manually interrupted this subagent” message (checkedpackages/agent-core/src/tools/builtin/collaboration/agent.tslines 283-303 and 309-318), but it does not setcancelledByUser. Because this new classifier now treats every unflagged error aserror, those user-cancelled Agent calls regress from the old string heuristic’scancelledoutcome toerror; either propagate the new flag from that tool path or keep a safe fallback for known internal cancellation outputs.Useful? React with 👍 / 👎.