From 0475ec43cea7d68fc8dcdc71e9af424f08c1f842 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Wed, 4 Jun 2025 15:05:50 +0530 Subject: [PATCH 1/2] fix: check for process.on In Cloudflare Workers / the workerd runtime, `process` can be defined, but `process.on()` isn't (yet). This adds a chck for the existence of `process.on` as a function before handing event handlers. --- packages/agents-core/src/index.ts | 2 +- packages/agents-core/src/tracing/index.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/agents-core/src/index.ts b/packages/agents-core/src/index.ts index 1a457f1c..80101f76 100644 --- a/packages/agents-core/src/index.ts +++ b/packages/agents-core/src/index.ts @@ -153,7 +153,7 @@ const cleanup = async () => { await getGlobalTraceProvider().shutdown(); }; -if (typeof process !== 'undefined') { +if (typeof process !== 'undefined' && typeof process.on === 'function') { // handling Node.js process termination // Handle normal termination diff --git a/packages/agents-core/src/tracing/index.ts b/packages/agents-core/src/tracing/index.ts index 7869699f..a50e6932 100644 --- a/packages/agents-core/src/tracing/index.ts +++ b/packages/agents-core/src/tracing/index.ts @@ -52,7 +52,7 @@ const cleanup = async () => { await getGlobalTraceProvider().shutdown(); }; -if (typeof process !== 'undefined') { +if (typeof process !== 'undefined' && typeof process.on === 'function') { // handling Node.js process termination // Handle normal termination From d19e50549edeaade413797cb567cf434af66cfe9 Mon Sep 17 00:00:00 2001 From: Sunil Pai Date: Wed, 4 Jun 2025 22:15:01 +0530 Subject: [PATCH 2/2] add a changeset --- .changeset/clear-pans-nail.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/clear-pans-nail.md diff --git a/.changeset/clear-pans-nail.md b/.changeset/clear-pans-nail.md new file mode 100644 index 00000000..b0895a6f --- /dev/null +++ b/.changeset/clear-pans-nail.md @@ -0,0 +1,5 @@ +--- +'@openai/agents-core': patch +--- + +fix: ensure process.on exists and is a function before adding event handlers