fulfill_contract
Submit final deliverables for a claimed FerryCat contract, verify the code baseline is unchanged, validate structured output against its schema, and transition the contract to COMPLETED.
Instructions
Submit execution or review deliverables for a CLAIMED contract, with TOCTOU soft-failure buffering and Ajv JSON Schema validation.
Purpose
Delivers the final output of a task, verifies that the code baseline was not mutated during execution, validates structured payloads, and transitions the contract to terminal COMPLETED.
Usage Guidelines
When to use: Use after completing task work to deliver result_summary, optional structured_output, and optional artifacts_pointers.
When NOT to use:
Do NOT use if you cannot complete the task (use release_contract to re-queue, or fail_contract to record failure).
Do NOT use if you modified pointer files directly on disk. If modified accidentally, run "git stash" or restore the files, run verify_contract, and pass proposed fixes inside structured_output.fixes.
Behavior & Side Effects
Authorization: Caller agent_id must match target_agent of the claimed contract.
TOCTOU Guard & Soft-Failure Buffer (ADR-0004) — exactly ONE recoverable rejection:
1st blocked fulfill: returns status='RETRY_NEEDED', keeps the contract CLAIMED, renews the execution window (claimed_at=now), and lists dirty_files with restore instructions.
2nd blocked fulfill: transitions to terminal status='POINTER_STALE', preserving your summary and payload in salvaged_result_json so the work is not lost.
Only ONE rejection is recoverable: restore/stash the files BEFORE retrying, and call verify_contract first so a stray second attempt cannot burn the buffer.
Schema Validation: If contract_schema was defined, validates structured_output via cached Ajv validator. Failures 1 & 2 return RETRY_NEEDED with flattened error paths and renew the execution window; 3rd failure transitions to terminal VALIDATION_FAILED.
On Success: Transitions to terminal status='COMPLETED', recording result_summary, structured_output, artifacts_pointers, and verified SHA-256 snapshot.
Return Value
Returns { ok: boolean, contract_id: string, status: 'COMPLETED' | 'RETRY_NEEDED' | 'POINTER_STALE' | 'VALIDATION_FAILED', retry_count: number, max_retries: number, toctou_strike?: number, max_toctou_strikes?: number, dirty_files?: Array<{ path, reason, detail }>, validation_errors?: string[], message: string }.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| agent_id | No | Worker agent identifier. Must match the contract target_agent (defaults to AGENT_NAME env var). | |
| claim_token | No | Exclusive lease token returned in contract.claim_token by poll_next_task (FC-301). Mutating operations must provide matching claim_token to prevent cross-worker interference. | |
| contract_id | Yes | The contract ID returned by poll_next_task that is currently in CLAIMED status. | |
| result_summary | Yes | Detailed markdown or plain text summary of review findings, implementation details, or test execution outcomes (1-20000 chars). | |
| structured_output | No | Structured JSON payload matching contract_schema. Bounded to 1MB and max 32 depth (FC-302). For code reviews, pass proposed patches in fixes: [{ path, patch, description }] rather than editing pointer files directly (ADR-0004). | |
| artifacts_pointers | No | Optional pointers to new or modified artifact files created during task execution (max 50 files). |