fix(provider/amazon-bedrock): omit assistant messages whose only remaining content is a cache point

Closed
NA
2mo ago
+129-1

Background

#18456 fixed assistant messages going out empty after unsigned reasoning is filtered on replay. There's a sibling case it misses: the guard runs after pushCachePoint, so a fully-filtered message that carries a cachePoint provider option still goes out as content: [{ cachePoint }]. Bedrock rejects it, non-retryable:

There is nothing available to cache. Please remove the invalid cache point and try again.

Same bricked-conversation story as #18452. It bites real users today via opencode, which puts cache points on the last two messages of every request — an assistant turn aborted mid-thinking then poisons the whole session (anomalyco/opencode#11210 has both error strings).

Summary

Strengthened the omission guard from "non-empty" to "has at least one non-cachePoint block":

if (amazonBedrockContent.some(block => !('cachePoint' in block))) {
  messages.push({ role: 'assistant', content: amazonBedrockContent });
}

Nothing changes for messages that keep real content — the cache point is still emitted after it. Added regression tests (message-level and part-level cache point omission, both fail without the fix, plus one confirming the cache point is kept when other content remains) and a patch changeset. 499/499 package tests pass on node and edge.

Contributor Credit

@yonatan-shorani — this builds directly on the #18452 reproduction and the #18456 fix.

End-to-End Verification

Sent the exact payloads to the live Converse API (eu-west-1, Claude): an assistant message whose content is only [{"cachePoint":{"type":"default"}}] returns the 400 above, and consecutive user messages — the conversation shape left behind after omission — are accepted, so dropping the message can't produce an invalid request. Applying the same omission downstream in opencode un-bricks a real poisoned session: the exact 400 before, normal completion after.

Checklist

  • All commits are signed (PRs with unsigned commits cannot be merged)
  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Related Issues

Fixes #19851