release_contract
Returns a claimed contract to the queue as SUBMITTED with a fresh window when an agent claimed it by mistake, lacks dependencies, or must switch branches.
Instructions
Hand a CLAIMED contract back to the queue tail as SUBMITTED with a fresh queue window.
Purpose
Allows an agent holding a claimed task to safely release ownership back to the queue without failing or aborting the task.
Usage Guidelines
When to use: Use when your agent claimed a task by mistake, encounters missing local dependencies/tools, or needs to switch git branches before processing.
When NOT to use:
Do NOT use if the task permanently failed or cannot ever be completed (use fail_contract).
Do NOT use if you simply need more time to finish active execution (use extend_ttl).
Prerequisites: Caller must be the current holder (agent_id matches target_agent) and contract status must be CLAIMED.
Behavior & Side Effects
Mutates database: Resets claimed_at=NULL, updates queued_at=nowMs, resets extend_count=0 (renewal quota is per holder), and increments release_count.
Preserves retry_count: The schema validation circuit-breaker quota is contract-level; releasing a contract cannot launder previously consumed retry attempts.
Audit history: Appends reason to error_reason history ("RELEASED_BY_HOLDER: | prev: ...").
Limits: Maximum 3 releases per contract. Refused once the contract reaches its absolute lifetime ceiling (nowMs >= created_at + 4 * queue_ttl_sec).
Return Value
Returns { ok: boolean, contract_id: string, status: 'SUBMITTED' | 'CLAIMED' | 'TIMED_OUT', release_count: number, max_releases: number, message: string }.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| reason | No | Optional reason for releasing (e.g., "wrong context", "missing tool", "switching git branch"). Appended to error_reason history. | |
| 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 release back to the queue tail as SUBMITTED. |