Add max-ai-credits budget support across frontmatter, AWF config, imports, and failure reporting, and remove default max-effective-tokens 25M fallback#37235
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
max-ai-credits budget support across frontmatter, AWF config, imports, and failure reporting
|
✅ PR Code Quality Reviewer completed the code quality review. |
|
🧪 Test Quality Sentinel completed test quality analysis. |
|
🧠 Matt Pocock Skills Reviewer failed during the skills-based review. |
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. |
There was a problem hiding this comment.
Pull request overview
Adds a new per-run AI credits budget control (max-ai-credits) and propagates it through workflow frontmatter/schema, import merging, compiler env defaults, AWF config generation (apiProxy.maxAiCredits), and failure reporting (issue/comment contexts + template) when the budget is exceeded.
Changes:
- Introduces
max-ai-creditsfrontmatter field (schema + typed config), plus import “first-wins” merging and engine config extraction. - Adds enterprise/repo/org default support via
GH_AW_DEFAULT_MAX_AI_CREDITSandgh aw envYAML keydefault_max_ai_credits. - Extends AWF config output + schemas and adds dedicated failure context/template for AI credits budget exhaustion.
Show a summary per file
| File | Description |
|---|---|
| pkg/workflow/testdata/TestWasmGolden_CompileFixtures/with-imports.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/testdata/TestWasmGolden_CompileFixtures/smoke-copilot.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/testdata/TestWasmGolden_CompileFixtures/playwright-cli-mode.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/testdata/TestWasmGolden_CompileFixtures/basic-copilot.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/pi.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/gemini.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/copilot.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/codex.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/testdata/TestWasmGolden_AllEngines/claude.golden | Updates golden output to include apiProxy.maxAiCredits. |
| pkg/workflow/schemas/awf-config.schema.json | Adds apiProxy.maxAiCredits to the embedded AWF config schema. |
| pkg/workflow/frontmatter_types.go | Adds typed frontmatter field MaxAICredits (max-ai-credits). |
| pkg/workflow/engine.go | Carries MaxAICredits through EngineConfig and extraction paths. |
| pkg/workflow/engine_config_parser.go | Adds parsing for max-ai-credits in engine/frontmatter extraction. |
| pkg/workflow/compilerenv/manager.go | Adds env default resolver for GH_AW_DEFAULT_MAX_AI_CREDITS. |
| pkg/workflow/compilerenv/manager_test.go | Tests ResolveDefaultMaxAICredits. |
| pkg/workflow/compiler_orchestrator_engine.go | Preserves/applies max-ai-credits across import/default resolution. |
| pkg/workflow/awf_config.go | Emits apiProxy.maxAiCredits in generated AWF config JSON. |
| pkg/parser/schemas/main_workflow_schema.json | Adds max-ai-credits to the main workflow schema contract. |
| pkg/parser/schema_test.go | Extends schema validation tests for expressions/suffixes and invalid zero. |
| pkg/parser/import_processor.go | Extends ImportsResult to carry merged max-ai-credits. |
| pkg/parser/import_field_extractor.go | Extracts max-ai-credits from imports using first-wins semantics. |
| pkg/parser/import_field_extractor_test.go | Tests import extraction/first-wins for max-ai-credits. |
| pkg/constants/constants.go | Introduces DefaultMaxAICredits constant. |
| pkg/cli/env_command.go | Adds default_max_ai_credits YAML binding + validation. |
| pkg/cli/env_command_test.go | Updates env command tests for the new defaults binding. |
| docs/public/editor/autocomplete-data.json | Adds editor autocomplete metadata for max-ai-credits. |
| actions/setup/md/ai_credits_rate_limit_error.md | Adds dedicated rendered context template for AI credits budget exceeded. |
| actions/setup/md/agent_failure_issue.md | Wires AI credits failure context into failure issue template. |
| actions/setup/md/agent_failure_comment.md | Wires AI credits failure context into failure comment template. |
| actions/setup/js/handle_agent_failure.test.cjs | Adds template vars + tests for AI credits failure state resolution. |
| actions/setup/js/handle_agent_failure.cjs | Adds AI credits failure detection, categorization, and context rendering. |
| actions/setup/js/effective_tokens_context.cjs | Adds parsing/suppression logic for AI credits signals from audit/env. |
| .github/workflows/smoke-update-cross-repo-pr.lock.yml | Regenerates locked workflow content; adds checkout manifest step. |
| .github/workflows/smoke-create-cross-repo-pr.lock.yml | Regenerates locked workflow content; adds checkout manifest step. |
| .github/workflows/smoke-copilot.lock.yml | Regenerates locked workflow content. |
| .github/workflows/smoke-copilot-arm.lock.yml | Regenerates locked workflow content. |
| .github/workflows/smoke-copilot-aoai-apikey.lock.yml | Regenerates locked workflow content. |
| .github/workflows/daily-regulatory.lock.yml | Regenerates locked workflow content. |
| .github/workflows/daily-performance-summary.lock.yml | Regenerates locked workflow content. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 39/39 changed files
- Comments generated: 2
| "maxAiCredits": { | ||
| "type": "number", | ||
| "exclusiveMinimum": 0, | ||
| "description": "Maximum cumulative AI credits allowed for a run. When reached, the API proxy rejects subsequent requests with HTTP 429 and error type 'ai_credits_limit_exceeded'." | ||
| }, |
| /** @param {unknown} value */ | ||
| function parsePositiveNumberString(value) { | ||
| if (typeof value === "number" && Number.isFinite(value) && value > 0) { | ||
| return String(value); | ||
| } | ||
| if (typeof value === "string") { | ||
| const trimmed = value.trim(); | ||
| if (trimmed === "") return ""; | ||
| const parsed = Number.parseFloat(trimmed); | ||
| if (Number.isFinite(parsed) && parsed > 0) return trimmed; | ||
| } | ||
| return ""; | ||
| } |
🏗️ Design Decision Gate — ADR RequiredThis PR makes significant changes to core business logic (185 new lines across 📄 Draft ADR committed:
📋 What to do next
Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision. ❓ Why ADRs MatterADRs create a searchable, permanent record of why the codebase looks the way it does — for example, why AI credit budgeting reuses the existing budget-field machinery instead of a standalone subsystem. Future contributors (and your future self) will thank you. 📋 Michael Nygard ADR Format ReferenceAn ADR must contain these four sections to be considered complete:
All ADRs are stored in
|
🧪 Test Quality Sentinel Report✅ Test Quality Score: 85/100 — Excellent
📊 Metrics & Test Classification (11 tests analyzed)
Test Classification Details
Language SupportTests analyzed:
|
There was a problem hiding this comment.
✅ Test Quality Sentinel: 85/100. Test quality is excellent — 0% of new tests are implementation tests (threshold: 30%). All 11 analyzed tests enforce behavioral contracts. Minor suggestions only: add assertion messages to TestResolveDefaultMaxAICredits sub-tests and add //go:build !integration to manager_test.go for consistency.
|
@copilot remove the default 25M max-effective-token |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Done in I removed the built-in |
max-ai-credits budget support across frontmatter, AWF config, imports, and failure reportingmax-ai-credits budget support across frontmatter, AWF config, imports, and failure reporting, and remove default max-effective-tokens 25M fallback
This change introduces a new top-level frontmatter field,
max-ai-credits, as a templatable integer budget (default1000), parallel to existing budget controls. It propagates through compile/import resolution into AWFapiProxy.maxAiCredits, and surfaces budget overage as a dedicated failure context in agent issues/comments.In addition, based on PR feedback, this update removes the built-in
25Mdefault formax-effective-tokens. When unset, ET budget is now omitted unless provided explicitly (frontmatter/imports) or via environment default override.Frontmatter + schema contract
max-ai-creditsto main workflow schema and typed frontmatter config.max-effective-tokensdefault (25000000) and updated description text to reflect unset-by-default behavior.Import + compiler resolution
max-ai-credits(matching other scalar budget fields).MaxAICreditsthrough orchestration paths.max-ai-credits).Environment defaults (
gh aw env)GH_AW_DEFAULT_MAX_AI_CREDITS.gh aw envflows:default_max_ai_credits.AWF config mapping
apiProxy.maxAiCredits.maxAiCredits.apiProxy.maxEffectiveTokensis omitted when unset by configuration.Failure issue/comment overage reporting
ai_credits_rate_limit_error.md).