Skip to content

LangChain callback handler keeps runs that never end in memory #25510

Open

Description

@RulaKhaled

createLangChainCallbackHandler() tracks each run in a map until its end or error callback fires. If LangChain never calls either, for example when a consumer abandons a stream, the entry and its span stay in the map forever. The auto-instrumentation path shares one handler for the whole process, so these add up. This predates #25364 (spanMap had it). Since #25364 each entry also holds the span that was active when the run started, which can keep a caller span outside the run's own tree alive.

Options: drop entries whose span has already ended when a new run starts, cap the map size, and store the active span's id instead of the span object.

Raised by @isaacs in #25364 (comment).

🤖 Generated with Claude Code

Activity

  1. linear-code commented on Oct 19, 2026

    @linear-code
  2. self-assigned this
    on Oct 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions