Skip to content

Conversation

@hediet
Copy link
Member

@hediet hediet commented Dec 5, 2025

Supersedes #2365. Fixes microsoft/vscode#281044

Copilot AI review requested due to automatic review settings December 5, 2025 11:18
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Dec 5, 2025
Copilot finished reviewing on behalf of hediet December 5, 2025 11:21
Copy link
Contributor

Copilot AI left a 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 enhances edit survival tracking by capturing the actual text content at three key stages: before AI edits, after AI edits, and after user edits. This data enables better analysis of what code changes survive and how users modify AI-generated code.

Key Changes:

  • Extends EditSurvivalTracker.computeTrackedEditsSurvivalScore() to return text arrays for each edit region
  • Adds text capture fields to EditSurvivalResult interface
  • Updates telemetry events across multiple tools to include serialized text arrays
  • Adds comprehensive test coverage for the new functionality

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
src/platform/editSurvivalTracking/common/editSurvivalTracker.ts Collects text snapshots from three stages (before AI edits, after AI edits, after user edits) and returns them as arrays alongside existing survival scores
src/platform/editSurvivalTracking/common/editSurvivalReporter.ts Extends EditSurvivalResult interface with optional text array fields and passes them through to telemetry
src/extension/tools/node/applyPatchTool.tsx Adds new internal telemetry event with JSON-stringified text arrays for apply patch operations
src/extension/tools/node/abstractReplaceStringTool.tsx Adds new internal telemetry event with JSON-stringified text arrays for string replace operations
src/extension/prompts/node/codeMapper/codeMapperService.ts Updates existing internal telemetry to include JSON-stringified text arrays
src/extension/test/node/utils.spec.ts Adds three new test cases validating text capture functionality with inline snapshots, refactors existing test to use expect/toMatchInlineSnapshot pattern

Comment on lines +279 to +281
textBeforeAiEdits: 'text1BeforeAiEdits',
textAfterAiEdits: 'text2AfterAiEdits',
textAfterUserEdits: 'text3AfterUserEdits',
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

[nitpick] The renameProps function is a test helper that renames properties in the test output to make the snapshots more readable (e.g., textBeforeAiEditstext1BeforeAiEdits). However, the naming convention with numbered prefixes (text1, text2, text3) is a bit unclear. Consider using more descriptive names like textOriginal, textAiEdited, textUserEdited to make the test snapshots more self-documenting.

Suggested change
textBeforeAiEdits: 'text1BeforeAiEdits',
textAfterAiEdits: 'text2AfterAiEdits',
textAfterUserEdits: 'text3AfterUserEdits',
textBeforeAiEdits: 'textOriginal',
textAfterAiEdits: 'textAiEdited',
textAfterUserEdits: 'textUserEdited',

Copilot uses AI. Check for mistakes.
Comment on lines 36 to 37
* fourGram: Number between 0 (no edits survived) and 1 (all edits survived).
* noRevert: Number between 0 (the text after user edits equals the text before the AI edits) and 1 (the text after user edits does not revert any text to the initial state)
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

The JSDoc comment describes the return value as having fourGram and noRevert properties, but the function now also returns textBeforeAiEdits, textAfterAiEdits, and textAfterUserEdits. The documentation should be updated to describe these new fields:

/**
 * Computes survival scores and text snapshots for tracked edits.
 * 
 * @returns An object containing:
 * - fourGram: Number between 0 (no edits survived) and 1 (all edits survived).
 * - noRevert: Number between 0 (the text after user edits equals the text before the AI edits) and 1 (the text after user edits does not revert any text to the initial state)
 * - textBeforeAiEdits: Array of text strings before AI edits were applied for each edit region
 * - textAfterAiEdits: Array of text strings after AI edits were applied for each edit region
 * - textAfterUserEdits: Array of text strings after user edits were applied for each edit region
 */
Suggested change
* fourGram: Number between 0 (no edits survived) and 1 (all edits survived).
* noRevert: Number between 0 (the text after user edits equals the text before the AI edits) and 1 (the text after user edits does not revert any text to the initial state)
* Computes survival scores and text snapshots for tracked edits.
*
* @returns An object containing:
* - fourGram: Number between 0 (no edits survived) and 1 (all edits survived).
* - noRevert: Number between 0 (the text after user edits equals the text before the AI edits) and 1 (the text after user edits does not revert any text to the initial state)
* - textBeforeAiEdits: Array of text strings before AI edits were applied for each edit region.
* - textAfterAiEdits: Array of text strings after AI edits were applied for each edit region.
* - textAfterUserEdits: Array of text strings after user edits were applied for each edit region.

Copilot uses AI. Check for mistakes.
Comment on lines +31 to +36
/**
* Text states for each edit region
*/
readonly textBeforeAiEdits?: string[];
readonly textAfterAiEdits?: string[];
readonly textAfterUserEdits?: string[];
Copy link

Copilot AI Dec 5, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider adding documentation about potential data size implications when serializing textBeforeAiEdits, textAfterAiEdits, and textAfterUserEdits arrays. For files with many edits or large edit regions, the JSON.stringify() calls could produce very large strings in telemetry events. Consider adding a note in the JSDoc about this being intended for internal-only telemetry, or potentially adding size limits/truncation logic if this becomes an issue.

Copilot uses AI. Check for mistakes.
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.

Track strings for codeSurvivalRate calculation

3 participants