Skip to content

Store real version and checksum for cached WASM parsers - #741

Open
IzonIcy wants to merge 1 commit into
athasdev:mainfrom
IzonIcy:wasm-parser-cache-metadata
Open

Store real version and checksum for cached WASM parsers#741
IzonIcy wants to merge 1 commit into
athasdev:mainfrom
IzonIcy:wasm-parser-cache-metadata

Conversation

@IzonIcy

@IzonIcy IzonIcy commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

Store real version and checksum for cached WASM parsers

Problem

Cached tree-sitter parser entries were written with a hardcoded version: "1.0.0" and an empty checksum (the two TODOs in loader.ts). The cache metadata carried no real information, and there was no way to detect corrupted or tampered parser bytes on disk.

Changes

  • New src/features/editor/lib/wasm-parser/checksum.ts: SHA-256 over the WASM bytes via WebCrypto (crypto.subtle.digest), plus a verification helper.
  • Cache writes (both the remote-download and local-path sites, now sharing one createCacheEntry builder) store:
    • the real SHA-256 checksum of the bytes,
    • the parser version resolved from the language extension manifest via getLanguageExtensionById, falling back to "unknown".
  • Cache reads verify the stored checksum. On mismatch the entry is deleted and treated as a cache miss so the loader re-downloads instead of loading broken bytes. Entries written before this change have an empty checksum and remain valid, so no user is forced to re-download.

Testing

  • New tests: src/features/editor/tests/wasm-parser-checksum.test.ts covers known SHA-256 vectors ("abc" and empty input), match/mismatch verification, and the legacy empty-checksum case.
  • Full suite passes: 358 files, 1755 tests. Typecheck and lint pass.
  • bun check still reports 5 pre-existing cargo fmt diffs that also appear on a clean checkout of main (stable rustfmt cannot apply the nightly-only options); nothing new from this change.

I agree to the Contributor License and Feedback Agreement.

Cached tree-sitter parser entries were written with a hardcoded
"1.0.0" version and an empty checksum, so cache metadata carried no
useful information and there was no way to detect corrupted downloads.

Cache writes now compute a SHA-256 checksum of the WASM bytes via
WebCrypto and resolve the parser version from the language extension
manifest when one is registered, falling back to "unknown". Both cache
write sites share a single entry builder instead of duplicating the
record shape.

Cache reads verify the stored checksum and treat a mismatch as a cache
miss, deleting the entry so the loader re-downloads instead of loading
broken bytes. Entries written before this change store an empty
checksum and stay readable without forcing a re-download.

Adds tests for checksum computation against known SHA-256 vectors and
for legacy and mismatched checksum verification.
Copilot AI lite review requested due to automatic review settings August 23, 2026 01:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

2 participants