Bezel API api_lite_claim_contract
internal prototype · canonical JSON + Dreamborn Forge HTML
internal generated
api_lite_claim_contract · supabase_json

Bezel API api_lite_claim_contract

api_lite_claim_contract artifact · for Bezel API · status draft

Planning Surface

Use this to decide what happens next.

Status

draft

Agent Handoff
Start Here

api_lite_claim_contract artifact · for Bezel API · status draft

Completion Evidence

No explicit evidence field yet. Require tests, screenshots, linked PRs, or reviewed outputs before marking complete.

Artifact Shape
  • mode: lite
  • product: Bezel API
  • purpose: Define the MVP claim-only coordination contract. Lite stores customer work data in DB/storage and uses HCS only to arbitrate/prove claims.
  • version: 0.1
  • state changes: claimed: object, no_tasks: object, rejected: object
  • bounded attempts: rationale: string, default_limit: number, response_when_exhausted: string
  • lite hcs message: principle: string, allowed_fields: object, forbidden_fields: object, proof_fields_projected_to_db: object
  • primary endpoint: auth: string, path: string, method: string, request: object, responses: object
  • direct task claim: note: string, path: string, status: string, use_cases: object
  • idempotency rules: 4 items
  • db selection rules: 6 items
  • privacy tests required: 6 items
Structured Payload

Machine-readable source fields

mode

lite

product

Bezel API

purpose

Define the MVP claim-only coordination contract. Lite stores customer work data in DB/storage and uses HCS only to arbitrate/prove claims.

version

0.1

state changes
claimed
  • insert claims row
  • tasks.status = claimed
  • tasks.claimed_by = agent_id
  • tasks.claim_id = claim_id
  • claims.hcs_proof = proof object
  • usage_events records claim arbitration write
no tasks
  • no HCS write if no candidate was attempted
  • optional poll metric only
rejected
  • no HCS write unless rejection follows a submitted claim race; auth/policy rejection is DB/API only
bounded attempts
rationale

Avoid claim-next spinning through a large queue during contention while still hiding ordinary missed races from agent clients.

default limit

3

response when exhausted

no_tasks with short backoff or rejected:rate_limited if contention/rate policy requires it

lite hcs message
principle

HCS contains only claim arbitration/proof data. It must be useless as a task data leak.

allowed fields
ts

producer timestamp

mode

lite_claim_v1

role id

role_* or hash/commitment depending privacy policy

task id

task_* or opaque task commitment id; no title/input/brief

agent id

agt_* or agent commitment id

claim id

clm_*

queue id

queue_* or hash/commitment depending privacy policy

lease seconds

integer

attempt number

integer

workspace hash

hash/workspace commitment or workspace_id if acceptable for product policy

idempotency key hash

sha256 of idempotency key

forbidden fields
  • task_title
  • task_brief
  • brief_ref
  • task_input
  • plan_json
  • workflow_name
  • dependency_graph
  • artifact_ref
  • artifact_body
  • completion_summary
  • model_output
  • logs
  • secrets
  • private_memory
proof fields projected to db
  • topic_id
  • sequence_number
  • consensus_timestamp
  • running_hash
  • transaction_id
  • claim_id
  • task_id
  • agent_id
primary endpoint
auth

workspace-scoped API key with agent:runtime scope

path

/queues/:queueId/claim-next

method

POST

request
agent id

agt_* required

role ids

role_*[] optional; defaults to roles assigned to agent in workspace

lease seconds

integer optional; defaults from role/queue policy

idempotency key

string required; unique per agent claim-next attempt unless intentionally replaying

responses
claimed
brief

task brief loaded from DB/storage after claim win

input

task input loaded from DB/storage after claim win

status

claimed

receipt
event id

evt_*

receipt url

string optional

receipt status

pending|verified

task id

task_*

claim id

clm_*

lease expires at

ISO timestamp

no tasks
status

no_tasks

agent id

agt_*

queue id

queue_*

next poll after ms

integer backoff hint

rejected
reason

inactive_agent|unauthorized_scope|queue_not_found|agent_not_in_workspace|role_not_assigned|missing_capability|invalid_lease|rate_limited|idempotency_conflict

status

rejected

retryable

boolean

next poll after ms

integer optional

direct task claim
note

Can return missed directly. Normal agents should use claim-next.

path

POST /tasks/:taskId/claim

status

secondary

use cases
  • debugging
  • UI explicit claim
  • specific task assignment
  • test fixtures
idempotency rules
  • Same workspace_id + agent_id + queue_id + idempotency_key returns the same terminal claim-next result while idempotency record is retained.
  • If first request returned claimed, replay returns the same claim/task lease if still valid, otherwise returns idempotency_conflict with retry guidance.
  • If first request returned no_tasks, replay returns the same no_tasks for a short TTL to prevent rapid duplicate polling.
  • If request body conflicts for an existing idempotency key, return rejected:idempotency_conflict.
db selection rules
  • Resolve workspace from API key and queue_id; reject cross-workspace access.
  • Load agent and verify active status, workspace membership, and role assignment.
  • Resolve candidate roles from request.role_ids intersected with assigned roles; if omitted use all assigned roles eligible for the queue.
  • Find available tasks in DB where queue_id matches, required_role_id is in eligible roles, dependencies are satisfied, status is available, and required capabilities are covered by the agent snapshot.
  • Order candidates by priority desc, created_at asc, then stable task id asc unless queue policy says otherwise.
  • Do not return task details until claim arbitration has been won.
privacy tests required
  • Lite HCS message schema rejects task_title.
  • Lite HCS message schema rejects task_input.
  • Lite HCS message schema rejects brief_ref.
  • Lite HCS message schema rejects plan_json.
  • Lite HCS message schema rejects artifact_ref and completion_summary.
  • Claimed API response can include task details only after DB claim state and HCS proof are recorded.
contract tests required
  • claim-next returns claimed for an eligible agent with one available task.
  • claim-next returns no_tasks when no eligible task exists and performs no HCS write.
  • claim-next returns rejected for inactive agent and performs no HCS write.
  • claim-next returns rejected for role/capability mismatch and performs no HCS write.
  • claim-next attempts next candidate after an internal missed race and returns claimed when the second candidate wins.
  • claim-next stops after bounded_attempt_limit and returns no_tasks/backoff.
  • idempotency replay returns same claimed result.
  • conflicting idempotency replay returns rejected:idempotency_conflict.
  • cross-workspace queue/agent/task access is rejected before HCS write.
claim arbitration algorithm
  • Create or reuse idempotency record for claim-next request.
  • Select first eligible DB candidate task according to queue policy.
  • Submit minimal lite claim message to the role HCS topic for the task required role.
  • Determine whether this claim is the winner by HCS topic ordering and task current claim state.
  • If winner, create claims row, set task status claimed, store HCS proof, and return task details from DB/storage.
  • If missed because another claim won, record internal miss and try next eligible candidate until bounded_attempt_limit is reached.
  • If no candidate can be won, return no_tasks with backoff.
  • If policy/auth/capability validation fails, return rejected and do not write HCS.