# Move replication RTC log-backup sync into workflow action

**Date**: 2026-05-20
**PR**: N/A
**Module**: `app/`
**Domain**: `BR`

---

## Background

`replicationRTCModifierImpl` in `app/models/backup/impl/replication_rtc.go` currently does two different jobs: it performs the prepare-phase model update and also mutates running log-backup snapshots before dispatching the workflow. The actual RTC change is applied later by `modifyReplicationRTCAction` in the workflow layer, so the log-backup snapshot sync belongs with that action-side effect instead of the model transaction.

This refactor keeps business behavior unchanged while moving the side effect to the worker that performs the AWS change. It also splits the workflow action's `run` method into smaller helpers so the idempotency path, validation path, and action path remain easier to review and test.

---

## Analysis

### Impact Table

| Area | File | Change | Verification | Success Criteria |
|------|------|--------|--------------|------------------|
| Model prepare path | `app/models/backup/impl/replication_rtc.go` | Remove `logBackupRepo` dependency and `updateRunningLogBackupSnapshots`, keep transaction focused on entity update + DAG creation | `go test ./app/models/backup/impl -run '^TestReplicationRTCModifierSuite$'` | Model tests pass without any log-backup repo expectations |
| Model wiring | `app/models/backup/impl/backup_setting.go` | Stop passing `logBackupRepo` into the replication RTC modifier proxy and trim constructor usage only if unused elsewhere | `go test ./app/models/backup/impl -run '^TestReplicationRTCModifierSuite$'` | Constructor still compiles and model package tests pass |
| Workflow action | `app/workflow/action/backup_setting/modify_replication_rtc.go` | Add `logBackupRepo`, split `run` into helpers, move snapshot sync beside AWS/DB side effect | `go test ./app/workflow/action/backup_setting -run '^TestModifyReplicationRTCActionSuite$'` | Action tests cover enable/disable/idempotent paths and log-backup sync |
| DAG wiring | `app/workflow/dag/backup_setting/aws/modify_replication_rtc.go` | Pass `container.Global().LogBackupRepo` into `NewModifyReplicationRTCAction` | `go test ./app/workflow/dag/backup_setting/aws ./app/workflow/action/backup_setting -run '^TestModifyReplicationRTCActionSuite$'` | Workflow packages compile with updated constructor |
| Regression coverage | `app/models/backup/impl/replication_rtc_test.go`, `app/workflow/action/backup_setting/modify_replication_rtc_test.go` | Move expectations from model tests into action tests | `make app-unit-test-local` | Full app unit test target passes |

### Dead Code Cascade

- **Remove** model-layer `updateRunningLogBackupSnapshots` because it is no longer responsible for workflow side effects.
- **Remove** `logBackupRepo` from `replicationRTCModifierImpl`, `newAWSModifyReplicationRTC`, and `newReplicationRTCModifierProxy`.
- **Keep** the model-layer RTC prepare flow and DAG creation logic unchanged so the public behavior of `ModifyReplicationRTC` remains stable.

### Symbols To Keep / Introduce / Remove

- **Keep**: `replicationRTCModifierImpl.execute`, `modifyReplicationRTCAction.Run`, `modifyReplicationRTCAction.run`
- **Introduce**: `loadAndValidate`, `ensureIdempotent`, `applyRTCChange`, workflow-layer `updateRunningLogBackupSnapshots`
- **Remove**: model-layer `updateRunningLogBackupSnapshots`, model-layer `logBackupRepo` field/constructor arg

---

## Execution Steps

1. **Update tests first for the new responsibility split**
   - Remove log-backup repo expectations from `app/models/backup/impl/replication_rtc_test.go`.
   - Add log-backup repo wiring and snapshot-sync assertions in `app/workflow/action/backup_setting/modify_replication_rtc_test.go`.
   - Verification: `go test ./app/models/backup/impl ./app/workflow/action/backup_setting -run 'TestReplicationRTCModifierSuite|TestModifyReplicationRTCActionSuite'`
   - Success criteria: tests fail only because production code still has the old constructor/layout, proving the new expectations exercise the refactor boundary.

2. **Move the snapshot sync from model to workflow action**
   - Remove the model-layer repo field, helper, and transaction call from `app/models/backup/impl/replication_rtc.go`.
   - Update constructor/proxy signatures in `app/models/backup/impl/replication_rtc.go` and `app/models/backup/impl/backup_setting.go`.
   - Add `logBackupRepo` and helper methods to `app/workflow/action/backup_setting/modify_replication_rtc.go`.
   - Verification: `go test ./app/models/backup/impl ./app/workflow/action/backup_setting -run 'TestReplicationRTCModifierSuite|TestModifyReplicationRTCActionSuite'`
   - Success criteria: targeted model/action suites pass with the new ownership split.

3. **Update workflow wiring and format touched files**
   - Pass `container.Global().LogBackupRepo` from `app/workflow/dag/backup_setting/aws/modify_replication_rtc.go`.
   - Run `gofmt -w` on all modified Go files.
   - Verification: `go test ./app/workflow/dag/backup_setting/aws ./app/workflow/action/backup_setting -run '^TestModifyReplicationRTCActionSuite$'`
   - Success criteria: workflow packages compile and action tests still pass after formatting.

4. **Run repository verification and prepare commit**
   - Execute the repository-standard unit test target, inspect the diff, and commit only the intended refactor.
   - Verification: `make app-unit-test-local`
   - Success criteria: command exits 0, modified files match the planned scope, and commit message clearly describes the refactor.

---

## Risk Assessment

| Risk | Likelihood | Impact | Mitigation |
|------|-----------|--------|------------|
| Model no longer updates log-backup snapshots before workflow dispatch, changing execution timing | Medium | Medium | Keep the snapshot sync in the workflow action immediately after the AWS/DB update and cover it in action tests |
| Constructor signature drift breaks workflow/model wiring | Medium | Medium | Update all call sites together and run targeted package tests before full-suite verification |
| Helper-method split changes idempotent behavior in `modifyReplicationRTCAction.run` | Low | Medium | Preserve existing branches exactly and assert both idempotent and AWS-call paths in the action suite |
