-
Notifications
You must be signed in to change notification settings - Fork 327
fix: cancel media uploads when mask_otel_spans drops the batch #1818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,7 @@ def __init__( | |
| self._enabled = os.environ.get( | ||
| LANGFUSE_MEDIA_UPLOAD_ENABLED, "True" | ||
| ).lower() not in ("false", "0") | ||
| self._cancelled_media_ids: set[str] = set() | ||
|
|
||
| def reinitialize( | ||
| self, | ||
|
|
@@ -65,6 +66,14 @@ def process_next_media_upload(self) -> None: | |
| self._queue.task_done() | ||
| return | ||
|
|
||
| if upload_job["media_id"] in self._cancelled_media_ids: | ||
| self._cancelled_media_ids.discard(upload_job["media_id"]) | ||
| logger.debug( | ||
| f"Media: Skipping cancelled upload for media_id={upload_job['media_id']} in trace_id={upload_job['trace_id']}" | ||
| ) | ||
| self._queue.task_done() | ||
| return | ||
|
Comment on lines
+69
to
+75
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When a media consumer dequeues a job before or while Knowledge Base Used: Prompt To Fix With AIThis is a comment left during a code review.
Path: langfuse/_task_manager/media_manager.py
Line: 69-75
Comment:
**Cancellation misses active uploads**
When a media consumer dequeues a job before or while `mask_otel_spans` runs, it can pass this sole cancellation check and begin the network upload before the hook drops the batch, causing media from a redacted span to be uploaded. **How this was verified:** Media is enqueued before the synchronous mask hook runs, while independent consumer threads dequeue jobs and never re-check cancellation inside the upload path.
**Knowledge Base Used:**
- [OTel Span Processing and Export Pipeline](https://app.greptile.com/personal-org-4986/-/custom-context/knowledge-base/langfuse/langfuse-python/-/docs/otel-pipeline.md)
- [Task Manager: Media Upload and Score Ingestion](https://app.greptile.com/personal-org-4986/-/custom-context/knowledge-base/langfuse/langfuse-python/-/docs/task-manager.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly. |
||
|
|
||
| logger.debug( | ||
| f"Media: Processing upload for media_id={upload_job['media_id']} in trace_id={upload_job['trace_id']}" | ||
| ) | ||
|
|
@@ -79,6 +88,16 @@ def process_next_media_upload(self) -> None: | |
| ) | ||
| self._queue.task_done() | ||
|
|
||
| def cancel_pending_uploads(self, *, media_ids: set[str]) -> None: | ||
| """Cancel media uploads enqueued for a batch that was dropped. | ||
|
|
||
| The mask hook runs after media attributes are processed, so upload jobs | ||
| for a batch are already queued by the time the hook decides to drop it. | ||
| Mark those media IDs so the consumer skips them instead of uploading the | ||
| bytes the hook just redacted. | ||
| """ | ||
| self._cancelled_media_ids.update(media_ids) | ||
|
|
||
| def signal_shutdown(self, *, count: int = 1) -> None: | ||
| for _ in range(count): | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an exported batch and a dropped batch enqueue identical media bytes, both jobs have the same deterministic
media_id, so this one-shot marker can skip the earlier legitimate job and then allow the dropped job to upload. A stale marker can likewise suppress a later legitimate upload of the same content.Knowledge Base Used: Task Manager: Media Upload and Score Ingestion
Prompt To Fix With AI