Skip to content

fix(tracing): record provider stream failures in Langfuse - #4875

Merged
lyingbug merged 1 commit into
Tencent:mainfrom
ydflow:fix/langfuse-stream-errors
Nov 2, 2026
Merged

lyingbug merged 1 commit into
Tencent:mainfrom
ydflow:fix/langfuse-stream-errors

Conversation

@ydflow

@ydflow ydflow commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Description

When a provider emits a ResponseTypeError chunk, langfuseChat.ChatStream forwards the error to its caller but finishes the Langfuse generation with a nil error. A failed model call therefore has no error status in tracing, even though the same failure is visible to the user and the debug wrapper.

Retain the stream error and pass it to Generation.Finish, matching the debug wrapper's handling. Keep partial output, usage and all forwarded chunks unchanged. Production changes are confined to the tracing decorator; no protocol, configuration or API changes.

Type of Change

  • Bug fix
  • Test

Related Issue

Found during source review; no separate issue. Searched open/closed issues and PRs for Langfuse stream error, generation error and tracing. No direct duplicate found; #3529 adds request metadata rather than stream error handling.

This is independent of #4872, which changes cancellation handling in the outer concurrency decorator. There are no shared files or required merge order; this fix also works with the current main's concurrency wrapper.

Testing

Windows/amd64, CGO enabled with existing portable GCC/G++.

  • Before the production change, a new regression receiving an error chunk fails because the exported generation has no error status. Its successful-stream control passes.
  • The regression uses a local OTLP/HTTP receiver and decodes the actual protobuf export. It verifies error code/message, a successful-stream control, preserved partial output/token usage, and unchanged forwarded chunks.
  • go test -race ./internal/models/chat ./internal/tracing/langfuse -count=1 -timeout=90s passes on Go 1.26.0; Go 1.27.0 also passed before adding the output/usage assertions.
  • golangci-lint run --new-from-rev=origin/main ./internal/models/chat/... passes with CI-pinned v2.12.2 on Go 1.26.0 (0 issues).
  • Changed files are gofmt clean; diff whitespace check and skill freshness/account/overlap preflight pass.

No real Langfuse instance, provider API or full-repository checks were used. The regression uses the existing OTLP/protobuf dependencies and does not change go.mod.

Checklist

  • git diff --check origin/main...HEAD passes
  • Changed source files are formatted
  • Targeted tests and diff-scoped lint pass
  • Self-reviewed the code
  • Added regression coverage
  • Full-repository checks were run
  • Documentation: not needed; no public API/configuration change
  • Breaking changes: none

Prepared with AI assistance.

@lyingbug
lyingbug merged commit 0231dfb into Tencent:main Nov 2, 2026
4 checks passed
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.

2 participants