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: Fix inconsistent workspace handling in agent #7160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fkling
Copy link
Contributor

@fkling fkling commented Feb 20, 2025

While trying to adapt #6947 to the changes from #6909, I noticed that workspace handling is inconsistent in the agent.
In particular:

  • The agent accepts a workspaceRootUri upon initialization and stores it on AgentWorkspaceDocuments. This value
    eventually ends up in workspaceFolders.
  • We support workspaceFolder/didChange, which updates workspaceFolders but doesn't affect workspaceRootUri in
    any way.
  • getWorkspaceFolder and asRelativePath ignore workspaces and work directly with workspaceRootUri

So it seems that any client that wants to use workspaceFolder/didChange will eventually end up with an inconsistent state.

This PR aims to fix that. It removes workspaceRootUri and updates all places that used it to work with workspaceFolders instead.
asAbsolutePath was updated to use the extension URI instead, which seems more in line with what the purpose of that method is (though it doesn't seem like we use it anywhere).
workspaceFolders is still initialized from the client info, directly instead of going through workspaceDocuments.

Test plan

I've tested this manually in the context of #6947 and https://github.com/sourcegraph/sourcegraph/pull/3333. The following secanarios work as expected:

  • On the chat page, remote repo mentions work (i.e. they appear in the mentions menu). No workspace is set.
  • When opening the cody sidebar on a repo page, the workspace is updated (deduced by seeing the Current repository at-mentions entry point to the current repository, as well the default file filtering logic only suggest files from the current repository)
  • With the cody sidebar open, navigate directory to a different repository via fuzzy finder. As above, the menu entry and the
    file search correctly resolve to the new repository.

Note

What I've not been able to successfully test is the Rules provider. But I suspect that there might be unrelated issues
with it, because the network requests it made in the web demo resulted in 428 errors, saying that the X-Requested-Width header was missing.

@fkling
Copy link
Contributor Author

fkling commented Feb 20, 2025

This change is part of the following stack:

Change managed by git-spice.

@fkling fkling force-pushed the fkling/fix-agent-workspace-inconsistencies branch from d2a5b3f to fb43d28 Compare February 20, 2025 13:45
@fkling fkling requested a review from a team February 20, 2025 13:46
@fkling
Copy link
Contributor Author

fkling commented Feb 20, 2025

Is @sourcegraph/cody-agent the right team to tag for review on this? "Agent" is appearing everywhere these days 😅

@fkling fkling changed the title fix: Fix inconsisten workspace handling in agent fix: Fix inconsistent workspace handling in agent Feb 20, 2025
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.

1 participant