mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-15 17:00:59 +00:00
Fix race condition by making window.complete() async and awaiting it
- window.complete() was fire-and-forget, causing execution-complete to arrive before console messages - This caused sandbox to unregister before console message responses arrived - Made complete() async and await sendRuntimeMessage() - SandboxedIframe wrapper now awaits window.complete() - Ensures all messages are processed before cleanup/unregister - Fixes 30-second timeout on javascript_repl
This commit is contained in:
parent
bb138307b1
commit
5dcb5ecc89
2 changed files with 10 additions and 14 deletions
|
|
@ -339,7 +339,7 @@ export class SandboxIframe extends LitElement {
|
|||
}
|
||||
}
|
||||
|
||||
window.complete();
|
||||
await window.complete();
|
||||
} catch (error) {
|
||||
console.error(error?.stack || error?.message || String(error));
|
||||
|
||||
|
|
@ -352,7 +352,7 @@ export class SandboxIframe extends LitElement {
|
|||
}
|
||||
}
|
||||
|
||||
window.complete({
|
||||
await window.complete({
|
||||
message: error?.message || String(error),
|
||||
stack: error?.stack || new Error().stack
|
||||
});
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ export class ConsoleRuntimeProvider implements SandboxRuntimeProvider {
|
|||
|
||||
// Expose complete() method for user code to call
|
||||
let completionSent = false;
|
||||
(window as any).complete = (error?: { message: string; stack: string }) => {
|
||||
(window as any).complete = async (error?: { message: string; stack: string }) => {
|
||||
if (completionSent) return;
|
||||
completionSent = true;
|
||||
|
||||
|
|
@ -128,18 +128,14 @@ export class ConsoleRuntimeProvider implements SandboxRuntimeProvider {
|
|||
|
||||
if ((window as any).sendRuntimeMessage) {
|
||||
if (finalError) {
|
||||
(window as any)
|
||||
.sendRuntimeMessage({
|
||||
type: "execution-error",
|
||||
error: finalError,
|
||||
})
|
||||
.catch(() => {});
|
||||
await (window as any).sendRuntimeMessage({
|
||||
type: "execution-error",
|
||||
error: finalError,
|
||||
});
|
||||
} else {
|
||||
(window as any)
|
||||
.sendRuntimeMessage({
|
||||
type: "execution-complete",
|
||||
})
|
||||
.catch(() => {});
|
||||
await (window as any).sendRuntimeMessage({
|
||||
type: "execution-complete",
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue