bug: LANGFUSE_MAX_EVENT_SIZE_BYTES is parsed but never enforced for score events
維護者通常 1 天內回覆
評估
這個 Issue 還沒有評估資料。
描述
Describe the bug
MAX_EVENT_SIZE_BYTES = int(os.environ.get("LANGFUSE_MAX_EVENT_SIZE_BYTES", 1_000_000)) (score_ingestion_consumer.py#L18) is not referenced anywhere else in the repo (grep -rn MAX_EVENT_SIZE langfuse only finds the definition). The env var was added in #1103 ("make max event and batch size configurable"), but it currently has no effect: an oversized score event is posted as-is instead of being dropped or truncated.
Secondary point: in _next() the running total is compared to MAX_BATCH_SIZE_BYTES only after the event has already been appended (score_ingestion_consumer.py#L83-L108), so a batch can exceed the batch limit by up to one event (and since single events are not capped, by an arbitrary amount).
Expected: events above LANGFUSE_MAX_EVENT_SIZE_BYTES are dropped (with a logged error) or truncated, and the batch limit is checked before appending.
Actual: a 10 MB score comment is sent in a single request. Whether the server then rejects it and how that is surfaced depends on the 4xx handling; today a rejected batch is dropped without a log line (see #1874, which is about that part). Users who set the env var, as in langfuse/langfuse#7027, get no client-side effect from it.
Severity is low to medium: it only affects unusually large score payloads, but the env var suggests protection that is not there.
Steps to reproduce
import httpx
from queue import Queue
from langfuse._utils.request import LangfuseClient
from langfuse._task_manager.score_ingestion_consumer import ScoreIngestionConsumer, MAX_EVENT_SIZE_BYTES, MAX_BATCH_SIZE_BYTES
sizes = []
def h(req): sizes.append(len(req.content)); return httpx.Response(200, json={})
cl = LangfuseClient("pk", "sk", "http://x", "1", 5, httpx.Client(transport=httpx.MockTransport(h)))
q = Queue(); c = ScoreIngestionConsumer(ingestion_queue=q, identifier=0, client=cl, public_key="pk", flush_at=15)
q.put({"id": "big", "type": "score-create", "body": {"comment": "x" * 10_000_000}})
c.upload()
print("MAX_EVENT", MAX_EVENT_SIZE_BYTES, "MAX_BATCH", MAX_BATCH_SIZE_BYTES, "posted bytes", sizes)
Observed output:
MAX_EVENT 1000000 MAX_BATCH 2500000 posted bytes [10000173]
Langfuse Cloud or self-hosted?
Either; the behaviour is client side only.
If self-hosted, what version are you running?
n/a
SDK and integration versions
langfuse 4.17.0 (main @ bf11ec121479145923ff27b32ec2ad1d06fd2d51), Python 3.14.0.
Additional information
Possible direction: after computing item_size in _next(), if item_size > MAX_EVENT_SIZE_BYTES: logger.error(...); self._ingestion_queue.task_done(); continue, and check total_size + item_size > MAX_BATCH_SIZE_BYTES before appending, carrying the event into the next batch. Alternatively remove the constant and the env var if client-side enforcement is not wanted.
Minor and separate: int(os.environ[...]) at import time makes import langfuse raise on a malformed value (this was also noted in the review of #1103).
Related: #1874 (4xx batch drops are not logged), langfuse/langfuse#7027 (413 from the server with LANGFUSE_MAX_EVENT_SIZE_BYTES set).
Are you interested in contributing a fix for this bug?
Yes
- 主要語言
- Python
- 星號
- 504
- 分支
- 391
- 平均合併
- 1 天 1 小時
- 30 天內合併 PR
- 64
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
langfuse/langfuse-python 的其他 Issue
-
bug(scores): create_score sends numpy.bool_ as JSON `true` and Decimal as "<Decimal>" since v5.0.2可能已有人在做 @lalith0407 於 4 天前認領。 未關閉bug feat-scores sdk-python
難度 2/5 1-3 小時 新手友好度 74/100
langfuse/langfuse-python#2057 ·
維護者通常 1 天內回覆
-
tests/unit/test_prompt.py fails on a fresh clone without LANGFUSE_* env vars可能已有人在做 @Mathoholic 於 17 天前認領。 未關閉bug feat-prompt-management sdk-python
難度 2/5 1-3 小時 新手友好度 80/100
langfuse/langfuse-python#1976 · 3 則留言 ·
維護者通常 1 天內回覆
-
bug(openai): a stream that fails mid-iteration ends the generation without level ERROR可能已有人在做 @hassiebp 於 7 天前認領。 未關閉bug integration-openai sdk-python
langfuse/langfuse-python#2039 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
fix(serializer): handle single-string __slots__ and detect cycles in slotted objects可能已有人在做 @hassiebp 於 13 天前認領。 未關閉bug sdk-python
langfuse/langfuse-python#2014 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
bug: ChatPromptClient.compile appends str(whole list) once per non-dict placeholder item可能已有人在做 @nimarb 於 7 天前認領。 未關閉bug feat-prompt-management sdk-python
langfuse/langfuse-python#1971 · 已指派 1 人 ·
維護者通常 1 天內回覆
查看 langfuse/langfuse-python 的全部 Issue
相似的 Issue
-
area/profiles comp/cli P3 type/feature
難度 2/5 1-3 小時 新手友好度 74/100
NousResearch/hermes-agent#146372 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 65/100
維護者通常 1 天內回覆
-
[oblt-aw][autodoc] Document obs-aw-automerge contract and fix automerge doc inconsistencies可能已有人在做 @github-actions 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 76/100
維護者通常 1 天內回覆
-
GeoSeries scale and skew tests fail with pytest 9.2.0可能已有人在做 @jiayuasu 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 82/100
維護者通常 1 天內回覆
-
admission-deferred priority: medium status: ready work-class: scoped
難度 2/5 1-3 小時 新手友好度 70/100
melodic-software/claude-code-plugins#10887 · 4 則留言 ·
維護者通常 1 天內回覆