Skip to content

fix(scores): drop score events above LANGFUSE_MAX_EVENT_SIZE_BYTES - #1970

Open
moneebullah25 wants to merge 2 commits into
langfuse:mainfrom
moneebullah25:fix/score-enforce-max-event-size
Open

moneebullah25 wants to merge 2 commits into
langfuse:mainfrom
moneebullah25:fix/score-enforce-max-event-size

Conversation

@moneebullah25

@moneebullah25 moneebullah25 commented Oct 9, 2026 •

Copy link
Copy Markdown

What does this PR do?

LANGFUSE_MAX_EVENT_SIZE_BYTES was parsed into MAX_EVENT_SIZE_BYTES but never used, so a 10 MB score was posted as a single request. ScoreIngestionConsumer._next() now drops any score event whose serialized size is above the limit, logs an error with the event id, size and limit (never the payload), and acknowledges the queue item so flush()/join() do not hang.

Behavior choice: the issue offers "dropped (with a logged error) or truncated". Dropping is the least surprising: truncating would silently change user data. A size exactly equal to the limit is allowed. The limit applies to the serialized event (id, type, timestamp, body), measured with the same encoder that is posted.

Not changed (separate points in the issue): checking the batch limit before appending (with this fix a batch can overshoot MAX_BATCH_SIZE_BYTES by at most one event of at most MAX_EVENT_SIZE_BYTES), and the import-time int() parsing of the env var. Logging of 4xx batch drops is covered by #1874.

Fixes #1966

Type of change

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

Verification

List the main commands you ran:

uv run --frozen ruff check .
uv run --frozen ruff format --check langfuse tests/unit/test_score_ingestion_consumer.py
uv run --frozen mypy langfuse --no-error-summary
uv run --frozen pytest tests/unit/test_score_ingestion_consumer.py
uv run --frozen pytest -n auto --dist worksteal tests/unit

Notes: the new tests fail without the fix and pass with it. ruff format --check . reports tests/unit/test_media.py as unformatted on current main (untouched by this PR). In the full unit run, tests/unit/test_prompt.py errors unless LANGFUSE_PUBLIC_KEY/LANGFUSE_SECRET_KEY are set in the environment; with dummy keys it passes (26 passed). Everything else passed (869 passed, 2 skipped).

Checklist

  • I self-reviewed the diff using code_review.md.
  • I added or updated tests for behavior changes.
  • I updated docs, examples, or .env.template if needed.
  • I did not hand-edit generated files; if generated files changed, I used the upstream regeneration path.
  • I did not commit secrets or credentials.

RetriggerConfidence Score: 5/5

The PR appears safe to merge; no actionable issues were found.

Summary

Drops score events above MAX_EVENT_SIZE_BYTES before uploading them. Events exactly at the limit remain allowed.

  • Logs the dropped event’s ID, size, and limit without its payload.
  • Acknowledges dropped queue items so flushing can finish.
  • Adds tests for mixed batches, all-dropped batches, the size boundary, and Pydantic bodies.
  • moneebullah25 explicitly deferred batch-limit enforcement and import-time environment parsing as separate work. The author also stated that logging dropped batches after HTTP 4xx responses is covered by fix: log non-retryable 4xx batch drops and warn on silently ignored sample_rate #1874.

Reviews (1) · Last reviewed commit: "fix(scores): drop score events above LAN..." · 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.

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.

bug: LANGFUSE_MAX_EVENT_SIZE_BYTES is parsed but never enforced for score events

1 participant