Quick note: When I mention "raws entry" I'm referring to the df.global.world.raws.creatures.all[number].raws dealy (sorry, don't know technical programming terms
)
I did a bit of investigation into how saving changes to creatures works and this is how I understand the process of saving and loading creatures works based off of the results:
When the game loads:
For any creature that isn't Generated, the game loads the raws from the save's raw/objects folder into the raws entry.
Generated creature information is stored somewhere separately and their raws are loaded into their raws entry.
The creature's information is then built using the information in the raws entry (flags set, etc.)
When the game saves:
If the creature doesn't have the GENERATED flag set (note: GENERATED flag, rather than [GENERATED] token in raws entry), it doesn't save any changes (flag changes, additions/edits to the raw entry, etc.).
If the creature has the GENERATED flag set, the game will save the creature's raws entry (including edits) to the special location Generated creatures are saved.
I think it might also be here where the Generated creatures are sorted into their neat little groups, though that might happen during loading, I'm not sure. Generated race ids are always added as a group onto the end of the regular creatures - if a creature wasn't a Generated creature prior to being saved with the Generated flag set, its race id is changed to suit wherever the grouping process deems fit to place it (Generated creatures without the other flags seem to go at the beginning of the list, before CASTE_FEATURE_BEASTs).
An interaction of note: Because the game only checks for the GENERATED flag to determine a creature should be saved as a Generated creature, it's entirely possible for it to save a creature whose raws entry lack the [GENERATED] tag. When the game is next loaded, the creature is built again and won't have the GENERATED flag set during the building process, meaning its raws entry will no longer be saved during the next save. If the creature was originally a normal creature it means that the next time it's loaded it'll use the raws from the save's raw/objects folder like normal (though it keeps the new race id if it got moved when Generated creatures were grouped). If the creature was originally a Generated creature I'd assume the game would just crash, but I haven't tested it