Skip to content

test(node): Fix flaky TypeSafe ESM integration tests - #24912

Closed
mydea wants to merge 1 commit into
developfrom
test/typesafe-esm-subscription-flake
Closed

mydea wants to merge 1 commit into
developfrom
test/typesafe-esm-subscription-flake

Conversation

@mydea

@mydea mydea commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

The TypeSafe `[esm]` integration tests flake on Node 22: the first `systemOne` call sometimes has no `evaluate` span, so the expected 4 spans never arrive and the test times out.

On Node < 24.13, the ESM build of `@typesafe-ai/sdk` is transformed on the `Module.register` loader thread, which reports the injection back over a `MessagePort`. That message is delivered asynchronously, so the integration can subscribe to its channel after the scenario already made its first call. CJS goes through the synchronous `_compile` patch, which is why only `[esm]` fails.

The scenario now waits until the channel has subscribers before making calls. The underlying race also affects real apps that call an ESM-only instrumented package right after importing it on older Node; fixing that needs a synchronous main-thread signal and is out of scope here.

NOTE: Likely we should not merge this but fix this at the core 🤔

🤖 Generated with Claude Code

On Node < 24.13 the ESM build is transformed on the Module.register loader
thread, which reports the injection over a MessagePort. The integration can
subscribe after the scenario's first call, leaving it uninstrumented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mydea mydea closed this Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant