← Back to Pull requests

feat(subjects): add Langfuse #58

Closed
unknown closed this pull request without merging on Nov 13, 2026 11:39 UTC
View on GitHub
unknown unknown commented on Nov 12, 2026 02:24 UTC
Author

Resolves #43.

What this PR does

Adds the Langfuse Python SDK (langfuse.openai) as a subject, reading its native langfuse.observation.* attributes:

1. Conventions (conventions.py & checks.py):
- Added in_langfuse: bool = True to Fact dataclass.
- Added "langfuse.observation.type" to LLM_MARKERS.
- Read token counts from JSON string langfuse.observation.usage_details (prompt_tokens and completion_tokens).
- Mapped langfuse.observation.model.name to response_model, and allow it to accept the request model name if unseparated.
- Facts undefined by Langfuse (request_model, response_id, finish_reasons, cache_read_tokens, cache_write_tokens, reasoning_tokens) are marked in_langfuse=False and graded as n/a via langfuse_only.
- On error scenarios, error.type is graded as n/a for Langfuse spans.

2. Subject Adapter (subjects/langfuse/):
- subject.toml: Pinned langfuse==5.2.0, providers = ["openai"], tracked.
- instrument.py: Initialized Langfuse with throwaway keys so it does not disable itself, and points base_url to the harness receiver so that Langfuse's internal OTLP export does not attempt outbound calls.

3. Tests & Changelog:
- Added unit tests in test_checks.py and test_subjects.py.
- Documented in CHANGELOG.md under [Unreleased].

Subject Findings (spantruth run --subject langfuse)

  • openai/stream-dropped & openai/async-stream-dropped (❌ wrong - ST07 False OK):

  • - In langfuse/openai.py:1102-1114, generator's traced_iterator executes finally: finalize_once() upon exception without marking the span status as ERROR, leaving it as UNSET.
  • openai/stream-helper & openai/async-stream-helper (🟡 missing - ST01 Ghost span):

  • - Raw response streaming calls are explicitly passed through untraced by Langfuse (openai.py:23-28).
  • All other OpenAI scenarios pass.
  • Verification

  • uv run pytest -m "not slow" -q: 422 passed

  • uv run pytest -m slow -q: 13 passed (both controls pass end-to-end)

  • uv run ruff check . && uv run ruff format --check .: Clean
  • Diff: 266 lines (+199 / -67) across 3 files Reviewer: chrikrah Review duration: 1994m
    All Vouch review confidence checks passed
    Residual risk 0.19 = Change Risk (0.44) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.44 · 266 lines diff across 3 files
    0.44
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.334
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #58"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 44.4% (MEDIUM) · Higher = larger blast radius
    44.4%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 19.2% · Safe to merge
    19.2%