Repository navigation
fix(langfuse): preserve Responses tool namespaces - #41401
CNSeniorious000 wants to merge 1 commit into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
| "arguments": arguments_obj, | ||
| } | ||
| if (namespace := getattr(item, "namespace", None)) is not None: | ||
| langfuse_tool_call["namespace"] = namespace |
There was a problem hiding this comment.
Dictionary update breaks coding rules
The new assignment mutates langfuse_tool_call, violating CLAUDE.md’s no-mutation directive for updated code. Build the optional field inside the dictionary expression before merging
Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
c7e863e to
423b6ba
Compare
TLDR
Problem this solves:
How it solves it:
User Flow
Before: the application's logged tool call loses its namespace
POST http://127.0.0.1:47381/v1/responseswith thediagnostics.echotool and"stream": truename: "echo"andnamespace: "diagnostics"name: "echo"withoutnamespaceAfter: the logged tool call identifies the same namespace as the response
POST http://127.0.0.1:47382/v1/responseswith thediagnostics.echotool and"stream": truename: "echo"andnamespace: "diagnostics"name: "echo"andnamespace: "diagnostics"Relevant issues
Fixes #41400
Affected release
Linear ticket
Pre-Submission checklist
The full mapped test file passes:
38 passed. The added named and empty namespace cases fail against the base revision, while the absent case passes. Ruff check/format and type-discipline comparison against the base also passScreenshots / Proof of Fix
Captured against real model calls, with no mocks, on Python 3.13. The model was
gpt-6-astrathrough an OpenAI-compatible endpoint. Only the private endpoint and credentials are replaced by environment variables belowSet
NAMESPACE_UPSTREAM_BASE_URLto the provider's/v1endpoint,NAMESPACE_UPSTREAM_KEYto its key, andLANGFUSE_HOST,LANGFUSE_PUBLIC_KEY,LANGFUSE_SECRET_KEYto a Langfuse project.PYTHONbelow points to the Python environment with proxy and OTEL dependencies installedRun each proxy in a separate terminal, from the corresponding checkout:
Shared request and capture commands (Bash, curl, jq):
Wait for export before reading the observation. The observation IDs below are from this capture. On a fresh run, find its trace with
GET $LANGFUSE_HOST/api/public/traces?sessionId=<session>&limit=10, then use the matching generation's observation ID.litellm_metadatakeeps this session association on the proxy being testedThe outputs below are the complete outputs of the jq projections shown above
Before (a8979fe)
Streaming
Send the request and inspect the returned tool call
run_smoke 47381 true db629521-fb40-491b-a642-81daf0beb0f8 proxy-before-stream{"name":"echo","namespace":"diagnostics","call_id":"call_k61isHCQAfXLKhxsaBReZSuY"}Read the same call from Langfuse
{"name":"echo","namespace_present":false,"namespace":null,"call_id":"call_k61isHCQAfXLKhxsaBReZSuY"}Non-streaming
Send the request and inspect the returned tool call
run_smoke 47381 false cfae92b5-a201-4d2d-9750-6524087d6062 proxy-before-json{"name":"echo","namespace":"diagnostics","call_id":"call_LIB2OnWL1bcAAENU33Fg4bMp"}Read the same call from Langfuse
{"name":"echo","namespace_present":false,"namespace":null,"call_id":"call_LIB2OnWL1bcAAENU33Fg4bMp"}After (c7e863e)
Streaming
Send the request and inspect the returned tool call
run_smoke 47382 true 09b4e387-71f2-4ddc-80c9-ee9e5fa2e751 proxy-after-stream{"name":"echo","namespace":"diagnostics","call_id":"call_ueLXXIOPkoPEgJ4SizZjgccS"}Read the same call from Langfuse
{"name":"echo","namespace_present":true,"namespace":"diagnostics","call_id":"call_ueLXXIOPkoPEgJ4SizZjgccS"}Non-streaming
Send the request and inspect the returned tool call
run_smoke 47382 false cbf26433-2772-44db-bf3a-368b14de5d99 proxy-after-json{"name":"echo","namespace":"diagnostics","call_id":"call_OcKZFo6fiNL1LfieVnLdE8sS"}Read the same call from Langfuse
{"name":"echo","namespace_present":true,"namespace":"diagnostics","call_id":"call_OcKZFo6fiNL1LfieVnLdE8sS"}Type
Bug Fix
Caveats (if any)
Low
custom_tool_callitems in Responses API output #36916Final Attestation