bug: Partial-failure (207) ingestion response retries the whole batch up to 3x; per-item error details only logged at DEBUG
维护者通常 1 天内回复
评估
这个 Issue 还没有评估数据。
描述
Describe the bug
LangfuseClient._process_response turns an ingestion 207 response that has a non-empty errors list into raise APIErrors([...]) (request.py#L91-L109).
APIErrors is not a subclass of APIError, so the "do not retry 4xx" check in the score ingestion consumer (isinstance(e, APIError) and 400 <= int(e.status) < 500, score_ingestion_consumer.py#L177-L192) never matches, and backoff.on_exception(Exception, max_tries=3) re-posts the whole batch.
Expected: when most events of a score ingestion batch were accepted (successes) and one was rejected with a per-item 4xx, the batch is not re-sent in full, a permanent per-item 4xx is not retried, and the failing event id/status/message is logged.
Actual: the full batch (including events the server already accepted) is POSTed 3 times, and the only thing logged at ERROR level is the generic canned text for the status code ("Bad request. Please check your request ..."), without the item id or the server's message. The server message is only visible at DEBUG level (parse_error.py#L75-L99).
Impact is modest: duplicate delivery is likely absorbed by server-side idempotency on event id (I have not verified this against a server), but it wastes traffic, triples the time the consumer thread spends on the batch (which flush() waits for), and retries errors that can never succeed.
Steps to reproduce
Uses httpx.MockTransport, no server needed (run from a checkout with the repo on PYTHONPATH):
import httpx, json
from queue import Queue
from langfuse._utils.request import LangfuseClient
from langfuse._task_manager.score_ingestion_consumer import ScoreIngestionConsumer
import time; time.sleep = lambda s: None # skip backoff waits
calls = []
body = {"successes": [{"id": "e0", "status": 201}, {"id": "e2", "status": 201}],
"errors": [{"id": "e1", "status": 400, "message": "Invalid request data", "error": "bad"}]}
def h(req):
calls.append(json.loads(req.content)["batch"]); return httpx.Response(207, json=body)
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=3)
for i in range(3): q.put({"id": f"e{i}", "type": "score-create", "body": {"n": i}})
c.upload()
print("POST count:", len(calls), "ids per post:", [[e["id"] for e in b] for b in calls])
Observed output:
API errors occurred: Bad request. Please check your request for any missing or incorrect parameters. Refer to our API docs: https://api.reference.langfuse.com for details.
POST count: 3 ids per post: [['e0', 'e1', 'e2'], ['e0', 'e1', 'e2'], ['e0', 'e1', 'e2']]
Variant (re-run on the same commit): if the 207 body is malformed ({"errors": ["boom"]} or a JSON list), the .get calls in the 207 branch raise AttributeError (only JSONDecodeError is caught there), and that is also retried 3 times (3 POSTs observed).
Langfuse Cloud or self-hosted?
Not server dependent (reproduced with a mock transport). The 207 shape is the one returned by /api/public/ingestion.
If self-hosted, what version are you running?
n/a
SDK and integration versions
langfuse 4.17.0 (main @ bf11ec121479145923ff27b32ec2ad1d06fd2d51), Python 3.14.0, httpx and backoff as pinned in uv.lock.
Additional information
Possible direction: handle APIErrors separately in _upload_batch: log each item (id, status, message) at warning/error level, treat per-item 4xx other than 429/408 as final, and optionally re-send only the items that failed with 429/5xx. A smaller change is to not retry an APIErrors whose statuses are all non-retryable 4xx. The 207 branch could also check isinstance(payload, dict) and the entries before calling .get.
Related but different: #1874 (log non-retryable 4xx batch drops) covers a plain 4xx response, not the 207 path.
Are you interested in contributing a fix for this bug?
Yes
- 主要语言
- Python
- 星标
- 498
- 派生
- 361
- 平均合并
- 16 小时 40 分钟
- 30 天内合并 PR
- 38
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
langfuse/langfuse-python 的其他 Issue
-
tests/unit/test_prompt.py fails on a fresh clone without LANGFUSE_* env vars可能已有人在做 @Mathoholic 于 1 天前认领。 未关闭bug feat-prompt-management sdk-python
难度 2/5 1-3 小时 新手友好度 80/100
langfuse/langfuse-python#1976 · 3 条评论 ·
维护者通常 1 天内回复
-
bug(langchain): failed streaming LLM runs retain IDs in callback memo可能已有人在做 @hassiebp 于 2 天前认领。 未关闭bug integration-langchain sdk-python
langfuse/langfuse-python#1977 · 已指派 1 人 ·
维护者通常 1 天内回复
-
bug: ChatPromptClient.compile appends str(whole list) once per non-dict placeholder item可能已有人在做 @hassiebp 于 3 天前认领。 未关闭bug feat-prompt-management sdk-python
langfuse/langfuse-python#1971 · 已指派 1 人 ·
维护者通常 1 天内回复
-
bug: LANGFUSE_MAX_EVENT_SIZE_BYTES is parsed but never enforced for score events可能已有人在做 @hassiebp 于 3 天前认领。 未关闭bug feat-scores sdk-python
langfuse/langfuse-python#1966 · 已指派 1 人 ·
维护者通常 1 天内回复
-
bug: non-numeric status in a 207 error entry raises inside handle_exception, kills the score consumer thread, flush()/shutdown() then hang可能已有人在做 @hassiebp 于 3 天前认领。 未关闭[Integrations] Language Clients bug feat-scores sdk-python
langfuse/langfuse-python#1967 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 langfuse/langfuse-python 的全部 Issue
相似的 Issue
-
SSM GetParameter throttling during concurrent workflow launches可能已有人在做 @alexiswl 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 80/100
-
[Bug] Dev image build fails: `npm install` in the root Dockerfile runs out of memory (exit 134)可能已有人在做 @andest01 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
Rename FunctionalRole BOT_DEV to DEV_STAFF可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭enhancement good first issue
难度 2/5 1-3 小时 新手友好度 79/100
pesu-dev/discord_bot#97 ·
-
难度 1/5 1-3 小时 新手友好度 88/100
gradio-app/gradio#13964 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 93/100
BSData/horus-heresy-3rd-edition#3232 · 1 条评论 ·
维护者通常 1 天内回复