SERP API workflows should recover a partial batch by reconciling each expected logical task, not by submitting the original batch again. Freeze the original manifest, preserve accepted SERP API batch results, classify every unresolved task, retry only the eligible subset, and close the run only when every expected task has either one accepted result or an explicit terminal disposition.
That requires three separate layers of state. The run says whether the batch is collecting, recovering, reconciling, or closed. The logical task says whether one requested SERP observation was accepted, exhausted, permanently failed, or canceled. The attempt says what happened to a particular submission or retry. If those layers are collapsed into one status field, a provider-level completed label can hide missing tasks, and a timed-out attempt can be mistaken for a permanently failed task even though its result may still arrive.
This separation is the recovery layer for asynchronous SERP collection, where provider tasks can finish independently and their results can reach the workflow through different delivery paths.
The recovery invariant is simple: do not lose a valid success, do not retry an ineligible failure, do not accept the same logical task twice, and do not call the run complete while expected work is still unresolved.
The Short Answer: Recover Tasks, Not the Whole Batch
A partial batch is a reconciliation problem. The workflow already knows what it intended to collect, so recovery should compare that expected set with what was actually accepted.
Use this sequence:
- Freeze the batch manifest and its expected logical task IDs.
- Record every submitted provider task ID as an attempt under a logical task.
- Preserve accepted results and remove their logical task IDs from recovery consideration.
- Classify every remaining task as still in flight, retryable, non-retryable, validation-blocked, canceled, or unknown.
- Build a retry set from retryable logical tasks only.
- Reconcile original and retry attempts through one atomic acceptance rule.
- Close the run only when the expected count balances and no task remains unresolved.
| Recovery question | Required answer |
|---|---|
| What work was expected? | A frozen manifest with a stable logical task ID for every query and search context. |
| What succeeded? | Accepted result IDs linked to logical tasks, not just a provider batch count. |
| What failed? | A classified failure with retryability and a reason. |
| What is still uncertain? | An explicit unresolved state, not a guessed failure or empty result. |
| What may be retried? | Only tasks that have no accepted result and meet the retry policy. |
| When is recovery finished? | Every expected task has one accepted result or one terminal non-success disposition. |
Resubmitting the original batch because one task failed is the main red flag. It can repeat successful searches, create competing results for the same query and collection window, and may create additional provider charges. Recovery should operate on task identity, not on the convenience of replaying the original payload.
Decision rule: if the workflow cannot name the exact logical tasks that remain unresolved, it is not ready to retry anything.
Keep Run, Task, and Attempt States Separate
The batch run, logical task, and attempt answer different questions. Their states may change independently, so each layer needs its own record.
| State layer | Identity | Useful states | Invariant |
|---|---|---|---|
| Batch run | run_id plus manifest identity |
collecting, recovering, reconciling, closed_complete, closed_with_failures |
A run cannot close while any expected logical task is unresolved. |
| Logical task | Stable logical_task_id inside the run |
expected, unresolved, retryable, validation_blocked, accepted, retry_exhausted, permanent_failure, canceled |
At most one result may be accepted for the task. |
| Attempt | attempt_id plus provider task ID |
submitted, processing, succeeded, retryable_failed, nonretryable_failed, timed_out, superseded |
Every retry is traceable to the same logical task without replacing earlier attempt history. |
A logical task represents the observation the workflow intended to collect. Its identity should include or point to the SERP API request context for the exact query, search engine or surface, country, language, location when relevant, device, page or result depth, and planned collection window. If downstream automation may act on an owned page, the task context should also carry a clear target_url.
An attempt represents one execution of that intent. The provider may assign a different task ID when the workflow retries, but the internal logical_task_id should stay stable. This is what lets the system recognize that the original attempt and the retry compete to satisfy the same unit of expected work.
Keep these control fields separate:
| Field | What it controls |
|---|---|
execution_status |
Whether this attempt was submitted, processed, failed, timed out, or completed. |
validation_status |
Whether the returned SERP is acceptable for the intended downstream decision. |
accepted_result_id |
The single result selected to satisfy the logical task. |
attempt_number |
The order of attempts under the logical task. |
retry_class |
Whether another attempt is allowed and why. |
terminal_disposition |
Why a task with no accepted result will receive no more attempts in this run. |
Do not make timed_out a terminal logical-task outcome by default. It describes an attempt from the caller's perspective. The provider may still be processing it, or the result may have completed while its response or callback was lost.
Practical takeaway: the run can be recovering while one task is accepted, another is permanent_failure, and two attempts for a third task are still competing. That is not contradictory when the layers are modeled separately.
Detect Incomplete Work Before Declaring the Batch Partial
The SERP API query manifest is the source of truth for completeness. Provider status, HTTP status, callback delivery, and parsed result counts are evidence about execution, but none of them independently proves that all expected work was resolved.
At minimum, the manifest should preserve:
| Manifest field | Why recovery needs it |
|---|---|
run_id |
Keeps one recovery cycle separate from earlier or later collections. |
manifest_id or checksum |
Proves which frozen expected set is being reconciled. |
logical_task_id |
Gives each requested observation a durable internal identity. |
| Request scope | Preserves query, market, language, location, device, page, and result depth. |
required_for_release |
Distinguishes tasks that block downstream use from optional tasks. |
target_url when applicable |
Prevents mixed-site automation from acting on an unspecified page. |
| Planned collection window | Stops a later retry from being silently treated as the original timed observation. |
Calculate completeness from task dispositions:
expected = accepted + permanent_failure + retry_exhausted + canceled + unresolved
The run is operationally closable only when unresolved = 0 and every expected logical task appears exactly once in that reconciliation. A task cannot be counted in both accepted and retry_exhausted, and two attempts cannot contribute two accepted results to the same logical task.
| Observed signal | What it proves | Recovery interpretation |
|---|---|---|
| The submission returned HTTP success. | The outer request was accepted or answered. | Inspect every task; the batch can still contain errors or omissions. |
| The provider labels the job completed. | The provider considers its job terminal under its contract. | Compare returned task identities with the manifest before closing. |
| A task is still processing. | It has no terminal provider result yet. | Keep it unresolved; poll or wait according to the delivery contract. |
| A callback did not arrive. | Delivery was not observed. | Look up the task before deciding it failed. |
| A completed-task list does not contain the ID yet. | The task is not currently discoverable through that path. | Allow for documented discovery delay; do not convert absence directly into failure. |
| A result array is empty. | No parsed items were returned. | Accept only if successful execution, scope, and validation prove a genuine empty SERP outcome. |
| A result failed validation. | Execution produced a response that is unsafe for the intended use. | Keep execution and acceptance separate; classify the cause before retrying. |
Consider a hypothetical run with eight logical tasks. Tasks T1 through T4 return valid SERPs and become accepted. T5 returns an explicitly transient provider failure. T6 contains an invalid location and cannot succeed unchanged. T7 has no delivered result and still appears in processing state. T8 completes, but the response lacks required request scope and cannot pass validation.
The run has four accepted tasks, one retryable task, one permanent failure for the current manifest, and two tasks that still block closure: T7 is in flight, while T8 is validation-blocked. The run is not ready to close. Recovery should retry T5, keep checking T7, and decide whether T8 needs recollection, manual review, or a terminal non-success disposition. T1 through T4 should remain untouched.
Red flag: a batch percentage is not a completeness model. A count such as seven returned results out of eight expected tasks cannot explain which task is missing, whether an empty result is legitimate, or whether one task was delivered twice.
Preserve Successes and Classify Every Non-Success
Accepted successes should become durable before recovery begins. Store the accepted result, its request scope, collected_at, provider task ID, attempt ID, validation status, and raw payload reference when retained. Then exclude that logical task from every retry query.
Execution success is not the same as result acceptance. The provider may finish a task that returns the wrong scope, malformed fields, an unexplained empty result, or data that is too stale for the decision. That is where SERP API data validation controls whether a completed response may become the accepted observation. Recovery should consume that validation decision without expanding into a second general validation system.
Use a classification table that leads to one action:
| Observed task state | Logical-task classification | Action |
|---|---|---|
| Completed response passes the required scope, status, result, and freshness checks. | accepted |
Persist it and exclude the task from retries. |
| Network interruption, rate limit, temporary provider error, or explicit retryable task status. | retryable |
Retry within the run's bounded policy. |
| Invalid parameters, unsupported market, authorization problem, or deterministic schema mapping defect. | nonretryable |
Fix the cause; do not resend the same request unchanged. |
| Provider still reports queued or processing. | in_flight |
Wait, poll, or use the documented result lookup path. |
| Callback is missing and provider state is unknown. | unknown |
Reconcile provider state before choosing retry or failure. |
| Execution completed, but the result fails acceptance checks. | validation_blocked |
Recollect only if a new attempt can address the cause; otherwise review or terminate. |
| Attempt budget is exhausted after retryable failures. | retry_exhausted |
Stop retrying and record the final reason. |
| The task was intentionally stopped under a documented cancellation rule. | canceled |
Record a terminal disposition and exclude it from retries. |
Some parameter failures require a corrected task, not a retry. If changing location, language, device, query, result depth, or collection window changes the intended observation, version the logical task or place it in a new run. Calling the changed request another attempt hides that the workflow asked a different question.
A valid empty SERP also needs careful handling. An empty list can be an accepted result when the provider completed the exact requested scope and the response contract proves that no supported results were found. It should not be accepted merely because the parser returned an empty array.
Decision rule: retry an execution problem only when another execution of the same logical intent can reasonably succeed. Fix or replace a task when the intent or request contract itself is wrong.
Retry Only the Failed Subset Without Creating Duplicates
The retry set should be derived, not hand-built. Select logical tasks that meet all of these conditions:
accepted_result_idis null;- no terminal disposition exists;
retry_classis retryable;- the task is not still in flight under the provider contract;
- the run's attempt or time budget has not been exhausted.
For every selected task, carry forward the original query, engine or surface, country, language, location, device, page, result depth, collection intent, run ID, and logical task ID. Preserve target_url when the batch may support owned-page automation. Dropping scope during recovery can produce a technically successful SERP that no longer satisfies the original task.
Assign a new internal attempt_id to the retry. Keep the logical_task_id stable. The provider's idempotency key requires a separate decision because providers do not all implement the same replay semantics.
| Situation | Identity behavior | Why |
|---|---|---|
| The submission response was lost, so the caller does not know whether the same request was accepted. | Replay the same body with the same idempotency key only when the provider documents that behavior. | This is a replay of an uncertain submission, not a new logical attempt. |
| The provider returned an explicit retryable terminal failure. | Create a new internal attempt; choose the provider key according to its documented failed-request replay rules. | Reusing the old key may replay the old failure instead of starting new work. |
| Request parameters must change. | Create a new or versioned logical task rather than hiding the change inside an attempt. | The requested observation is no longer semantically identical. |
| A valid result is already accepted. | Do not submit another request. | The logical task is already satisfied. |
Duplicate prevention must also work when polling, callbacks, and retries race. Use an atomic acceptance operation keyed by (run_id, logical_task_id). The operation should:
- confirm that no
accepted_result_idis already set; - confirm that the candidate attempt belongs to the logical task;
- confirm that the result passes the task's acceptance policy;
- set
accepted_result_idand the accepted attempt in one transaction; - mark other non-terminal attempts as
cancel_requestedorsupersededwhen appropriate.
If another result wins the race first, the losing attempt should remain recorded but must not create another ranking row, alert input, source queue item, or AI evidence record for the same logical task.
Practical rule: idempotency protects a submission operation; a stable logical task key and atomic acceptance protect the batch result. A reliable workflow usually needs both.
Reconcile Late Original Results and Retry Results
A timeout or missing callback does not guarantee that the original task stopped. The original result can arrive after a retry has been submitted, after the retry has completed, or even after the run has closed. The workflow needs a predeclared rule for each case.
Store enough attempt context to compare the candidates:
| Field | Reconciliation use |
|---|---|
logical_task_id |
Proves that the results compete for the same expected work. |
attempt_id and provider task ID |
Keeps each execution traceable. |
requested_at |
Shows when each attempt began. |
collected_at |
Identifies when the SERP was actually observed. |
received_at |
Shows delivery order without pretending it is collection order. |
validation_status |
Prevents an early malformed result from winning. |
raw_payload_ref |
Supports investigation when the results differ materially. |
disposition |
Records whether the attempt was accepted, late, superseded, rejected, or retained for review. |
Those fields also determine whether two responses are retry artifacts or distinct snapshots. Apply the same scope and timing checks used to compare repeated SERP API requests before interpreting their differences as ranking movement.
For most recovery runs, the first policy-compliant result to complete the atomic acceptance operation should satisfy the logical task. "First" should not mean the first network payload blindly. It means the first candidate that matches the frozen scope, belongs to the collection contract, and passes the required validation gate.
Return to hypothetical task T7. Suppose it reaches the recovery cutoff with no delivered result, so the workflow submits attempt A2. A2 returns a valid SERP and atomically claims accepted_result_id. Later, original attempt A1 arrives with its own valid response. Store A1 as late_valid_superseded; do not overwrite the accepted result and do not count both observations in the same batch.
The two SERPs may differ because they were collected at different times. That does not automatically make either response corrupt. If the difference matters to rank history, freshness, or an alert, retain the late response as a separately labeled capture or route it to review. Do not silently substitute it into the recovered batch.
If A1 arrives and is accepted before A2 completes, mark A2 superseded and cancel it when the provider supports safe cancellation. If cancellation is not possible, allow it to finish but prevent it from claiming the logical task.
After a run is closed, a late callback should be recorded against the closed run but should not reopen it automatically. Reopening can cause downstream reports, alerts, and AI workflows to change after they were released. Use an explicit correction path that records who or what reopened the run, which accepted result changed, and which downstream outputs need recomputation.
Decision rule: late delivery changes attempt history. It changes the accepted batch result only through an explicit, auditable correction policy.
Red Flags That Should Stop or Downgrade Recovery
Selective recovery is unsafe when the system cannot reconstruct stable task identity or the original collection contract. In that case, quarantine the run and start a clearly identified replacement batch rather than pretending that a blind replay is precise recovery.
| Red flag | Risk | Safer action |
|---|---|---|
| The manifest changed after submission. | Expected work cannot be reconciled against one stable set. | Freeze a version and recover only against that version. |
| Successful tasks are included in the retry payload. | Duplicate collection and competing accepted results. | Remove every task with an accepted result before submission. |
| Missing tasks are immediately labeled failed. | A late original and a retry may both complete. | Reconcile provider state and apply an unresolved cutoff first. |
| One status field represents run, task, attempt, and validation. | A terminal label at one layer hides open work at another. | Split the state layers before automating recovery. |
| The workflow branches on human-readable error text. | Wording changes can alter retry behavior. | Use documented codes or internally normalized failure classes. |
| The same idempotency key is reused for a known failed attempt without checking provider semantics. | The provider may replay the failure or reject the request. | Separate uncertain submission replay from a new recovery attempt. |
| The accepted result can be overwritten by a later callback. | Historical rankings and downstream decisions can change silently. | Use atomic acceptance and an explicit correction workflow. |
Request scope or target_url is missing. |
A recovered response may be routed to the wrong market, device, or owned page. | Downgrade to exploration or block owned-page automation. |
| The run closes with unresolved tasks. | Missing work is hidden inside a terminal batch label. | Keep the run reconciling or assign documented terminal dispositions. |
Do not use selective retry when a logical task cannot be reconstructed from the original request. A query string alone is not enough if market, language, location, device, result depth, or collection window changed the meaning of the SERP. Preserve any already accepted evidence, but do not merge a replacement collection into the old run without labeling it.
Stop condition: if the workflow cannot prove task identity, retry eligibility, and single-result acceptance, pause automation. Another request will add data but will not repair the missing control model.
Close the Run With a Reconciliation Record
Closing a run is a state transition, not a timeout side effect. The final reconciliation should satisfy this equation:
expected_count = accepted_count + permanent_failure_count + retry_exhausted_count + canceled_count
It should also prove that unresolved_count = 0, every logical task belongs to exactly one final category, and every accepted task has exactly one accepted_result_id.
Use two terminal run states rather than calling every reconciled batch successful:
| Run state | Meaning | Downstream implication |
|---|---|---|
closed_complete |
Every expected logical task has an accepted result. | The batch may proceed if its separate release and validation rules pass. |
closed_with_failures |
Reconciliation is finished, but one or more tasks ended as permanent failure, retry exhausted, or canceled. | Downstream use must apply required-task and partial-data policy. |
The reconciliation record should preserve:
run_id, manifest ID or checksum, and manifest version;- expected and final per-outcome counts;
- every logical task ID and its terminal category;
- accepted result IDs and accepted attempt IDs;
- failure class and final reason for tasks without results;
- retry lineage and provider task IDs;
closed_atand the policy version used to close;- late-result and correction dispositions;
- the downstream release decision.
Run the final go or no-go process step by step:
- Confirm that the manifest is frozen and its expected count matches the task ledger.
- Confirm that every expected logical task has one final category.
- Confirm that no logical task has more than one accepted result.
- Confirm that no retryable or in-flight attempt remains unresolved.
- Confirm that every accepted result passed the required acceptance gate.
- Confirm that all required tasks succeeded, or apply the declared partial-release rule.
- Confirm that owned-page actions have a clear
target_url; otherwise keep the output exploratory. - Write the reconciliation record, set the terminal run state, and prevent automatic reopening by late delivery.
Operational closure and downstream release are different decisions. A run can be correctly closed_with_failures while a client-facing report remains blocked because one required market is missing. An exploratory competitor scan may tolerate a failed optional task if the output is labeled partial. A ranking alert should not quietly treat missing required tasks as no visibility. An owned-page recommendation should remain blocked when the evidence cannot be tied to the intended target_url.
The durable recovery pattern is therefore not "retry until the batch looks full." It is: preserve what is already trustworthy, account for every expected task, retry only what can safely improve, accept one result per logical task, record late arrivals without rewriting history, and close the run only when the ledger balances.
Want more SEO data?
Get started with seodataforai →