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 mView on GitHub (pinned to 12126d8942)
Solutions
- Adjust ExtractOutput to a supported signature (e.g. func ExtractOutput() T0 or (T0, error)) matching a generated wrapper variant.
- Remove the explicit ExtractOutput method and let the SDK use reflection-based defaults.
- Register custom types with register.Type / register.Function so type inference succeeds.
- 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
- Return a single value (optionally with error) from ExtractOutput.
- Register accumulator types so codegen can infer them.
- Test combiner registration in a tiny pipeline before deploying.
- Match method signatures to the Beam version's documented combiner interface.
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
- Failed to optimize AddInput for combiner %v. Failed to infer
- MergeAccumulators must be defined on accumulator %v
- the bound has overflown double type.
- Type interface{} isn't a supported PCollection type
- Iterators with timestamp values (<ET,V> and <ET, K, V>) are
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/985151915d5a4c00.
Report an issue: GitHub.