Skip to content

External: copilot-sdk Environment.Clear() replaces child process environment instead of merging #441

@PureWeen

Description

@PureWeen

External: github/copilot-sdk

Problem

CopilotClientOptions.Environment silently clears and replaces the child process environment rather than merging with the inherited environment. Decompiled from GitHub.Copilot.SDK v0.2.0:

if (options.Environment != null)
{
    processStartInfo.Environment.Clear();
    foreach (var (key, value) in options.Environment)
    {
        processStartInfo.Environment[key] = value;
    }
}

Any embedder that sets Environment to augment PATH (the obvious use case — MAUI apps don't inherit terminal PATH) will unknowingly strip critical platform variables (COMSPEC, SystemRoot, TEMP, LOCALAPPDATA, etc.) from the CLI child process.

On Windows this breaks ConPTY shell spawning entirely — the CLI's PowerShell tool fails with File not found: (empty path) because ConPTY can't resolve the shell executable without these env vars.

Expected behavior

Either:

  • Merge options.Environment with the inherited environment (set/override only the specified keys), or
  • Document clearly that Environment is a full replacement and embedders must copy Environment.GetEnvironmentVariables() first

Workaround

Copy the full system environment before augmenting:

var env = new Dictionary<string, string>(
    OperatingSystem.IsWindows() ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal);
foreach (DictionaryEntry entry in Environment.GetEnvironmentVariables())
{
    if (entry.Key is string key && entry.Value is string val)
        env[key] = val;
}
// Now augment PATH, HOME, etc.
options.Environment = env;

PolyPilot fix

PR #439

Metadata

Metadata

Assignees

No one assigned

    Labels

    externalUpstream bug or dependency issue

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions