Skip to content

Fix error when adding multiple repositories with at-mention in chat #8134

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 30 commits into
base: M106
Choose a base branch
from

Conversation

mkondratek
Copy link
Contributor

Test plan

julialeex and others added 30 commits June 19, 2025 09:21
Creates an interactive script to guide release captains through the
complete Cody release process.

Note: This is just an initial PR. I might have more PRs to improve the
script later.

## Test plan
./release/release-captain.sh
![Screenshot 2025-06-18 at 6 09
53 PM](https://github.com/user-attachments/assets/bfb55b35-7a1c-442d-b20f-1510e3764849)


<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
This PR is a minor follow up to
#8071.
Accidentally I made lookups hint disappear just after they are shown.
That is clearly wrong. This PR makes sure that we dispose hints only if
there is an active autoedit.

Also, the only reasonable way to dismiss the auto edit popup is to use
the message bus - this PR does this change.

## Test plan
- lookups work
- lookup hint does not show with auto edit popup


<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
Before this change, when we were updating the config with a string
value, the resulting payload was smth like ""auto-edit"" (not double
nesting!). That caused a parsing error in JB client. Eventually, we were
saving a double nested string. Weird and incorrect. This PR fixes that.

## Test plan
- Make sure that double nested strings are not saved in the config. E.g.
play with auto-edit enrolment.

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
Fixes
https://linear.app/sourcegraph/issue/QA-700/jb-onlywindows-only-cody-gets-crashed-when-user-tries-to-save-searched

## Changes

### Bugfix

Before my changes the test I added was failing with:

```
Caused by: java.net.URISyntaxException: Illegal character in path at index 22: 
file:///C:/Users/Rajat Nagoria/PycharmProjects/pythonProject2/Untitled\

Illegal character in path at index 24: file:///C:/dev/Jetbrains Tests Projects/kotlin/TestProject/Validate.kt
java.net.URISyntaxException: Illegal character in path at index 24: file:///C:/dev/Jetbrains Tests Projects/kotlin/TestProject/Validate.kt
	at java.base/java.net.URI$Parser.fail(URI.java:2976)
	at java.base/java.net.URI$Parser.checkChars(URI.java:3147)
	at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3229)
```

It was cause by usage of `URLDecoder.decode` which e.g. converts `%20`
to spaces, which are illegal in the URI.
We should not use it at all in this specific place. I fixed that and
added few other tweaks.

### Architecture changes

In the process of fixing the bug I came to the conclusion that whole
`untitled` documents handling we had in the agent was error prone, not
fully correctly implemented, and in fact not really needed. If we make
sure we only show saved files to the user (and we have control over
that) we can completely remove quite a bit of custom logic. I removed
`textDocument/openUntitledDocument` endpoint, and instead implemented
`AgentTextDocument::save` and used it in one additional place.

That decision reduces a lot of the complexity on the clients/agent side,
but also have one downside.
There is no easy way to ensure at compile time that we never try to show
an untitled document. We could add a logic for checking that in the
`showTextDocument` but we cannot handle it in any reasonable way. We
could try to save file there first if it is untitled, but untitled file
is not guaranteed to have reasonable name/path.
Ultimately it might be just easier and better to QA our edit logic to
make sure it does not try to show such files, and do not overcomplicated
the implementation otherwise.

## Test plan

Unit test covering problematic scenario was added.

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
…Item (#8084)

Refs CODY-5966 Cody Web crashes with an error when error.message was
undefined as seen in this screenshot

![image](https://github.com/user-attachments/assets/b49e8ded-d558-4475-83e5-3d676eb980e6)

This PR attempts to provide a fallback reply to avoid a crash and to
check in case we receive a string error
instead of a real error object


## Test plan
- Build Cody web and try to add a really large reply with a model such
as Sonnet 4
- Investigate if there is a crash that allows the history to be viewed
This PR makes auto-edits the default suggestion mode for all clients. 

## Test plan
1. Having an IDE with autocompletion mode turned on (also, note that
there is a local flag handled by `markUserAsAutoEditBetaEnrolled`, you
may need to manually modify some code to see it working. I do not know
how to clear the state of that config.)
2. Run IDE

Expected:
Cody switches to auto-edits automatically. A notification appears with
an option to switch back to autocompletion mode.

<img width="410" alt="image"
src="https://github.com/user-attachments/assets/b1874d20-021b-48d6-9484-14b2955455d2"
/>

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
## Changes

I verified that adding a sleep next to
`CopyPasteManager.getInstance().setContents` call causes IDE to hang.
We do not control if that call is blocking or not, but we can run it in
a background thread.

That will prevent hangs, but in case of slow `setContents` call it may
cause delay in clipboard copying operation (text in the clipboard may
not be available immediately).
But it is better alternative to hang, and in the majority of cases that
operation is instant.

## Test plan

1. Generate some code with Cody chat
2. Click "Copy" button under the snapshot
3. Do it a few times
4. No hands should be observed


<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
…duplicate workspace name (#8082)

Fixes CODY-5064 CODY-5830 CODY-6023 


## Test plan
- Have a workspace that follows this path cli -> cli -> hello.ts
- ask any llm to make some changes to hello.ts
- hit smart apply and notice smart apply changes are added to
cli/cli/hello.ts instead of cli/hello.ts
…ce settings (#8037) (#8089)

Refs CODY-6090 
This reverts commit 5fb5d0e.


## Test plan
- Test that you can open .py files even if you have them in
.sourcegraph/.ignore
Cody Web version bump to 32.9


## Test plan
- cd web
- pnpm dev
- test new chat and core cody interactions
Automated release and changelog for Cody VS Code 1.106.0
  ## Test plan
  N/A - changelog update

---------

Co-authored-by: sourcegraph-bot <bot@sourcegraph.com>
Co-authored-by: julialeex <julia.xu@sourcegraph.com>
Relates to #8063.

It looks like tool window `show` needs to be run in EDT.

## Test plan
No error on startup.

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
Related to 8063 and #8102.

One more part need to be run in EDT.

## Test plan
No errors from Cody console.

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
Adds Cody Sunset notice and removes Upgrade CTAs.

## Test plan
<img width="746" alt="image"
src="https://github.com/user-attachments/assets/d7ac3aec-9a16-4a31-b764-1d0d6f5d7c31"
/>

<img width="1779" alt="image"
src="https://github.com/user-attachments/assets/7ec0acb1-1303-4fa9-8912-67e13e6aa686"
/>


- Connect to dotcom and an "Important Notice" should be visible in Cody
chat.
- All the upgrade CTAs will be removed as well.
closes:
https://linear.app/sourcegraph/issue/CODY-6059/error-with-context-filters-in-cody-setup-for-client

context:
https://sourcegraph.slack.com/archives/C04MSD3DP5L/p1750104540995199

> I have a client trying to use Cody context filters, but they are
running into the error in the attached image. I was able to recreate the
same error when I set up [context
filters](https://sourcegraph.com/docs/cody/capabilities/ignore-context#context-filters)
in our test instance.

<img width="759" alt="image"
src="https://github.com/user-attachments/assets/12ae4f7b-eb67-4b47-a997-f03242c343a6"
/>


From the client as per the network request and the error message we are
sending the client-name=vscode in the query params.

The issue is that the backend API only checks for
`X-Sourcegraph-API-Client-Name` header field and not the `client-name`
query param, but the error message says that we need to pass query
param. [backend
code](https://github.com/sourcegraph/sourcegraph/blob/dd29700643bac8f56bfff49e44722b4e17cccaa3/internal/requestclient/http.go#L187-L188)
[error
message](https://github.com/sourcegraph/sourcegraph/blob/dd29700643bac8f56bfff49e44722b4e17cccaa3/cmd/frontend/internal/httpapi/completions/handler.go#L875-L876)

And the Cody client only sends the client-name query param and not the
header field.

The quicker fix is to start sending `X-Sourcegraph-API-Client-Name`
header field from the Cody Client. As the Cody releases are on weekly
cadence the issue will be resolved quicker.

But I will update the backend code error message separately to say that
the header field is expected and not the query param.

## Test plan

- Follow the
[guide](https://sourcegraph.com/docs/cody/capabilities/ignore-context#context-filters)
to configure context filters on the connected sourcegraph instance.
- Reload the Cody App
- Submit a chat mentioning a non-blocked (not filtered out) repo and
make sure no error occurs.
- Try mentioning a blocked repo, it should be disabled to do so.
Auto-edits are not stable in the remote mode. We need further changes
(work in progress: #7641). Let's
switch it off for now.

## Test plan
Auto-edits on in the normal mode.
Auto-edits off in the remote mode.

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
…n callbacks (#8114)

fixes:
https://linear.app/sourcegraph/issue/QA-739/core-user-is-unable-to-login-to-cody

The handler was accidentally removed in #8095 (the method name was
misleading, indicated that the handlers refer to upgrade logic only).
This PR brings back that handler (and gives a proper name to the
method).

## Test plan
auth with google/gitlab/github works in JB 

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
)

Slack:
https://sourcegraph.slack.com/archives/C04MSD3DP5L/p1750890657414519?thread_ts=1750800304.225009&cid=C04MSD3DP5L
The `cody.characters:flush` telemetry events were firing at multiple
30-minute intervals instead of a single consistent interval due to
multiple CharactersLogger instances being created during extension
restarts without proper cleanup.

- Implemented the singleton pattern to ensure that only one
CharactersLogger instance exists
- Fixed timer cleanup in flush() method to properly clear existing
timers before creating new ones

## Test plan
vscode/src/services/CharactersLogger.test.ts
<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
Automated release and changelog for Cody VS Code 1.106.1
  ## Test plan
  N/A - changelog update

---------

Co-authored-by: sourcegraph-bot <bot@sourcegraph.com>
…ent (#8120)

This commit enhances the Cody deprecation notice displayed to users by making it context-aware of whether Cody is enabled at the site level or if the user has an active subscription.

## Test plan
- Test that sunset message is changed with a workspace that doesn't have
cody enabled anymore
…ad of periods (#8125)

Refs CODY-6090 fix skipping of files from the @ mention files search
when .gitignore contains rules such as *,something

## Test plan
- Try to add a *,py to .gitignore and notice that you can no longer find
files previous to this fix
- We replace , with , so now only *.py would be valid instead of every
file, py
This commit ensures that the `authStatus.update` command is only
executed when running inside the agent context. This command is
exclusively registered within the agent and not in the VS Code extension
itself. This prevents errors and ensures the command is only called
where it is defined.

Started from this pr #7298

## Test plan
- Open VSCode and notice we no longer receive the error
Stack trace: Error: command 'authStatus.update' not found
at Jze.n
(vscode-file://vscode-app/Applications/Visual%20Studio%20Code%20-%20Insiders.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js:1243:3892)
…8128)

This PR is a rework of the @ichim-david PR:
#8126
I think deduplication may be done a bit more efficiently, but scope of
the changes (especially for e2e integration tests) was too big to make
sensible suggestion in the PR so I raised a new one.

Description copied from David's PR:

-----------------

This commit introduces deduplication of files returned by
`findWorkspaceFiles` when workspace folders overlap. This situation
commonly occurs in monorepos or when users add subdirectories as
separate workspace folders in VS Code for better Git integration.

Also contains the changes from this pr
#8125

See this youtube video where I show what this work fixes:
https://www.youtube.com/watch?v=CzJTgUoBcLk

## Test plan

- Test on a monorepo where you have a project repository and within a
certain folder, you have other packages that are cloned from other
repositories
- Test that when you search for any file it is not duplicated
https://www.youtube.com/watch?v=V-PnNRUo5Jo

## Test plan
- Use the mention menu and notice that we no longer get a fake scroll
down as we type
A follow up to #8079 (comment)

The problem is that we want to control both the client in the agent in
the tests.

Initially, I tried to use the embedded agent in TestClient. Sadly, there
are more complex dependencies that I could not pass (related to
`ExtensionActivate`). Eventually, the approach is different. I added an
endpoint to handle a custom instruction from a test case.

## Test plan
- green CI

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
I have accidentally added these comments in
#8093. They are redundant.

## Test plan
n/a

<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
Fixes
https://linear.app/sourcegraph/issue/CODY-6132/cody-document-code-placement-issue-in-intellij-idea.

This PR extends work done by @mkondratek in
#8129

## Test plan

**Test 1**

1. Select a block of code in the editor
2. Right click within the selection (about the middle)
3. Trigger Document Code
4. Created comment should relate to the selected block (not only to the
area at the caret).

**Test 2**

1. Double click on a text token
2. Check if selection changes properly in cody chat window

**Test 3**

1. Select few lines of the code
2. Move them to different position using mouse
3. Check if selection changes properly in cody chat window

**Test 4**

1. Select few text tokens using Shift + Arrow
2. Check if selection changes properly in cody chat window


<!-- Required. See
https://docs-legacy.sourcegraph.com/dev/background-information/testing_principles.
-->
Resolves issue where users encountered 'Failed to retrieve search context' error
when adding two or more repositories using at-mention. This occurred when git
operations failed while retrieving locally modified files.
@mkondratek mkondratek force-pushed the mkondratek/fix/context-retriever-multiple-repos-error branch from da09064 to d689611 Compare July 2, 2025 12:42
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.

6 participants