-
Notifications
You must be signed in to change notification settings - Fork 83
fix(amazonq): prevent base64 encoding error by passing undefined instead of empty object #2459
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
base: feature/bug-fix
Are you sure you want to change the base?
Conversation
…ead of empty object
Fixes #8253, #7896, #8076, #8184
When userInputMessageContext was undefined, it was being replaced with an
empty object {}. The AWS SDK's base64 encoder attempted to encode this
empty object and threw: "toBase64 encoder function only accepts string |
Uint8Array".
Changed messageToStreamingMessage() and chatMessageToMessage() to pass
undefined instead of {} when userInputMessageContext is not provided.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feature/bug-fix #2459 +/- ##
================================================
Coverage 62.73% 62.73%
================================================
Files 266 266
Lines 59697 59697
Branches 3842 3840 -2
================================================
Hits 37451 37451
Misses 22170 22170
Partials 76 76
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| userIntent: msg.userIntent, | ||
| origin: msg.origin || 'IDE', | ||
| userInputMessageContext: msg.userInputMessageContext || {}, | ||
| userInputMessageContext: msg.userInputMessageContext, |
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.
have we figured out a reason why this codepath is being hit more now? Why would the msg's context be empty/undefined at all? Should we instead have handling to not try and send undefined messages over to chat?
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.
have we figured out a reason why this codepath is being hit more now?
This issue exist since the launch of Agentic chat!
Why would the msg's context be empty/undefined at all?
yes, this is happening more in windows machine! which we are not reproduce it.
Should we instead have handling to not try and send undefined messages over to chat?
We will be sending user prompt messages but we have some edge case where we are not able to send editor state and other context.
Do we need to fix this original issue?
YES but this PR helps to unblock the customer and process the response instead of failing!
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.
Could this be caused by a change in behavior in v2 to v3 sdk? We should confirm this nuallable is handled appropriately across all IDEs
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.
also a follow-up what exactly is "userInputMessageContext" and how is it different from content?
Problem
@smithy/util-base64: toBase64 encoder function only accepts string | Uint8ArrayRoot Cause
In
/server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/util.ts:messageToStreamingMessage()was settinguserInputMessageContext: msg.userInputMessageContext || {}chatMessageToMessage()was settinguserInputMessageContext: userInputMessage.userInputMessageContext || {}When
userInputMessageContextwas undefined, it was being replaced with an empty object{}. The AWS SDK's serialization layer tries to base64-encode certain nested fields, and when it encountered the empty object instead of undefined, it threw the error.Solution
undefinedinstead of empty objectConclusion
userInputMessageContextis undefined, it remains undefined (not converted to{})userInputMessageContexthas a value, it's preserved correctlyLicense
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.