Skip to content

Conversation

@andrewyuq
Copy link
Contributor

@andrewyuq andrewyuq commented Mar 19, 2025

  • Add size limits for different context types (user input, prompts, rules, files, workspace)
  • Implement truncation logic to preserve content around the middle of file text
  • Replace static contextMaxLength with workspaceChunkMaxSize for workspace content
  • Add debug logging for tracking payload sizes of different components
  • Filter out empty contexts from additionalContents and relevantTextDocuments
  • Update type definitions to include content type in AdditionalContentEntryAddition

debug log:
Screenshot 2025-03-24 at 3 31 00 AM

telemetry:

Screenshot 2025-03-24 at 3 32 13 AM

Unit tests and telemetry pending update.

Problem

Solution


  • Treat all work as PUBLIC. Private feature/x branches will not be squash-merged at release time.
  • Your code changes must meet the guidelines in CONTRIBUTING.md.
  • License: I confirm that my contribution is made under the terms of the Apache 2.0 license.

@andrewyuq andrewyuq requested review from avi-alpert and leigaol March 19, 2025 23:38
@andrewyuq andrewyuq requested a review from a team as a code owner March 19, 2025 23:38
@github-actions
Copy link

  • This pull request modifies code in src/* but no tests were added/updated.
    • Confirm whether tests should be added or ensure the PR description explains why tests are not required.
  • This pull request implements a feat or fix, so it must include a changelog entry (unless the fix is for an unreleased feature). Review the changelog guidelines.
    • Note: beta or "experiment" features that have active users should announce fixes in the changelog.
    • If this is not a feature or fix, use an appropriate type from the title guidelines. For example, telemetry-only changes should use the telemetry type.

getLogger().debug(`current request total prompts size: ${totalPromptSize}`)

// Type C context: Preserving current file context as much as possible
// truncate the text to keep texts in the middle instead of blindly truncating the tail
Copy link
Contributor

Choose a reason for hiding this comment

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

out of curiosity did this show better improvements on the backend or anything? Or was it just an idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously we cap userInput at 4k which is very hardcoded, for now it can allow up to 100k when there's no other context which can be flexible, backend always allow up to 100k for now so we fully utilize this. This was aligned within the product and eng.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh, I think you are referring to the specific "truncating to preserve the middle" logic. If this is the case, I do this because when we include current file context, we expand from the current highlighted code abvoe and below in parallel, so considering the "middle context" which is the highlighted code or current cursor to be the most relevant, we truncate head and tail instead of truncating tail, which may truncate out the middle context first.

By doing the above, we always truncate the middle context at last.


// Type B2(explicit @files) context: Preserving files as much as possible
if (triggerPayload.additionalContents !== undefined) {
for (const additionalContent of triggerPayload.additionalContents) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not inline with 97 just so you could have seperatation for the different type of processing you have to do? I think theres a lot that relies on additionalContents being defined?

Copy link
Contributor Author

@andrewyuq andrewyuq Mar 20, 2025

Choose a reason for hiding this comment

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

Not sure if I understand the question, this logic is very similar to line 97 logic, only difference being, line 97 is for @ prompt and line 114 is for @ files. Since we aligned that @ prompt has a higher priority than @ files, we preserve @ prompt first and then @ files comes in if there's still available space.

Copy link
Contributor

@jpinkney-aws jpinkney-aws left a comment

Choose a reason for hiding this comment

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

lgtm, i'll wait until someone from codewhisperer reviews it though. The lint is failing with a minor thing btw

@andrewyuq andrewyuq requested a review from a team as a code owner March 24, 2025 10:43
"description": "User clicked on add region command"
},
{
"name": "amazonq_addMessage",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this here instead of using the ones from commons ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that just got merged, I will quickly replace.

- Add size limits for different context types (user input, prompts, rules, files, workspace)
- Implement truncation logic to preserve content around the middle of file text
- Replace static contextMaxLength with workspaceChunkMaxSize for workspace content
- Add debug logging for tracking payload sizes of different components
- Filter out empty contexts from additionalContents and relevantTextDocuments
- Update type definitions to include content type in AdditionalContentEntryAddition
…ed many undefined checks becaus we are treating them as 0 in the end anyway
@jpinkney-aws jpinkney-aws merged commit d9a1041 into aws:master Mar 25, 2025
25 of 26 checks passed
}
}

function preserveContexts(
Copy link
Contributor

@justinmk3 justinmk3 Mar 31, 2025

Choose a reason for hiding this comment

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

What is the purpose of this function? Needs a docstring, with an input => output example.

return truncationInfo
}

function truncateUserSpecificContexts(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why doesn't the service do this, why does the client need to do it?

@justinmk3
Copy link
Contributor

Surely this has a customer-facing impact that should be called out in the changelog?

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