Skip to content
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

fix(autoedit): fix shrink prediction logic #6404

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

Conversation

valerybugakov
Copy link
Member

Test plan

  1. CI
  2. New unit tests
  3. Manually tested on cody-chat-eval examples

@@ -16,27 +14,25 @@ export function shrinkPredictionUntilSuffix(
const suffix = codeToReplaceData.suffixInArea + codeToReplaceData.suffixAfterArea

// Split the prediction and suffix into arrays of lines
const predictionLines = lines(prediction)
const predictionLines = lines(stripLastEmptyLineIfExists(prediction))
Copy link
Contributor

Choose a reason for hiding this comment

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

can we add a comment why do we want to strip the last empty line

Copy link
Member Author

Choose a reason for hiding this comment

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

Added 👍

if (!suffixSlice[j].trim().startsWith(predictionSlice[j].trim())) {
matches = false
if (
(suffixSlice[j].length > 0 && predictionSlice[j].startsWith(suffixSlice[j])) ||
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we only checking if predictionSlice[j].startsWith(suffixSlice[j]). If we want to see that prediction lines matches with suffix, shouldn't we check === condition

Copy link
Member Author

Choose a reason for hiding this comment

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

See the test case with self.email = email in vscode/src/autoedits/shrink-prediction.test.ts. I want to catch cases where something is added to the end of the suffix line, too.

Copy link
Contributor

@hitesh-1997 hitesh-1997 Dec 18, 2024

Choose a reason for hiding this comment

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

I don't think that should be the expectation since suffix self.email = and not self.email = email which is in the prediction. So, we can't match it suffix. There is risk of prediction getting trimmed just because suffix prefixed with prediction.

I added a test case here which will have issues because .startsWith logic just because the suffix had bunch of empty lines below and prediction added lines at the same indentation level, so prediction.startwith(suffix) becomes true because suffix is only the spaces with same indentation level, and all the prediction lines gets trimmed.

(please note that I had to turn off trim_trailing_whitespace = false in .editorconfig in our code to add trailing spaces in the code, so if we git pull and save, the trailing space would get trimmed and test case might not work, so please turn off this settting before git pull)

Copy link
Member Author

@valerybugakov valerybugakov Dec 19, 2024

Choose a reason for hiding this comment

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

The partial match logic is giving us too many false positives. Even after fixing the test case you pushed (thanks for that!), I found this behavior popping up in several places during manual testing. So, I reverted the logic back to an exact match.

Could we handle this at the model layer? Is there a way to nudge the model to only make changes within the code-to-rewrite block? I guess this issue comes from the training dataset, where suffix changes sometimes get duplicated in the updated code section. Could this be the case?

You can check the test case with self.email = email to see an example. Even though this line is part of the suffix, the model still modifies it and includes it in the response. Ideally, it should only return new line insertions.

Copy link
Member Author

Choose a reason for hiding this comment

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

The goal of the shrink-until-suffix logic was to ensure we still show parts of suggestions that are relevant, even if they only partially match the suffix. Previously, we had logic using startsWith() that would hide the entire suggestion if its last lines were partially present in the document. Let’s chat about the best way to solve this over Zoom.

Copy link
Member Author

Choose a reason for hiding this comment

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

I traced the addition of this logic to the feature, which comes from this PR, which does not give much context for this specific change. I wonder how critical was the starsWith() bit back then when it was introduced and why didn't we opt-in for the exact match instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

The reasoning behind the old logic was that, if model includes the suffix code, than they can only be new added lines from the code to rewrite, and I used startsWith there because we were not doing the line level comparison, but the whole suffix is the whole suffix in the file.
But the logic earlier also had its flaws and not very well though, but it mitigated some issues I encountered while manual testing.
I think it would be okay to just let the model output wrong predictions and we can figure out the severity from the logs.

Copy link
Contributor

@hitesh-1997 hitesh-1997 left a comment

Choose a reason for hiding this comment

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

I had confusion in some statements, added comments to clarify

Copy link
Contributor

@hitesh-1997 hitesh-1997 left a comment

Choose a reason for hiding this comment

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

Added test case which would have issue with the current logic, please check this commit (comment)

vscode/src/autoedits/shrink-prediction.test.ts Outdated Show resolved Hide resolved
repro issue because of partial suffix match with predictions

repro issue because of partial suffix match with predictions
@hitesh-1997 hitesh-1997 force-pushed the vb/shrink-prediction-fix branch from 7d781bd to e159e22 Compare December 18, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants