Skip to content

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

Open
codeg-dev wants to merge 1 commit into
anomalyco:devfrom
codeg-dev:codeg/anthropic-transform-boundary
Open

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

Conversation

@codeg-dev
Copy link
Copy Markdown

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

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 codeg-mtb, codeg-fob, codeg-ops, 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
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 6, 2026

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

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 b96e71d to 083778d Compare June 7, 2026 01:43
@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!

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.

Anthropic compacted tool histories need a leading user boundary

2 participants