Work Run Correction API Error Guide

Use this page when a developer script handles Work Run correction failures across create, list, apply, reject, and retry-request. The operation pages show the full happy paths; this guide keeps the shared error, retry, request ID, idempotency, expected-version, expected_work_run_version, and pagination rules in one place.

Current status: the examples below are source-publication examples tied to the site-side fixture in docs-api/work-run-correction-openapi-sdk-fixtures.json. Exact operation IDs, auth scopes, production schemas, Problem extension names, generated SDK methods, and hosted API docs remain pending until retvest-platform commits the reviewed OpenAPI snapshot and downstream contract fixtures exist for consumers.

Do not use this page as customer automation proof, legal approval, production installation proof, or a claim that generated correction SDK methods are available.

Contract Fixture Source

Keep public examples aligned with the checked contract fixture names below. They are intentionally synthetic and metadata-bounded: no bearer tokens, tenant identifiers, raw customer documents, generated answers, citation bodies, private evidence refs, idempotency-key values from production, or full UUID-heavy payload dumps.

Operation Success fixture ID Problem fixture IDs checked by this repo
Create pending correction work-run-correction.create.success.v1 work-run-correction.create.validation-failed.v1, work-run-correction.create.idempotency-conflict.v1, work-run-correction.create.forbidden.v1, work-run-correction.create.tenant-mismatch.v1, work-run-correction.create.rate-limited.v1, work-run-correction.create.unavailable.v1, work-run-correction.create.timeout.v1
List correction history work-run-correction.list.success-page.v1 work-run-correction.list.invalid-cursor.v1, work-run-correction.list.forbidden.v1, work-run-correction.list.tenant-mismatch.v1, work-run-correction.list.rate-limited.v1, work-run-correction.list.unavailable.v1, work-run-correction.list.timeout.v1
Apply pending correction work-run-correction.apply.success.v1 work-run-correction.apply.validation-failed.v1, work-run-correction.apply.version-conflict.v1, work-run-correction.apply.invalid-transition.v1, work-run-correction.apply.idempotency-conflict.v1, work-run-correction.apply.forbidden.v1, work-run-correction.apply.tenant-mismatch.v1, work-run-correction.apply.rate-limited.v1, work-run-correction.apply.unavailable.v1, work-run-correction.apply.timeout.v1
Reject pending correction work-run-correction.reject.success.v1 work-run-correction.reject.validation-failed.v1, work-run-correction.reject.version-conflict.v1, work-run-correction.reject.invalid-transition.v1, work-run-correction.reject.idempotency-conflict.v1, work-run-correction.reject.forbidden.v1, work-run-correction.reject.tenant-mismatch.v1, work-run-correction.reject.rate-limited.v1, work-run-correction.reject.unavailable.v1, work-run-correction.reject.timeout.v1
Request retry for pending correction work-run-correction.retry.success.v1 work-run-correction.retry.validation-failed.v1, work-run-correction.retry.version-conflict.v1, work-run-correction.retry.already-finalized.v1, work-run-correction.retry.invalid-transition.v1, work-run-correction.retry.idempotency-conflict.v1, work-run-correction.retry.forbidden.v1, work-run-correction.retry.tenant-mismatch.v1, work-run-correction.retry.rate-limited.v1, work-run-correction.retry.unavailable.v1, work-run-correction.retry.timeout.v1

If a future fixture shape changes, update the operation page and this guide in the same patch. Do not invent replacement fields in public docs before the contract fixture and platform-owned schema agree.

Operation Problem Variant Matrix

Use this matrix when wiring operator-facing error states. Each row names the checked fixture ID used by these source docs and the safe remediation to show in operator UI, SDK examples, or support notes. Do not expose raw Problem detail, tenant metadata, request bodies, correction text, bearer tokens, idempotency keys, or private evidence refs.

Operation Problem variant and fixture Typical status Operator-safe remediation
Create validation_failed / work-run-correction.create.validation-failed.v1 422 Preserve the local draft, remove unsafe text, fix the bounded validation fields, and use a new idempotency key only if the body changes.
Create idempotency_conflict / work-run-correction.create.idempotency-conflict.v1 409 Stop replaying; the key was reused with a different body or target, so ask the operator whether this is a new correction action.
Create forbidden / work-run-correction.create.forbidden.v1 403 Hide create controls for this actor and avoid exposing review-only correction metadata.
Create tenant_mismatch / work-run-correction.create.tenant-mismatch.v1 404 Show a safe unavailable state and do not reveal whether another tenant's Work Run exists.
Create rate_limited / work-run-correction.create.rate-limited.v1 429 Respect Retry-After only for the exact idempotent create replay with the same body, key, and target.
Create unavailable / work-run-correction.create.unavailable.v1 503 Keep the draft visible, wait for Retry-After when present, and replay only the exact same idempotent create.
Create timeout / work-run-correction.create.timeout.v1 504 Reuse the same idempotency key and request body once local policy allows, then list corrections to confirm whether the pending row exists.
List invalid_cursor / work-run-correction.list.invalid-cursor.v1 400 Drop only the cursor, reload the first page, and do not log the cursor value.
List forbidden / work-run-correction.list.forbidden.v1 403 Hide restricted history fields and do not reveal review-only correction metadata.
List tenant_mismatch / work-run-correction.list.tenant-mismatch.v1 404 Show a safe unavailable state and do not reveal whether another tenant's Work Run or correction exists.
List rate_limited / work-run-correction.list.rate-limited.v1 429 Respect Retry-After before the next safe read.
List unavailable / work-run-correction.list.unavailable.v1 503 Keep the previous visible rows and retry the read after Retry-After when present.
List timeout / work-run-correction.list.timeout.v1 504 Keep the previous visible rows, wait for Retry-After when present, and retry the safe read.
Apply validation_failed / work-run-correction.apply.validation-failed.v1 422 Preserve the reviewer note locally, fix bounded fields, and do not submit a different decision under the same key.
Apply version_conflict / work-run-correction.apply.version-conflict.v1 409 Treat it as stale-version: refresh correction history, compare the latest sequence or expected version, and ask the reviewer to choose again.
Apply invalid_transition / work-run-correction.apply.invalid-transition.v1 409 Show the latest pending, applied, or rejected state; do not retry apply while the transition is invalid.
Apply idempotency_conflict / work-run-correction.apply.idempotency-conflict.v1 409 Stop replaying and investigate the conflicting review action before the reviewer decides again.
Apply forbidden / work-run-correction.apply.forbidden.v1 403 Disable review controls and do not reveal restricted correction text or metadata.
Apply tenant_mismatch / work-run-correction.apply.tenant-mismatch.v1 404 Show a safe unavailable state and do not reveal whether another tenant's Work Run or correction exists.
Apply rate_limited / work-run-correction.apply.rate-limited.v1 429 Respect Retry-After only for an exact idempotent replay allowed by local policy; otherwise refresh before a new human decision.
Apply unavailable / work-run-correction.apply.unavailable.v1 503 Keep the reviewer on the current ledger, wait for Retry-After when present, then refresh before any new decision.
Apply timeout / work-run-correction.apply.timeout.v1 504 Refresh the ledger before changing reviewer state; replay only with the same body, target, expected version, and idempotency key.
Reject validation_failed / work-run-correction.reject.validation-failed.v1 422 Preserve the reviewer note locally, fix bounded fields, and keep raw rejected correction text out of public notes.
Reject version_conflict / work-run-correction.reject.version-conflict.v1 409 Treat it as stale-version: refresh correction history, compare the latest sequence or expected version, and ask the reviewer to choose again.
Reject invalid_transition / work-run-correction.reject.invalid-transition.v1 409 Show the latest pending, applied, or rejected state; do not retry reject while the transition is invalid.
Reject idempotency_conflict / work-run-correction.reject.idempotency-conflict.v1 409 Stop replaying and investigate the conflicting review action before the reviewer decides again.
Reject forbidden / work-run-correction.reject.forbidden.v1 403 Disable review controls and do not reveal restricted correction text or metadata.
Reject tenant_mismatch / work-run-correction.reject.tenant-mismatch.v1 404 Show a safe unavailable state and do not reveal whether another tenant's Work Run or correction exists.
Reject rate_limited / work-run-correction.reject.rate-limited.v1 429 Respect Retry-After only for an exact idempotent replay allowed by local policy; otherwise refresh before a new human decision.
Reject unavailable / work-run-correction.reject.unavailable.v1 503 Keep the reviewer on the current ledger, wait for Retry-After when present, then refresh before any new decision.
Reject timeout / work-run-correction.reject.timeout.v1 504 Refresh the ledger before changing reviewer state; replay only with the same body, target, expected version, and idempotency key.
Retry validation_failed / work-run-correction.retry.validation-failed.v1 422 Preserve the reviewer note locally and keep raw correction text out of public notes.
Retry version_conflict / work-run-correction.retry.version-conflict.v1 409 Refresh correction history, compare the latest work_run_version, and ask the reviewer to choose again.
Retry already_finalized / work-run-correction.retry.already-finalized.v1 409 Show the latest terminal review decision and do not send another review decision for that correction.
Retry invalid_transition / work-run-correction.retry.invalid-transition.v1 409 Keep approval/export disabled when a retry gate is unresolved and ask the reviewer for a valid next action.
Retry idempotency_conflict / work-run-correction.retry.idempotency-conflict.v1 409 Stop replaying and investigate the conflicting retry request before the reviewer decides again.
Retry forbidden / work-run-correction.retry.forbidden.v1 403 Disable retry controls and do not reveal restricted correction text or metadata.
Retry tenant_mismatch / work-run-correction.retry.tenant-mismatch.v1 404 Show a safe unavailable state and do not reveal whether another tenant's Work Run or correction exists.
Retry rate_limited / work-run-correction.retry.rate-limited.v1 429 Respect Retry-After only for an exact idempotent replay allowed by local policy; otherwise refresh before a new human decision.
Retry unavailable / work-run-correction.retry.unavailable.v1 503 Keep the reviewer on the current ledger, wait for Retry-After when present, then refresh before any new decision.
Retry timeout / work-run-correction.retry.timeout.v1 504 Refresh the ledger before changing reviewer state; replay only with the same body, target, expected Work Run version, and idempotency key.

Operation Examples

Create

POST /admin/work-runs/{work_run_id}/corrections records a pending correction. It is the only correction write that may be replayed automatically, and only when the script sends the exact same body, target URL, and Idempotency-Key.

curl -i -sS -X POST \
  "$RETVEST_API_BASE/admin/work-runs/$WORK_RUN_ID/corrections" \
  -H "Authorization: Bearer $RETVEST_API_KEY" \
  -H "Accept: application/json, application/problem+json" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: correction-wr-example-20260618-create-001" \
  -H "X-Request-Id: req_correction_create_example_001" \
  -d '{
    "correction_type": "claim_language",
    "original_summary": "The evidence pack is legally approved for filing.",
    "corrected_summary": "The evidence pack is a starter export marked TEMPLATE - legal review required.",
    "reason": "The reviewed evidence supports export readiness, not legal approval.",
    "evidence_refs": [{ "type": "gate", "label": "legal-review-caveat" }]
  }'
{
  "fixture_id": "work-run-correction.create.success.v1",
  "correction_id": "wrc_example_001",
  "work_run_id": "wr_example",
  "correction_sequence": 1,
  "correction_status": "pending",
  "request_id": "req_correction_create_example_001"
}

List

GET /admin/work-runs/{work_run_id}/corrections reads the append-only correction history. Use cursor pagination; do not guess offsets or sequence ranges.

curl -i -sS \
  "$RETVEST_API_BASE/admin/work-runs/$WORK_RUN_ID/corrections?limit=25&cursor=$CORRECTION_CURSOR" \
  -H "Authorization: Bearer $RETVEST_API_KEY" \
  -H "Accept: application/json, application/problem+json" \
  -H "X-Request-Id: req_correction_list_example_001"
{
  "fixture_id": "work-run-correction.list.success-page.v1",
  "items": [
    {
      "correction_id": "wrc_example_001",
      "work_run_id": "wr_example",
      "correction_sequence": 1,
      "correction_status": "pending",
      "receipt_type": "correction_recorded",
      "request_id": "req_correction_create_example_001"
    }
  ],
  "pagination": {
    "limit": 25,
    "next_cursor": "cursor_example_next"
  },
  "request_id": "req_correction_list_example_001"
}

