fix(repositories): read workspaces from the branch-scoped layout - #397
Open
jirisacha wants to merge 1 commit into
Open
fix(repositories): read workspaces from the branch-scoped layout#397jirisacha wants to merge 1 commit into
jirisacha wants to merge 1 commit into
Conversation
Since 0254c3c ("fix: isolate branch generation workspaces") repositories are cloned to {RepositoriesDirectory}/{org}/{repo}/branches/{branch}/tree, but every reader still resolved the pre-existing flat path {RepositoriesDirectory}/{org}/ {repo}/tree, which nothing writes any more: - McpRepositoryTools.ReadFile and GetRepoStructure always answer "Repository workspace not found on server". - McpRepositoryTools.SearchDoc silently attaches no GitTool, so its summaries never see the source. - ChatAssistantService and EmbedService fall back to a documentation-only chat for the same reason. Add RepositoryWorkspacePath, a single resolver shared by the analyzer and the readers, and use it everywhere. It prefers the requested branch workspace, falls back to the most recently written one when the caller has no branch context, and finally to the legacy flat layout so workspaces created before 0254c3c keep working.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a current build, the MCP file tools never work:
{"error":true,"message":"Repository workspace not found on server"}read_fileandget_repo_structurereturn this for every repository, no matter howit was indexed, while
search_docand the wiki keep working — so it looks like a partialindex rather than a bug. The same root cause silently degrades two more features:
search_docattachesGitToolonly when the workspace exists, so its AI summaries aregenerated without ever reading the source.
documentation-only conversation.
Root cause
0254c3c("fix: isolate branch generation workspaces", #375) moved clones fromto
in
RepositoryAnalyzer.GetWorkingDirectory, but the readers were not updated. Nothingwrites the flat path any more, so
Directory.Existsis always false for:McpRepositoryTools.GetRepoStructure/ReadFileMcpRepositoryTools.SearchDocGitTool— summaries never see the codeChatAssistantService.GetRepositoryPathGitToolin chatEmbedService.GetRepositoryPathGitToolin the embedded widgetEach of the four had its own copy of the path expression, which is how they drifted apart
from the writer in the first place.
Fix
RepositoryWorkspacePath— one resolver shared by the writer and all readers:ForBranch(options, org, repo, branch)— the branch workspace path, existing or not;RepositoryAnalyzer.GetWorkingDirectorynow delegates to it (behaviour unchanged, itsstricter validation stays where it is).
Resolve(options, org, repo, branch?)— best existing workspace for a reader:the requested branch, then (when the caller has no branch context) the most recently
written branch workspace, then the legacy flat layout so workspaces created before
0254c3ckeep working.SearchDocpasses theRepositoryBranchit already loads.GetRepoStructureandReadFilenow load it too — the MCP scope carries owner/repo only — and tolerate itsabsence. Both chat services pass the branch they already have (
Context.Branch/request.Branch, the latter optional). The staleRepositoryWorkspace.WorkingDirectorydoc comment is corrected as well.
Tests
New
RepositoryWorkspacePathTestscovers the branch-scoped layout, path-traversalsanitisation, branch preference, the newest-workspace fallback, the legacy fallback and
the "nothing exists" case. No test asserted the workspace path shape before.
Note, not part of this PR
CheckoutBranchin both chat services runsgit checkoutinside the shared clone and, ifthe requested branch is missing, looks for a branch literally named
tree— that is theworkspace directory name, never a branch, so the fallback is dead code. With per-branch
workspaces the whole checkout step looks unnecessary; happy to follow up separately.