Stop wasm type-check feeds serving stale Salsa results

Merged
RE
4mo ago
+113-6

type_check.spec.ts > "failing snippet does not execute and session survives" fails intermittently because Salsa treats a file as unchanged when its modified time is unchanged, and wasm's clock only ticks once a millisecond. So with two writes to the same file in a millisecond Salsa does not detect the change.

Observed in CI:

DateBranchRun
2026-08-13host-memory-probe31736318169
2026-08-14fix-chain-source-latch (#748)31837343813

https://github.com/pydantic/monty/blob/edeb82a6d2594410010cdb319419289decbf3399/crates/monty-js/__test__/type_check.spec.ts#L161

Changes:

  • bump_revisions is to bump Salsa revisions explicitly on write instead of relying on modified times
  • adjust_annotation_span is a defensive clamp if invalid to prevent crash

šŸ¤– Generated with Claude Code


Summary by cubic

Prevents wasm type-check feeds from reusing stale Salsa results and crashing by explicitly bumping file and directory revisions and clamping diagnostic spans to the source. Previously, consecutive writes could share an mtime-based revision in wasm, causing stale checks and TextSize wrap that killed the worker; now each write produces a fresh revision and span math is safe.

  • TypeChecker::{write_root_file,rewrite_root_file} call bump_revisions after write_file.
  • bump_revisions walks ancestor directories and sets the next FileRevision via salsa::Setter, avoiding mtime reliance and fixing stub re-resolution after reset.
  • adjust_annotation_span takes source_len and clamps with checked_sub/min to prevent wrap on injected import offsets.
  • Adds crates/monty-js/__test__/wasm_type_check.spec.ts to verify session survivability and consistent diagnostics across repeated failures using @pydantic/monty/wasm.