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

Context: avoid panic on stopwords query #62026

Merged
merged 1 commit into from
Apr 19, 2024
Merged

Context: avoid panic on stopwords query #62026

merged 1 commit into from
Apr 19, 2024

Conversation

jtibshirani
Copy link
Member

@jtibshirani jtibshirani commented Apr 18, 2024

In #61848, we tried to fix an issue when the query contained only stopwords and
we interpreted this as "match all files". Unfortunately this fix introduced a panic by
returning a nil search job, which is not allowed by the our job framework.

Now, we return a noopJob which returns no results. This is the same approach
we use when an AND/ OR query has no operands.

Test plan

My testing was clearly lacking in the previous fix!! This time, I've added new
end-to-end GraphQL tests using patterntype:codycontext. Also tested manually
and checked there are no errors or panics in logs.

@cla-bot cla-bot bot added the cla-signed label Apr 18, 2024
@github-actions github-actions bot added team/product-platform team/search-platform Issues owned by the search platform team labels Apr 18, 2024
@@ -70,3 +74,18 @@ func (j *searchJob) MapChildren(fn job.MapFunc) job.Job {
cp.child = job.Map(j.child, fn)
return &cp
}

func newNoopJob() *noopJob {
Copy link
Member Author

Choose a reason for hiding this comment

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

We already have NewNoopJob in jobutil, but using it would introduce an import cycle. I opted to create a new private one since it's really simple, and it's nice to keep this Cody context logic very separate.

@jtibshirani jtibshirani marked this pull request as ready for review April 19, 2024 16:46
@jtibshirani jtibshirani requested a review from a team April 19, 2024 16:55
@@ -1137,6 +1137,52 @@ func testSearchClient(t *testing.T, client searchClient) {
}
})

t.Run("Cody context search", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would not have guessed to look here for end to end tests. Glad I learned this 😀

@jtibshirani
Copy link
Member Author

Thanks for the speedy review! I'm going to merge + backport as I want to make the patch release Monday.

@jtibshirani jtibshirani merged commit fe58531 into main Apr 19, 2024
18 checks passed
@jtibshirani jtibshirani deleted the jtibs/stopwords branch April 19, 2024 17:08
@sourcegraph-release-bot
Copy link
Collaborator

The backport to 5.3.9104 failed at https://github.com/sourcegraph/sourcegraph/actions/runs/8757155170:

The process '/usr/bin/git' failed with exit code 1

To backport this PR manually, you can either:

Via the sg tool

Use the sg backport command to backport your commit to the release branch.

sg backport -r 5.3.9104 -p 62026
Via your terminal

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add .worktrees/backport-5.3.9104 5.3.9104
# Navigate to the new working tree
cd .worktrees/backport-5.3.9104
# Create a new branch
git switch --create backport-62026-to-5.3.9104
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 fe5853195ee5c421ad8de16579652fd2854c1022
# Push it to GitHub
git push --set-upstream origin backport-62026-to-5.3.9104
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.3.9104

If you encouter conflict, first resolve the conflict and stage all files, then run the commands below:

git cherry-pick --continue
# Push it to GitHub
git push --set-upstream origin backport-62026-to-5.3.9104
# Go back to the original working tree
cd ../..
# Delete the working tree
git worktree remove .worktrees/backport-5.3.9104
  • Follow above instructions to backport the commit.
  • Create a pull request where the base branch is 5.3.9104 and the compare/head branch is backport-62026-to-5.3.9104., click here to create the pull request.

Once the pull request has been created, please ensure the following:

  • Make sure to tag @sourcegraph/release in the pull request description.

  • kindly remove the release-blocker from this pull request.

@sourcegraph-release-bot sourcegraph-release-bot added backports failed-backport-to-5.3.9104 release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases labels Apr 19, 2024
jtibshirani added a commit that referenced this pull request Apr 19, 2024
In #61848, we tried to fix an issue when the query contained only stopwords and
we interpreted this as "match all files". Unfortunately this fix introduced a panic by
returning a nil search job, which is not allowed by the our job framework.

Now, we return a `noopJob` which returns no results. This is the same approach
we use when an AND/ OR query has no operands.
keegancsmith pushed a commit that referenced this pull request Apr 21, 2024
…62055)

* Context: return no results for stopwords query (#61848)

In #60106, we fixed a bug where the context search threw an error when the query
was composed entirely of stopwords. However, the queries were still returning
results (based on filename match). This means that for a stopwords-only query
like "what's going on?" we return a fairly random set of files, which confuses
the LLM.

Now we make sure to return an empty search, which returns no results.

* Context: avoid panic on stopwords query (#62026)

In #61848, we tried to fix an issue when the query contained only stopwords and
we interpreted this as "match all files". Unfortunately this fix introduced a panic by
returning a nil search job, which is not allowed by the our job framework.

Now, we return a `noopJob` which returns no results. This is the same approach
we use when an AND/ OR query has no operands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backports cla-signed failed-backport-to-5.3.9104 release-blocker Prevents us from releasing: https://about.sourcegraph.com/handbook/engineering/releases team/product-platform team/search-platform Issues owned by the search platform team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants