Skip to content

fix(code): scope project dotenv to workspaces - #5980

Open
Mason Daugherty (mdrxy) wants to merge 3 commits into
mainfrom
mdrxy/code/workspace-dotenv
Open

fix(code): scope project dotenv to workspaces#5980
Mason Daugherty (mdrxy) wants to merge 3 commits into
mainfrom
mdrxy/code/workspace-dotenv

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Aug 28, 2026

Copy link
Copy Markdown
Member

Each validated conversation workspace now keeps its own project .env values without changing the server process environment.


The server can host conversations from different workspaces at the same time. Process-wide dotenv reloads could expose one workspace's model settings, credentials, tracing settings, or tool configuration to another workspace.

This change builds one immutable environment snapshot for each validated workspace. It applies launch environment values first, then the nearest project .env, then the global profile .env. Existing denied-key checks still apply.

Runtime construction and supported lazy model paths use that snapshot. Local shell execution receives a frozen copy with environment inheritance disabled. Web search receives a workspace-bound Tavily client. Stored model credentials remain paired with their stored endpoint without writing to os.environ.

The implementation keeps the existing serialized dotenv reload for the single-workspace client. It does not use process-wide reloads in the multi-workspace server because runtime builds and offload work can overlap. It also does not reject later workspaces, because the server is designed to host them concurrently.

Arbitrary third-party code that reads os.environ during invocation is not isolated by this change. Supported internal consumers keep the workspace snapshot explicitly.

Made by Open SWE

References

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
@github-actions github-actions Bot added dcode Related to `deepagents-code` fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: XL 1000+ LOC labels Aug 28, 2026
@mdrxy
Mason Daugherty (mdrxy) marked this pull request as ready for review August 28, 2026 23:53

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Open SWE Review found 1 potential issue.

Open in WebView Open SWE trace

Comment on lines +277 to +283
with use_environment(workspace_env):
return await _make_graphs_in_environment(
config=config,
project_context_override=project_context_override,
workspace_env=workspace_env,
workspace_credentials=workspace_credentials,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟠 Workspace tracing client remains process-global

Building workspace A and then workspace B does not keep their LangSmith credentials isolated. This context only scopes active_environment() while _make_graphs_in_environment() runs, but that function calls configure_langsmith_secret_redaction(), which installs langsmith.configure(client=Client(...)) process-wide. The second workspace therefore replaces the client used by the first runtime; later traces from A can be uploaded with B's API key/endpoint (and a workspace with tracing disabled also leaves the previous configured client intact). The tracing client/configuration needs to be bound per runtime/invocation rather than published globally during each workspace build.

(Refers to lines 277-283)


Your feedback helps Open SWE learn. React with 👍 or 👎 to tell us if this review comment was useful.

The dotenv workspace-scoping change moved the reviewed process-directory
reads: `Path.cwd()` moved from `_preview_dotenv_environ` into
`_dotenv_environment`, and `find_project_root` moved from
`Credentials.from_environment` into `Credentials.snapshot_from_environment`.
Update the `check_process_cwd` allowlist to match the actual call sites so
`make lint` passes again.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dcode Related to `deepagents-code` fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: XL 1000+ LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant