Skip to content
This repository was archived by the owner on Sep 1, 2026. It is now read-only.

Fix parse cache ref race during cloned program updates - #4400

Closed
Daniel Rosenwasser (DanielRosenwasser) with Copilot wants to merge 10 commits into
mainfrom
copilot/fix-cache-entry-not-found-error
Closed

Fix parse cache ref race during cloned program updates#4400
Daniel Rosenwasser (DanielRosenwasser) with Copilot wants to merge 10 commits into
mainfrom
copilot/fix-cache-entry-not-found-error

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

A cloned project update can reuse SourceFile pointers after their parse-cache entries were concurrently released by snapshot disposal. Re-refing those reused files with Ref could panic with cache entry not found.

  • Parse cache

    • Added RefValue, which refs an existing entry or restores it from the reused value if it was deleted before the ref.
    • Added RefIfPresent for optional duplicate-source bookkeeping refs.
  • Program clone path

    • Reused source files now restore parse-cache ownership from the SourceFile pointer.
    • Duplicate source entries use optional refs because they only represent previously acquired cache entries and do not carry a restorable SourceFile.
p.host.builder.parseCache.RefValue(
    NewParseCacheKey(file.ParseOptions(), file.Hash, file.ScriptKind),
    file,
)
  • Coverage
    • Added focused refcount cache coverage for restoring a deleted entry without reparsing.

Copilot AI and others added 8 commits June 22, 2026 20:01
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Co-authored-by: DanielRosenwasser <972891+DanielRosenwasser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix panic: cache entry not found issue Fix parse cache ref race during cloned program updates Jun 22, 2026
@andrewbranch

Copy link
Copy Markdown
Member

Copilot a snapshot should never be cloned after it's released. The ref count cache is the wrong place to look for the problem. If you can't reproduce the crash by driving a real project.Session in a test—with whatever custom hosts with blocking channels to manipulate timing you want—then you don't have a credible theory of the problem, and therefore no credible fix. Putting a band-aid over your best guess is never acceptable.

Co-authored-by: andrewbranch <3277153+andrewbranch@users.noreply.github.com>

Copilot AI commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

Copilot a snapshot should never be cloned after it's released. The ref count cache is the wrong place to look for the problem. If you can't reproduce the crash by driving a real project.Session in ...

Reverted the unsupported parse-cache refcount changes in f23fd18. I did not keep the band-aid; without a real project.Session reproduction, the PR now leaves the refcount cache behavior unchanged.

@andrewbranch

Copy link
Copy Markdown
Member

Very good PR now, approved

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants