You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug: server-side compaction is not emitted on Responses tool-call-only turns #3075
I see different behavior depending on the output type of the turn:
For a long plain request, response.output contains:
message
compaction
For a long request that returns only function_call, response.output contains only:
function_call
If I continue the tool loop and the next turn is again only function_call, there is still no compaction.
Only when the model finally returns an assistant message does response.output include:
message
compaction
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 no compaction item in response.output.
Observe that compaction only appears once the model finally emits an assistant message.
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
importasynciofromopenaiimportAsyncOpenAIfromazure.identity.aioimportDefaultAzureCredential, get_bearer_token_providerAZURE_ENDPOINT="https://<your-resource>.openai.azure.com/openai/v1/"MODEL="gpt-5.4"asyncdefmain():
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 "*5000tools= [{
"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."
)
}]
forstepinrange(1, 5):
response=awaitclient.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) foriinresponse.output])
conversation.extend(response.output)
function_calls= [iforiinresponse.outputifgetattr(i, "type", None) =="function_call"]
iffunction_calls:
foridx, fcinenumerate(function_calls, start=1):
conversation.append({
"type": "function_call_output",
"call_id": fc.call_id,
"output": f"tool-result-{step}-{idx}",
})
else:
breakawaitclient.close()
awaitcred.close()
asyncio.run(main())
Thanks for reporting this! There have been several API and SDK updates since this was opened, so we’re closing it for now. If this is still affecting you, please retry with the latest SDK and share a minimal reproduction. We’re happy to reopen and take another look.
Activity
nightcityblade commentedon May 2, 2026
Hi, I'd like to work on this. I'll submit a PR shortly.
fix: preserve response compaction output items (closes openai#3075)
marcuswood-oai commentedon Oct 23, 2026
Thanks for reporting this! There have been several API and SDK updates since this was opened, so we’re closing it for now. If this is still affecting you, please retry with the latest SDK and share a minimal reproduction. We’re happy to reopen and take another look.