{"record":{"id":"6d5d811b0d7ee499","repo":"vitessio/vitess","slug":"failed-to-marshal-pk-fields-and-value-into-query-r","errorCode":null,"errorMessage":"failed to marshal pk fields and value into query result: %s","messagePattern":"failed to marshal pk fields and value into query result: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"go/vt/vttablet/tabletmanager/vreplication/vcopier.go","lineNumber":666,"sourceCode":"\t\t\t\t\tterrs = append(terrs, result.err)\n\t\t\t\t}\n\t\t\t}\n\t\tdefault:\n\t\t\tempty = true\n\t\t}\n\t}\n\tif terr := formatTaskError(terrs); terr != nil {\n\t\tlog.Warn(fmt.Sprintf(\"task error in workflow %s: %v\", vc.vr.WorkflowName, terr))\n\t\treturn terr\n\t}\n\n\t// Get the last committed pk into a loggable form.\n\tlastpkbuf, merr := prototext.Marshal(&querypb.QueryResult{\n\t\tFields: pkfields,\n\t\tRows:   []*querypb.Row{lastpk},\n\t})\n\tif merr != nil {\n\t\treturn fmt.Errorf(\"failed to marshal pk fields and value into query result: %s\", merr.Error())\n\t}\n\tlastpkbv := map[string]*querypb.BindVariable{\n\t\t\"lastpk\": {\n\t\t\tType:  sqltypes.VarBinary,\n\t\t\tValue: lastpkbuf,\n\t\t},\n\t}\n\n\t// A context expiration was probably caused by a PlannedReparentShard or an\n\t// elapsed copy phase duration. Those are normal, non-error interruptions\n\t// of a copy phase.\n\tselect {\n\tcase <-ctx.Done():\n\t\tlog.Info(fmt.Sprintf(\"Copy of %v stopped at lastpk: %v\", tableName, lastpkbv))\n\t\treturn nil\n\tdefault:\n\t}\n\tif serr != nil {","sourceCodeStart":648,"sourceCodeEnd":684,"githubUrl":"https://github.com/vitessio/vitess/blob/01a25a7d176f94613b8d59d799f438380a8760e4/go/vt/vttablet/tabletmanager/vreplication/vcopier.go#L648-L684","documentation":"At the end of copying a table, vcopier logs the last copied primary key by marshalling the PK fields and last row into a prototext QueryResult. If prototext.Marshal fails (unexpected), copyTable returns this wrapping error instead of losing the progress log.","triggerScenarios":"prototext.Marshal of &querypb.QueryResult{Fields: pkfields, Rows: []*querypb.Row{lastpk}} returns an error in copyTable; this is nearly always caused by malformed protobuf state (e.g. nil/invalid field descriptors) rather than user input.","commonSituations":"Very rare; indicates an internal bug, corrupted plan metadata (bad pkfields), or a binary/protobuf version mismatch between components.","solutions":["Collect vttablet logs and report — this indicates an internal inconsistency in the copy plan's pkfields","Restart the workflow copy phase to rebuild the plan from current schema","Ensure all Vitess components run the same version to avoid protobuf mismatches"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := copyTable(ctx, ...); err != nil {\n  if strings.Contains(err.Error(), \"failed to marshal pk fields\") {\n    // log and report: internal protobuf inconsistency; restart copy phase\n  }\n  return err\n}","preventionTips":["Run same-version Vitess components","Avoid manual edits to _vt.copy_state rows","Report occurrences as bugs with full logs"],"tags":["vreplication","vcopier","protobuf","logging"],"backgroundTag":"protobuf-marshal-failed","analyzedSha":"01a25a7d176f94613b8d59d799f438380a8760e4","analyzedAt":"2026-09-01T17:28:30.605Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}