fix(core): Release LS trace clients on run finalization (no-changelog)#28254
Merged
OlegIvaniv merged 2 commits intomasterfrom Apr 10, 2026
Merged
fix(core): Release LS trace clients on run finalization (no-changelog)#28254OlegIvaniv merged 2 commits intomasterfrom
OlegIvaniv merged 2 commits intomasterfrom
Conversation
…angelog) The module-level traceClients Map in langsmith-tracing.ts was only cleaned when a root run finished successfully via finishRun(). If a run was aborted, timed out, or the finishRun HTTP call failed, the Client and its entire RunTree hierarchy stayed in the Map indefinitely. Add releaseTraceClient() that unconditionally deletes the entry, and call it from: - finalizeMessageTraceRoot (normal message run completion) - finalizeDetachedTraceRun (background task completion) - deleteTraceContextsForThread (safety net on thread deletion) Each call site uses a finally block so cleanup happens regardless of whether the trace HTTP calls succeed or fail. Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
There was a problem hiding this comment.
No issues found across 3 files
Architecture diagram
sequenceDiagram
participant Svc as InstanceAiService
participant Tracing as LangSmith Tracing Module
participant Cache as traceClients (Map)
participant LS as LangSmith API
Note over Svc, LS: Run Finalization (Success or Failure)
Svc->>Tracing: finalizeMessageTraceRoot / finalizeDetachedTraceRun
rect rgb(240, 240, 240)
Note right of Svc: try block
Svc->>LS: finishRun (via SDK)
end
alt on Error
LS-->>Svc: Error (Timeout/Network)
Svc->>Svc: Log Error
else on Success
LS-->>Svc: 200 OK
end
Note right of Svc: finally block
Svc->>Tracing: NEW: releaseTraceClient(traceId)
Tracing->>Cache: NEW: delete(traceId)
Note over Cache: GC can now reclaim Client<br/>and RunTree hierarchy
Note over Svc, Cache: Thread Deletion (Safety Net)
Svc->>Svc: deleteTraceContextsForThread(threadId)
loop for each run context
Svc->>Tracing: NEW: releaseTraceClient(traceId)
Tracing->>Cache: NEW: delete(traceId)
end
Contributor
|
Got released with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The module-level traceClients Map in langsmith-tracing.ts was only cleaned when a root run finished successfully via finishRun(). If a run was aborted, timed out, or the finishRun HTTP call failed, the Client and its entire RunTree hierarchy stayed in the Map indefinitely.
Add releaseTraceClient() that unconditionally deletes the entry, and call it from:
Measured impact (parallel workflow building benchmark: 3 tabs × 3 rounds)
The remaining ~80 MB delta is one-time lazy loading (node type catalog, source maps, Zod schemas) that loads on first workflow build and stays flat across subsequent rounds.
Related Linear tickets, Github issues, and Community forum posts
Review / Merge checklist
Backport to Beta,Backport to Stable, orBackport to v1(if the PR is an urgent fix that needs to be backported)