-
Notifications
You must be signed in to change notification settings - Fork 2.5k
fix(vertex-anthropic): retry without prompt caching on Vertex SDK "path must be of type string. Received an instance of Array" error #7694
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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.
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.
There was a problem hiding this 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) => |
There was a problem hiding this comment.
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:
| 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.
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:
| 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.
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( |
There was a problem hiding this comment.
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:
| 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.