Ingestion Protocol & CAS Concurrency
Machine agents (GrokBot and Mango) sync mutations from Notion into Cloudflare D1 via:
POST /v1/finances/changes
(Also available via the alias /v1/finanzas/cambios)
Payload Specification
Each payload contains a batch of up to 50 operations wrapped in an atomic envelope.
{
"schema_version": 1,
"request_id": "req-2026-11-10-001",
"atomic": true,
"events": [
{
"event_id": "evt-001",
"entity_type": "movement",
"entity_id": "mov-coto-101",
"revision": 1,
"operation": "upsert",
"payload": {
"kind": "expense",
"status": "confirmed",
"description": "Coto Supermercado",
"occurred_on": "2026-11-10",
"amount_minor": 4500000,
"currency": "ARS",
"category_id": "cat-super",
"from_account_id": "acc-bbva-ars",
"source_refs": [
{ "type": "notion", "ref": "page_notion_49182", "role": "capture" }
]
}
}
]
}
Durable Receipt Response
{
"request_id": "req-2026-11-10-001",
"committed": true,
"processed_count": 1,
"results": [
{
"event_id": "evt-001",
"entity_type": "movement",
"entity_id": "mov-coto-101",
"status": "applied",
"current_revision": 1
}
]
}
CAS Concurrency & Idempotency Rules
- Exact Idempotency Replay:
Submitting an identical
request_idwith matching body hash returns the durable receipt directly with HTTP 200 without executing duplicate writes. - Request ID Collision:
Submitting an identical
request_idwith altered content returns409 Conflict. - Optimistic Locking (CAS):
- If an entity exists at
revision = N:- Ingesting
revision < Nreturns statusstale_rejected. - Ingesting
revision = Nwith identical payload hash returns statusduplicate. - Ingesting
revision = Nwith altered content throws409 Conflict. - Ingesting
revision > Napplies the update and updates the revision counter.
- Ingesting
- If an entity exists at
- All-or-Nothing Batch Atomicity: If any single item in an atomic batch fails schema validation or database constraints, all operations within that batch are reverted without partial commits.