Skip to content

agentHost: preserve account identity across discovery cache expiry - #346295

Merged
Aaron Munger (amunger) merged 3 commits into
mainfrom
agents/can-you-implement-the-fix-and-manually-test
Nov 9, 2026
Merged

Aaron Munger (amunger) merged 3 commits into
mainfrom
agents/can-you-implement-the-fix-and-manually-test

Conversation

@amunger

@amunger Aaron Munger (amunger) commented Nov 5, 2026 •

Copy link
Copy Markdown
Collaborator

Follow-up to #345691 and microsoft/vscode-internalbacklog#10569.

What and why

Keep a known Copilot account tracking ID available during long-running Agent Host work after endpoint/SKU discovery expires.

Previously, captureCopilotTelemetryContext read identity through the same 30-minute freshness check as routing and SKU data. A file tool starting after that boundary could capture no identity even though the same account was still authenticated; refreshing discovery later could restore the ID for turn completion without repairing the edit's earlier snapshot.

Store the most recently published tracking ID on the existing credential-scoped cache cell, independently of the expiring discovery value. Expiry and transient refresh failures can now omit stale SKU without dropping known identity, including before the first telemetry reader is captured. Successful discovery replaces or clears the identity, and explicit credential invalidation, endpoint changes, and disposal still clear it. Existing account-generation guards remain authoritative.

Retain the last published CAPI client separately so a deferred 401/403 can invalidate the correct credential context even after a transient refresh failure clears the discovery value. Rejection from an older client cannot invalidate a newer published discovery.

This does not extend endpoint/entitlement freshness or introduce extra discovery requests. Identity that has never been discovered remains unavailable.

Validation

fnm exec --using 24.22.1 -- .\scripts\test.bat --run src\vs\platform\agentHost\test\node\shared\copilotApiService.test.ts --reporter dot

135 passing. Covers expiry, transient failure/recovery, credential rejection, account isolation, endpoint changes, disposal, missing identity, competing discovery refreshes, deferred rejection ordering, and refresh failures before the first telemetry reader.

Manually tested the full Code OSS Agents build with a copied authenticated profile and a scratch Git repository. Temporarily shortened the cache TTL to 2 seconds and refresh buffer to 1 second, and used a local boolean-only probe to confirm that the cache was expired at actual file-tool execution.

Three real file-edit turns retained tracking identity while omitting expired SKU. Two real hashChange reporting windows carried IDs matching the originating discovery and turn-completion records. No synthetic telemetry or identity was injected.

All temporary timing changes and probes were removed, normal constants restored, and tests rerun before publication. The manual single-account run predates the deferred-rejection and pre-first-reader follow-ups; those scenarios and live multi-account/rejection boundaries are covered by automated regression tests rather than a repeat manual run. Deployed telemetry ingestion remains a post-rollout check.

Keep the tracking ID in the existing credential-scoped cell independently of endpoint and SKU freshness. Preserve identity on transient discovery failures while retaining authoritative replacement and invalidation behavior.

Follow-up to #345691.

Co-authored-by: Copilot <[email protected]>
Copilot AI balanced review requested due to automatic review settings November 5, 2026 17:04

Copilot AI left a comment

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.

🟡 Changes recommended

Transient discovery-refresh failures can leave a rejected credential’s identity available after an in-flight 401/403 or discard a known tracking ID before telemetry capture.

2 open issues
What changed in this PR

This follow-up separates Copilot account identity from expiring discovery data so long-running Agent Host work can retain edit-survival telemetry attribution without extending endpoint or SKU freshness.

Changes:

  • Stores the latest tracking ID separately on the credential-scoped cache cell.
  • Updates identity publication and invalidation alongside discovery results.
  • Adds regression coverage for expiry, refresh failures, account isolation, rejection, and lifecycle cleanup.
File Description
src/​vs/​platform/​agentHost/​test/​node/​shared/​copilotApiService.test.ts Expands tests for identity retention, replacement, and invalidation.
src/​vs/​platform/​agentHost/​node/​shared/​copilotApiService.ts Separates tracking-ID retention from discovery-cache freshness.

Review effort: Balanced

Keep the last published CAPI client separately from expiring discovery data so delayed credential rejection invalidates the correct account context without clearing newer discovery. Retain known identity even before a telemetry reader is captured.

Co-authored-by: Copilot <[email protected]>
Bring in the corrected CodeQL workflow while preserving the account identity cache changes and regression coverage.

Co-authored-by: Copilot <[email protected]>
@amunger
Aaron Munger (amunger) marked this pull request as ready for review November 9, 2026 22:17
@amunger
Aaron Munger (amunger) merged commit 465d6e7 into main Nov 9, 2026
53 checks passed
@amunger
Aaron Munger (amunger) deleted the agents/can-you-implement-the-fix-and-manually-test branch November 9, 2026 22:19
@vs-code-engineering vs-code-engineering Bot added this to the 1.147.0 milestone Nov 9, 2026
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