-
-
Notifications
You must be signed in to change notification settings - Fork 201
fix(ai-isolate-cloudflare): port worker from unsafe_eval to worker_loader #523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sriketk
wants to merge
6
commits into
TanStack:main
Choose a base branch
from
Sriketk:fix/ai-isolate-cloudflare-worker-loader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
167d052
fix(ai-isolate-cloudflare): port worker from unsafe_eval to worker_loβ¦
Sriketk 669a2aa
fix(ai-isolate-cloudflare): cancel in-flight fetch on timeout + happyβ¦
Sriketk b2ce85f
fix(ai-isolate-cloudflare): tighten timeout test + happy-path assertions
Sriketk a266c41
Updated wrangler
tombeckenham 6d877b7
Merge remote-tracking branch 'origin/main' into fix/ai-isolate-cloudfβ¦
tombeckenham 4d4fb19
chore(ai-isolate-cloudflare): drop unused esbuild and miniflare devDeps
tombeckenham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| --- | ||
| '@tanstack/ai-isolate-cloudflare': minor | ||
| --- | ||
|
|
||
| Port the Cloudflare worker driver from `unsafe_eval` to `worker_loader` (Dynamic Workers). | ||
|
|
||
| Cloudflare gates the `unsafe_eval` binding for all customer prod accounts; the previous driver was unusable in production and broken in `wrangler dev` on current Wrangler 4.x. The supported replacement is the `worker_loader` binding (GA-beta'd 2026-03-24). | ||
|
|
||
| **Breaking:** the worker now requires the `LOADER` binding instead of `UNSAFE_EVAL`. Update your `wrangler.toml`: | ||
|
|
||
| ```toml | ||
| # before | ||
| [[unsafe.bindings]] | ||
| name = "UNSAFE_EVAL" | ||
| type = "unsafe_eval" | ||
|
|
||
| # after | ||
| [[worker_loaders]] | ||
| binding = "LOADER" | ||
| ``` | ||
|
|
||
| The HTTP tool-callback protocol and public driver API are unchanged. Workers Paid plan is required for any edge usage (deploy or `wrangler dev --remote`); local `wrangler dev` works on the Free plan. | ||
|
|
||
| Closes #522. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -46,6 +46,7 @@ stats.html | |
| .tsup | ||
| .vinxi | ||
| temp | ||
| .wrangler | ||
|
|
||
| vite.config.js.timestamp-* | ||
| vite.config.ts.timestamp-* | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/typescript/ai-isolate-cloudflare/src/worker/wrap-code.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catch serialization failures inside the child worker.
wrapCode()can producevalue: unknown, but this path assumes the full result is JSON-serializable. Values likeBigIntor circular objects will throw here, outside the wrapped IIFE, so the parent only sees an opaque fetch/JSON failure and loses the structured sandbox result.Suggested fix
export default { async fetch() { const __result = await ${wrappedCode}; - return new Response(JSON.stringify(__result), { - headers: { 'Content-Type': 'application/json' }, - }); + try { + return new Response(JSON.stringify(__result), { + headers: { 'Content-Type': 'application/json' }, + }); + } catch (__error) { + return new Response( + JSON.stringify({ + status: 'done', + success: false, + error: { + name: __error?.name ?? 'SerializationError', + message: __error?.message ?? String(__error), + }, + logs: __result?.logs ?? [], + }), + { + headers: { 'Content-Type': 'application/json' }, + }, + ); + } } };π€ Prompt for AI Agents