When duplicating a layer with layer attribute, caught an assert hit at `attribute_to_writer()` due to size mismatch between attribute domain (layers count) and attribute length. Now fixed by moving `add_node()` prior to `foreach_attribute()`. This way, extra node already added to runtime data and layer count is updated inside `ensure_nodes_cache` with the next layers() call Noticed it during review of !141090 Pull Request: https://projects.blender.org/blender/blender/pulls/141722