Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/rude-pianos-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@voltagent/serverless-hono": patch
---

fix(serverless-hono): withWaitUntil must not destroy global state when context has no waitUntil
25 changes: 13 additions & 12 deletions packages/serverless-hono/src/utils/wait-until-wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,21 @@ export function withWaitUntil(context?: WaitUntilContext | null): () => void {

if (currentWaitUntil && typeof currentWaitUntil === "function") {
// Bind to context to avoid "Illegal invocation" errors
// And allow errors (like DataCloneError) to propagate so caller can handle fallback
globals.___voltagent_wait_until = currentWaitUntil.bind(context);
} else {
globals.___voltagent_wait_until = undefined;
// Wrap in try/catch so errors (like DataCloneError) are swallowed and don't break the caller
const boundWaitUntil = currentWaitUntil.bind(context);
globals.___voltagent_wait_until = (promise: Promise<unknown>) => {
try {
boundWaitUntil(promise);
} catch {
// Swallow errors to avoid breaking the caller
}
};
}
// No else branch — don't touch global when context has no waitUntil,
// to avoid destroying a previously set value from an outer scope

// Return cleanup function
// Return cleanup function that always restores the previous state
return () => {
if (currentWaitUntil) {
if (previousWaitUntil) {
globals.___voltagent_wait_until = previousWaitUntil;
} else {
globals.___voltagent_wait_until = undefined;
}
}
globals.___voltagent_wait_until = previousWaitUntil;
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: Cleanup unconditionally restores a stale global snapshot even when this call never set the global, allowing interleaved executions to be clobbered.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At packages/serverless-hono/src/utils/wait-until-wrapper.ts, line 52:

<comment>Cleanup unconditionally restores a stale global snapshot even when this call never set the global, allowing interleaved executions to be clobbered.</comment>

<file context>
@@ -34,20 +34,21 @@ export function withWaitUntil(context?: WaitUntilContext | null): () => void {
-        globals.___voltagent_wait_until = undefined;
-      }
-    }
+    globals.___voltagent_wait_until = previousWaitUntil;
   };
 }
</file context>
Fix with Cubic

};
}
Loading