Fix GPT-5.x reasoning-item orphaning in history compaction + persist foundry resource name#307
Open
breedx wants to merge 3 commits intompfaffenberger:mainfrom
Open
Fix GPT-5.x reasoning-item orphaning in history compaction + persist foundry resource name#307breedx wants to merge 3 commits intompfaffenberger:mainfrom
breedx wants to merge 3 commits intompfaffenberger:mainfrom
Conversation
…state _strip_empty_thinking_parts was dropping any ThinkingPart with empty content, including the empty-content-but-signed reasoning items that the OpenAI Responses API returns for GPT-5. Dropping those orphans the paired msg_... TextPart on the next turn and the API rejects with: 'msg_...' of type 'message' was provided without its required 'reasoning' item: 'rs_...' Now we only strip when content is empty AND there is no signature, id, or provider_details — anything carrying provider state survives.
/foundry-setup previously prompted for the resource name every run unless the user exported ANTHROPIC_FOUNDRY_RESOURCE. Save the chosen name to puppy.cfg under `azure_foundry_resource` so the next run pre-populates it. Resolution order is preserved for env-var users: ANTHROPIC_FOUNDRY_RESOURCE (env) -> puppy.cfg -> None
Contributor
Author
CI uses unpinned 'pip install ruff' and picked up 0.15, which wraps the negated isinstance lambda differently. Apply the format.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
Two related fixes for GPT-5.x reasoning models on the OpenAI Responses API and Azure AI Foundry, both surfaced while using
foundry-gpt-5.5.1.
fix(compaction): preserve ThinkingParts carrying encrypted reasoning stateThis is the important one — it affects any GPT-5 / o-series model on the Responses API (OpenAI, Azure Foundry OpenAI, ChatGPT OAuth), not just Foundry.
On the OpenAI Responses API, reasoning items arrive as
ThinkingPart(content='', signature='<encrypted>', id='rs_...')— empty text, but the signature carries the encrypted reasoning state that must round-trip back so the pairedmsg_...item in the next turn is not orphaned._strip_empty_thinking_partsincode_puppy/agents/_compaction.pywas dropping any ThinkingPart with empty content, including those carrying encrypted reasoning. On the next turn the API rejected with:Now we only strip when
contentis empty and there is nosignature,id, orprovider_details— anything carrying provider state survives compaction.2.
feat(azure_foundry): persist resource name across sessions/foundry-setupre-prompted for the resource name every run unless the user exportedANTHROPIC_FOUNDRY_RESOURCE. The wizard now saves the chosen name topuppy.cfgunderazure_foundry_resource, so the next run pre-populates it.Resolution order is preserved for env-var users:
ANTHROPIC_FOUNDRY_RESOURCE(env) →puppy.cfg→None(Happy to split this into a separate PR if you'd prefer to land #1 on its own.)
Test plan
uv run pytest tests/agents/test_compaction.py— all pass (includes newtest_preserves_empty_thinking_with_signature)uv run pytest tests/plugins/test_azure_foundry.py— all pass (includes new tests for cfg fallback, env precedence, and persistence)uv run ruff format --check— cleanuv run ruff check— cleanfoundry-gpt-5.5— the originalmsg_.../rs_...error no longer fires on multi-turn conversations