Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

OpenAI Responses streams that end incomplete or failed are logged without token metrics

Đang mở Phù hợp với người mới
#962 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
77/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
observability

Hướng nghiên cứu

Bắt đầu tại py/src/braintrust/integrations/openai/tracing.py, ở ResponseWrapper._postprocess_streaming_results, rồi lần theo cách response.completed cung cấp thông tin sử dụng và đầu ra trong cả hai nhánh. Kiểm tra cách các sự kiện kết thúc response.incomplete và response.failed cung cấp phản hồi cuối cùng, sau đó tái hiện bằng lệnh gọi streaming đã cung cấp. Hoàn tất khi các sự kiện kết thúc này ghi lại các chỉ số token và đầu ra cuối cùng, đồng thời có cassette đã ghi lại bao quát hành vi này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

ResponseWrapper._postprocess_streaming_results (py/src/braintrust/integrations/openai/tracing.py) reads the final response only from response.completed. That event's response.usage populates the metrics, and its response.output becomes the logged output.

A Responses stream can also end on response.incomplete (for example when max_output_tokens is reached) or response.failed. Both events carry the same final response, with its usage and output. For those streams:

  • no token metrics are logged: the intermediate events carry no usage, and the terminal response's usage is only read for response.completed
  • the logged output is the partial reconstruction from the deltas, not the final response.output

Repro: client.responses.create(model="gpt-4.1", input="Write a long essay", max_output_tokens=16, stream=True) with the wrapped client. The stream ends on response.incomplete and the span has no prompt_tokens/completion_tokens metrics.

Suggested fix: handle response.incomplete and response.failed the same way as response.completed in both branches. I'm happy to send a PR with a recorded cassette if that works for you.

This issue was written with help from an AI coding assistant (Claude Code); the code path above was checked on main.

Ngôn ngữ chính
Python
Star
22
Fork
27
Merge trung bình
14 giờ 49 phút
Pull request đã merge (30 ngày)
126

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của braintrustdata/braintrust-sdk-python

Tất cả issue của braintrustdata/braintrust-sdk-python

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.