Skip to content

Don't throw when dedicated snapshot is missing in dynamic workers.#6428

Merged
dom96 merged 1 commit intomainfrom
dominik/EW-10700
Mar 27, 2026
Merged

Don't throw when dedicated snapshot is missing in dynamic workers.#6428
dom96 merged 1 commit intomainfrom
dominik/EW-10700

Conversation

@dom96
Copy link
Copy Markdown
Contributor

@dom96 dom96 commented Mar 26, 2026

This fixes an issue with dynamic workers created in a Python Worker failing with "Received non-dedicated snapshot but compat flag for dedicated snapshots is enabled"

@dom96 dom96 requested review from hoodmane and ryanking13 March 26, 2026 16:30
@dom96 dom96 requested review from a team as code owners March 26, 2026 16:30
@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk bot commented Mar 26, 2026

I now have a thorough understanding of this PR. Let me analyze the changes:

Summary: This PR adds an isDynamicWorker flag to ArtifactBundler_State and exposes it to the Python runtime via JSG so that checkSnapshotType() in snapshot.ts can skip snapshot type validation for dynamic workers that don't yet support dedicated snapshots.

Analysis:

  1. C++ changes (pyodide.h): New bool isDynamicWorkerFlag field, constructor parameter with default false, propagated in clone(), exposed via JSG_METHOD. Clean and straightforward. Default parameter means existing callers are unaffected.

  2. TypeScript changes: New IS_DYNAMIC_WORKER export, used in checkSnapshotType() to early-return before the mismatch validation. Type declaration added.

  3. Backward compatibility: The constructor has isDynamicWorker = false as a default parameter, so all existing call sites (in server.c++, worker-modules.h) continue to work unchanged. No behavioral change for non-dynamic workers.

  4. Security: The flag only skips a validation that throws an internal error when snapshot type doesn't match the compat flag. It doesn't grant any new capabilities or bypass sandbox restrictions. The flag is set server-side, not by user code.

  5. No tests: There are no tests for this change. However, this is a narrow fix for a specific production issue with Python dynamic workers, and the checkSnapshotType function itself has no existing tests either. The code path is clearly correct — when a dynamic worker receives a baseline snapshot but has dedicated snapshot compat flag enabled, it should not throw.

  6. One potential concern: The early return in checkSnapshotType skips ALL validation for dynamic workers, including the check that throws when a dedicated snapshot is received but the compat flag is NOT enabled (lines 773-781), and the second validation phase check (lines 796-801). The comment says "Dynamic workers don't yet support dedicated snapshots", so skipping all checks is reasonable for now, but it means if a dynamic worker somehow receives a dedicated snapshot, no error will be raised.

This is a clean, well-scoped bugfix. The code is correct and the approach is sound. There are no actionable issues.

LGTM

github run

@dom96 dom96 force-pushed the dominik/EW-10700 branch from a9b1f4f to 550daf0 Compare March 27, 2026 11:23
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 27, 2026

Merging this PR will improve performance by 12.73%

⚡ 1 improved benchmark
✅ 69 untouched benchmarks
⏩ 129 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
Encode_ASCII_1024[TextEncoder][0/0/1024] 3.6 ms 3.2 ms +12.73%

Comparing dominik/EW-10700 (550daf0) with main (0d830b1)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@dom96 dom96 merged commit 0f907f5 into main Mar 27, 2026
43 of 46 checks passed
@dom96 dom96 deleted the dominik/EW-10700 branch March 27, 2026 13:51
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.

3 participants