Skip to content

fix: extract sandbox.agent.memory from frontmatter so --memory-limit reaches AWF - #49448

Merged
pelikhan merged 5 commits into
mainfrom
copilot/fix-sandbox-agent-memory-issue
Aug 1, 2026
Merged

fix: extract sandbox.agent.memory from frontmatter so --memory-limit reaches AWF#49448
pelikhan merged 5 commits into
mainfrom
copilot/fix-sandbox-agent-memory-issue

Conversation

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

sandbox.agent.memory was declared, schema-documented, and consumed by the AWF arg builder, but extractAgentSandboxConfig never assigned it — causing --memory-limit to silently disappear from every compiled lock file.

Changes

  • Extraction (frontmatter_extraction_security.go): add memory extraction block in extractAgentSandboxConfig, mirroring the mounts/runtime pattern
  • Validation (sandbox_validation.go): add validateAgentMemoryLimit (reuses existing memoryLimitPattern) and call it from validateSandboxConfig — invalid formats (e.g. 48gb, 48) are rejected at compile time
  • Tests (frontmatter_extraction_security_test.go, sandbox_validation_test.go): extraction cases (valid string, absent, non-string), format validation cases, and integration through validateSandboxConfig
  • Docs (docs/reference/sandbox.md): document sandbox.agent.memory with valid format examples and a note on exit 137
sandbox:
  agent:
    memory: 8g   # now reaches awf as --memory-limit 8g

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Run: https://github.com/github/gh-aw/actions/runs/30680808859

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 6.35 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix sandbox.agent.memory extraction from frontmatter fix: extract sandbox.agent.memory from frontmatter so --memory-limit reaches AWF Aug 1, 2026
Copilot AI requested a review from pelikhan August 1, 2026 02:12
@pelikhan
pelikhan marked this pull request as ready for review August 1, 2026 02:36
Copilot AI review requested due to automatic review settings August 1, 2026 02:36

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes sandbox.agent.memory propagation so compiled AWF commands receive --memory-limit.

Changes:

  • Extracts and validates agent memory limits.
  • Adds extraction and validation tests.
  • Documents memory configuration and troubleshooting.
Show a summary per file
File Description
pkg/workflow/frontmatter_extraction_security.go Extracts the memory value.
pkg/workflow/frontmatter_extraction_security_test.go Tests memory extraction.
pkg/workflow/sandbox_validation.go Validates memory-limit syntax.
pkg/workflow/sandbox_validation_test.go Tests validation behavior.
docs/src/content/docs/reference/sandbox.md Documents memory limits.

Review details

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 5/5 changed files
  • Comments generated: 4
  • Review effort level: Balanced


