Create Work Run Corrections
Use this page when a developer script needs to submit a pending correction for a Compliance Work Run. For operator context, start with the correction lifecycle guide.
Current status: the route shape below is checked against the site-side source
fixture in docs-api/work-run-correction-openapi-sdk-fixtures.json. Exact
production schemas, auth scopes, Problem extension members, and generated SDK
method names remain owned by the platform OpenAPI snapshot and the SDK owner
repo before customer automation targets a deployment.
Raw HTTP Create
POST /admin/work-runs/{work_run_id}/corrections appends a pending
correction row. Send one Idempotency-Key for the user action. Reuse the same
key only when retrying the exact same request body after a timeout or dropped
connection.
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": "citation", "label": "reviewed-citation-2" },
{ "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"
}
Do not send an Expected-Version header on create unless the generated OpenAPI
schema later requires it. Expected-version checks matter when a reviewer applies
or rejects an existing pending correction.
SDK Example
Until generated correction SDK methods are published, keep SDK-side examples as source-only helpers around the pinned route. This helper returns bounded metadata and does not log request bodies, idempotency keys, bearer tokens, raw customer text, citation bodies, or private evidence refs.
type CorrectionProblemCode =
| "validation_failed"
| "idempotency_conflict"
| "forbidden"
| "tenant_mismatch"
| "rate_limited"
| "unavailable"
| "timeout";
type CorrectionProblem = {
status?: number;
code?: CorrectionProblemCode;
category?: CorrectionProblemCode;
request_id?: string;
retry_after?: string;
};
type CreateCorrectionResult = {
correction_id: string;
work_run_id: string;
correction_sequence: number;
correction_status: "pending";
request_id?: 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;
}
export async function createWorkRunCorrection(options: {
baseUrl: string;
apiKey: string;
workRunId: string;
idempotencyKey: string;
requestId: string;
}) {
const response = await fetch(
`${options.baseUrl}/admin/work-runs/${encodeURIComponent(options.workRunId)}/corrections`,
{
method: "POST",
headers: {
Authorization: `Bearer ${options.apiKey}`,
Accept: "application/json, application/problem+json",
"Content-Type": "application/json",
"Idempotency-Key": options.idempotencyKey,
"X-Request-Id": options.requestId
},
body: JSON.stringify({
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" }]
})
}
);
if (!response.ok) {
const problem = (await response.json().catch(() => ({}))) as CorrectionProblem;
const retryAfter = retryAfterMillis(response.headers.get("Retry-After"));
throw { problem, retryAfter };
}
return (await response.json()) as CreateCorrectionResult;
}
Retry And Problem Handling
Create is the only correction write that developer scripts may safely auto-retry
when the request body, Idempotency-Key, and request target are unchanged. A
different body with the same key should surface idempotency_conflict and stop
the retry path.
| Problem code | Developer handling |
|---|---|
validation_failed |
Preserve the draft, remove raw customer text, fix bounded fields, and use a new key only if the body changes. |
idempotency_conflict |
Stop retrying and ask the operator whether this is a new correction action. |
forbidden |
Hide create controls for the actor and avoid review-only metadata. |
tenant_mismatch |
Show a generic unavailable state; do not reveal whether another tenant's Work Run exists. |
rate_limited |
Respect Retry-After for the exact idempotent replay only. |
unavailable or timeout |
Retry the exact same body and key after Retry-After, then list corrections to confirm the ledger state. |
Related Docs
- List Work Run corrections to confirm whether the pending row was recorded.
- Correction API errors for fixture-aligned Problem codes, request IDs, and retry boundaries.
- Apply Work Run corrections for reviewer expected-version checks.
- Reject Work Run corrections for unsafe review retry rules.
- Recording corrections for the operator-safe Problem runbook.