[Bug]: Background Responses calls on gpt-5.4 return reasoning_tokens equal to output_tokens
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ó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Start with the provided AsyncOpenAI background Responses API reproduction and retrieve the completed response through with_raw_response. Compare the wire usage fields with the parsed response and review agent_framework_openai._chat_client._parse_usage_from_openai, along with the linked agent-framework issue. Done means determining whether ownership belongs in the SDK or the service.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What happened
On gpt-5.4 via Azure OpenAI, a Responses API call made with background=True intermittently returns usage.output_tokens_details.reasoning_tokens set equal to usage.output_tokens, implying the model produced zero visible output - while the response body contains a complete, schema-valid answer of 10,000+ characters.
agent_framework_openai._chat_client._parse_usage_from_openai copies these through to UsageDetails["reasoning_output_token_count"] and output_token_count, so anything computing visible output as output_token_count - reasoning_output_token_count gets zero.
It happens on roughly 50% of background gpt-5.4 calls. In one 64-call production run, 27 calls were affected and the reported reasoning total was inflated by about 61,000 tokens (~23%). total_tokens stays internally consistent (input + output), so a sanity check on the top-level fields does not catch it.
What I expected
reasoning_tokens to be the reasoning portion of output_tokens, as it is on synchronous calls with identical input.
Steps to reproduce
- Call the Responses API with
background=True,store=True, a JSON schema, and an input that
drives several thousand reasoning tokens (I used an 11.5 KB plain-text document and
reasoning={"effort": "high"}). - Poll
responses.retrieve(id)untilstatus == "completed". - Read
usage.output_tokens_details.reasoning_tokensand compare withusage.output_tokens. - Repeat a few times - it is intermittent, about one call in two on
gpt-5.4.
The same request run synchronously never shows it (0 of 5).
Ruled out
| Hypothesis | Test | Result |
|---|---|---|
| SDK mis-parses the payload | Compared with_raw_response HTTP text against the parsed object |
Identical; the wire is already wrong |
Caused by store=True |
Synchronous call with store=True |
Correct |
| Caused by background mode alone | Background at low effort, small output | Correct |
| Stale read | Retrieved the same completed id twice | Byte-identical usage |
| Long duration or poll count | 64-call sample | Overlaps: a healthy call ran 98 s, 44 polls, 13,236 output tokens |
Code Sample
# Reproduced with the raw openai client, no agent-framework in the path,
# which is what points at the service rather than the SDK.
import asyncio, json
from openai import AsyncOpenAI
SCHEMA = {
"type": "json_schema", "name": "Findings", "strict": True,
"schema": {
"type": "object", "additionalProperties": False,
"required": ["summary", "requirements", "risks"],
"properties": {
"summary": {"type": "string"},
"requirements": {"type": "array", "items": {"type": "string"}},
"risks": {"type": "array", "items": {"type": "string"}},
},
},
}
async def main(client: AsyncOpenAI, document: str) -> None:
resp = await client.responses.create(
model="gpt-5.4",
input=[{"role": "user",
"content": f"Extract every requirement and risk. Be exhaustive.\n\n{document}"}],
text={"format": SCHEMA},
reasoning={"effort": "high"},
background=True,
store=True,
)
while resp.status in ("queued", "in_progress"):
await asyncio.sleep(2)
resp = await client.responses.retrieve(resp.id)
# Read the wire, not the parsed object, to show the SDK is not at fault.
http = await client.responses.with_raw_response.retrieve(resp.id)
usage = json.loads(http.http_response.text)["usage"]
out = usage["output_tokens"]
reasoning = usage["output_tokens_details"]["reasoning_tokens"]
print(f"status={resp.status} chars={len(resp.output_text)} out={out} reasoning={reasoning}")
assert reasoning < out, "reasoning_tokens == output_tokens: visible output reported as zero"
Error Messages / Stack Traces
No exception is raised. The failure is silent: usage is wrong, the response is valid.
Raw wire body from one affected call (retrieved, not parsed):
{"input_tokens": 1504,
"input_tokens_details": {"cache_write_tokens": 0, "cached_tokens": 1280},
"output_tokens": 6713,
"output_tokens_details": {"reasoning_tokens": 6713},
"total_tokens": 8217}
That response had status "completed" and carried 10,344 characters of schema-valid JSON. Retrieving the same id a second time returned byte-identical usage.
Package Versions
agent-framework-core: 1.17.0, agent-framework-openai: 1.14.2, openai: 2.48.0
Python Version
Python 3.14.7
Additional Context
Model comparison
Same document, same prompt, effort: high, background: true, three runs each:
| deployment | output tokens | reasoning reported | corrupted |
|---|---|---|---|
gpt-5.4 |
19,133 - 19,822 | equal to output | 3 / 3 |
gpt-5.6-luna |
10,569 - 12,092 | 5,612 - 5,696 | 0 / 3 |
gpt-5.6-sol |
7,009 - 9,502 | 2,817 - 4,753 | 0 / 3 |
Totals across everything I ran:
| model | background calls | corrupted |
|---|---|---|
gpt-5.4 |
64 | ~34 (about 50%) |
gpt-5.4-mini |
10 | 0 |
gpt-5.6 sol / luna / terra |
24 | 0 |
gpt-5.4, synchronous |
5 | 0 |
Both the chat and the "workflow" deployment of gpt-5.4 are affected equally, so it is not a deployment configuration difference.
Environment
Azure OpenAI behind APIM, managed-identity auth, OpenAI-compatible /v1 endpoint. Client built as OpenAIChatClient(model=..., base_url=..., credential=...).
Workaround
Stop deriving visible output by subtraction. I now measure it by tokenising the parsed response with tiktoken o200k_base. It is an estimate, but it does not depend on a field that is wrong half the time on this model. output_tokens itself remains trustworthy - only reasoning_tokens is corrupted.
See https://github.com/microsoft/agent-framework/issues/8191
- Ngôn ngữ chính
- Python
- Star
- 5.6k
- Fork
- 3.4k
- Merge trung bình
- 1 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 189
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Azure/azure-sdk-for-python
-
needs-triage
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
Azure/azure-sdk-for-python#50155 · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Teams Chatbot]: next-mypy install 404s should point to CFS auth or --pypi workaroundCó thể đã có người làm @jianingwang123 đã nhận 17 ngày trước. Đang mởneeds-triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 72/100
Azure/azure-sdk-for-python#49886 · 1 bình luận · 2 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[AI Projects] AIProjectInstrumentor: non-streamed responses.create raises AttributeError ('NonRecordingSpan' object has no attribute 'attributes') when the span is not sampledCó thể đã có người làm @14H034160212 đã nhận 19 ngày trước. Đang mởAI Projects Client customer-reported question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Azure/azure-sdk-for-python#49854 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
azure-eventhub migration guide: legacy checkpoint sample writes "None" metadata for partitions that were never checkpointedCó thể đã có người làm @hidingmyname đã nhận 27 ngày trước. Đang mởClient customer-reported Event Hubs needs-team-attention question Service Attention
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Azure/azure-sdk-for-python#49723 · 2 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Scheduled test pipelines fail at the Analyze_Test stage due to date formattingCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mởEngSys
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Azure/azure-sdk-for-python#49614 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Azure/azure-sdk-for-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
vllm-project/vllm#70030 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
TigreGotico/tugaphone#408 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
gke-labs/kube-agents#7308 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
t: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
chore
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
lugassawan/swe-workbench#841 ·