-
-
Notifications
You must be signed in to change notification settings - Fork 327
fix(isolate-quickjs): enforce timeout while suspended in host calls #905
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
Closed
jan-kubica
wants to merge
1
commit into
TanStack:main
from
jan-kubica:fix/isolate-quickjs-timeout-host-calls
Closed
Changes from all commits
Commits
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,22 @@ | ||
| --- | ||
| '@tanstack/ai-isolate-quickjs': patch | ||
| --- | ||
|
|
||
| Enforce `timeout` as a wall-clock deadline that covers host-call suspensions. | ||
|
|
||
| Previously the only deadline mechanism was QuickJS's `setInterruptHandler`, which | ||
| fires only while the sandbox is stepping bytecode. While the isolate is | ||
| asyncify-suspended awaiting a host binding's Promise, no interrupt fires, so the | ||
| configured `timeout` was silently ignored: a run with `timeout: 100` and an | ||
| 800 ms host binding resolved successfully after ~800 ms, and a hung host binding | ||
| could hang `execute()` indefinitely. | ||
|
|
||
| `execute()` now races the run against a wall-clock timer, so `timeout` bounds the | ||
| entire execution including time spent suspended in a host call. On the deadline | ||
| it returns a normalized `TimeoutError` immediately. The suspended host Promise | ||
| cannot be cancelled and the VM cannot be freed mid-asyncify, so disposal and the | ||
| internal execution-queue turn are deferred until the orphaned run unwinds (the | ||
| still-armed interrupt handler aborts it the moment the host Promise settles), | ||
| which prevents a late host result from resuming a dead execution and avoids | ||
| leaking the context. CPU-bound loops are still interrupted as before and leave | ||
| the context reusable. The public API is unchanged. |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: TanStack/ai
Length of output: 22246
🏁 Script executed:
Repository: TanStack/ai
Length of output: 2258
🏁 Script executed:
Repository: TanStack/ai
Length of output: 4272
Gate the
interruptedmatch onerror.name === 'InternalError'.As written, any host error whose message contains
interruptedis normalized toTimeoutError, which can mask the real failure and drop the original error name/message. Matching the QuickJSInternalError: interruptedshape keeps unrelated interruptions from being misclassified.🤖 Prompt for AI Agents
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.
Valid on this branch. Current main already gates this path on
error.name === 'InternalError'(and the dumped-object path does the same). That landed in #948. This PR should not be merged on top of that rewrite.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.
@AlemTuzlak, understood. The finding is valid for this branch. Currentmainalready contains the required guards from#948. This pull request should not merge on top of that rewrite.You are interacting with an AI system.