Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Follow-up code quality improvements for environment variable mirroring added in #11980.

Changes

  • Pre-sort at init: Sort MirroredEnvVars once in init() instead of on every call to GetMirroredEnvArgs() and GetMirroredEnvVarsList()
  • Simplify test extraction: Replace manual character loop with strings.SplitN() for parsing KEY=${KEY} format
  • Add PYENV_ROOT: Include Python environment variable for pyenv-based runner configurations
// Before: sorted on every call
func GetMirroredEnvArgs() []string {
    sortedVars := make([]string, len(MirroredEnvVars))
    copy(sortedVars, MirroredEnvVars)
    sort.Strings(sortedVars)
    // ...
}

// After: pre-sorted in init()
func init() {
    sort.Strings(MirroredEnvVars)
}

func GetMirroredEnvArgs() []string {
    // MirroredEnvVars is pre-sorted in init(), no need to sort here
    // ...
}
Original prompt

This section details on the original issue you should resolve

<issue_title>Minor improvements for env_mirror.go</issue_title>
<issue_description>## Context

Follow-up from PR #11980 which added environment variable mirroring from runner to agent container.

Minor Improvements

1. Pre-sort MirroredEnvVars at initialization time

In pkg/workflow/env_mirror.go:108-110, the GetMirroredEnvArgs() function sorts the variable list on every call:

sortedVars := make([]string, len(MirroredEnvVars))
copy(sortedVars, MirroredEnvVars)
sort.Strings(sortedVars)

Suggestion: Either define MirroredEnvVars in sorted order in the source code, or sort once in an init() function. This is a minor optimization since the function is called once per workflow compilation.

2. Simplify test code variable extraction

In pkg/workflow/env_mirror_test.go:44-52, the variable name extraction could use strings.SplitN() for clarity:

// Current:
for j := 0; j < len(envAssignment); j++ {
    if envAssignment[j] == '=' {
        varSet[envAssignment[:j]] = true
        break
    }
}

// Simpler:
parts := strings.SplitN(envAssignment, "=", 2)
varSet[parts[0]] = true

3. Consider adding PYENV_ROOT

Python environment setup sometimes uses PYENV_ROOT on certain runner configurations. Consider adding it to the mirrored variables list if relevant for Python workflows.

Priority

Low - these are minor code quality improvements, not functional issues.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits January 27, 2026 19:06
Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
… tests, add PYENV_ROOT

Co-authored-by: Mossaka <5447827+Mossaka@users.noreply.github.com>
Copilot AI changed the title [WIP] Improve initialization of mirrored environment variables Minor improvements for env_mirror.go Jan 27, 2026
Copilot AI requested a review from Mossaka January 27, 2026 19:21
@github-actions
Copy link
Contributor

🔍 PR Triage Results

Category: refactor | Risk: medium | Priority: 37/100

Scores Breakdown

  • Impact: 22/50 - Code quality improvement
  • Urgency: 5/30 - Recent PR
  • Quality: 10/20 - CI status unknown

📋 Recommended Action: batch_review

This PR contains minor code quality improvements to the env_mirror.go implementation:

Changes:

  1. Pre-sort MirroredEnvVars in init() instead of on every call (performance optimization)
  2. Simplify test code with strings.SplitN() (readability improvement)
  3. Add PYENV_ROOT environment variable (completeness)

All improvements are low-risk refactoring with no functional changes. Touches 140 files due to workflow recompilation.


Triaged by PR Triage Agent on 2026-01-28T00:34:49Z

AI generated by PR Triage Agent

@Mossaka Mossaka closed this Jan 28, 2026
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.

Minor improvements for env_mirror.go

2 participants