Prevent lost updates to loan variable-rate schedules

Merged
BE
11d ago
+1187-45

Fixes #4442.

Serialize loan term and rate-schedule updates with one Account β†’ Loan lock order across forms, Redbark and Plaid. Refresh before reading the rate, deciding whether it changed and saving. Keep field locks, provenance and rollback of account/loan writes.

Reconcile form edits against their original snapshot so unrelated provider additions survive. Explicit edits still win for the user. A row deleted in the form is removed only if it still holds the rate the form saw; if a provider corrected that date in the meantime, the provider's value is kept. Reject old submissions without a snapshot before writing, preserve failed-form rows for retry, and reconcile each submission once so rendering cannot duplicate validation errors.

Merged current main df79e067c. #4395 has merged, so Plaid now writes through LoanTermWriter; its two saves run under Loan#with_schedule_lock, so the variable-rate decision reads the schedule under the lock. No migration or dependency is needed.

After deploy: loan edit forms opened before this change don't have the new hidden rate_schedule_snapshot field. When one of those forms submits rate changes, it is rejected once with loans.edit.stale_rate_schedule. Nothing is written: the account, the balance and DataEnrichment all stay unchanged. The re-rendered form shows what is stored now, so the user's other edits in that submission are lost and need to be entered again after a reload. This is intentional: a submission with no snapshot can't tell which provider rows it saw, so rejecting it is the only safe option.

@coderabbitai ignore