fix(vertex-anthropic): retry without prompt caching on Vertex SDK "path must be of type string. Received an instance of Array" error#7694
Conversation
…hrows "path must be of type string. Received an instance of Array"
| // 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) => |
There was a problem hiding this comment.
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.
| // 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) => |
There was a problem hiding this comment.
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:
| 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( |
There was a problem hiding this comment.
Consider including the model ID in the warning message for better debugging context:
| 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) => |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
Similar to the streaming case, consider including the model ID in this warning:
| 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, | |
| ) |
Summary
Key Changes
Tests
Risk/Impact
Requested Review
Branch: fix/vertex-path-array-retry
Important
Fixes Vertex AI SDK error by retrying without prompt caching in
AnthropicVertexHandleron specific error signature.AnthropicVertexHandler.createMessage(), wrapsmessages.create()in try/catch to retry without prompt caching on "path must be of type string. Received an instance of Array" error.AnthropicVertexHandler.completePrompt(), mirrors retry logic for non-streaming flows.isPathArrayError()function to detect specific error signature in both methods.anthropic-vertex.spec.tspass (18/18).This description was created by
for ccd68ac. You can customize this summary. It will automatically update as commits are pushed.