Patch Changes
-
#701
c4f01e6
Thanks @omeraplak! - fix: observability spans terminating prematurely on Vercel Edge and Deno DeployThe Problem
Observability spans were being cut short on Vercel Edge and Deno Deploy runtimes because the
toVercelEdge()
andtoDeno()
adapters didn't implementwaitUntil
support. UnliketoCloudflareWorker()
, which properly extracted and set upwaitUntil
from the execution context, these adapters would terminate async operations (like span exports) as soon as the response was returned.This caused the observability pipeline's
FetchTraceExporter
andFetchLogExporter
to have their export promises cancelled mid-flight, resulting in incomplete or missing observability data.The Solution
Refactored all serverless adapters to use a new
withWaitUntil()
helper utility that:- Extracts
waitUntil
from the runtime context (Cloudflare'sexecutionCtx
, Vercel'scontext
, or Deno'sinfo
) - Sets it as
globalThis.___voltagent_wait_until
for the observability exporters to use - Returns a cleanup function that properly restores previous state
- Handles errors gracefully and supports nested calls
Now all three adapters (
toCloudflareWorker
,toVercelEdge
,toDeno
) use the same battle-tested pattern:const cleanup = withWaitUntil(context); try { return await processRequest(request); } finally { cleanup(); }
Impact
- ✅ Observability spans now export successfully on Vercel Edge Runtime
- ✅ Observability spans now export successfully on Deno Deploy
- ✅ Consistent
waitUntil
behavior across all serverless platforms - ✅ DRY principle: eliminated duplicate code across adapters
- ✅ Comprehensive test coverage with 11 unit tests covering edge cases, nested calls, and error scenarios
Technical Details
The fix introduces:
utils/wait-until-wrapper.ts
: ReusablewithWaitUntil()
helperutils/wait-until-wrapper.spec.ts
: Complete test suite (11/11 passing)- Updated
toCloudflareWorker()
: Simplified using helper - Fixed
toVercelEdge()
: Now properly supportswaitUntil
- Fixed
toDeno()
: Now properly supportswaitUntil
- Extracts