You need to either use only the `.dataProvider()` (`QgsVectorDataProvider`) methods which call the underlying data and modify it or use the edit methods of `QgsVectorLayer`.

so, either :
```py
layer = iface.activeLayer()
layer.startEditing()
all_features = layer.getFeatures()
for feat in all_features:
    geom = feat.geometry()
    x = geom.asPoint().x()
    y = geom.asPoint().y()
    
    feat.setAttribute('x', x)
    feat.setAttribute('y', y)
    
    layer.updateFeature(feat)
 
# Commit changes
layer.commitChanges()
```
or
```py
layer = iface.activeLayer()
all_features = layer.getFeatures()
for feat in all_features:
    geom = feat.geometry()
    x = geom.asPoint().x()
    y = geom.asPoint().y()
    
    new_xy = {
        feat.fieldNameIndex('x'): x, 
        feat.fieldNameIndex('y'): y
    }
    layer.dataProvider().changeAttributeValues({feat.id(): new_xy }
```