# RetrySyncJob

## Permission Scope

marketplace

## Overview

RetrySyncJob replays a previously failed, partial, or cancelled sync job using controlled idempotency. It creates a new running attempt while preserving traceability to the original job.

## Business Rules

- Only FAILED, PARTIALLY_SUCCEEDED, or CANCELLED jobs may be retried.
- Retry must preserve the same channel and execution direction.
- Retry logic must reuse idempotent channel-order identities instead of blindly duplicating records.

## Process Flow

```mermaid
flowchart TD
    A[Receive retry request] --> B[Load sync job]
    B --> C{Status retryable?}
    C -->|No| D[Return INVALID_SYNC_JOB_STATUS]
    C -->|Yes| E[Create new RUNNING retry attempt]
    E --> F[Replay sync workload with idempotent keys]
    F --> G[Return retried job]
```

## External Dependencies

- [getSyncJob](../query/GetSyncJob.md) - Load the original sync job and retry context.

## Error Scenarios

- **SYNC_JOB_NOT_FOUND**: Referenced sync job does not exist.
- **INVALID_SYNC_JOB_STATUS**: Sync job is not in a valid status for this operation

## Test Cases

- retries a failed sync job
- retries a partially succeeded sync job
- throws when sync job is still running
- preserves idempotent identity during retry
