{"record":{"id":"96bb74caaa0821e1","repo":"apache/beam","slug":"failed-to-optimize-mergeaccumulators-for-combiner-v-failed","errorCode":null,"errorMessage":"Failed to optimize MergeAccumulators for combiner %v. Failed to infer types","messagePattern":"Failed to optimize MergeAccumulators for combiner (.+?)\\. Failed to infer types","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/register/register.go","lineNumber":7894,"sourceCode":"\t\t\t\treturn fn.(mergeAccumulators2x2[T0]).MergeAccumulators(a0, a1)\n\t\t\t})\n\t\t}\n\t} else if _, ok := accum.(mergeAccumulators2x1[T0]); ok {\n\t\tcaller := func(fn any) reflectx.Func {\n\t\t\tf := fn.(func(T0, T0) T0)\n\t\t\treturn &caller2x1[T0, T0, T0]{fn: f}\n\t\t}\n\t\treflectx.RegisterFunc(reflect.TypeOf((*func(T0, T0) T0)(nil)).Elem(), caller)\n\n\t\tmergeAccumulatorsWrapper = func(fn any) reflectx.Func {\n\t\t\treturn reflectx.MakeFunc(func(a0 T0, a1 T0) T0 {\n\t\t\t\treturn fn.(mergeAccumulators2x1[T0]).MergeAccumulators(a0, a1)\n\t\t\t})\n\t\t}\n\t}\n\n\tif mergeAccumulatorsWrapper == nil {\n\t\tpanic(fmt.Sprintf(\"Failed to optimize MergeAccumulators for combiner %v. Failed to infer types\", accum))\n\t}\n\n\tvar createAccumulatorWrapper func(fn any) reflectx.Func\n\tif _, ok := accum.(createAccumulator0x2[T0]); ok {\n\t\tcaller := func(fn any) reflectx.Func {\n\t\t\tf := fn.(func() (T0, error))\n\t\t\treturn &caller0x2[T0, error]{fn: f}\n\t\t}\n\t\treflectx.RegisterFunc(reflect.TypeOf((*func() (T0, error))(nil)).Elem(), caller)\n\n\t\tcreateAccumulatorWrapper = func(fn any) reflectx.Func {\n\t\t\treturn reflectx.MakeFunc(func() (T0, error) {\n\t\t\t\treturn fn.(createAccumulator0x2[T0]).CreateAccumulator()\n\t\t\t})\n\t\t}\n\t} else if _, ok := accum.(createAccumulator0x1[T0]); ok {\n\t\tcaller := func(fn any) reflectx.Func {\n\t\t\tf := fn.(func() T0)","sourceCodeStart":7876,"sourceCodeEnd":7912,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/register/register.go#L7876-L7912","documentation":"During combiner registration, register.go tries to optimize MergeAccumulators by type-asserting the accumulator against generated mergeAccumulatorsNxM shapes. If none match (mergeAccumulatorsWrapper stays nil), it panics because the combiner's accumulator merge signature cannot be inferred and no optimized wrapper can be built.","triggerScenarios":"Registering a combiner (via beam.CombineWithContext/register combinators) whose accumulator type does not implement any enumerated mergeAccumulatorsNxM interface — e.g. MergeAccumulators with an unexpected parameter/return combination or a custom accumulator type not tied to the combiner's generic T0.","commonSituations":"Custom combiners with non-standard MergeAccumulators signatures (extra parameters, non-pair returns), generic combiners instantiated with types that never satisfy mergeAccumulators2x1[T0], or copying combiner code across Beam versions where the enumerated shapes changed.","solutions":["Implement MergeAccumulators with the canonical signature: MergeAccumulators(a, b A) (A, error) or (a, b A) A, matching the accumulators type used in CreateAccumulator/AddInput","Ensure the combiner is registered with register.Combiner/register.DoFn generics so T0 binds to the accumulator type","Compare your merge method against the mergeAccumulatorsNxM assertions above line 7894 in register.go","Check for Beam version drift between combiner helper signatures"],"exampleFix":"// before\nfunc (fn *avgFn) MergeAccumulators(a, b AvgAccum) (AvgAccum, bool) { ... }\n// after\nfunc (fn *avgFn) MergeAccumulators(a, b AvgAccum) (AvgAccum, error) { ... }","handlingStrategy":"validation","validationCode":"var _ interface { MergeAccumulators(a, b MyAccum) (MyAccum, error) } = (*myCombiner)(nil)","typeGuard":"func isMergeable2x1[T any](c any) bool {\n\t_, ok := c.(interface {\n\t\tMergeAccumulators(a, b T) (T, error)\n\t})\n\treturn ok\n}","tryCatchPattern":"defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"combiner registration failed: %v\", r) } }()","preventionTips":["Use canonical MergeAccumulators(a, b A) (A, error) or (a, b A) A signatures","Keep accumulator type consistent across CreateAccumulator/AddInput/MergeAccumulators/ExtractOutput","Assert combiner interfaces at compile time","Test combiner registration before running pipelines"],"tags":["go","apache-beam","combiner","reflection","panic"],"backgroundTag":"unable-to-infer-types","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}