fix: prevent wrong-cwd auto-detection when workspace not detected#175
Merged
ichoosetoaccept merged 1 commit intomainfrom Feb 17, 2026
Conversation
Greptile SummaryFixed a bug where the server could auto-detect the wrong repository when workspace detection fails. The PR introduces a new Key Changes:
Impact: Confidence Score: 5/5
Important Files Changed
Flowchartflowchart TD
A[MCP Tool Called] --> B[get_workspace_cwd]
B --> C{MCP Roots Available?}
C -->|Yes| D[Return MCP Root Path]
C -->|No| E{CRB_WORKSPACE Set?}
E -->|Yes| F[Return Env Var Path]
E -->|No| G[Return None + Warning]
D --> H[check_auto_detect_prerequisites]
F --> H
G --> H
H --> I{cwd Detected?}
I -->|Yes| J[Auto-detection Safe]
I -->|No| K{All Params Explicit?}
K -->|Yes| J
K -->|No| L[Raise GhError with Help]
J --> M[Proceed with Auto-detection]
M --> N[Execute Tool Logic]
Last reviewed commit: 0c72cf9 |
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
When the MCP client doesn't provide workspace roots and
CRB_WORKSPACEisn't set,_get_workspace_cwdreturnsNone. This causesghCLI commands to silently use the server's process directory — almost certainly the wrong git repo — producing confusing errors like "no pull requests found for branch main".Solution
_check_auto_detect_prerequisites— new guard that raises a clear, actionableGhErrorwhencwdisNoneand the caller didn't provide explicitrepo/pr_numberparams. Tells the agent exactly what to pass._get_workspace_cwdlogging — granular warnings for empty roots list, unsupported URI scheme, exception details, and an explicit warning when falling back toNonein MCP context.CRB_WORKSPACE— it's a per-process env var that breaks multi-window setups (multiple editors sharing one MCP server config but working on different repos).Tests
_check_auto_detect_prerequisites(noop when cwd detected, noop when all params explicit, raises for missing pr/repo/both, fix guidance text, correct Missing: line)_get_workspace_cwdFixes #174