Skip to content

perf(media): reuse downloads for repeated references within a call - #2022

Open
Apeksha9389 wants to merge 1 commit into
langfuse:mainfrom
Apeksha9389:perf/reuse-resolved-media
Open

Apeksha9389 wants to merge 1 commit into
langfuse:mainfrom
Apeksha9389:perf/reuse-resolved-media

Conversation

@Apeksha9389

@Apeksha9389 Apeksha9389 commented Oct 19, 2026 •

Copy link
Copy Markdown

What does this PR do?

Reuse successful media resolutions within one LangfuseMedia.resolve_media_references() call. Repeated image or audio references in multimodal inputs now share their metadata lookup and download, including across nested messages. A new call fetches fresh content, and failed resolutions remain retryable at later positions.

The regression input has three copies of one reference. On main it makes three metadata requests and three downloads; with this change it makes one of each and produces the same resolved content. Additional tests cover distinct references, fetch failures, input preservation, call isolation and the traversal depth limit.

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor
  • Documentation update
  • Tooling, CI, or repo maintenance

Verification

.venv/bin/python -m pytest tests/unit/test_media.py tests/unit/test_json_path.py -q
.venv/bin/ruff check .
.venv/bin/ruff format --check langfuse/media.py tests/unit/test_media.py
.venv/bin/mypy langfuse --no-error-summary

All pass on macOS/Python 3.12.14; 48 tests pass. The repeated-reference regression was confirmed failing before the implementation. Dependencies were installed with uv sync --locked; commands used the resulting .venv executables. Backend e2e and live-provider tests were not run because this change is covered by offline media-resolution tests.

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I updated the method documentation.
  • I did not hand-edit generated files.
  • I did not commit secrets or credentials.

AI disclosure: The change, tests and description were prepared with OpenAI Codex assistance. All reported checks were executed locally.

RetriggerView in GreptileConfidence Score: 5/5

This PR appears safe to merge.

Summary

LangfuseMedia.resolve_media_references() now reuses successful downloads within one call.

  • Repeated media references reuse successful downloads within one call.

Reviews (1) · Last reviewed commit: "perf(media): reuse successful resolution..." · Reviewed by Greptile

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@CLAassistant

CLAassistant commented Oct 19, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants