Repository navigation
fix: valid LangFuse trace ids, trace metadata, feedback scores - #518
Merged
neuromechanist merged 3 commits intoSep 25, 2026
Merged
neuromechanist merged 3 commits into
neuromechanist merged 3 commits into
Conversation
added 2 commits
September 25, 2026 15:43
LangFuse requires 32-char lowercase hex trace ids. The previous '<community>-<12 hex>' ids were rejected, so the root span was never created: each LLM and tool call became its own trace and request_log.langfuse_trace_id matched nothing. Traces now also carry the community as a tag, the X-User-ID as the user, and the chat session id for /chat and streaming chat. Refs OpenScience-Collective#515
POST /feedback now attaches thumbs up/down (and the comment) to the rated answer's LangFuse trace as a user_feedback score, using request_log.langfuse_trace_id. Best-effort: skipped when LangFuse is not configured or the request was not traced, and errors are logged without failing the request. Refs OpenScience-Collective#515
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
neuromechanist
merged commit Sep 25, 2026
bbaf9b7
into
OpenScience-Collective:develop
7 checks passed
This was referenced Sep 30, 2026
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #515.
Summary
1. Valid trace ids (bug fix).
create_community_assistantbuilt trace ids asf"{community_id}-{uuid.uuid4().hex[:12]}". LangFuse requires 32 lowercase hex characters, so it rejected those ids (Passed trace ID 'nwb-…' is not a valid 32 lowercase hex char Langfuse trace id, then aValueErrorinon_chain_start). As a result, every LLM call and tool call became its own trace, andrequest_log.langfuse_trace_idmatched nothing. Trace ids are nowuuid.uuid4().hex.2. Trace metadata. The LangChain run config now carries
langfuse_tags: [community_id],langfuse_user_id(fromX-User-ID), andlangfuse_session_idfor/chatand streaming chat. This keeps the community filterable now that it's no longer in the id, and groups a conversation's turns.create_community_assistantgains an optionalsession_idparameter for this.3. Feedback as scores.
POST /feedbacknow looks up the rated request'slangfuse_trace_idand attaches auser_feedbackscore (categoricalup/down, with the comment) to that trace. The LangFuse client is built fromSettings, so this also works before the first traced request. It's best-effort, likewrite_feedback: it's skipped when LangFuse isn't configured or the request wasn't traced, and it logs errors without failing the request.Tests
tests/test_api/test_community_router.py:TestLangfuseTracingchecks the trace metadata variants, and thatcreate_community_assistantrequests a 32-hex trace id and attaches the metadata. The tracing service is faked, solangfuseisn't needed.tests/test_api/test_feedback_endpoint.py: the score is sent to the answer's trace, nothing is sent when the request wasn't traced or LangFuse isn't configured, and a LangFuse error still returns 200. These use a fakelangfusemodule.pytest -m "not network": 2978 passed. Excluded are tests that also fail ondevelopin my environment (they needbun, or hit an existingAttributeErrorintests/test_integration/test_llm.py); see feat: add NWB community #517 for details.ruff checkandruff format --checkare clean.langfuse3.11.2 SDK: one/hed/asknow produces a single trace whose id matchesrequest_log, with tag['hed']and the user id.POST /feedbackfor that request adds auser_feedbackscore to the same trace. Before this change, the same request produced one trace per LLM or tool call.