Apply

POST /admin/work-runs/{work_run_id}/corrections/{correction_id}/apply is a reviewer decision. Send the version or correction sequence the reviewer inspected as Expected-Version, then refresh the ledger before changing the UI state if the response is unknown.

curl -i -sS -X POST \
  "$RETVEST_API_BASE/admin/work-runs/$WORK_RUN_ID/corrections/$CORRECTION_ID/apply" \
  -H "Authorization: Bearer $RETVEST_API_KEY" \
  -H "Accept: application/json, application/problem+json" \
  -H "Content-Type: application/json" \
  -H "Expected-Version: $CORRECTION_EXPECTED_VERSION" \
  -H "Idempotency-Key: correction-wr-example-20260618-apply-001" \
  -H "X-Request-Id: req_correction_apply_example_001" \
  -d '{
    "reviewer_note": "Reviewed evidence supports the narrower replacement claim."
  }'
{
  "fixture_id": "work-run-correction.apply.success.v1",
  "correction_id": "wrc_example_001",
  "work_run_id": "wr_example",
  "correction_sequence": 2,
  "correction_status": "applied",
  "expected_version": 1,
  "request_id": "req_correction_apply_example_001"
}

Reject

POST /admin/work-runs/{work_run_id}/corrections/{correction_id}/reject is also a reviewer decision. Keep the reason bounded and metadata-only; do not publish raw rejected correction text.

curl -i -sS -X POST \
  "$RETVEST_API_BASE/admin/work-runs/$WORK_RUN_ID/corrections/$CORRECTION_ID/reject" \
  -H "Authorization: Bearer $RETVEST_API_KEY" \
  -H "Accept: application/json, application/problem+json" \
  -H "Content-Type: application/json" \
  -H "Expected-Version: $CORRECTION_EXPECTED_VERSION" \
  -H "Idempotency-Key: correction-wr-example-20260618-reject-001" \
  -H "X-Request-Id: req_correction_reject_example_001" \
  -d '{
    "rejection_reason_code": "unsupported_evidence",
    "reviewer_note": "Reviewed evidence does not support applying this correction."
  }'
{
  "fixture_id": "work-run-correction.reject.success.v1",
  "correction_id": "wrc_example_002",
  "work_run_id": "wr_example",
  "correction_sequence": 3,
  "correction_status": "rejected",
  "rejection_reason_code": "unsupported_evidence",
  "expected_version": 2,
  "request_id": "req_correction_reject_example_001"
}

Retry Request

POST /admin/work-runs/{work_run_id}/corrections/{correction_id}/retry records that a pending correction needs operator follow-up before approval or export can continue. Use expected_work_run_version from the Work Run state the reviewer inspected.

curl -i -sS -X POST \
  "$RETVEST_API_BASE/admin/work-runs/$WORK_RUN_ID/corrections/$CORRECTION_ID/retry" \
  -H "Authorization: Bearer $RETVEST_API_KEY" \
  -H "Accept: application/json, application/problem+json" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: correction-wr-example-20260618-retry-001" \
  -H "X-Request-Id: req_correction_retry_example_001" \
  -d '{
    "expected_work_run_version": 8,
    "resolution_reason_code": "operator_requested_retry",
    "resolution_note": "Retry review after the external evidence attachment was corrected."
  }'
{
  "fixture_id": "work-run-correction.retry.success.v1",
  "correction_id": "wrc_example_003",
  "work_run_id": "wr_example",
  "correction_sequence": 5,
  "correction_status": "pending",
  "work_run_version": 8,
  "approval_export_blocked": true,
  "request_id": "req_correction_retry_example_001"
}

Problem Codes

Branch on the HTTP status plus a bounded category or code. Do not log raw Problem detail, request bodies, idempotency keys, bearer tokens, correction text, tenant metadata, customer evidence, generated answers, citation bodies, or private evidence refs.

{
  "fixture_id": "work-run-correction.apply.version-conflict.v1",
  "type": "<platform-problem-type-uri>",
  "title": "Expected version is stale",
  "status": 409,
  "category": "version_conflict",
  "request_id": "req_correction_apply_example_002"
}
Problem code Typical status Safe handling
validation_failed 422 Preserve the local draft, remove unsafe text, fix bounded fields, and use a new idempotency key only if the body changes.
invalid_cursor 400 Drop only the cursor, reload the first list page, and keep rendered rows keyed by correction_id plus correction_sequence.
version_conflict 409 Refresh correction history, compare the latest correction_sequence or expected version, and ask the reviewer to choose again.
invalid_transition 409 Show the latest pending/applied/rejected/superseded state; do not retry apply, reject, or request retry while the transition is invalid.
already_finalized 409 Show the latest terminal review decision; do not send another apply, reject, or retry request for that correction.
idempotency_conflict 409 Stop replaying; the same key was used with a different body or target.
forbidden 403 Disable restricted actions and do not reveal review-only correction metadata.
tenant_mismatch 404 Show a safe unavailable state and do not reveal whether another tenant's Work Run or correction exists.
rate_limited 429 Respect Retry-After for safe reads or exact idempotent replays only.
unavailable 503 Retry safe reads or the exact idempotent replay after Retry-After; keep previous visible state until replacement data arrives.
timeout 504 Refresh the ledger before changing reviewer state; replay only with the same body, target, expected version, and idempotency key.

Retry-After And Request IDs

Capture a request ID for every response. Prefer the X-Request-Id response header, then the bounded request_id response member, then the client-generated X-Request-Id if the platform did not return one. Store only the opaque request ID in support notes.

Treat Retry-After as a wait hint for 429, 503, and explicit timeout fixtures. Parse seconds and HTTP-date values. It is not permission to invent a new correction action.

type CorrectionProblemCode =
  | "validation_failed"
  | "invalid_cursor"
  | "version_conflict"
  | "invalid_transition"
  | "already_finalized"
  | "idempotency_conflict"
  | "forbidden"
  | "tenant_mismatch"
  | "rate_limited"
  | "unavailable"
  | "timeout";

type CorrectionProblem = {
  status?: number;
  category?: CorrectionProblemCode;
  code?: CorrectionProblemCode;
  request_id?: string;
  retry_after?: string;
};

function retryAfterMillis(value: string | null) {
  if (!value) return null;
  const seconds = Number(value);
  if (Number.isFinite(seconds)) return Math.max(0, seconds * 1000);
  const date = Date.parse(value);
  return Number.isFinite(date) ? Math.max(0, date - Date.now()) : null;
}

function correctionProblemCode(problem: CorrectionProblem) {
  return problem.category ?? problem.code ?? "unavailable";
}

Idempotency And Expected-Version Boundaries

  • Create: require one Idempotency-Key per user action. Reuse it only for the exact same create body and target.
  • List: do not send Idempotency-Key or Expected-Version; reads are safe to retry after Retry-After when auth and tenant scope remain valid.
  • Apply and reject: require both Idempotency-Key and Expected-Version, but do not blind-retry. On version_conflict, invalid_transition, idempotency_conflict, unknown timeout, or route changes, refresh the ledger and ask the reviewer to choose again.
  • Retry request: require Idempotency-Key, X-Request-Id, and expected_work_run_version in the request body. On version_conflict, already_finalized, invalid_transition, idempotency_conflict, unknown timeout, or route changes, refresh the ledger and keep approval/export disabled until the follow-up correction is resolved.

Cursor Pagination

Use next_cursor from the list response with the same filters and limit. If the API returns invalid_cursor, discard only that cursor, reload the first page, and do not log the cursor value. Render history rows by correction_sequence and key rows by correction_id plus correction_sequence.

Unsafe Retry Boundaries

Never turn a retry into unattended approval automation. Create may replay only the exact same correction request. Apply, reject, and request retry are human review decisions: the reviewer must inspect the refreshed ledger before a new action is sent.

Do not claim these examples provide legal approval, compliance guarantees, hosted API publication, OpenAPI-generated SDK availability, or production installation proof.

Choose what this site may use. Your choice is kept in this browser only.