Skip to content

Conversation

RomneyDa
Copy link
Collaborator

@RomneyDa RomneyDa commented Oct 18, 2025

Description

Fixes #8314

It already works this way in open ai adapters


Summary by cubic

Prevents malformed Anthropic payloads by stripping empty text parts and dropping thinking blocks without a signature. Fixes #8314.

  • Bug Fixes
    • Skip empty text when converting message content to blocks.
    • Require a signature for thinking blocks; discard if missing or content is empty (no unsafe default signature).

@RomneyDa RomneyDa requested a review from a team as a code owner October 18, 2025 07:57
@RomneyDa RomneyDa requested review from Patrick-Erichsen and removed request for a team October 18, 2025 07:57
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Oct 18, 2025
Copy link

github-actions bot commented Oct 18, 2025

✅ Review Complete

Code Review for PR #8329

The changes look good overall and properly address the issue of malformed Anthropic payloads. Here are a few observations:

Positive aspects:

  1. ✅ Correctly filters out empty text content to prevent malformed payloads
  2. ✅ Properly validates that thinking blocks have a signature before including them
  3. ✅ Removes the unsafe default empty signature (?? "") which was flagged in TODOs
  4. ✅ Consistent filtering approach across both string and array content types

Potential issues to consider:

  1. Silent data loss (Lines 161-164, 169-171, 179-181):
    The code now silently drops thinking blocks without signatures and empty content by returning empty arrays. While this prevents malformed payloads, it might hide issues where data is unexpectedly lost. Consider adding a warning log when dropping content:

    if (!signature) {
      console.warn("Dropping thinking block without signature");
      return [];
    }
  2. Missing test coverage:
    No test file changes are included. This fix should have tests covering:

    • Empty string content filtering
    • Empty text parts in arrays
    • Thinking blocks without signatures
    • Thinking blocks with empty content
  3. Image handling inconsistency (Lines 107-116):
    Images are not filtered for empty/invalid data like text is. Consider whether images should also be validated before being added to the parts array (e.g., checking if part.imageUrl.url exists and is properly formatted).

Suggestion: Add unit tests in core/llm/llms/Anthropic.vitest.ts or Anthropic.test.ts to verify these edge cases are handled correctly.


Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

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

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Haiku 4.5 appears unable to browse project files

1 participant