fix: redirect wandb .netrc to temp dir for read-only environments#33604
fix: redirect wandb .netrc to temp dir for read-only environments#33604ForeignKeyCN wants to merge 5 commits intolanggenius:mainfrom
Conversation
wandb.login() persists credentials to ~/.netrc, which fails when the home directory is read-only (e.g. Dify Cloud containers). Set NETRC env var to a temp directory before importing wandb to avoid the error.
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a critical authentication failure for Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
Pyrefly DiffNo changes detected. |
There was a problem hiding this comment.
Code Review
This pull request addresses a crash when wandb.login() tries to write to ~/.netrc in a read-only environment by redirecting it to a temporary file. This is a good fix for the immediate problem. However, the current implementation with a fixed filename (.wandb_netrc) introduces a race condition in multi-process and multi-threaded server environments, which can lead to credential leakage between tenants or authentication failures. I've added a specific comment with a suggestion to make the filename unique per-process, which mitigates the issue between different worker processes. A more subtle race condition can still exist within a single process handling concurrent requests for different tenants, which I've also detailed in the comment. Addressing the per-process issue is a critical improvement.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Pyrefly DiffNo changes detected. |
Pyrefly DiffNo changes detected. |
|
Thank you for your contribution! This seems still problematic for the following reasons:
I'm not sure if it's possible to initialize weave client without setting credential to |
…rc writes Replace wandb.login() with WANDB_API_KEY/WANDB_BASE_URL env vars before weave.init(). This avoids writing credentials to .netrc, which fails in read-only environments (Dify Cloud) and risks credential leakage between tenants in multi-tenant deployments. Per Weave docs, setting WANDB_API_KEY before weave.init() is sufficient for authentication without any disk writes. Fixes langgenius#33603
Pyrefly DiffNo changes detected. |
|
Thanks Lin! I just looked up weave's doc and find the possible way. Now there will no longer be disk write. Everything are written in trace_app_config table. Should we follow this PR or we should start a new one? |
|
I suggest following on this PR and adjusting the PR title accordingly @ForeignKeyCN. |
| # Login with API key first, including host if provided | ||
| # Authenticate via env var instead of wandb.login() to avoid | ||
| # writing credentials to .netrc (fails in read-only environments) | ||
| os.environ["WANDB_API_KEY"] = self.weave_api_key |
There was a problem hiding this comment.
The environment variables remain shared across the entire API server process, meaning the cross-tenant overwrite issue persists.
It is unclear whether the wandb SDK supports multiple client instances within a single process. If not, the weave_trace integration may be fundamentally unsuitable for robust multi-tenancy, limiting its applicability primarily to self-hosted deployments where a single entity maintains full control and strict tenant isolation is less critical.
Replace weave.init() with direct construction of RemoteHTTPTraceServer and WeaveClient. This avoids: 1. Writing credentials to ~/.netrc (fails in read-only environments) 2. Using process-wide env vars (cross-tenant credential leakage) Credentials are now held only in the client instance, matching the Langfuse integration pattern. The endpoint from WeaveConfig is used as the trace server URL. Fixes langgenius#33603
Pyrefly Diffbase → PR--- /tmp/pyrefly_base.txt 2026-03-19 06:00:28.493406080 +0000
+++ /tmp/pyrefly_pr.txt 2026-03-19 06:00:19.602416482 +0000
@@ -3790,6 +3790,10 @@
--> tests/unit_tests/core/ops/test_utils.py:107:41
ERROR Argument `None` is not assignable to parameter `project` with type `str` in function `core.ops.utils.validate_project_name` [bad-argument-type]
--> tests/unit_tests/core/ops/test_utils.py:136:40
+ERROR Object of class `WeaveDataTrace` has no attribute `weave_api_key` [missing-attribute]
+ --> tests/unit_tests/core/ops/weave_trace/test_weave_trace.py:234:16
+ERROR Object of class `WeaveDataTrace` has no attribute `host` [missing-attribute]
+ --> tests/unit_tests/core/ops/weave_trace/test_weave_trace.py:246:16
ERROR This `yield` expression is unreachable [unreachable]
--> tests/unit_tests/core/plugin/impl/test_model_client.py:168:13
ERROR This `yield` expression is unreachable [unreachable]
|
|
LGTM now. However the CI failed. |
|
Hi Team. Sorry it's been a week. Since weave package is not really well maintained and they didn't ship their own stubs for its internal trace_server_bindings module, the CI couldn't pass. Do you think we can ignore this or should we add a weave specific stub file? |
Fixes #33603
Summary
wandb.login()persists credentials to~/.netrc, which fails when the home directory is read-only (e.g. Dify Cloud containers). This PR sets theNETRCenv var to point to a temp directory before importingwandb, so authentication succeeds regardless of home directory permissions.Related PRs: #14262 (initial Weave integration), #28289 (last Weave update)
Screenshots
| Before |

| After |
|
Checklist
make lintandmake type-check(backend) andcd web && npx lint-staged(frontend) to appease the lint gods