-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand conversation.repetition.detected telemetry to cancelled requests #2892
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
base: main
Are you sure you want to change the base?
Conversation
- Add checkRepetitionInDeltas method to analyze partial responses - Modify processCanceledResponse to check for repetition before returning - Send conversation.repetition.detected telemetry for both token and line repetition - Mark finishReason as 'canceled' to distinguish from completed requests Co-authored-by: vijayupadya <[email protected]>
Co-authored-by: vijayupadya <[email protected]>
- Filter out undefined/null delta.text values before joining - Add requestId to telemetry properties for consistency with completed requests - Clarify comment about token approximation Co-authored-by: vijayupadya <[email protected]>
- Filter out null, undefined, and empty text values from deltas - Remove manual requestId assignment for enhanced telemetry (not needed) - Add clarifying comment about RequestId object unavailability Co-authored-by: vijayupadya <[email protected]>
- Document key differences from completed request handling - Explain token approximation limitations - Document missing telemetry fields for cancelled requests - Clarify finishReason usage Co-authored-by: vijayupadya <[email protected]>
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.
Pull request overview
This PR extends the conversation.repetition.detected telemetry event to fire for cancelled requests, addressing a gap where thought looping that leads to user cancellation was not being tracked.
Changes:
- Added
checkRepetitionInDeltasmethod to detect repetition patterns in partial responses from cancelled requests - Updated
processCanceledResponseto accept additional parameters and invoke repetition checking before returning - Modified the cancelled request handling flow to pass
streamRecorderandtelemetryPropertiesfor repetition detection
| telemetryProperties?: TelemetryProperties | ||
| ): void { | ||
| // Reconstruct the text content from deltas (filter out null, undefined, and empty text values) | ||
| const textContent = deltas.filter(delta => delta.text != null && delta.text !== '').map(delta => delta.text).join(''); |
Copilot
AI
Jan 16, 2026
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.
The filtering condition delta.text != null && delta.text !== '' could be simplified using a more idiomatic approach. Consider extracting this to a named function or using a clearer filter condition like delta.text?.length > 0 which combines null/undefined checking with empty string checking.
| const textContent = deltas.filter(delta => delta.text != null && delta.text !== '').map(delta => delta.text).join(''); | |
| const textContent = deltas.filter(delta => delta.text?.length > 0).map(delta => delta.text).join(''); |
|
|
||
| // For cancelled requests, we don't have the actual token array (only available in ChatCompletion), | ||
| // so we approximate by splitting text content on whitespace. This is less precise than actual | ||
| // tokenization but sufficient for detecting obvious repetition patterns. |
Copilot
AI
Jan 16, 2026
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.
While the comment above explains that this is an approximation, it would be helpful to add a brief inline comment noting that this tokenization approach will differ from actual LLM tokenization (which may split on different boundaries). This would help future maintainers understand why results might differ between completed and cancelled requests.
| // tokenization but sufficient for detecting obvious repetition patterns. | |
| // tokenization but sufficient for detecting obvious repetition patterns. | |
| // Note: This whitespace-based split does not match the model's real tokenization, so | |
| // repetition metrics here may differ slightly from those computed for completed responses. |
Fixes microsoft/vscode#287573
The
conversation.repetition.detectedevent was not firing for cancelled requests, missing cases where thought looping leads to user cancellation.Changes
Added
checkRepetitionInDeltasmethodisRepetitive()for token patterns,calculateLineRepetitionStats()for line repetitionfinishReason: 'canceled'Updated
processCanceledResponsestreamRecorderandtelemetryPropertiesparametersLimitations
Enhanced telemetry for cancelled requests lacks
RequestIdobject fields (completionId, deploymentId, serverExperiments) since only the headerRequestId string is available. Token approximation is less precise than actual tokenization but sufficient for detecting obvious repetition patterns.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.