fail_contract
Mark a claimed contract as terminally failed with a required reason, so unrecoverable tasks stop immediately and requesters are freed from waiting for the execution TTL to expire.
Instructions
Explicitly mark a CLAIMED contract as terminal FAILED with a mandatory failure reason.
Purpose
Immediately terminates a claimed task that cannot be completed, recording actionable diagnostic reasons and freeing the requester from waiting for the execution TTL to expire.
Usage Guidelines
When to use: Use when a task encounters an unrecoverable failure (e.g. fatal syntax error, broken test suite, missing required environment).
When NOT to use:
Do NOT use if the task succeeded (use fulfill_contract).
Do NOT use if the task is recoverable by another agent or retryable (use release_contract).
Prerequisites: Caller must be the current holder and reason must be non-empty.
Behavior & Side Effects
Mutates database: Sets status='FAILED', error_reason='WORKER_FAILED: ', and completed_at=nowMs.
Late report handling: If the execution window already expired before fail_contract was called, the status becomes TIMED_OUT while faithfully preserving the worker's reason for the requester.
Return Value
Returns { ok: boolean, contract_id: string, status: 'FAILED' | 'TIMED_OUT', message: string }.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| reason | Yes | Mandatory explanation of why the task cannot be completed. Stored in error_reason for the requester. | |
| agent_id | No | Current holder agent identifier. Must match target_agent of the claimed contract (defaults to AGENT_NAME env var). | |
| claim_token | No | Exclusive lease token returned in contract.claim_token by poll_next_task (FC-301). | |
| contract_id | Yes | The CLAIMED contract ID to mark as terminal FAILED. |