Bug: server-side compaction is not emitted on Responses tool-call-only turns
Maintainer thường phản hồi trong vòng 1 ngày
@nightcityblade đang làm issue này rồi.
Từ ngày 2/5/2026.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
Bắt đầu bằng cách tái hiện chuỗi thao tác được báo cáo với responses.create và responses.parse, sử dụng vòng lặp gọi công cụ và các thiết lập context_management được cung cấp. So sánh các mục đầu ra do SDK trả về với hành vi bên dưới của Responses API. Công việc được xem là hoàn tất khi xác định được liệu thư viện Python có loại bỏ các compaction items trong những lượt chỉ có tool call hay không và, nếu có, xác định một bài kiểm thử hồi quy cho hành vi đã được sửa.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
Describe the bug
I am using the Responses API through openai-python with:
context_management=[{"type": "compaction", "compact_threshold": 1000}]store=Falsegpt-5.4
I see different behavior depending on the output type of the turn:
-
For a long plain request,
response.outputcontains:messagecompaction
-
For a long request that returns only
function_call,response.outputcontains only:function_call
-
If I continue the tool loop and the next turn is again only
function_call, there is still nocompaction. -
Only when the model finally returns an assistant
messagedoesresponse.outputinclude:messagecompaction
This means that in tool-heavy agent loops with several consecutive tool-call turns, context can continue growing without any emitted compaction item, and the loop can eventually hit
context_length_exceeded before compaction appears.
I reproduced this through openai-python using both client.responses.create(...) and client.responses.parse(...).
If this is expected backend/API behavior rather than a Python SDK issue, please let me know and I can move the report.
To Reproduce
- Create a long input that is clearly above the compaction threshold.
- Enable server-side compaction with a very low threshold, for example:
context_management=[{"type": "compaction", "compact_threshold": 1000}] - Force the first turn to produce a
function_call. - Send the corresponding
function_call_output. - If the model produces another
function_call, observe that there is still nocompactionitem inresponse.output. - Observe that
compactiononly appears once the model finally emits an assistantmessage.
Observed output from my repro:
R1 input_tokens 5084
R1 output_types ['function_call']
R2 input_tokens 5119
R2 output_types ['function_call']
R3 input_tokens 5154
R3 output_types ['message', 'compaction']
For comparison, a plain long request with the same threshold produces compaction immediately:
CREATE input_tokens 5007
CREATE output_types ['message', 'compaction']
To Reproduce
import asyncio
from openai import AsyncOpenAI
from azure.identity.aio import DefaultAzureCredential, get_bearer_token_provider
AZURE_ENDPOINT = "https://<your-resource>.openai.azure.com/openai/v1/"
MODEL = "gpt-5.4"
async def main():
cred = DefaultAzureCredential()
token_provider = get_bearer_token_provider(
cred,
"https://cognitiveservices.azure.com/.default"
)
client = AsyncOpenAI(
base_url=AZURE_ENDPOINT,
api_key=token_provider,
)
long_text = "context " * 5000
tools = [{
"type": "function",
"name": "echo_tool",
"description": "Echo a short string",
"parameters": {
"type": "object",
"properties": {
"text": {"type": "string"}
},
"required": ["text"],
"additionalProperties": False
}
}]
cm = [{"type": "compaction", "compact_threshold": 1000}]
conversation = [{
"role": "user",
"content": (
long_text +
"\n\nCall echo_tool twice in sequence. "
"First with text=first. After I return the tool result, "
"call echo_tool again with text=second. "
"Only after the second tool result, answer DONE."
)
}]
for step in range(1, 5):
response = await client.responses.create(
model=MODEL,
input=conversation,
tools=tools,
store=False,
context_management=cm,
)
print(f"R{step} input_tokens:", response.usage.input_tokens)
print(f"R{step} output_types:", [getattr(i, 'type', None) for i in response.output])
conversation.extend(response.output)
function_calls = [i for i in response.output if getattr(i, "type", None) == "function_call"]
if function_calls:
for idx, fc in enumerate(function_calls, start=1):
conversation.append({
"type": "function_call_output",
"call_id": fc.call_id,
"output": f"tool-result-{step}-{idx}",
})
else:
break
await client.close()
await cred.close()
asyncio.run(main())
Code snippets
OS
Windows
Python version
3.11.5
Library version
openai 2.21.0
- Ngôn ngữ chính
- Python
- Star
- 31.8k
- Fork
- 7.3k
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 131
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 openai/openai-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
openai/openai-python#4022 · 19 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
fix(auth): SubjectTokenProviderError drops response and duplicates error message in workload identity providersCó thể đã có người làm @mohmedmm đã nhận 8 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
openai/openai-python#4017 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Querystring drops explicit empty-string scalar valuesCó thể đã có người làm @sylvesterkaczmarek đã nhận 31 ngày trước. Đang mởsdk-breaking-change v4
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
openai/openai-python#3837 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Define + export `ServiceTiers` string literalCó thể đã có người làm @SparshGarg999 đã nhận 57 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openai/openai-python#3556 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Empty OPENAI_BASE_URL prevents fallback to default API endpointCó thể đã có người làm @Sehastrajit-S đã nhận 23 ngày trước. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
openai/openai-python#2927 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
NousResearch/hermes-agent#136483 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] LazyStackedTensorDictStore zeroes the last byte of a new key set on the last elementCó thể đã có người làm @peterdsharpe đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pytorch/tensordict#2307 ·
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
Maintainer thường phản hồi trong vòng 1 ngày
-
GrokModel.generate/a_generate pass an OpenAI-style list-of-dicts to xai_sdk.chat.user(), so every call crashes with a protobuf TypeError before any network I/OCó thể đã có người làm @Christian-Sidak đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
confident-ai/deepeval#3436 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày