Fix subagent project scope corrections - #1920
Merged
Merged
Conversation
Aaronontheweb
enabled auto-merge (squash)
August 13, 2026 10:31
| { | ||
| const string projectGuidance = "Project instructions that must not load."; | ||
| var worktree = Path.GetFullPath(AppContext.BaseDirectory); | ||
| var controlledDirectory = Path.Combine(worktree, $"project-{controlCharacter}-candidate"); |
| { | ||
| var allowedRoot = scopeToolAccepts | ||
| ? worktree | ||
| : Path.Combine(worktree, "different-workspace-root"); |
Merged
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.
Summary
set_working_directorydeclaration only to the child run, reload its project instructions, and keep the parent project unchangedWhy
A subagent could issue reviewed-safe work beneath an undeclared project cwd, receive a user approval prompt, and never get the same model-facing correction available to a parent session. Merely returning the correction was insufficient: the child did not apply the declaration to later tool contexts or reload project guidance.
This keeps the original shell call and history intact. It teaches the child to declare the project through the existing tool and filesystem policy, then reevaluates the unchanged retry under the resulting child scope.
Validation
The full solution run also surfaced one unrelated existing MCP diagnostic assertion mismatch in
McpSdkCatalogNotificationIntegrationTests; this PR does not touch that test or MCP production code.