{"record":{"id":"7f204a52925f2a4c","repo":"apache/beam","slug":"expected-wv-coder-for-user-state-v-v","errorCode":null,"errorMessage":"expected WV coder for user state %v: %v","messagePattern":"expected WV coder for user state (.+?): (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/runtime/exec/userstate.go","lineNumber":648,"sourceCode":"type UserStateAdapter interface {\n\tNewStateProvider(ctx context.Context, reader StateReader, w typex.Window, element any) (stateProvider, error)\n}\n\ntype userStateAdapter struct {\n\tsid                StreamID\n\twc                 WindowEncoder\n\tkc                 ElementEncoder\n\tstateIDToCoder     map[string]*coder.Coder\n\tstateIDToKeyCoder  map[string]*coder.Coder\n\tstateIDToCombineFn map[string]*graph.CombineFn\n\tc                  *coder.Coder\n}\n\n// NewUserStateAdapter returns a user state adapter for the given StreamID and coder.\n// It expects a W<V> or W<KV<K,V>> coder, because the protocol requires windowing information.\nfunc NewUserStateAdapter(sid StreamID, c *coder.Coder, stateIDToCoder map[string]*coder.Coder, stateIDToKeyCoder map[string]*coder.Coder, stateIDToCombineFn map[string]*graph.CombineFn) UserStateAdapter {\n\tif !coder.IsW(c) {\n\t\tpanic(fmt.Sprintf(\"expected WV coder for user state %v: %v\", sid, c))\n\t}\n\n\twc := MakeWindowEncoder(c.Window)\n\tvar kc ElementEncoder\n\tif coder.IsKV(coder.SkipW(c)) {\n\t\tkc = MakeElementEncoder(coder.SkipW(c).Components[0])\n\t}\n\treturn &userStateAdapter{sid: sid, wc: wc, kc: kc, c: c, stateIDToCoder: stateIDToCoder, stateIDToKeyCoder: stateIDToKeyCoder, stateIDToCombineFn: stateIDToCombineFn}\n}\n\n// NewStateProvider creates a stateProvider with the ability to talk to the state API.\nfunc (s *userStateAdapter) NewStateProvider(ctx context.Context, reader StateReader, w typex.Window, element any) (stateProvider, error) {\n\tif s.kc == nil {\n\t\treturn stateProvider{}, fmt.Errorf(\"cannot make a state provider for an unkeyed input %v\", element)\n\t}\n\telementKey, err := EncodeElement(s.kc, element.(*MainInput).Key.Elm)\n\tif err != nil {\n\t\treturn stateProvider{}, err","sourceCodeStart":630,"sourceCodeEnd":666,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/runtime/exec/userstate.go#L630-L666","documentation":"NewUserStateAdapter builds a state adapter for Beam Go user state. The runner protocol requires state coders to carry windowing information, so the coder must be a W<V> or W<KV<K,V>> wrapper. If coder.IsW(c) is false, the library panics because state without window encoding cannot round-trip correctly.","triggerScenarios":"Calling exec.NewUserStateAdapter with a coder that is not a windowed coder (e.g. a plain V or KV<K,V> coder) instead of coder.NewW(...) of the value coder.","commonSituations":"Constructing state adapters manually in custom runners or tests; passing a coder produced by graphx without wrapping; migrating pipelines between SDK versions where state coder wrapping conventions changed.","solutions":["Wrap the coder with coder.NewW(valueCoder) before passing it to NewUserStateAdapter","Verify with coder.IsW(c) and inspect coder.SkipW(c) to confirm the inner coder is V or KV<K,V>","Ensure the pipeline graph is built via the standard graphx/translate path, which applies window wrapping automatically"],"exampleFix":"// before\nexec.NewUserStateAdapter(sid, kvCoder, ...)\n// after\nexec.NewUserStateAdapter(sid, coder.NewW(kvCoder), ...)","handlingStrategy":"validation","validationCode":"if !coder.IsW(c) { return fmt.Errorf(\"state coder must be windowed: %v\", c) }\nexec.NewUserStateAdapter(sid, c, ...)","typeGuard":"func isWindowedCoder(c *coder.Coder) bool { return coder.IsW(c) }","tryCatchPattern":"defer func() { if r := recover(); r != nil { err = fmt.Errorf(\"user state adapter: %v\", r) } }()","preventionTips":["Always wrap state coders with coder.NewW","Assert coder.IsW in unit tests around state adapters","Let the standard translate pipeline construct coders"],"tags":["go","apache-beam","coder","panic"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}