Skip to content

SPMI: Pass explicit environments to subprocesses instead of mutating os.environ - #134508

Open
jakobbotsch wants to merge 1 commit into
dotnet:mainfrom
jakobbotsch:spmi-explicit-subprocess-env
Open

jakobbotsch wants to merge 1 commit into
dotnet:mainfrom
jakobbotsch:spmi-explicit-subprocess-env

Conversation

@jakobbotsch

@jakobbotsch jakobbotsch commented Sep 23, 2026 •

Copy link
Copy Markdown
Member

Mutating os.environ in this way is lossy -- when you add an environment variable with an empty string as a value, it is equivalent to deleting that environment variable on Windows. Subprocesses will not see the environment variable set at all.

I hit this for superpmi asmdiffs reports generated through copilot. Copilot apparently sets GIT_CONFIG_VALUE_N and this environment mutation got rid of some of those environment variables which resulted in git errors in subprocesses.

Also make the example generation in the asm diffs summary report git diff failures instead of treating them as "No diffs found?".

…os.environ

superpmi.py modified os.environ to pass environment variables to collection
subprocesses, and restored it afterwards with os.environ.clear() followed by
os.environ.update(saved). AsyncSubprocessHelper.run_to_completion also did this
defensively around every run.

That restore is lossy on Windows: assigning an empty string to an os.environ key
calls _wputenv("NAME="), which removes the variable from the process
environment. Environment variables with empty values were therefore silently
dropped for all subsequent child processes. For example, with
GIT_CONFIG_COUNT/GIT_CONFIG_KEY_n/GIT_CONFIG_VALUE_n where one value is empty,
every later git invocation failed with "unable to parse command-line config",
and the asm diffs summary showed "No diffs found?" for all examples.

Instead, pass the environment explicitly via env= to the PMI, crossgen2 and
NativeAOT collection subprocesses (the dicts are already based on a copy of
os.environ), and remove all os.environ mutation.

Also make the example generation in the asm diffs summary report git diff
failures instead of treating them as "No diffs found?".

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ef38ea02-2a4e-45b5-8127-86b751617a68
Copilot AI lite review requested due to automatic review settings September 23, 2026 11:05
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 23, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
13 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI 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.

Copilot review overview

🔵 Needs a closer look

Decode Git stderr with replacement handling to prevent reporting failures from aborting on non-UTF-8 output.

Review effort: Lite
Findings: None

What changed in this PR

This PR avoids mutating os.environ for SuperPMI subprocesses and improves Git diff failure reporting.

Changes:

  • Passes explicit environment dictionaries to collection subprocesses.
  • Removes lossy environment restoration.
  • Reports Git diff failures in asm-diff summaries.
File Description
src/​coreclr/​scripts/​superpmi.py Updates subprocess environment handling and Git diff diagnostics.

@jakobbotsch

Copy link
Copy Markdown
Member Author

/azp run runtime

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).

@jakobbotsch

Copy link
Copy Markdown
Member Author

PTAL @dotnet/jit-contrib

@adamperlin adamperlin 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.

LGTM, passing through an env explicitly like this seems less error prone all around I think.

This branch has not been deployed

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

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants