apache/beam · error
Failed to optimize AddInput for combiner %v. Failed to infer
Error message
Failed to optimize AddInput for combiner %v. Failed to infer types
What it means
Panicked from register.Combiner1/Combiner2 in register.go. After failing to build a typed AddInput wrapper, the code checks reflectively whether the combiner has an AddInput method at all; if it does but the method doesn't satisfy addInput2x2[T0,T0] (AddInput(T0, T0) (T0, error)) or addInput2x1[T0,T0] (AddInput(T0, T0) T0) for the inferred types, registration panics with this message.
Source
Thrown at sdks/go/pkg/beam/register/register.go:7955
return fn.(addInput2x2[T0, T0]).AddInput(a0, a1)
})
}
} else if _, ok := accum.(addInput2x1[T0, T0]); ok {
caller := func(fn any) reflectx.Func {
f := fn.(func(T0, T0) T0)
return &caller2x1[T0, T0, T0]{fn: f}
}
reflectx.RegisterFunc(reflect.TypeOf((*func(T0, T0) T0)(nil)).Elem(), caller)
addInputWrapper = func(fn any) reflectx.Func {
return reflectx.MakeFunc(func(a0 T0, a1 T0) T0 {
return fn.(addInput2x1[T0, T0]).AddInput(a0, a1)
})
}
}
if m := accumVal.MethodByName("AddInput"); m.IsValid() && addInputWrapper == nil {
panic(fmt.Sprintf("Failed to optimize AddInput for combiner %v. Failed to infer types", accum))
}
var extractOutputWrapper func(fn any) reflectx.Func
if _, ok := accum.(extractOutput1x2[T0, T0]); ok {
caller := func(fn any) reflectx.Func {
f := fn.(func(T0) (T0, error))
return &caller1x2[T0, T0, error]{fn: f}
}
reflectx.RegisterFunc(reflect.TypeOf((*func(T0) (T0, error))(nil)).Elem(), caller)
extractOutputWrapper = func(fn any) reflectx.Func {
return reflectx.MakeFunc(func(a0 T0) (T0, error) {
return fn.(extractOutput1x2[T0, T0]).ExtractOutput(a0)
})
}
} else if _, ok := accum.(extractOutput1x1[T0, T0]); ok {
caller := func(fn any) reflectx.Func {
f := fn.(func(T0) T0)View on GitHub (pinned to 12126d8942)
Solutions
- Make AddInput match `func (c *C) AddInput(accum T, input T) T` or `func (c *C) AddInput(accum T, input T) (T, error)` with T equal to the first type parameter.
- If input type differs from accumulator type, use register.Combiner2[AccumT, InputT] instead of Combiner1.
- Verify AddInput takes exactly two parameters and returns the accumulator type (optionally with error).
- Drop AddInput if unused, or implement one of the register package's addInput interfaces explicitly to catch signature drift at compile time.
Example fix
// before
func (c *Avg) AddInput(a float64, v int) float64 { return a + float64(v) }
register.Combiner1[float64](&Avg{})
// after
func (c *Avg) AddInput(a float64, v float64) float64 { return a + v }
register.Combiner1[float64](&Avg{}) Defensive patterns
Strategy: validation
Validate before calling
func validateAddInput[T0 any](c any) bool {
_, ok1 := c.(interface{ AddInput(T0, T0) T0 })
_, ok2 := c.(interface{ AddInput(T0, T0) (T0, error) })
return ok1 || ok2
}
// call before register.Combiner1[T0](&c{}); panic in a test if false Type guard
func hasTypedAddInput[T0 any](c any) bool {
_, ok1 := c.(interface{ AddInput(T0, T0) T0 })
_, ok2 := c.(interface{ AddInput(T0, T0) (T0, error) })
return ok1 || ok2
} Prevention
- Keep AddInput's parameter and return types identical to the accumulator type parameter.
- Use Combiner2[AccumT, InputT] whenever input type differs from accumulator type.
- Add compile-time assertions for the addInput interfaces your combiner intends to satisfy.
- Test registration in unit tests by invoking the register call directly.
When it happens
Trigger: register.Combiner1[T](&c{}) or Combiner2 where c.AddInput has a signature other than `(T0, T0) T0` or `(T0, T0) (T0, error)` — e.g. AddInput(accum T0, input T1) with a distinct input type while using Combiner1, extra parameters, or return type not matching T0.
Common situations: Using Combiner1 for a combiner whose input type differs from accumulator type (needs Combiner2); AddInput defined with a value receiver type vs pointer mismatch is not the issue here but wrong generic parameters are; hand-written CombineFn ported from Java/Python with a differently shaped AddInput.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Failed to optimize ExtractOutput for combiner %v. Failed to
- panic(formatParDoError(dofn, len(ret), 3))
- panic(formatParDoError(dofn, len(ret), 4))
- panic(formatParDoError(dofn, len(ret), 5))
- panic(formatParDoError(dofn, len(ret), 6))
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/dcb0a527b0b832cf.
Report an issue: GitHub.