Skip to content

fix(scores): parse session ID correctly#1582

Merged
hassiebp merged 4 commits intomainfrom
hassieb/lfe-9008-bug-session_id-not-working-on-langfusecreate_score
Mar 27, 2026
Merged

fix(scores): parse session ID correctly#1582
hassiebp merged 4 commits intomainfrom
hassieb/lfe-9008-bug-session_id-not-working-on-langfusecreate_score

Conversation

@hassiebp
Copy link
Copy Markdown
Contributor

@hassiebp hassiebp commented Mar 27, 2026

Disclaimer: Experimental PR review

Greptile Summary

This PR fixes a bug where session_id was not serialized correctly when creating scores. In ScoreBody, all fields use camelCase alias forms in the constructor (traceId, observationId, datasetRunId, etc.) — the score creation code was the only place using the Python snake_case name session_id= instead of the alias sessionId=, causing the session ID to be silently dropped or misrouted. The fix aligns it with the existing pattern. A debug log statement is also cleaned up from batch_post (equivalent logging remains in post()), and an integration test is added to verify the session-level score round-trip.

  • langfuse/_client/client.py: One-line fix — session_id=session_idsessionId=session_id in the ScoreBody constructor call
  • langfuse/_utils/request.py: Removes redundant logger.debug("uploading data: %s", kwargs) from batch_post; the same data is already logged after serialization inside post()
  • tests/test_core_sdk.py: New integration test test_create_session_score creates a session-scoped score and asserts it is retrievable with the correct session_id; has minor cleanup items (unused api_wrapper, a debug print, missing blank line)

Confidence Score: 5/5

Safe to merge — the core fix is a minimal, correct one-line change aligned with existing patterns; all remaining findings are P2 style issues in the new test

The bug fix itself is straightforward and consistent with every other camelCase field in the same constructor. No P0 or P1 issues were found. The three findings are all minor test-code style issues (unused variable, debug print, missing blank line) that do not affect correctness or reliability.

tests/test_core_sdk.py — minor cleanup (unused api_wrapper, print statement, missing blank line)

Important Files Changed

Filename Overview
langfuse/_client/client.py Core fix: changes session_id=session_id to sessionId=session_id in ScoreBody constructor to use the camelCase alias, consistent with all other fields (traceId, observationId, datasetRunId, etc.)
langfuse/_utils/request.py Removes the redundant logger.debug("uploading data: %s", kwargs) from batch_post; equivalent debug logging still exists in the downstream post() method after serialization
tests/test_core_sdk.py New integration test test_create_session_score validates the session-level score fix; has minor style issues: unused api_wrapper variable, a leftover print statement, and a missing blank line before the next test

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Langfuse as Langfuse.create_score()
    participant ScoreBody
    participant LangfuseClient as LangfuseClient.batch_post()
    participant API as Langfuse API

    Caller->>Langfuse: create_score(session_id="s1", name="score", value=1)
    Langfuse->>ScoreBody: ScoreBody(sessionId="s1", traceId=..., ...)
    Note over ScoreBody: Field stored via camelCase alias<br/>(consistent with traceId, observationId, etc.)
    ScoreBody-->>Langfuse: score_body (frozen model)
    Langfuse->>Langfuse: wrap in event dict {type: "score-create", body: score_body}
    Langfuse->>LangfuseClient: batch_post(batch=[event])
    LangfuseClient->>LangfuseClient: post() — json.dumps via EventSerializer
    Note over LangfuseClient: dict(by_alias=True) +<br/>convert_and_respect_annotation_metadata<br/>→ {"sessionId": "s1", ...}
    LangfuseClient->>API: POST /api/public/ingestion
    API-->>LangfuseClient: 200 OK
    LangfuseClient-->>Langfuse: response
Loading

Reviews (1): Last reviewed commit: "fix(scores): parse session ID correctly" | Re-trigger Greptile

@github-actions
Copy link
Copy Markdown

@claude review

Copy link
Copy Markdown

@claude claude bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — the field name fix is correct and the change is minimal.

Extended reasoning...

Overview

The PR fixes a field name mismatch in langfuse/_client/client.py where session_id (snake_case) was passed to ScoreBody instead of the correct camelCase sessionId. A minor debug log removal in request.py is also included, along with a new integration test test_create_session_score that exercises the fix.

Security risks

None. This is a field-name bug fix with no auth, crypto, or permission changes.

Level of scrutiny

Low — the change is a one-line rename of a keyword argument to the correct camelCase form that the Pydantic model expects. The intent is clear and the fix is mechanical.

Other factors

The only bugs found are test-quality nits (an unused api_wrapper variable and a leftover print statement in the new test). These are already noted as inline comments and do not affect correctness or CI reliability in a meaningful way. The core fix is straightforward enough to approve.

@hassiebp hassiebp merged commit 0ec542e into main Mar 27, 2026
7 of 13 checks passed
@hassiebp hassiebp deleted the hassieb/lfe-9008-bug-session_id-not-working-on-langfusecreate_score branch March 27, 2026 11:57
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.

1 participant