Fix memory leak in OTEL traces#1639
Open
michael-rubel wants to merge 3 commits intolangfuse:mainfrom
Open
Conversation
- address AI review
Contributor
|
@claude review |
- apply fix after claude review
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.
Fixes #12164
Disclaimer: Experimental PR review
Greptile Summary
This PR fixes a memory issue in
_find_and_process_mediaby switching from a "permanently mark all visited nodes" strategy to a DFS path-based tracking strategy: each container (list,dict, Pydantic model) now adds itsidtoseenbefore recursing and discards it in afinallyblock on return. This keepsseenbounded to the current call-stack depth rather than growing monotonically. The PR also adds explicit Pydantic v1 and v2 model handling, using__pydantic_fields__(Pydantic v2-specific) as a precise guard.Confidence Score: 5/5
PR is safe to merge — the memory fix is logically correct and prior review concerns have been addressed.
The DFS backtracking approach (add on enter, discard on exit via try/finally) is the correct fix for keeping the seen set bounded. Pydantic v1/v2 detection is precise. No P0 or P1 issues remain; the previous review concerns about cycle protection and the model_dump heuristic have both been addressed in this revision.
No files require special attention.
Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[_process_data_recursively] --> B{level > max_levels?} B -- yes --> Z[return data] B -- no --> C{LangfuseMedia?} C -- yes --> D[process_media + return] C -- no --> E{base64 string?} E -- yes --> F[create LangfuseMedia + return] E -- no --> G{Anthropic dict pattern?} G -- yes --> H[copy dict, replace data field + return] G -- no --> I{Vertex dict pattern?} I -- yes --> J[copy dict, replace data field + return] I -- no --> K{isinstance list?} K -- yes --> L{id in seen?} L -- yes --> Z L -- no --> M[seen.add, recurse items, seen.discard in finally] M --> Z K -- no --> O{isinstance dict?} O -- yes --> P{id in seen?} P -- yes --> Z P -- no --> Q[seen.add, recurse values, seen.discard in finally] Q --> Z O -- no --> S{Pydantic v2 model?} S -- yes --> T{id in seen?} T -- yes --> Z T -- no --> U[seen.add, model_dump, recurse, seen.discard in finally] U --> Z S -- no --> W{Pydantic v1 model?} W -- yes --> X{id in seen?} X -- yes --> Z X -- no --> Y[seen.add, model.dict, recurse, seen.discard in finally] Y --> Z W -- no --> ZReviews (2): Last reviewed commit: "fix: memory leak in OTEL traces" | Re-trigger Greptile