Apply Work Run Corrections

Use this page when a permitted reviewer applies a pending correction after inspecting the governed Work Run evidence. This is a review decision, not an unattended automation step. For operator context, read the correction lifecycle guide. If the reviewer needs an operator follow-up instead of accepting the pending correction, use Request retry.

Current status: the route shape below is the public docs path for apply review actions. Exact request fields, auth scopes, expected-version member names, and SDK method names remain pending until the platform-owned OpenAPI snapshot and SDK package evidence exist.

Raw HTTP Apply

POST /admin/work-runs/{work_run_id}/corrections/{correction_id}/apply appends an applied history row when the pending correction still matches the version the reviewer inspected.

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"
}

SDK Example

This source-only helper shows the expected-version and request metadata a reviewer action should carry. It does not claim a generated SDK method exists.

type ReviewProblemCode =
  | "validation_failed"
  | "version_conflict"
  | "invalid_transition"
  | "idempotency_conflict"
  | "forbidden"
  | "tenant_mismatch"
  | "rate_limited"
  | "unavailable"
  | "timeout";

type ReviewProblem = {
  status?: number;
  code?: ReviewProblemCode;
  category?: ReviewProblemCode;
  request_id?: string;
  retry_after?: string;
};

type ReviewMutationResult = {
  correction_id: string;
  correction_sequence: number;
  correction_status: "applied";
  expected_version: number;
  request_id?: string;
};

export async function applyWorkRunCorrection(options: {
  baseUrl: string;
  apiKey: string;
  workRunId: string;
  correctionId: string;
  expectedVersion: number;
  idempotencyKey: string;
  requestId: string;
}) {
  const response = await fetch(
    `${options.baseUrl}/admin/work-runs/${encodeURIComponent(options.workRunId)}/corrections/${encodeURIComponent(options.correctionId)}/apply`,
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${options.apiKey}`,
        Accept: "application/json, application/problem+json",
        "Content-Type": "application/json",
        "Expected-Version": String(options.expectedVersion),
        "Idempotency-Key": options.idempotencyKey,
        "X-Request-Id": options.requestId
      },
      body: JSON.stringify({
        reviewer_note: "Reviewed evidence supports the narrower replacement claim."
      })
    }
  );

  if (!response.ok) {
    const problem = (await response.json().catch(() => ({}))) as ReviewProblem;
    throw {
      problem,
      retryAfter: response.headers.get("Retry-After") ?? problem.retry_after ?? null
    };
  }

  return (await response.json()) as ReviewMutationResult;
}

Expected-Version Handling

Read the correction ledger, show the reviewer the pending row, and send the latest inspected correction_sequence or version as Expected-Version. On version_conflict or invalid_transition, refresh List Work Run corrections, show the latest pending/applied/rejected state, and ask the reviewer to choose again.

Unsafe Review Retries

Apply is not a safe blind retry. Do not auto-generate a new idempotency key or repeat an apply after route changes, duplicate clicks, stale state, or an unknown timeout. If a retry is permitted by local policy, it must reuse the same request body, Expected-Version, Idempotency-Key, and target correction; then list corrections to confirm the final ledger state.

Problem code Developer handling
validation_failed Preserve the review draft and fix bounded fields before sending a new action.
version_conflict Refresh the ledger and ask the reviewer to confirm the current pending row.
invalid_transition Show the latest correction status, including superseded; do not retry apply while the state is not pending.
idempotency_conflict Stop retrying and investigate the conflicting review action.
forbidden Hide review-only controls and metadata for this actor.
tenant_mismatch Show a generic unavailable state; do not reveal whether another tenant's Work Run exists.
rate_limited Respect Retry-After only for an exact idempotent replay allowed by local policy.
unavailable or timeout Refresh the ledger before asking the reviewer whether to retry.

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