Skip to content

👺 Havoc: Remove unsafe env mutations#602

Open
madmax983 wants to merge 1 commit into
trunkfrom
havoc-unsafe-env-3538405074395992898
Open

👺 Havoc: Remove unsafe env mutations#602
madmax983 wants to merge 1 commit into
trunkfrom
havoc-unsafe-env-3538405074395992898

Conversation

@madmax983
Copy link
Copy Markdown
Owner

  • 🧨 The Trigger: Test environment mutation via unsafe { std::env::set_var(...) } caused data races and panics during concurrent cargo test runs on Rust 1.80+.
  • 📉 The Stack Trace: (Omitted - data race)
  • 🧪 Reproduction: Run cargo test concurrently on Rust 1.80+.
  • 😈 Comment: You assumed std::env::set_var was safe in a single-threaded test. You were wrong. Other concurrent tests will still panic.

PR created automatically by Jules for task 3538405074395992898 started by @madmax983

Replaces `unsafe { std::env::set_var(...) }` calls with `temp_env::with_vars` or
`temp_env::async_with_vars` to prevent data races during concurrent test runs.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request replaces unsafe environment variable mutations in tests with the temp-env crate across multiple files, including src/run/mini.rs, src/run/redact_audit.rs, src/stream/sweep_webhook.rs, and src/telemetry/mod.rs. It also simplifies a socket-reading loop in src/run/swebench.rs and improves error reporting in webhook tests. Feedback is provided to remove the temporary Python scripts and the plan.md file that were committed to the repository to keep the codebase clean.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread plan.md
Comment on lines +1 to +24
1. **Remove `unsafe` environment variable mutations in `src/run/mini.rs`**.
- I will replace `unsafe { std::env::set_var(...) }` and `unsafe { std::env::remove_var(...) }` in `mini_manifest_does_not_contain_env_secrets` with `temp_env::async_with_vars`.

2. **Remove `unsafe` environment variable mutations in `src/stream/sweep_webhook.rs`**.
- I will replace `unsafe { std::env::set_var(...) }` and `unsafe { std::env::remove_var(...) }` in `redactor_strips_sensitive_env_var_from_instance_id` with `temp_env::async_with_vars`.

3. **Remove `unsafe` environment variable mutations in `src/run/redact_audit.rs`**.
- I will replace `unsafe { std::env::set_var(...) }` and `unsafe { std::env::remove_var(...) }` in `oracle_catches_ambient_env_value` with `temp_env::with_vars`.

4. **Remove `unsafe` environment variable mutations in `src/telemetry/mod.rs`**.
- I will use a Python script with bash heredoc to replace all `unsafe { std::env::set_var(...) }` usages across several tests in `src/telemetry/mod.rs` with `temp_env::with_vars`. I will also remove `ENV_LOCK`.

5. **Run tests**
- Run `cargo test --lib -- run::mini run::redact_audit stream::sweep_webhook telemetry`.

6. Complete pre-commit steps to ensure proper testing, verification, review, and reflection are done.

7. Submit the PR.
- Title: '👺 Havoc: Remove unsafe env mutations'
- Description:
* 🧨 **The Trigger:** Test environment mutation via `unsafe { std::env::set_var(...) }` caused data races and panics during concurrent `cargo test` runs on Rust 1.80+.
* 📉 **The Stack Trace:** (Omitted - data race)
* 🧪 **Reproduction:** Run `cargo test` concurrently on Rust 1.80+.
* 😈 **Comment:** You assumed `std::env::set_var` was safe in a single-threaded test. You were wrong. Other concurrent tests will still panic.
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.

medium

It looks like several temporary Python scripts (replace_*.py, fix_*.py) and the plan.md file itself were committed to the repository. While these scripts are highly useful for automating the refactoring process, they are not part of the application or the test suite. To keep the repository clean and avoid cluttering the codebase with temporary automation artifacts, please delete these files before merging this pull request.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 5, 2026

Codecov Report

❌ Patch coverage is 97.22222% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.19%. Comparing base (9aa2ad9) to head (4c1cb30).

Files with missing lines Patch % Lines
src/stream/sweep_webhook.rs 90.00% 2 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##            trunk     #602   +/-   ##
=======================================
  Coverage   85.19%   85.19%           
=======================================
  Files         114      114           
  Lines       65408    65403    -5     
=======================================
- Hits        55725    55721    -4     
+ Misses       9683     9682    -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant