apache/beam · error

Invalid to nest WindowedValue

Error message

Invalid to nest WindowedValue

What it means

FullType.New forbids a WindowedValue component whose own element is another WindowedValue; nesting windowing wrappers is unsupported and panics. Window metadata exists at most once per value in the SDK's type model.

Source

Thrown at sdks/go/pkg/beam/core/typex/fulltype.go:138

		default:
			panic(fmt.Sprintf("Unexpected aggregate type: %v", t))
		}
	case Composite:
		switch t {
		case KVType:
			if len(components) != 2 {
				panic(fmt.Sprintf("Invalid number of components for KV: %v, %v", t, components))
			}
			if isAnyNonKVAndNonWindowedComposite(components) {
				panic(fmt.Sprintf("Invalid to nest composite composites inside KV: %v, %v", t, components))
			}
			return &tree{class, t, components}
		case WindowedValueType:
			if len(components) != 1 {
				panic("Invalid number of components for WindowedValue")
			}
			if components[0].Type() == WindowedValueType {
				panic("Invalid to nest WindowedValue")
			}
			return &tree{class, t, components}
		case CoGBKType:
			if len(components) < 2 {
				panic(fmt.Sprintf("Invalid number of components for CoGBK: %v", t))
			}
			if isAnyNonKVComposite(components) {
				panic(fmt.Sprintf("Invalid to nest composites inside CoGBK: %v", t))
			}
			return &tree{class, t, components}
		case TimersType:
			return &tree{class, t, components}
		case ShardedKeyType:
			if len(components) != 1 {
				panic(fmt.Sprintf("Invalid number of components for ShardedKey: %v, %v", t, components))
			}
			if components[0].Class() == Composite {
				panic(fmt.Sprintf("Invalid to nest composite inside ShardedKey: %v, %v", t, components))

View on GitHub (pinned to 12126d8942)

Solutions

  1. Remove the redundant windowing step; window a PCollection only once.
  2. Unwrap to the inner element type before applying another WindowInto.
  3. If layered windowing semantics are needed, merge window assignments instead of nesting types.

Example fix

// before
typex.New(typex.WindowedValueType, typex.New(typex.WindowedValueType, elemFT)) // nested: panics
// after
typex.New(typex.WindowedValueType, elemFT)
Defensive patterns

Strategy: validation

Validate before calling

if components[0].Type() == typex.WindowedValueType {
	return errors.New("cannot nest WindowedValue inside WindowedValue")
}

Prevention

When it happens

Trigger: Calling typex.New with WindowedValueType where components[0].Type() == WindowedValueType — i.e. the wrapped element is itself windowed, typically after multiple windowing passes or manual re-wrapping of already-windowed types.

Common situations: Applying beam.WindowInto to a PCollection already producing WindowedValue types; custom transforms re-wrapping values with additional window metadata.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/beam@12126d8942 (2026-09-13). Data as JSON: /api/errors/c53360993c331459. Report an issue: GitHub.