Skip to content

fix(provider): keep compacted Anthropic tool histories user-led - #31052

Closed
codeg-dev wants to merge 2 commits into
anomalyco:devfrom
codeg-dev:codeg/anthropic-transform-boundary
Closed

fix(provider): keep compacted Anthropic tool histories user-led#31052
codeg-dev wants to merge 2 commits into
anomalyco:devfrom
codeg-dev:codeg/anthropic-transform-boundary

Conversation

@codeg-dev

@codeg-dev codeg-dev commented Jun 6, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #31048

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Normalizes Anthropic-bound message histories in two narrowly scoped cases:

  1. Strips trailing assistant prefill for affected Claude 4.6/4.7/4.8 model IDs that reject assistant-final requests.
  2. Prepends a minimal synthetic user boundary when a compacted Anthropic history starts with an assistant tool-call message and the immediately following tool message satisfies every leading tool call.

This keeps Anthropic request histories user-led where required while leaving non-Anthropic providers unchanged. Assistant tool-call prefill is preserved when thinking mode still needs it.

Prepared with AI assistance.

How did you verify your code works?

  • git diff --check -- packages/opencode/src/provider/transform.ts
  • Built a v1.16.2 custom artifact from the same transform change plus the already-open session processor patch.
  • Deployed the artifact to private host, private host, private host, and codeg-hq.
  • Verified openai/gpt-5.5 normal smoke and tool-failure recovery on all custom hosts; hq also verified the Windows desktop backend /, /agent, and /config returned 200.

Screenshots / recordings

Not a UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. and removed needs:compliance This means the issue will auto-close after 2 hours. labels Jun 6, 2026
@github-actions

github-actions Bot commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@codeg-dev

Copy link
Copy Markdown
Author

Rebased onto latest dev and force-pushed. CI is green (check-compliance ✅, check-standards ✅). This PR fixes #31048 — ready for review whenever you have a moment. Thanks!

codeg-old and others added 2 commits June 18, 2026 16:46
Strip unsupported Claude assistant prefill and prepend a synthetic user boundary when a compacted Anthropic history starts with a fully matched assistant tool-call exchange.

Constraint: Anthropic rejects assistant-prefill and assistant-led tool histories for affected Claude 4.6-4.8 paths.

Rejected: Rewrite session compaction | provider-bound normalization is narrower and leaves non-Anthropic histories unchanged.

Confidence: medium

Scope-risk: moderate

Directive: Keep this provider-specific; do not apply synthetic boundaries to providers that support assistant-led histories.

Tested: v1.16.2-codeg.20260606 custom artifact built and deployed; GPT-5.5 and tool-failure smoke passed on mtb/fob/ops/hq.

Not-tested: Full upstream dev test suite for this focused branch.
@codeg-dev
codeg-dev force-pushed the codeg/anthropic-transform-boundary branch from 083778d to aada8db Compare June 18, 2026 07:49
@github-actions

github-actions Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Automated PR Cleanup

Thank you for contributing to opencode.

Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions.

This PR was closed because it matched the following cleanup criteria:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

PRs created within the last month are not affected by this cleanup.

If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate.

Thanks again for taking the time to contribute.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Anthropic compacted tool histories need a leading user boundary

2 participants