Skip to content

Refactor AI CoAuthor Attribution#311796

Draft
cwebster-99 wants to merge 5 commits intomainfrom
resident-seahorse
Draft

Refactor AI CoAuthor Attribution#311796
cwebster-99 wants to merge 5 commits intomainfrom
resident-seahorse

Conversation

@cwebster-99
Copy link
Copy Markdown
Member

Persistence and Attribution Tracking:

  • aiContributionFeature.ts now records AI contributions per-URI in a ResourceMap, persisting this state in workspace storage so that attributions survive document closure and window reloads.
  • The feature triggers storage writes on changes, debounced for efficiency, and flushes pending writes on disposal or when the workspace state is saved.

API and Command Changes:

  • The commands for checking and clearing AI contributions now operate on the new persistent map, and a new command is added to clear all contributions.

Dependency and Construction Updates:

  • The feature is now constructed with an ObservableWorkspace and IStorageService instead of annotated documents, updating all instantiations and tests accordingly. [1] [2]

Testing Improvements:

  • Tests are updated to verify that contributions persist after documents are closed, survive workspace reloads, and are correctly cleared from storage. New tests ensure pending writes are flushed on disposal and that clearing works for files tracked only in storage. [1] [2] [3]

Code Cleanup:

  • Removes unused dependencies and legacy tracking logic, simplifying the codebase and test setup. [1] [2]

cwebster-99 and others added 3 commits April 21, 2026 17:08
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Copilot AI review requested due to automatic review settings April 21, 2026 22:37
Copy link
Copy Markdown
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

Refactors AI co-author attribution tracking to persist AI contributions per-URI in workspace storage, so Git’s addAICoAuthor behavior survives document close and window reloads.

Changes:

  • Replace per-open-document tracking with a persisted ResourceMap<AiContributionLevel> keyed by URI and backed by IStorageService.
  • Debounce storage writes and flush pending state on workspace save and on dispose; add a command to clear all contributions.
  • Update contribution wiring and tests to use ObservableWorkspace + storage-backed persistence semantics.
Show a summary per file
File Description
src/vs/workbench/contrib/editTelemetry/browser/aiContributionFeature.ts Implements per-URI contribution recording, persistence, debounced saving, and updated commands.
src/vs/workbench/contrib/editTelemetry/browser/editTelemetryContribution.ts Updates feature instantiation to pass ObservableWorkspace instead of annotated documents.
src/vs/workbench/contrib/editTelemetry/test/browser/aiContributionFeature.test.ts Updates and extends tests for persistence across close/reload, clearing persisted-only entries, and dispose flush behavior.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment thread src/vs/workbench/contrib/editTelemetry/test/browser/aiContributionFeature.test.ts Outdated
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

Screenshot Changes

Base: 498c4699 Current: d0d77247

Changed (1)

chat/aiCustomizations/aiCustomizationManagementEditor/McpBrowseMode/Light
Before After
before after

Copy link
Copy Markdown
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.

Copilot's findings

Comments suppressed due to low confidence (1)

src/vs/workbench/contrib/editTelemetry/browser/aiContributionFeature.ts:128

  • Same concern here: _clearAiContributions revives untrusted URI components via URI.revive. Use URI.from(..., true) (or otherwise validate) to avoid accepting invalid/malicious URIs and to keep persisted keys stable.
			for (const r of resources) {
				if (this._contributions.delete(URI.revive(r))) {
					changed = true;
				}
			}
  • Files reviewed: 3/3 changed files
  • Comments generated: 3

Comment on lines +170 to +176
const obj: Record<string, AiContributionLevel> = {};
for (const [uri, level] of this._contributions) {
obj[uri.toString()] = level;
}
// MACHINE: attribution is tied to on-disk content of this
// workspace, which differs per machine.
this._storageService.store(STORAGE_KEY, JSON.stringify(obj), StorageScope.WORKSPACE, StorageTarget.MACHINE);
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

When building the persisted snapshot, using a normal object ({}) with dynamic string keys can be vulnerable to prototype-pollution edge cases (e.g. a crafted URI string of __proto__) and can also behave oddly with such keys. Use a null-prototype dictionary (Object.create(null)) or persist as an array of [uriString, level] tuples instead.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in e608489 — switched to Object.create(null) for the persisted snapshot object.

Comment on lines +217 to +223
test('persisted AI ranges survive a workspace reload', () => runWithFakedTimers({}, async () => {
const reloadStore = new DisposableStore();
const sharedStorage = reloadStore.add(new TestStorageService());

setup(sharedStorage);
const d = disposables.add(workspace.createDocument({ uri: fileA, initialValue: 'hello' }, undefined));
await timeout(1500);
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

Test name still refers to “AI ranges”, but the feature now persists per-URI contribution levels (not tracked ranges). Renaming this test (and any related comments) would keep the test intent aligned with the new behavior.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in e608489 — renamed to "persisted AI contribution levels survive a workspace reload".

Comment on lines 103 to +110
private _hasAiContributions(resources: UriComponents[], level: AiContributionLevel): boolean {
for (const resource of resources) {
const entry = this._trackers.get(URI.revive(resource));
if (entry) {
for (const edit of entry.tracker.getTrackedRanges()) {
if (edit.source.category === 'ai' && (level === 'all' || edit.source.feature === 'chat')) {
return true;
}
}
for (const r of resources) {
const recorded = this._contributions.get(URI.revive(r));
if (recorded === undefined) {
continue;
}
if (level === 'all' || recorded === 'chatAndAgent') {
return true;
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

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

resources are command arguments coming from extensions (untrusted URI components). URI.revive explicitly does no validation and is intended for URI#toJSON data; using it here can accept malformed URIs and create surprising keys/collisions (and interacts badly with the object-key persistence below). Prefer URI.from(resource, /*strict*/ true) (or validate with isUriComponents + URI.from) when reviving command args.

This issue also appears on line 124 of the same file.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fixed in e608489 — replaced URI.revive(r) with URI.from(r, true) on both lines 105 and 125.

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 21, 2026

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • redirector.gvt1.com
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --no-sandbox --enable-crash-reporter=d4475174-6a12-456d-ac43-765d2d549e47,no_channel --user-data-dir=/tmp/vscode-tests-1776812786381 --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,7274595108555188822,12434028639023770613,262144 --enable-features=PdfUseShowSaveFilePicker --disable-features=LocalNetworkAccessChecks,ScreenAIOCREnabled,SpareRendererForSitePerProcess,TraceSiteInstanceGetProcessCreation --variations-seed-version --trace-process-track-uuid=3190708989122997041 (dns block)
    • Triggering command: .build/electron/code-oss .build/electron/code-oss --no-sandbox test/unit/electron/index.js --run src/vs/workbench/contrib/editTelemetry/test/browser/aiContributionFeature.test.ts (dns block)
    • Triggering command: /proc/self/exe /proc/self/exe --type=utility --utility-sub-type=network.mojom.NetworkService --lang=en-US --service-sandbox-type=none --no-sandbox --enable-crash-reporter=7ee17427-6805-46a9-a808-bd418a9f6ac1,no_channel --user-data-dir=/tmp/vscode-tests-1776812801673 --shared-files=v8_context_snapshot_data:100 --field-trial-handle=3,i,12745415684127993355,3422542758782645387,262144 --enable-features=PdfUseShowSaveFilePicker --disable-features=LocalNetworkAccessChecks,ScreenAIOCREnabled,SpareRendererForSitePerProcess,TraceSiteInstanceGetProcessCreation --variations-seed-version --trace-process-track-uuid=3190708989122997041 onFeature.test.ts de/node/bin/git (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

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.

3 participants