Skip to content

Consolidate wazero guard runtime/module config and disable DWARF debug info by default - #11505

Merged
lpcox merged 5 commits into
mainfrom
copilot/go-fan-module-review
Aug 19, 2026
Merged

Consolidate wazero guard runtime/module config and disable DWARF debug info by default#11505
lpcox merged 5 commits into
mainfrom
copilot/go-fan-module-review

Conversation

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

The wazero module review flagged duplicated runtime/module construction across production and test code, and suggested disabling DWARF debug info for the production guard compiler since guard binaries are untrusted artifacts whose stack traces are never symbolicated.

Production (internal/guard/wasm_lifecycle.go)

  • Extracted newGuardRuntimeConfig(opts): compiler engine, WithCloseOnContextDone(true), WithMemoryLimitPages(guardMemoryLimitPages) (named constant replacing the inline 512), and the three-way compilation-cache selection (opt-out / injected / global).
  • Debug info is now disabled unless guard debug logging is on (WithDebugInfoEnabled(logWasm.Enabled())), so DWARF parsing cost is skipped in production while remaining available under DEBUG=guard:wasm.
  • Extracted newGuardModuleConfig(name, stdout, stderr) so the WithStartFunctions() suppression and stdin/stdout isolation guarantees are defined once.
  • Added getGlobalCompilationCache(), which reads the process-global cache under the existing mutex. Previously the cache was read unlocked while ConfigureGlobalCompilationCache / CloseGlobalCompilationCache could concurrently swap it.
runtimeConfig := wazero.NewRuntimeConfigCompiler().
    WithCloseOnContextDone(true).
    WithMemoryLimitPages(guardMemoryLimitPages).
    WithDebugInfoEnabled(logWasm.Enabled())

