Skip to content

Tighten wazero guard lifecycle semantics and document start suppression#7275

Open
Copilot wants to merge 2 commits into
mainfrom
copilot/go-fan-review-wazero-module
Open

Tighten wazero guard lifecycle semantics and document start suppression#7275
Copilot wants to merge 2 commits into
mainfrom
copilot/go-fan-review-wazero-module

Conversation

Copilot AI commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

This PR addresses the wazero review follow-ups in the guard runtime: it makes guard failure state observable, aligns test/runtime configuration, and hardens cleanup behavior during cancellation. It also documents one non-obvious instantiation choice that is easy to regress during future refactors.

  • Guard lifecycle

    • add (*WasmGuard).IsHealthy() bool to expose whether a prior WASM trap has poisoned the instance
    • preserve cleanup on shutdown by closing the module/runtime with context.WithoutCancel(ctx), so caller cancellation does not skip resource release
  • Instantiation behavior

    • document why WithStartFunctions() is called with no args: guard load should not auto-run _start and accidentally block on stdin or perform side effects during instantiation
  • Test fidelity

    • switch the context-cancellation test to wazero.NewRuntimeConfigCompiler() so it matches production runtime construction
    • add focused coverage for IsHealthy() and for closing a guard after the caller context has already been cancelled
moduleConfig := wazero.NewModuleConfig().
    WithName(name).
    // WithStartFunctions with no args suppresses automatic _start execution
    // so guard loading cannot block on stdin or perform unexpected I/O.
    WithStartFunctions()

func (g *WasmGuard) IsHealthy() bool {
    g.mu.Lock()
    defer g.mu.Unlock()
    return !g.failed
}

Copilot AI linked an issue Jun 9, 2026 that may be closed by this pull request
6 tasks
GitHub Advanced Security started work on behalf of lpcox June 9, 2026 15:25 View session
GitHub Advanced Security finished work on behalf of lpcox June 9, 2026 15:27
Copilot AI changed the title [WIP] Review wazero module for DIFC security integration Tighten wazero guard lifecycle semantics and document start suppression Jun 9, 2026
Copilot AI requested a review from lpcox June 9, 2026 15:35
Copilot finished work on behalf of lpcox June 9, 2026 15:35
GitHub Advanced Security started work on behalf of lpcox June 9, 2026 15:44 View session
GitHub Advanced Security finished work on behalf of lpcox June 9, 2026 15:45
@lpcox lpcox marked this pull request as ready for review June 10, 2026 13:44
Copilot AI review requested due to automatic review settings June 10, 2026 13:44

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

This PR tightens WASM guard lifecycle behavior in internal/guard by preventing unintended _start execution during instantiation, exposing guard “poisoned” state after traps, and ensuring cleanup proceeds even when callers cancel contexts.

Changes:

  • Suppress automatic WASM _start execution during guard instantiation via WithStartFunctions() and document the rationale.
  • Add (*WasmGuard).IsHealthy() bool to expose whether a prior WASM trap has permanently failed the guard.
  • Improve shutdown/cancellation fidelity by closing module/runtime with context.WithoutCancel(ctx) and aligning a cancellation test with the compiler runtime config.
Show a summary per file
File Description
internal/guard/wasm.go Documents _start suppression, adds IsHealthy(), and hardens cleanup to ignore caller cancellation during Close.
internal/guard/wasm_test.go Updates runtime config in cancellation test and adds coverage for IsHealthy() plus Close behavior under canceled contexts.

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants