Skip to content

Preserve thinking content for providers that require it - #8857

Merged
jh-block merged 14 commits into
mainfrom
jhugo/investigate-issue-7363
May 15, 2026
Merged

Preserve thinking content for providers that require it#8857
jh-block merged 14 commits into
mainfrom
jhugo/investigate-issue-7363

Conversation

@jh-block

@jh-block jh-block commented Apr 27, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Support clear_thinking: false in OpenAI-compatible providers
  • Fix possible duplicate reasoning content in streaming OpenAI-compatible code path
  • Add a declarative preserves_thinking flag for Anthropic-compatible providers
  • Add a built-in Z.AI declarative provider (Anthropic-compatible) that enables preserved thinking

Testing

  • Added unit tests for declarative provider deserialization and Anthropic formatting behavior
  • Added regression tests for OpenAI streaming reasoning around tool calls

Fixes #7363

@jh-block jh-block changed the title Add declarative Anthropic thinking preservation support Preserve thinking content for providers that require it Apr 27, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a02a417871

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/goose/src/providers/formats/openai.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 81da1fb0e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/goose/src/providers/formats/openai.rs
Comment thread crates/goose/src/providers/formats/openai.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd13ad1937

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/goose/src/providers/formats/openai.rs Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 95a5facfa1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/goose/src/config/declarative_providers.rs Outdated

@DOsinga DOsinga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Removed the two trivial tests for format_options_for_provider (they just asserted the implementation is what it is).

Note: the original commits are missing DCO sign-off (Signed-off-by trailer). Please rebase with git rebase --signoff or amend the commits to add sign-off before merge.

@DOsinga

DOsinga commented May 13, 2026

Copy link
Copy Markdown
Collaborator

Hey @jh-block — this PR has merge conflicts with main. Could you rebase to resolve them? Once clean we can get it moving again.

jh-block added 6 commits May 15, 2026 09:29
Signed-off-by: jh-block <jhugo@block.xyz>
Signed-off-by: jh-block <jhugo@block.xyz>
Signed-off-by: jh-block <jhugo@block.xyz>
Signed-off-by: jh-block <jhugo@block.xyz>
Signed-off-by: jh-block <jhugo@block.xyz>
Signed-off-by: jh-block <jhugo@block.xyz>
@jh-block
jh-block enabled auto-merge May 15, 2026 07:41
Signed-off-by: jh-block <jhugo@block.xyz>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 09230b9766

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/goose/src/providers/formats/openai.rs Outdated
jh-block added 2 commits May 15, 2026 10:36
Signed-off-by: jh-block <jhugo@block.xyz>
Signed-off-by: jh-block <jhugo@block.xyz>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1732a6670b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/goose/src/providers/formats/openai.rs Outdated
@jh-block
jh-block added this pull request to the merge queue May 15, 2026
@jh-block
jh-block removed this pull request from the merge queue due to a manual request May 15, 2026
Signed-off-by: jh-block <jhugo@block.xyz>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9d2f3d557d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/goose/src/providers/openai.rs
Comment thread crates/goose/src/acp/server/providers.rs Outdated
Signed-off-by: jh-block <jhugo@block.xyz>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3926d4d540

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/goose/src/providers/formats/openai.rs Outdated
Comment thread crates/goose/src/providers/declarative/opencode_go.json
Signed-off-by: jh-block <jhugo@block.xyz>
Signed-off-by: jh-block <jhugo@block.xyz>
@jh-block
jh-block added this pull request to the merge queue May 15, 2026
Merged via the queue into main with commit 537eb23 May 15, 2026
27 checks passed
@jh-block
jh-block deleted the jhugo/investigate-issue-7363 branch May 15, 2026 10:50
JAManfredi added a commit to JAManfredi/goose that referenced this pull request Aug 5, 2026
`apply_thinking_config` adds `clear_thinking: false` to the thinking
object whenever `preserve_thinking_context` is set. That field is part
of the manual `type: "enabled"` thinking shape used by OpenAI-compatible
reasoning providers (e.g. Z.AI/GLM, added in aaif-goose#8857 to fix aaif-goose#7363), where
`false` preserves prior reasoning across turns.

It is not part of the adaptive thinking interface. An adaptive request
carries only `{"type": "adaptive"}` alongside `output_config.effort`.
For adaptive-mode models (Opus 4.6/4.7/4.8, Sonnet 4.6/5, Fable 5) the
preserve-context block still stamps `clear_thinking` onto the adaptive
object, producing e.g.:

    "thinking": { "type": "adaptive", "clear_thinking": false }

The public Anthropic API tolerates the unknown key, but endpoints that
validate the adaptive shape strictly reject it with a 400
(`thinking.adaptive.clear_thinking: Extra inputs are not permitted`),
breaking every request for those models once thinking is on. aaif-goose#9746
widened the exposure by routing 4.7/4.8 down the adaptive path.

Only emit `clear_thinking` when the resolved thinking shape is not
adaptive, so GLM/enabled-shape preservation is unchanged while adaptive
requests stay spec-compliant. Adds a regression test asserting an
adaptive model with preserved thinking context omits `clear_thinking`.
shafqatevo pushed a commit to shafqatevo/goose that referenced this pull request Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GLM-4.7/GLM-5 (Z.AI) loses reasoning state between turns causing infinite loops

2 participants