Skip to content

Conversation

@laileni-aws
Copy link
Contributor

Problem

  • Amazon Q chat was failing with error: @smithy/util-base64: toBase64 encoder function only accepts string | Uint8Array
  • Fix for GitHub Issues #8253, #7896, #8076, #8184

Root Cause

In /server/aws-lsp-codewhisperer/src/language-server/agenticChat/tools/chatDb/util.ts:

  • messageToStreamingMessage() was setting userInputMessageContext: msg.userInputMessageContext || {}
  • chatMessageToMessage() was setting userInputMessageContext: userInputMessage.userInputMessageContext || {}

When userInputMessageContext was 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

  • Pass undefined instead of empty object
  • Added test cases accordingly.

Conclusion

  1. When userInputMessageContext is undefined, it remains undefined (not converted to {})
  2. When userInputMessageContext has a value, it's preserved correctly
  3. The AWS SDK can properly serialize the message without attempting to base64-encode an empty object

License

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

…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.
@laileni-aws laileni-aws changed the base branch from main to feature/bug-fix November 4, 2025 20:28
@laileni-aws laileni-aws marked this pull request as ready for review November 4, 2025 20:28
@laileni-aws laileni-aws requested a review from a team as a code owner November 4, 2025 20:28
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.73%. Comparing base (44df68d) to head (1ca9116).

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           
Flag Coverage Δ
unittests 62.73% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

userIntent: msg.userIntent,
origin: msg.origin || 'IDE',
userInputMessageContext: msg.userInputMessageContext || {},
userInputMessageContext: msg.userInputMessageContext,
Copy link
Contributor

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?

Copy link
Contributor Author

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!

Copy link
Contributor

@shruti0085 shruti0085 Nov 5, 2025

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

Copy link
Contributor

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?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants