# Resume and auto-resume

A run can stop before the end: the daily lookup limit is reached, a credit limit is hit, you cancel it, or
some lookups fail. The rows already done are kept, and the run can **continue where it stopped**. Rows
already looked up are neither looked up again nor charged again.

## Resume by running it again

Run the same call again: same tool, input table, columns, options and output table. If the previous run
stopped early, or had failed lookups, the app continues it:

```sql
CALL TOMBA.core.find_emails('CRM.PUBLIC.LEADS', 'COMPANY_DOMAIN', 'FIRST_NAME', 'LAST_NAME', 'LEADS_FOUND', 100000);
-- ... stops at the daily limit. Tomorrow, the same call continues it:
CALL TOMBA.core.find_emails('CRM.PUBLIC.LEADS', 'COMPANY_DOMAIN', 'FIRST_NAME', 'LAST_NAME', 'LEADS_FOUND', 100000);
```

The summary shows `resumed: true`, `rows_already_done`, and the new rows looked up. Rows marked `skipped` or
`error` are retried; `found`, `not_found` and `invalid` rows are kept.

When the previous run **finished cleanly**, or you change the tool, columns or options, the output table is
replaced instead.

## Resume a specific run

```sql
CALL TOMBA.core.resume_run('<run_id>');
```

Find run ids in `TOMBA.core.runs`, or use **Resume** on the History page.

## Auto-resume

Runs that stopped for a temporary reason resume **by themselves**:

| Stopped because                                    | Auto-resumes                            |
| -------------------------------------------------- | --------------------------------------- |
| The daily lookup limit was reached                 | Yes, after it resets at 00:00 UTC       |
| The monthly credit budget was reached              | Yes, when a new month starts            |
| Some lookups failed (network, temporary errors)    | Yes                                     |
| The run was interrupted (timeout)                  | Yes                                     |
| You cancelled it                                   | No                                      |
| The run's credit limit (`max_credits`) was reached | No: resume it yourself if you want more |
| The Tomba quota or the install was refused         | No: contact support                     |

The app checks every day at **00:05 UTC** and tries each run up to **3 times**. Auto-resume uses the app's
background task, so it needs the task privileges (see
[Installation](./installation#2-approve-the-connection-and-the-privileges)).

Turn it on or off for one run:

```sql
CALL TOMBA.core.set_auto_resume('<run_id>', FALSE);
```

The History page has the same **Auto-resume** switch.

## See what stopped and why

```sql
SELECT run_id, tool, output_table, status, stop_kind, auto_resume, rows_total, message
  FROM TOMBA.core.runs
 WHERE status IN ('PARTIAL', 'FAILED', 'CANCELLED', 'ABANDONED')
 ORDER BY started_at DESC;
```
