Skip to content

feat(csr): version drift detection between SDK and worker - #415

Draft
nicklasl wants to merge 4 commits into
mainfrom
nicklasl/csr-version-drift
Draft

feat(csr): version drift detection between SDK and worker#415
nicklasl wants to merge 4 commits into
mainfrom
nicklasl/csr-version-drift

Conversation

@nicklasl

@nicklasl nicklasl commented Jul 17, 2026

Copy link
Copy Markdown
Member

Depends on #412 — merge that first.

Summary

  • Detect stale self-hosted worker files using a content hash instead of version numbers
  • build-worker.mjs computes a SHA-256 hash of the bundled worker code and writes it to worker-hash.ts
  • emit-worker-file.mjs prepends globalThis.__WORKER_HASH__ to the standalone file
  • Worker reads the hash from globalThis and sends it in the welcome message
  • Tab imports the precomputed hash and compares on welcome — mismatch logs a warning via debugLogger, recording still proceeds
  • Hash check only fires for self-hosted workers (urlScheme === 'custom') — inlined workers (data:/blob:) can't drift

Why hashes instead of versions

csr-common and session-recording have independent version numbers. Using either package's version for the drift check would show a version the customer doesn't recognize. A content hash sidesteps versioning entirely — if the worker code changed, the hash changed, regardless of which package bumped.

Test plan

  • workerHash included in welcome when globalThis.__WORKER_HASH__ is set
  • workerHash is undefined when not set (inlined worker path)
  • Mismatch warning logged when urlScheme === 'custom' and hashes differ
  • No warning when hashes match
  • No warning for data:/blob: URL schemes
  • No warning when workerHash absent (graceful degradation for old workers)
  • Build produces standalone file with hash prepended
  • Full CSR test suite passes (142 tests)

🤖 Generated with Claude Code

@nicklasl
nicklasl force-pushed the nicklasl/csr-version-drift branch from 2cb3fb4 to 5b04414 Compare July 17, 2026 11:19
@nicklasl
nicklasl changed the base branch from nicklasl/csr-ship-worker-js to main July 17, 2026 11:23
@nicklasl
nicklasl force-pushed the nicklasl/csr-version-drift branch from 5b04414 to 0a33c63 Compare July 17, 2026 12:46
The worker file now carries a content hash (SHA-256 prefix) set at build
time via globalThis.__WORKER_HASH__. When using a custom workerUrl and
the hash doesn't match the installed SDK, a warning is logged via
debugLogger. Recording still proceeds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@nicklasl
nicklasl force-pushed the nicklasl/csr-version-drift branch from 0a33c63 to 3a43c81 Compare August 18, 2026 13:30
nicklasl and others added 3 commits August 19, 2026 15:17
Move vi.mock for worker-hash into loadCreateUploader so it applies
fresh after each vi.resetModules call. The module-level mock leaked
into blob: fallback tests on CI.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Codex <noreply@openai.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant