Skip to main content
Glama

Fulfill Contract

fulfill_contract

Submit execution or review deliverables for a claimed contract, enforcing TOCTOU workspace integrity, JSON schema validation, and SHA-256 auditing before completion.

Instructions

Submit execution or review deliverables for a CLAIMED contract under Dual-Track TOCTOU verification (ADR-0004 / ADR-0006 / ADR-0007) and Ajv JSON Schema validation.

Purpose

Delivers task outputs, enforces track-specific workspace integrity and cryptographic SHA-256 auditing, validates structured payloads, and transitions the contract to terminal COMPLETED.

Track-Specific Fulfillment Rules

  1. Track A — Read-Only Audit (code_review | architecture_audit, ADR-0004):

    • Pointer files on disk MUST remain 100% unchanged (verifyAllPointers). Pass suggested code fixes in structured_output.fixes.

    • Accidental disk edits trigger a 1-strike recoverable RETRY_NEEDED buffer (restore via git checkout/stash, call verify_contract, then retry); a 2nd dirty attempt transitions to terminal POINTER_STALE while salvaging your output.

  2. Track B1 — Direct Mutation (implementation | test_generation with write_mode="direct", default, ADR-0006):

    • Editing pointer files on disk and creating declared artifacts_pointers files is expected and permitted (SECURITY_REJECTED and FILE_MISSING remain hard blockers).

    • Post-mutation full-file SHA-256 hashes are committed into verified_sha256 while pointers preserves the pre-mutation baseline.

  3. Track B2 — Zero-Write Proposal Mode (implementation | test_generation with write_mode="proposal", ADR-0007):

    • Pointer files on disk MUST remain 100% unchanged (enforced by the same 1-strike TOCTOU guard as Track A).

    • You MUST provide a valid non-empty unified git diff (<= 512KB) in proposed_patch touching only safe workspace paths and declared existing pointer files (or new files from /dev/null). Missing or invalid patches return recoverable RETRY_NEEDED (remediation.action="FIX_PATCH_AND_RESUBMIT").

Return Value

Returns { ok, contract_id, status: 'COMPLETED' | 'RETRY_NEEDED' | 'POINTER_STALE' | 'VALIDATION_FAILED' | 'TIMED_OUT', retry_count, max_retries, toctou_strike?, max_toctou_strikes?, dirty_files?, validation_errors?, no_op?, proposed_patch_sha256?, proposed_patch_bytes?, remediation?, message }.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "contract_id": "<contract_id>",
      "result_summary": "<result_summary>"
    },
    "name": "fulfill_contract"
  }
}

Input Schema

NameRequiredDescriptionDefault
agent_idNoWorker agent identifier. Must match the contract target_agent (defaults to AGENT_NAME env var).
claim_tokenNoExclusive 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_idYesThe contract ID returned by poll_next_task that is currently in CLAIMED status.
proposed_patchNoUnified git diff patch payload (max 524288 bytes / 512KB, ADR-0007) required when fulfilling a contract dispatched with write_mode="proposal". Do NOT modify pointer files on disk in proposal mode; submit all file edits and new files in this unified diff.
result_summaryYesDetailed markdown or plain text summary of review findings, implementation details, or test execution outcomes (1-20000 chars).
structured_outputNoStructured 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_pointersNoOptional pointers to new or modified artifact files created during task execution (max 50 files).

Schema Changelog

Changes observed during successful MCP inspections.

  1. Changed1 schema field changedv0.6.0
    • addedInput schema / properties / proposed_patch
      Added value: +{
      +  "description": "Unified git diff patch payload (max 524288 bytes / 512KB, ADR-0007) required when fulfilling a contract dispatched with write_mode=\"proposal\". Do NOT modify pointer files on disk in proposal mode; submit all file edits and new files in this unified diff.",
      +  "type": "string"
      +}
  2. Changed2 schema fields changedv0.3.2
    • addedInput schema / properties / claim_token
      Added value: +{
      +  "description": "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.",
      +  "maxLength": 128,
      +  "minLength": 1,
      +  "type": "string"
      +}
    • changedInput schema / properties / structured_output / description
      Previous value: -"Structured JSON payload matching contract_schema. For code reviews, pass proposed patches in fixes: [{ path, patch, description }] rather than editing pointer files directly (ADR-0004)."New value: +"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)."
  3. Changed7 schema fields changedv0.3.0
    • changedInput schema / properties / agent_id / description
      Previous value: -"Worker agent identifier (defaults to AGENT_NAME env var)"New value: +"Worker agent identifier. Must match the contract target_agent (defaults to AGENT_NAME env var)."
    • changedInput schema / properties / artifacts_pointers / description
      Previous value: -"Optional pointers to files created or modified during task execution"New value: +"Optional pointers to new or modified artifact files created during task execution (max 50 files)."
    • addedInput schema / properties / artifacts_pointers / items / properties / description / description
      Added value: +"Description of the artifact and its role"
    • addedInput schema / properties / artifacts_pointers / items / properties / path / description
      Added value: +"File path of created or modified artifact relative to workspace_root"
    • changedInput schema / properties / contract_id / description
      Previous value: -"The contract ID returned by poll_next_task"New value: +"The contract ID returned by poll_next_task that is currently in CLAIMED status."
    • changedInput schema / properties / result_summary / description
      Previous value: -"Human-readable summary of findings or implementation"New value: +"Detailed markdown or plain text summary of review findings, implementation details, or test execution outcomes (1-20000 chars)."
    • changedInput schema / properties / structured_output / description
      Previous value: -"Structured JSON payload matching the contract_schema"New value: +"Structured JSON payload matching contract_schema. For code reviews, pass proposed patches in fixes: [{ path, patch, description }] rather than editing pointer files directly (ADR-0004)."
  4. First observedv0.1.0

TDQS

A4.3/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations only tell the agent this is a non-read-only, non-idempotent, closed-world call; the description goes far beyond that with the TOCTOU 1-strike/2-strike escalation (RETRY_NEEDED → POINTER_STALE), what gets hashed and where (verified_sha256 vs pointers baseline), and the 512KB patch ceiling. It also discloses the salvage behavior on a second dirty attempt and the recoverable-validation semantics with remediation.action. This is exactly the mutation-risk context the agent needs and cannot get from the annotations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Markdown headings (Purpose, Track-Specific Fulfillment Rules, Return Value) front-load the intent and make the three tracks scannable. The Return Value block is justified because there is no output schema. It is on the long side, with some restatement of the 1-strike guard across Track A and Track B2 that could be consolidated into a single shared-rule note.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a 7-parameter, nested-object mutation tool with no output schema, the description covers the missing pieces: the full status enum returned, retry_count/max_retries, strike counters, dirty_files, validation_errors, and remediation guidance. Track-specific expectations for artifacts_pointers and pointer-file immutability are stated where the schema is silent. An agent has enough to call it correctly on the first attempt in any of the three modes.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so the baseline would be 3, but the description adds conditional semantics the schema does not encode – proposed_patch is only required when the contract was dispatched with write_mode="proposal", and code-review fixes belong in structured_output.fixes rather than disk edits. That materially changes how an agent should populate the payload for each track. It still does not clarify claim_token/agent_id failure behavior (cross-worker mismatch) beyond restating the schema requirement.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The first sentence gives a specific verb and resource ('Submit execution or review deliverables for a CLAIMED contract') and enumerates the concrete outcomes (workspace integrity checks, SHA-256 auditing, Ajv validation, transition to COMPLETED). It clearly separates the three fulfillment tracks by task type and write_mode, so an agent knows which rule set applies. It stops short of naming a sibling such as apply_contract_patch, so the boundary with that tool is left to inference.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It states the precondition explicitly – the contract must be 'currently in CLAIMED status' with a claim_token from poll_next_task – and gives track-conditional instructions for when a proposed_patch is mandatory versus when direct disk edits are expected. Failure and recovery paths (restore via git checkout/stash, call verify_contract, then retry) are spelled out. No explicit 'do not use this when…' routing against the patch/fail siblings is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.