// validateAgentMemoryLimit checks that a sandbox.agent.memory string has the correct format.
func validateAgentMemoryLimit(memory string) error {
if !memoryLimitPattern.MatchString(memory) {
Comment thread pkg/workflow/sandbox_validation.go Outdated
return NewValidationError(
"sandbox.agent.memory",
memory,
"memory value is not a valid limit. Expected a positive number followed by a unit: b, k, m, or g (e.g. \"4g\", \"512m\")",
Comment on lines +199 to +201
config := compiler.extractAgentSandboxConfig(agentObj)
require.NotNil(t, config, "Should extract agent sandbox config")
assert.Equal(t, "48g", config.Memory, "Should extract sandbox.agent.memory")
When omitted, AWF's own default memory limit applies. Specifying an invalid format (e.g., `48gb` or `48`) is rejected at compile time.

> [!NOTE]
> If your build tools (MSBuild, `csc`, large JVM processes) are killed with exit code 137, the container is hitting its memory limit. Set `memory` to match your runner's available RAM.
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Design Decision Gate 🏗️ completed the design decision gate check.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Test Quality Sentinel completed test quality analysis.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

PR Code Quality Reviewer completed the code quality review.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Review: fix: extract sandbox.agent.memory from frontmatter

The fix correctly adds the missing extraction and validation path. Four pre-existing inline comments call out issues that should be addressed:

  1. Schema/validator mismatch (sandbox_validation.go:457) — main_workflow_schema.json still accepts formats (e.g. 48gb, 0m, 08g) that the new validator rejects. These need to be aligned.
  2. Error message (sandbox_validation.go:461) — the guidance text does not mention the no-leading-zeros rule, so 08g looks valid to users.
  3. Test coverage gap (frontmatter_extraction_security_test.go:201) — no end-to-end test from workflow frontmatter to the compiled --memory-limit flag; adding one would prevent regression.
  4. Exit 137 docs (sandbox.md:163) — exit 137 is SIGKILL, not conclusively a container memory limit hit; the note should be qualified.

Item 1 (schema mismatch) is the most impactful: it causes silent divergence between editor validation and compile-time validation.

🧵 Reviewed using Impeccable skills by Impeccable Skills Reviewer · sonnet46 · 13.5 AIC · ⊞ 5.3K

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd — the fix is correct and well-tested. Four inline comments have been added (by a prior review pass) covering the most impactful issues; this review summarises the overall picture.

📋 Key Themes & Highlights

Issues to Address

  • Schema/validator mismatch: memoryLimitPattern rejects values (48gb, 0m, 08g) that the JSON schema still accepts — users will get a compile-time error with no schema-level warning in editors.
  • Error message clarity: The error message does not call out the leading-zero restriction, so 08g looks like it satisfies the guidance.
  • Integration test gap: Extraction tests call extractAgentSandboxConfig directly; no test compiles a full workflow and confirms --memory-limit appears in the generated lock file (the regression path from the linked issue).
  • Docs: exit 137 wording: Exit 137 = SIGKILL, which has multiple causes; the note should qualify that OOM is one possible cause, not the definitive one.

Positive Highlights

  • ✅ Root cause properly fixed — extraction was the missing link, not the arg builder
  • ✅ Mirrors the existing mounts/runtime pattern cleanly
  • ✅ Comprehensive unit test matrix (8 format cases + integration)
  • ✅ Compile-time rejection of invalid formats is the right UX

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 · 18.8 AIC · ⊞ 7K
Comment /matt to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧪 Test Quality Sentinel Report

Test Quality Score: 90/100 — Excellent

Analyzed 14 test(s): 14 design, 0 implementation, 0 violation(s).

📊 Metrics (14 tests)
Metric Value
Analyzed 14 (Go: 14, JS: 0)
✅ Design 14 (100%)
⚠️ Implementation 0 (0%)
Edge/error coverage 14 (100%)
Duplicate clusters 0
Inflation Yes (3.6:1 ratio)
🚨 Violations 0
Test File Classification Coverage
TestExtractAgentSandboxConfigMemory (3 subtests) frontmatter_extraction_security_test.go design_test Happy path (present value), edge cases (missing, wrong type)
TestValidateAgentMemoryLimit (9 table cases) sandbox_validation_test.go design_test Format validation: valid units, missing units, invalid suffixes, leading zeros, zero value, empty string
TestValidateSandboxConfigMemory (3 subtests) sandbox_validation_test.go design_test Integration: valid memory, invalid format with error message, absent memory

Analysis

All tests are design-level contract tests verifying user-facing behavior:

  • ✅ Extraction logic correctly reads and ignores non-string values
  • ✅ Validation enforces strict format (lowercase/uppercase units, no leading zeros, positive)
  • ✅ Integration tests confirm validation is wired into the sandbox config pipeline

Test inflation note: The 3.6:1 ratio (101 test lines / 28 production lines) is justified—this is a critical security and container-tuning feature requiring comprehensive edge-case coverage across extraction, validation, and integration layers. No redundant tests detected.

Code quality signal: All assertions include descriptive failure messages (per Go convention). No mock libraries used. Boundary testing is thorough.

Verdict

passed. 0% implementation tests (threshold: 30%). 14/14 design tests verify critical sandbox memory feature contracts.

@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (129 new lines in pkg/) but does not have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/49448-extract-sandbox-agent-memory-with-compile-time-validation.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the PR diff
  2. Complete the missing sections — add context the AI could not infer, refine the decision rationale, and list real alternatives you considered
  3. Commit the finalized ADR to docs/adr/ on your branch
  4. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-49448: Extract sandbox.agent.memory with Compile-Time Validation

Once an ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

❓ Why ADRs Matter

"AI made me procrastinate on key design decisions. Because refactoring was cheap, I could always say 'I'll deal with this later.' Deferring decisions corroded my ability to think clearly."

ADRs create a searchable, permanent record of why the codebase looks the way it does. Future contributors (and your future self) will thank you.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 0042-use-postgresql.md for PR #42).

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · sonnet46 · 39.7 AIC · ⌖ 23.8 AIC · ⊞ 9.6K ·
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

Verdict: Request changes

Core fix (wiring sandbox.agent.memory extraction to the already-existing AWF --memory-limit arg builder) is correct and well-tested at the unit level, but the new validation regex conflicts with the published JSON schema, and non-string YAML values silently bypass validation entirely.

💡 Themes
  • Schema/validator drift (blocking): memoryLimitPattern (^[1-9][0-9]*[bkmgBKMG]$) rejects 48gb/0m/08g/two-letter units, while main_workflow_schema.json still accepts them — editors and gh aw compile will disagree on the same input, and the docs' own "invalid" example is schema-valid.
  • Silent failure mode (blocking-adjacent): a non-string memory value (e.g. unquoted memory: 48) is dropped with no error and no validation, silently disabling the feature this PR exists to fix.
  • Minor: validateAgentMemoryLimit duplicates validateBoundedQueryMemoryLimit almost verbatim — worth consolidating to avoid future drift (as already demonstrated here).
  • Tests are solid at the extraction/validation unit level but don't exercise the full frontmatter → compile → AWF-args regression path the linked issue was about.

🔎 Code quality review by PR Code Quality Reviewer · auto · 40.2 AIC · ⊞ 7.8K
Comment /review to run again

}

// validateAgentMemoryLimit checks that a sandbox.agent.memory string has the correct format.
func validateAgentMemoryLimit(memory string) error {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Go regex is stricter than — and inconsistent with — the published JSON schema for the same field, so identical values pass one gate and fail the other.

💡 Details

memoryLimitPattern here is ^[1-9][0-9]*[bkmgBKMG]$ (single-letter units, no leading zero, no zero value), but pkg/parser/schemas/main_workflow_schema.json for sandbox.agent.memory still uses ^[0-9]+(b|k|m|g|kb|mb|gb|B|K|M|G|KB|MB|GB)$, which accepts 48gb, 0m, 08g, and two-letter units (kb/mb/gb) that the Go validator rejects, and also accepts 0m/08g which Go rejects.

Result: editor/IDE JSON-schema validation (via the schema) will happily accept memory: 48gb or memory: 0m, but gh aw compile then rejects them with a Go-level error — a confusing split-brain UX. The docs' own "rejected" example (48gb) is actually schema-valid, compounding the confusion.

Fix: align the schema pattern with memoryLimitPattern, or relax the Go validator to accept the schema's broader set (kb/mb/gb suffixes), and update the docs example accordingly so all three sources of truth agree.

}

// Extract memory (memory limit for the AWF container)
if memoryVal, hasMemory := agentObj["memory"]; hasMemory {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-string memory values (e.g. unquoted YAML memory: 48) are silently dropped — no warning, no error — and validation is skipped entirely.

💡 Details

if memoryStr, ok := memoryVal.(string); ok { ... } silently no-ops when the type assertion fails. A very plausible authoring mistake — writing memory: 48 instead of memory: "48g" — parses as a YAML int, fails the type check, and agentConfig.Memory stays empty. Since validateAgentMemoryLimit is only invoked when Memory != "", this bad input never triggers the intended validation error; the workflow just compiles with the default AWF memory limit and no diagnostic at all, silently defeating the entire feature this PR is meant to fix.

Suggested fix: when hasMemory is true but the type assertion fails, return/record a validation error (mirroring how invalid string values are already caught by validateAgentMemoryLimit) rather than silently ignoring it.

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

Warning

threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding.

Details

The threat detection engine failed to produce results.

Review the workflow run logs for details.

@copilot please run the pr-finisher skill, address the current blocking review feedback, refresh the branch if GitHub allows it, and rerun the relevant checks once ready. Current blockers include schema/validator drift for sandbox.agent.memory, missing end-to-end coverage from frontmatter to compiled --memory-limit, and the docs wording around exit 137. Run details: https://github.com/github/gh-aw/actions/runs/30680808859

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 6.35 AIC · ⊞ 8.1K ·
Comment /souschef to run again

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>

Copilot AI commented Aug 1, 2026

Copy link
Copy Markdown
Contributor Author

[!WARNING]
threat detection engine error
The threat detection engine encountered an error and could not complete analysis. This is a tooling failure, not a security finding....

Addressed in commit d70f34d.

  • Aligned sandbox.agent.memory schema pattern with validator (^[1-9][0-9]*[bkmgBKMG]$)
  • Updated validation message to explicitly require no leading zeros
  • Added end-to-end compile test asserting --memory-limit 48g is present in the generated lock file
  • Corrected docs wording for exit code 137 to note it is SIGKILL and not conclusive OOM proof

I also ran local validation (make fmt, make lint, targeted go test, make test, and make agent-report-progress) plus parallel_validation. This agent push won’t auto-rerun PR workflows, so CI on this new HEAD needs a maintainer-triggered rerun.

Copilot AI requested a review from gh-aw-bot August 1, 2026 03:23
@pelikhan
pelikhan merged commit 0c1d649 into main Aug 1, 2026
28 checks passed
@pelikhan
pelikhan deleted the copilot/fix-sandbox-agent-memory-issue branch August 1, 2026 03:38
@github-actions

github-actions Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.84.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sandbox.agent.memory is silently ignored: never extracted from frontmatter

4 participants