Integrate state preservation into propagation worker

Summary

When the propagation worker overwrites a descendant's state, preserve the descendant's previous state in state_metadata so it can be restored if the parent operation is cancelled.

Tasks

  • Before each batch UPDATE, read the current states of the namespaces being updated
  • For each namespace whose state will change, write the previous state to state_metadata under preserved_states using the existing StatePreservation concern
  • When propagating active (restore/unarchive), clear preserved_states from state_metadata since descendants are being restored to their default state
  • Ensure state preservation writes are done in the same transaction as the state UPDATE
  • Add specs covering:
    • Previous state preserved when overwritten by propagation
    • Preserved state cleared when propagating active
    • Correct preserved state for nested hierarchies (e.g., archived subgroup inside deletion_scheduled parent)

References

Edited by 🤖 GitLab Bot 🤖