Tests

  • New wasm_testruntime_test.go provides newTestWasmRuntime, newTestWasmModuleConfig, instantiateTestWasmModule, and setupTestWasmGuard. The near-identical setupRawWasmModule / setupWasmGuard helpers and the inline interpreter constructions in wasm_test.go now route through them, removing the test/production config drift risk called out in the review.
  • New wasm_config_test.go covers module-name defaulting ("""guard") and instantiation through each cache-selection path of the runtime config builder.

Disk-backed caching (recommendation 3) is left as-is: it is already opt-in via MCP_GATEWAY_WASM_CACHE_DIR / ConfigureGlobalCompilationCache, and changing the default is a deployment-policy decision rather than a code fix.

Copilot AI linked an issue Aug 19, 2026 that may be closed by this pull request
Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
Copilot AI changed the title [WIP] Review Go module tetratelabs/wazero Consolidate wazero guard runtime/module config and disable DWARF debug info by default Aug 19, 2026
Copilot AI requested a review from lpcox August 19, 2026 14:06
@lpcox
lpcox marked this pull request as ready for review August 19, 2026 14:37
Copilot AI balanced review requested due to automatic review settings August 19, 2026 14:37

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

Consolidates wazero guard configuration to reduce drift and disable unnecessary DWARF processing by default.

Changes:

  • Centralizes production runtime, module, and cache configuration.
  • Adds shared WASM test helpers.
  • Adds coverage for module naming and cache-selection paths.
Show a summary per file
File Description
internal/guard/wasm_lifecycle.go Centralizes wazero configuration and synchronizes cache reads.
internal/guard/wasm_testruntime_test.go Adds shared test runtime helpers.
internal/guard/wasm_config_test.go Tests runtime and module configuration.
internal/guard/wasm_test.go Adopts shared test helpers.
internal/guard/wasm_dispatch_test.go Reuses centralized guard setup.
internal/guard/wasm_parse_coverage_test.go Reuses centralized guard setup.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Balanced

Comment thread internal/guard/wasm_testruntime_test.go Outdated
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lpcox

lpcox commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

@copilot resolve the merge conflicts in this pull request

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Resolved the merge conflicts and pushed merge commit 1b011ef. Validation passed: go test ./internal/guard ./internal/config ./internal/cmd, CodeQL found 0 alerts, and make agent-finished completed successfully.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@lpcox

lpcox commented Aug 19, 2026

Copy link
Copy Markdown
Collaborator

Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>

Copilot AI commented Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

@copilot fix the failing ci checks https://github.com/github/gh-aw-mcpg/actions/runs/32266659434/job/96113498889?pr=11505 https://github.com/github/gh-aw-mcpg/actions/runs/32266651262/job/96113486100...

Fixed in 3fed... — the lint failure was an unused newTestInterpreterRuntime helper left in internal/guard/wasm_test.go after consolidating test runtime construction into the new shared helpers; removed it and confirmed golangci-lint run is clean and make agent-finished passes.

The race-test failure (TestValidateAgainstCustomSchema_RemoteRefByteBudgetIsEnforced in internal/config) is unrelated to this PR — no commits here touch that file, and it passes consistently locally (10+ runs, with and without -race). This looks like CI flakiness; will keep an eye on the next run.

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — default

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: default AWF (normal container isolation)

Part Surface Op Result Expected Status
A MCP reads (list_issues/prs/commits, get_file_contents) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) tools absent from catalog BLOCKED ⚠️
C CLI reads (list_issues, get_file_contents) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) gh unauthenticated BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) gh unauthenticated BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Gaps:

  • Part B: All 7 write tools absent from the MCP catalog (backend launched with GITHUB_READ_ONLY=1). This confirms the gh-aw framework defense-in-depth, but the gateway's own independent DIFC/guard enforcement layer was not exercised — write tool calls never reached a write-capable backend. Reported as INCONCLUSIVE per methodology.
  • Parts D/E: gh CLI is not authenticated in this environment (no GH_TOKEN). The REST/GraphQL token-scope boundary could not be validated. All D/E rows are INCONCLUSIVE.

No writes leaked. No FAIL conditions observed.

References: §32268247381

🔒 mcpg read-only stress (default AWF runtime) by Read-Only Stress: default runtime

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — gVisor

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: gVisor (runsc) kernel-level isolation

Part Surface Op Result Expected Status
A MCP list_issues 3 issues returned ALLOWED
A MCP list_pull_requests 3 PRs returned ALLOWED
A MCP get_file_contents (README.md) content returned ALLOWED
A MCP list_commits 3 commits returned ALLOWED
B MCP add_issue_comment unknown tool — absent from backend catalog BLOCKED ⚠️
B MCP star_repository unknown tool — absent from backend catalog BLOCKED ⚠️
B MCP issue_write (create) unknown tool — absent from backend catalog BLOCKED ⚠️
B MCP create_branch unknown tool — absent from backend catalog BLOCKED ⚠️
C CLI (github) list_issues data returned ALLOWED
C CLI (github) get_file_contents data returned ALLOWED
D CLI (gh) reaction/star/issue/comment/file writes gh unauthenticated (no GH_TOKEN) BLOCKED ⚠️
E CLI (gh) GraphQL addReaction/addStar/createIssue gh unauthenticated (no GH_TOKEN) BLOCKED ⚠️

Overall: INCONCLUSIVE

⚠️ Gaps to note:

  • Part B: All write MCP tools (add_issue_comment, star_repository, issue_write, create_branch, create_or_update_file, create_pull_request) returned Error [-32602]: unknown tool — absent from the backend catalog because GITHUB_READ_ONLY=1 prevents the GitHub MCP server from registering write tools. This confirms the gh-aw framework defense-in-depth, but does not independently confirm mcpg's own DIFC/guard layer since write calls never reach a write-capable backend.
  • Parts D & E: gh CLI has no GH_TOKEN set in this environment. All gh api write attempts returned "set the GH_TOKEN environment variable" without reaching GitHub API. Cannot confirm token-scope boundary enforcement.

No writes succeeded. No data was created, modified, or leaked.

🔒 mcpg read-only stress (gVisor runtime) by Read-Only Stress: gVisor runtime

@github-actions

Copy link
Copy Markdown
Contributor

🔒 mcpg Read-Only Stress — docker-sbx

Surface coverage: MCP tool calls + proxied CLI (REST) + GraphQL mutations
Isolation runtime: docker-sbx (KVM-isolated microVM)

Part Surface Op Result Expected Status
A MCP reads (issues/PRs/file/commits) data returned ALLOWED
B MCP writes (reaction/star/issue/comment/branch/file/PR) all 7 tools absent from catalog BLOCKED ⚠️
C CLI reads (issues, file contents) data returned ALLOWED
D CLI REST writes (reaction/star/issue/comment/file) 401 Bad credentials BLOCKED ⚠️
E CLI GraphQL mutations (addReaction/addStar/createIssue) 401 Bad credentials BLOCKED ⚠️

Overall: INCONCLUSIVE

Gaps:

  • ⚠️ Part B: All 7 write tools absent from MCP catalog. The GitHub MCP backend runs with GITHUB_READ_ONLY=1 (gh-aw framework guarantee), so write tools are never registered. This confirms the backend defense-in-depth but cannot independently confirm mcpg DIFC/guard enforcement since write calls never reach a write-capable backend. Tracked as methodology gap.
  • ⚠️ Parts D/E: gh token invalid (Bad credentials). All REST/GraphQL write attempts returned 401 — unauthenticated rejections, not gateway enforcement. No write leaked, but token-scope boundary could not be validated for this run.

No writes succeeded. All reads returned data.

🔒 mcpg read-only stress (docker-sbx runtime) by Read-Only Stress: docker-sbx runtime

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.

[go-fan] Go Module Review: tetratelabs/wazero

3 participants