Skip to content

Conversation

@roomote
Copy link
Contributor

@roomote roomote bot commented Sep 5, 2025

Summary

  • Addresses regression reported for v3.26.7 when using Vertex AI (Claude Sonnet) where simple prompts fail with API Streaming Failed and error: The "path" argument must be of type string. Received an instance of Array.
  • Root cause: certain Vertex SDK environments reject array-form system/content blocks (used for prompt caching).
  • Fix: In AnthropicVertexHandler, wrap messages.create() in a defensive try/catch and retry without prompt caching upon detecting the specific error, for BOTH streaming and non-streaming flows.

Key Changes

Tests

  • Existing Vertex tests pass: cd src && npx vitest run api/providers/tests/anthropic-vertex.spec.ts (18/18 passing).
  • Manual reasoning: primary call uses caching if supported; on path/Array error, retry with caching disabled; other errors are rethrown.

Risk/Impact

  • Minimal surface area; change is localized to Vertex/Anthropic handler.
  • Caching retained unless problematic error is observed.

Requested Review

  • Validate approach and logging.
  • Optionally refactor duplicated error matcher into a shared helper in the class.

Branch: fix/vertex-path-array-retry


Important

Fixes Vertex AI SDK error by retrying without prompt caching in AnthropicVertexHandler on specific error signature.

  • Behavior:
    • In AnthropicVertexHandler.createMessage(), wraps messages.create() in try/catch to retry without prompt caching on "path must be of type string. Received an instance of Array" error.
    • In AnthropicVertexHandler.completePrompt(), mirrors retry logic for non-streaming flows.
    • Preserves prompt caching unless the specific error is detected.
  • Error Handling:
    • Adds isPathArrayError() function to detect specific error signature in both methods.
  • Tests:
    • Existing tests in anthropic-vertex.spec.ts pass (18/18).
    • Manual reasoning confirms retry logic works as intended.

This description was created by Ellipsis for ccd68ac. You can customize this summary. It will automatically update as commits are pushed.

…hrows "path must be of type string. Received an instance of Array"
@roomote roomote bot requested review from cte, jr and mrubens as code owners September 5, 2025 06:35
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. bug Something isn't working labels Sep 5, 2025
// TypeError("'path' argument must be of type string. Received an instance of Array")
// when the SDK receives array-form system/content blocks. As a safe fallback,
// retry without prompt caching if we detect this error.
const isPathArrayError = (err: unknown) =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider extracting the isPathArrayError function into a shared helper to avoid duplicating this logic in both createMessage and completePrompt.

This comment was generated because it violated a code review rule: irule_tTqpIuNs8DV0QFGj.

Copy link
Contributor Author

@roomote roomote bot left a comment

Choose a reason for hiding this comment

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

I wrote this code 5 minutes ago and already forgot why. Classic me.

// TypeError("'path' argument must be of type string. Received an instance of Array")
// when the SDK receives array-form system/content blocks. As a safe fallback,
// retry without prompt caching if we detect this error.
const isPathArrayError = (err: unknown) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The isPathArrayError helper function is duplicated here and in completePrompt() (line 227). As mentioned in the PR description, could we refactor this into a shared private method of the class? Something like:

Suggested change
const isPathArrayError = (err: unknown) =>
private isPathArrayError(err: unknown): boolean {
return typeof (err as any)?.message === "string" &&
(err as any).message.includes("'path'") &&
(err as any).message.includes("type string") &&
(err as any).message.includes("Array")
}

stream = await this.client.messages.create(buildParams(!!supportsPromptCache))
} catch (err) {
if (supportsPromptCache && isPathArrayError(err)) {
console.warn(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Consider including the model ID in the warning message for better debugging context:

Suggested change
console.warn(
console.warn(
`Roo Code <Vertex/Anthropic>: Retry without prompt caching for model ${id} due to path/Array error:`,
(err as any).message,
)

stream: false,
})

const isPathArrayError = (err: unknown) =>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same duplication of isPathArrayError as mentioned above. This should use the shared class method once refactored.

response = await this.client.messages.create(buildParams(!!supportsPromptCache))
} catch (err) {
if (supportsPromptCache && isPathArrayError(err)) {
console.warn(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to the streaming case, consider including the model ID in this warning:

Suggested change
console.warn(
console.warn(
`Roo Code <Vertex/Anthropic>: Non-streaming retry without prompt caching for model ${id} due to path/Array error:`,
(err as any).message,
)

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Sep 5, 2025
@daniel-lxs
Copy link
Member

#7697

@daniel-lxs daniel-lxs closed this Sep 5, 2025
@github-project-automation github-project-automation bot moved this from Triage to Done in Roo Code Roadmap Sep 5, 2025
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Sep 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants