Skip to content

Add second check for prompt length before autocomplete #6451

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

lwang2070
Copy link

@lwang2070 lwang2070 commented Jul 4, 2025

Description

There has been reports showing that continue will truncate prefix when sending request to LLM for autocompletion, See #3372 and #6003. The reason is that the renderPrompt function does not strictly follow the contextLength restriction, which causes the prompt to be truncated before sending to LLM.

To fix the issue, I

  1. add checks to ensure the final prompt length is less then (contextLength - reservedTokens - safetyBuffer)
  2. If exceeded, truncate the prefix and suffix proportion to their length.

and that's it!

Checklist

  • I've read the contributing guide
  • The relevant docs, if any, have been updated or created
  • [] The relevant tests, if any, have been updated or created

My first PR, not sure how to test the code here. Would be happy to update if any guidance are provided :)


Summary by cubic

Added a second check to ensure prompt length stays within model limits before sending autocomplete requests, preventing prompt truncation.

  • Bug Fixes
    • Truncates prefix and suffix proportionally if the prompt is too long, so the full prompt fits within allowed context.

@lwang2070 lwang2070 requested a review from a team as a code owner July 4, 2025 11:30
@lwang2070 lwang2070 requested review from Patrick-Erichsen and removed request for a team July 4, 2025 11:30
Copy link

netlify bot commented Jul 4, 2025

👷 Deploy request for continuedev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 103c8ad

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 4, 2025
Copy link

github-actions bot commented Jul 4, 2025

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@lwang2070
Copy link
Author

recheck

@lwang2070
Copy link
Author

I have read the CLA Document and I hereby sign the CLA

@Patrick-Erichsen Patrick-Erichsen requested review from jpoly1219 and removed request for Patrick-Erichsen July 7, 2025 18:14
@Patrick-Erichsen
Copy link
Collaborator

Passing this to @jpoly1219 who is working on autocomplete things at the moment

@@ -126,3 +135,163 @@ export function renderPrompt({
},
};
}

/** Builds the final prompt by applying prefix/suffix compilation or snippet formatting, then rendering the template. */
function buildPrompt(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we add unit tests for this new function?

@@ -126,3 +135,163 @@ export function renderPrompt({
},
};
}

/** Builds the final prompt by applying prefix/suffix compilation or snippet formatting, then rendering the template. */
function buildPrompt(
Copy link
Collaborator

Choose a reason for hiding this comment

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

The core logic of this is a duplicate of renderPrompt. I think a good next step to take here is to refactor renderPrompt using buildPrompt. Also +1 to adding unit tests.

Copy link
Collaborator

@jpoly1219 jpoly1219 left a comment

Choose a reason for hiding this comment

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

It looks good overall. I think reducing repetitive logic and adding unit tests would be greatly appreciated!

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Issues and PRs Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:L This PR changes 100-499 lines, ignoring generated files.
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

3 participants