Conversation
| .dispatch_tool_call( | ||
| &session.id, | ||
| tool_call.clone(), | ||
| Some(session.working_dir.as_path()), |
There was a problem hiding this comment.
maybe dispatch_tool_call should just take a reference to the session itself? now that we're passing two fields from it
There was a problem hiding this comment.
I looked into this and its a pretty large refactor because not all call sites have access to a full session and it would add additional overhead to create a session and/or mock a fake one etc. Gonna punt on this for now and we can come back to it later..
There was a problem hiding this comment.
that makes sense - thanks for looking into it
|
this looks a lot nicer than what we have now, thanks for doing this. but a propos now, shouldn't this be matched by the deletion of a bunch of corresponding lines? pub async fn add_extension( still takes a working_dir for example |
|
The |
|
thanks @zanesq - you are right that's still needed I guess |
|
np here is the follow up just making it a bit clearer for now why we do this #6958 |
Signed-off-by: Harrison <hcstebbins@gmail.com>
Problem
Working directory was not isolated per chat session. Changing the working directory in one
session would affect other sessions because:
currentWorkingDirinworkingDir.tswas sharedacross all sessions
std::env::set_var("GOOSE_WORKING_DIR", ...)set a process-globalenvironment variable that all sessions read from
Solution
Pass the working directory per-request through MCP metadata instead of using global state.
Frontend Changes
ui/desktop/src/utils/workingDir.ts: RemovedcurrentWorkingDirglobal andsetCurrentWorkingDir()functionui/desktop/src/components/bottom_menu/DirSwitcher.tsx: Removed call tosetCurrentWorkingDir()Backend Changes
Core plumbing:
session_context.rs: AddedWORKING_DIR_HEADERconstant for MCP metadata keymcp_client.rs:working_dirparameter toMcpClientTrait::call_tool()inject_session_context_into_extensions()andinject_session_context_into_request()to inject both session_id and working_dir into MCP request metadata
send_request_with_context()to handle working directory injectionExtension manager:
extension_manager.rs:working_dir: Option<&Path>parameter todispatch_tool_call()std::env::set_var("GOOSE_WORKING_DIR", ...)for builtin extensionsMcpClient::call_tool()Developer extension:
rmcp_developer.rs:extract_working_dir_from_meta()helper to read working_dir from MCP contextshell()to extract working_dir from request metadataexecute_shell_command()to acceptworking_dir: Option<PathBuf>parameterinstead of reading from environment variable
Call sites updated:
agent.rs- passesSome(session.working_dir.as_path())goose-server/routes/agent.rs- passesNone(direct API calls)code_execution_extension.rs- passesNoneMcpClientTraitimplementations updated with_working_dirparameterResult
Each session's working directory is now passed through the request chain and isolated
from other sessions. No more global state pollution.
fixes #6909