Fix non-deterministic secret replacement in workflows with shared fallback expressions#33441
Merged
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot
AI
changed the title
Fix non-deterministic env var generation when importing multiple workflows with shared fallback secrets
Fix non-deterministic secret replacement in workflows with shared fallback expressions
May 20, 2026
Copilot created this pull request from a session on behalf of
pelikhan
May 20, 2026 03:46
View session
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes non-deterministic secret/env expression replacement caused by randomized Go map iteration when multiple keys share the same fallback expression, ensuring stable compiled lock.yml output across runs.
Changes:
- Iterates over secret/env maps in deterministic (sorted) key order in replacement helpers.
- Adds regression tests that repeatedly run replacements to assert stable output for shared fallback expressions.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/secret_extraction.go | Uses sortedMapKeys when replacing secrets/env expressions to ensure deterministic output when multiple keys map to the same expression. |
| pkg/workflow/secret_extraction_test.go | Adds determinism regression tests for fallback secret expressions in both env-var and bash-var replacement functions. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When two imported workflows (e.g.
shared/datadog.md+shared/mcp/datadog.md) both reference the same fallback secret expression, the compiledlock.ymlproduces different env var names across runs.Root cause
ExtractSecretsFromValue("${{ secrets.DD_APPLICATION_KEY || secrets.DD_APP_KEY }}")returns amap[string]stringwith two keys (DD_APPLICATION_KEY,DD_APP_KEY) sharing the same expression value. Three replacement functions iterated over this map with Go's randomizedrange— whichever key came first consumed the expression viastrings.ReplaceAll; the other was a no-op. Winner was random per run.Fix
ReplaceSecretsWithEnvVars,ReplaceSecretsWithBashVars,ReplaceTemplateExpressionsWithEnvVars: replace barefor k := range secretswith the existingsortedMapKeyshelper, ensuring stable iteration order.Since
'L'(76) <'_'(95),DD_APPLICATION_KEYsorts beforeDD_APP_KEYand consistently wins — matching the primary-secret-first semantics of the||expression.Regression tests:
TestReplaceSecretsWithEnvVars_FallbackExpressionDeterminismandTestReplaceSecretsWithBashVars_FallbackExpressionDeterminismeach call the affected function 50 times with a shared-expression map and assert identical output every run.