apache/beam · error

Failed to optimize ExtractOutput for combiner %v. Failed to

Error message

Failed to optimize ExtractOutput for combiner %v. Failed to infer types

What it means

This panic is raised by Apache Beam Go SDK's generated combiner wrapper code when the accumulator type has an ExtractOutput method but no type-specialized wrapper could be generated for it. The template only instantiates wrappers for a fixed set of ExtractOutput signatures; an unrecognized signature leaves extractOutputWrapper nil and the code panics rather than producing a broken combiner.

Source

Thrown at sdks/go/pkg/beam/register/register.tmpl:521

				return fn.(extractOutput1x2[T0, T2]).ExtractOutput(a0)
			})
		}
    } else if _, ok := accum.(extractOutput1x1[T0, T2]); ok {
        caller := func(fn any) reflectx.Func {
            f := fn.(func(T0) T2)
            return &caller1x1[T0, T2]{fn: f}
        }
		reflectx.RegisterFunc(reflect.TypeOf((*func(T0) T2)(nil)).Elem(), caller)

        extractOutputWrapper = func(fn any) reflectx.Func {
			return reflectx.MakeFunc(func(a0 T0) T2 {
				return fn.(extractOutput1x1[T0, T2]).ExtractOutput(a0)
			})
		}
    } {{end}}

    if m := accumVal.MethodByName("ExtractOutput"); m.IsValid() && extractOutputWrapper == nil {
        panic(fmt.Sprintf("Failed to optimize ExtractOutput for combiner %v. Failed to infer types", accum))
    }

	wrapperFn := func(fn any) map[string]reflectx.Func {
		m := map[string]reflectx.Func{}
		if mergeAccumulatorsWrapper != nil {
			m["MergeAccumulators"] = mergeAccumulatorsWrapper(fn)
		}
		if createAccumulatorWrapper != nil {
			m["CreateAccumulator"] = createAccumulatorWrapper(fn)
		}
		if addInputWrapper != nil {
			m["AddInput"] = addInputWrapper(fn)
		}
		if extractOutputWrapper != nil {
			m["ExtractOutput"] = extractOutputWrapper(fn)
		}

		return m

View on GitHub (pinned to 12126d8942)

Solutions

  1. Adjust ExtractOutput to a supported signature (e.g. func ExtractOutput() T0 or (T0, error)) matching a generated wrapper variant.
  2. Remove the explicit ExtractOutput method and let the SDK use reflection-based defaults.
  3. Register custom types with register.Type / register.Function so type inference succeeds.
  4. Pin compatible Beam SDK version matching your combiner's method shapes.

Example fix

// before
func (a *acc) ExtractOutput() (int64, int, error) { return a.sum, a.n, nil }

// after
func (a *acc) ExtractOutput() int64 { return a.sum / int64(a.n) }
Defensive patterns

Strategy: validation

Validate before calling

// Verify ExtractOutput returns at most one value plus optional error
m := reflect.ValueOf(myAcc{}).MethodByName("ExtractOutput")
if m.IsValid() {
    t := m.Type()
    if t.NumOut() > 2 {
        panic("ExtractOutput must return (T) or (T, error)")
    }
}

Type guard

func hasSupportedExtractOutput(acc any) bool {
    m := reflect.ValueOf(acc).MethodByName("ExtractOutput")
    if !m.IsValid() { return true }
    t := m.Type()
    return t.NumOut() == 1 || (t.NumOut() == 2 && t.Out(1) == reflect.TypeOf((*error)(nil)).Elem())
}

Try / catch

// Validate combiner shape at process start
func init() {
    if !hasSupportedExtractOutput(myAcc{}) {
        panic("combiner ExtractOutput signature unsupported by beam codegen")
    }
}

Prevention

When it happens

Trigger: Using beam.Combine with a combiner whose accumulator defines ExtractOutput with a return type or arity that does not match any generated variant (e.g. ExtractOutput returning three values or unregistered custom types), triggering the MethodByName("ExtractOutput") check with a nil wrapper.

Common situations: Custom combiners written against an older Beam template shape, accumulator methods returning multiple values, or using types not registered with the SDK so codegen cannot infer them.

Understand the failure class

Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.

Related errors


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