Skip to content

Logger.traced ends spans before promises from another realm settle #2753

Closed

Description

runCatchFinally checks asynchronous results with "ret instanceof Promise". A native Promise created in another JavaScript realm, such as Node's vm context, fails that check.

Logger.traced therefore calls span.end() immediately when the callback returns a still-pending foreign Promise. Rejection also bypasses the error handler. A conforming thenable without catch/finally methods has the same premature-cleanup behavior.

I reproduced this against current main with real package tests:

  • A Node vm Promise is still pending, but a spy on the public Logger.traced span's end method already records one call.
  • The helper's cleanup runs before fulfillment.
  • A rejected foreign Promise never reaches the helper's catch handler.
  • A then-only PromiseLike also triggers immediate cleanup.

The new focused Vitest tests produce four failures and five passes on the unchanged implementation, including a passing synchronous-return/error control. The logger test uses the SDK's in-memory test logger; it does not call a model or require service credentials.

I plan to recognize PromiseLike results, preserve normal Promise chaining (including subclass behavior), assimilate then-only values when necessary, and add the regression coverage and a patch changeset. I will run the package typing and relevant test checks before opening a PR.

AI assistance: Codex helped inspect the helper and execute these reproductions.

Activity

  1. lforst commented on Nov 10, 2026

    @lforst
    Member

    Hi, thanks for the report. I think we'll defer on this for now since Node.js realm usage intuitively seems quite low. Let us know if you face any concrete issues with the braintrust SDK in prod and we may find a solution/workaround for your situation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions