Validate default AI credit guardrails in compiler output, runtime env wiring, and compile logs#38184
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
| GH_AW_WORKFLOW_DISPATCH_AW_CONTEXT: ${{ github.event.inputs.aw_context || '' }} | ||
| GH_AW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GH_AW_MAX_DAILY_AI_CREDITS: "500000" | ||
| GH_AW_MAX_DAILY_AI_CREDITS: "5000" |
There was a problem hiding this comment.
@copilot this value should first look up the env variable gh aw default max daily ai credits
There was a problem hiding this comment.
Fixed in ef514cd. The emitted guardrail now uses vars.GH_AW_DEFAULT_MAX_DAILY_AI_CREDITS first and only falls back to the compiler-resolved default.
| GH_AW_WORKFLOW_DISPATCH_AW_CONTEXT: ${{ github.event.inputs.aw_context || '' }} | ||
| GH_AW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GH_AW_MAX_DAILY_AI_CREDITS: "500000" | ||
| GH_AW_MAX_DAILY_AI_CREDITS: "5000" |
There was a problem hiding this comment.
@copilot this value should first look up the env variable gh aw default daily ai credits
There was a problem hiding this comment.
Fixed in ef514cd. The compiled guardrail env now checks vars.GH_AW_DEFAULT_MAX_DAILY_AI_CREDITS before falling back to the default value.
| GH_AW_WORKFLOW_DISPATCH_AW_CONTEXT: ${{ github.event.inputs.aw_context || '' }} | ||
| GH_AW_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| GH_AW_MAX_DAILY_AI_CREDITS: "500000" | ||
| GH_AW_MAX_DAILY_AI_CREDITS: "5000" |
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>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
|
@copilot the following fallback logic should be applied for each metric. Recompile and validate that it is correctly configured. Add sanity unit tests to validate that the lock.yml files contains those values |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
... Addressed in 1404779. The compiled workflows now use frontmatter → GitHub Actions default var → built-in constant for both AI credit guardrails, and I added sanity tests that assert the generated lock files contain those values. |
There was a problem hiding this comment.
Pull request overview
Updates compiler and emitted workflow runtime wiring so daily and per-run AI credit guardrails consistently resolve as: frontmatter value → GitHub Actions repo variable (vars.*) → built-in default, while also refreshing generated .lock.yml/golden outputs and adding test coverage around the new behavior.
Changes:
- Emit runtime
vars.* || '<builtin>'expressions forGH_AW_MAX_DAILY_AI_CREDITS(default 5000) andGH_AW_MAX_AI_CREDITS(default 1000) in compiled workflows. - Add per-run credit env injection across engines and a runtime AWF-config updater script to apply
GH_AW_MAX_AI_CREDITStoapiProxy.maxAiCredits(including-1disablement). - Add/adjust unit + integration tests and regenerate wasm goldens and repository workflow
.lock.ymlfiles.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/testdata/TestWasmGolden_CompileFixtures/with-imports.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/testdata/TestWasmGolden_CompileFixtures/smoke-copilot.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/testdata/TestWasmGolden_CompileFixtures/playwright-cli-mode.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/testdata/TestWasmGolden_CompileFixtures/basic-copilot.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/pi.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/gemini.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/copilot.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/codex.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/claude.golden | Golden update for daily vars-fallback + per-run max-ai-credits env + runtime AWF config patching script. |
| pkg/workflow/pi_engine.go | Inject per-run max AI credits env into Pi engine execution env. |
| pkg/workflow/opencode_engine.go | Inject per-run max AI credits env into OpenCode engine env. |
| pkg/workflow/gemini_engine.go | Inject per-run max AI credits env into Gemini engine env. |
| pkg/workflow/engine.go | Add shared per-run max AI credits env injection with runtime vars-fallback. |
| pkg/workflow/daily_aic_workflow.go | Switch daily default wiring to runtime vars-fallback expression and add default-resolution debug logs. |
| pkg/workflow/daily_aic_workflow_guardrail_test.go | Update daily guardrail default-resolution unit tests for new expression-based defaults. |
| pkg/workflow/crush_engine.go | Inject per-run max AI credits env into Crush engine env. |
| pkg/workflow/copilot_engine_execution.go | Inject per-run max AI credits env into Copilot engine env. |
| pkg/workflow/compilerenv/manager.go | Add helpers to build `vars.* |
| pkg/workflow/compilerenv/manager_test.go | Add tests for new expression builders and update daily default fallback expectations. |
| pkg/workflow/codex_engine.go | Inject per-run max AI credits env into Codex engine env. |
| pkg/workflow/claude_engine.go | Inject per-run max AI credits env into Claude engine env. |
| pkg/workflow/awf_helpers.go | Add runtime AWF-config update script to apply GH_AW_MAX_AI_CREDITS at runtime. |
| pkg/workflow/awf_config.go | Add debug log for resolved maxAiCredits in generated AWF config. |
| pkg/workflow/awf_config_test.go | Add test asserting the AWF runtime updater script is included. |
| pkg/workflow/antigravity_engine.go | Inject per-run max AI credits env into Antigravity engine env. |
| pkg/workflow/ai_credits_lock_test.go | New unit tests asserting compiled lock output contains the expected fallback expressions and respects explicit frontmatter values. |
| pkg/constants/constants.go | Introduce built-in daily default constant (5000). |
| pkg/cli/env_command_test.go | Update defaults-file tests for new daily default value. |
| pkg/cli/compile_integration_test.go | Add integration test asserting compile debug logs include resolved daily/per-run defaults. |
| .github/workflows/test-workflow.lock.yml | Regenerated lock workflow with daily vars-fallback and per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/smoke-ci.lock.yml | Regenerated lock workflow with daily vars-fallback and per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/release.lock.yml | Regenerated lock workflow with daily vars-fallback and per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/hippo-embed.lock.yml | Regenerated lock workflow with daily vars-fallback and per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/firewall.lock.yml | Regenerated lock workflow with daily vars-fallback and per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/example-permissions-warning.lock.yml | Regenerated lock workflow with daily vars-fallback and per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/daily-max-ai-credits-test.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script (including explicit max-ai-credits cases). |
| .github/workflows/daily-malicious-code-scan.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/daily-credit-limit-test.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/daily-community-attribution.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/daily-cache-strategy-analyzer.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/daily-byok-ollama-test.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/constraint-solving-potd.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/codex-github-remote-mcp-test.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/code-simplifier.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/bot-detection.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/ai-moderator.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/agentic-token-optimizer.lock.yml | Regenerated lock workflow with daily vars-fallback and per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/agent-persona-explorer.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
| .github/workflows/ace-editor.lock.yml | Regenerated lock workflow with per-run max-ai-credits env + runtime AWF config patching script. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 94/277 changed files
- Comments generated: 4
| cmd := exec.Command(setup.binaryPath, "compile", testWorkflowPath) | ||
| cmd.Env = append(os.Environ(), "DEBUG=workflow:daily_effective_workflow,workflow:awf_config") | ||
| output, err := cmd.CombinedOutput() |
| func resolveDefaultMaxDailyAIC() *string { | ||
| return parseMaxDailyAICValue(compilerenv.BuildDefaultMaxDailyAICreditsExpression(constants.DefaultMaxDailyAICredits)) | ||
| } | ||
|
|
||
| func resolveMaxDailyAIC(frontmatter map[string]any, importedJSON string) *string { |
| t.Run("uses GitHub variable fallback when unset even with compiler env override", func(t *testing.T) { | ||
| t.Setenv(compilerenv.DefaultMaxDailyAICredits, "2222") | ||
| got := resolveMaxDailyAIC(map[string]any{}, "") | ||
| if got == nil || *got != "2222" { | ||
| t.Fatalf("expected enterprise default, got %v", got) | ||
| if got == nil || *got != "${{ vars.GH_AW_DEFAULT_MAX_DAILY_AI_CREDITS || '5000' }}" { | ||
| t.Fatalf("expected GitHub variable fallback with built-in default, got %v", got) |
| } | ||
| awfConfigLog.Printf("API proxy: resolved maxAiCredits=%d", maxAICredits) |
The compiler defaulted
max-ai-creditsandmax-daily-ai-creditsthrough different paths, but the generated runtime wiring did not consistently apply the same fallback order for both metrics. This updates the built-in daily default to5000, preserves the per-run default of1000, and makes the compiled workflow output consistently resolve both guardrails as: frontmatter value → GitHub Actions default var → built-in constant.Default guardrail constants
DefaultMaxDailyAICredits = "5000"constant.DefaultMaxAICredits = 1000unchanged.Compiler default resolution
"500000"fallbacks in daily AI credit resolution with the shared constant.GH_AW_DEFAULT_MAX_DAILY_AI_CREDITSfor compile-time resolution and logging.Runtime guardrail env wiring
GH_AW_MAX_DAILY_AI_CREDITS: ${{ vars.GH_AW_DEFAULT_MAX_DAILY_AI_CREDITS || '5000' }}when frontmatter does not set a value.GH_AW_MAX_AI_CREDITS: ${{ vars.GH_AW_DEFAULT_MAX_AI_CREDITS || '1000' }}when frontmatter does not set a value, and update the generated AWF config at runtime from that env value.-1handling for per-run disablement.Compile log verification
daily_aic_workflow.goawf_config.gogh aw compilewith debug logging, writes the combined output to acompile.log, and asserts both defaults are present.Test and golden updates
lock.ymloutput contains the expected per-run and daily fallback values..lock.ymlfiles so compiled workflow output now reflects the runtime fallback order for both metrics.