Skip to content

Preserve inferred project ATA state - #64327

Draft
Jake Bailey (jakebailey) wants to merge 5 commits into
microsoft:mainfrom
jakebailey:preserve-inferred-ata
Draft

Jake Bailey (jakebailey) wants to merge 5 commits into
microsoft:mainfrom
jakebailey:preserve-inferred-ata

Conversation

@jakebailey

Copy link
Copy Markdown
Member

I noticed in our scripts dir (no tsconfig), that clicking on a file flashed errors. I closed it, opened another file, and the errors appeared and disappeared again! If I opened another file without closing the first, that one was fine.

The issue is that we lose the ATA state when inferred projects go away, so reopening causes ATA to happen again.

Save the state and apply it directly to inferred projects if present.

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.

Copilot review overview

🟡 Changes recommended

Cached ATA state can be incorrectly reused across unrelated roots or changed manifests.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
What changed in this PR

Preserves ATA results when inferred projects are recreated.

Changes:

  • Stores and restores inferred-project typings state.
  • Adds a reopening regression test.
File Description
projectcollectionbuilder.go Transfers cached ATA state.
projectcollection.go Stores cached ATA state.
project.go Defines ATA state capture/application.
ata/​ata_test.go Tests immediate typings restoration.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread tsc/internal/project/projectcollectionbuilder.go Outdated

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.

Copilot review overview

🟡 Changes recommended

Cache validation misses filesystem invalidation and changed ATA inputs, and content-mapped roots use incompatible hashes.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 3 Medium severity

Open (3)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Invalidate ATA cache when inferred-project options change

tsc/​internal/​project/​project.go:214

Root names and contents are not the complete ATA input. If inferred-project compiler options change while no inferred project exists, the cached state is left untouched; reopening the same roots applies typings computed under the old options before ATA is queued in the background (and resolution-affecting options can also change the unresolved-import set). Preserve and compare the relevant command-line/mapping inputs, or invalidate this cache when those inputs change.

Comment thread tsc/internal/project/project.go Outdated
Comment thread tsc/internal/project/projectcollectionbuilder.go Outdated

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.

Copilot review overview

🟡 Changes recommended

Stale ATA results can still overwrite invalidated configured or synthetic project state, and key new branches lack regression coverage.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 2 Low severity

Open (3)
Resolved since last review (3)

logger.Embed(ataChange.Logs)
if _, ok := projectID.Inferred(); ok {
updateProject(b.inferredProject, ataChange)
if ataChange.SnapshotID < b.inferredProjectATAInvalidationSnapshotID {
packageNameToTypingLocation.Range(func(name string, typing *CachedTyping) bool {
registryEntry := typesRegistry[name]
if inferredTypings[name] == "" && registryEntry != nil && isTypingUpToDate(typing, registryEntry) {
if inferred, ok := inferredTypings[name]; ok && inferred == "" && registryEntry != nil && isTypingUpToDate(typing, registryEntry) {
}
if b.inferredProject.Value() != nil {
updateProject(b.inferredProject, ataChange)
} else {

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.

Copilot review overview

🟡 Changes recommended

The invalidation tombstone map grows indefinitely and adds increasing cloning cost to every snapshot.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 1 Medium severity · 2 Low severity

Open (4)

Comment thread tsc/internal/project/projectcollectionbuilder.go Outdated

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.

Copilot review overview

🟡 Changes recommended

Unbuilt inferred-project transitions can discard valid cached results or temporarily unregister their watches.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 3 Medium severity · 2 Low severity

Open (6)
Resolved since last review (1)

Comment thread tsc/internal/project/projectcollection.go Outdated
Comment thread tsc/internal/project/projectcollectionbuilder.go Outdated
Comment thread tsc/internal/project/projectcollectionbuilder.go Outdated
An inferred project can exist without a program while cached ATA state is still authoritative. Keep that state and its watcher until a built program validates it, and reject results older than the latest installed or confirmed state.

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.

Copilot review overview

🟡 Changes recommended

ATA results can invalidate themselves during concurrent watcher events, and some installed-typing changes bypass invalidation.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 2 Medium severity · 2 Low severity

Open (5)
Resolved since last review (3)

Comment on lines +527 to +529
if len(filesToWatch) == 0 {
return false
}
Comment on lines +1060 to +1064
if fileChangeSummaryAffectsTypingsWatch(
fileChanges,
slices.Concat(ataChange.TypingsFilesToWatch, ataChange.FileNames),
ataChange.TypingsFiles,
b.sessionOptions.TypingsLocation,
Typings cache writes are outputs of acquisition, not discovery changes, and can arrive in the same flush as their result. Keep those events available to the program while excluding them from ATA invalidation, without losing real package-owned inputs or full invalidations.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

Status: Not started

Development

Successfully merging this pull request may close these issues.

2 participants