Expand description
SQLite-backed outbox queue for fire-and-forget cloud uploads.
Every fire-and-forget cloud POST (trajectory, review_metrics,
accepted_edit, mcp_query, imported_reviews) is first appended as a
pending row in the global ~/.difflore/data.db. Drain is triggered
synchronously from hook / CLI cold paths — there is deliberately no
background daemon.
Claim/confirm semantics:
enqueue() -> INSERT status='pending'
claim_next() -> UPDATE status='processing' (atomic, oldest first)
confirm(id) -> DELETE
mark_failed() -> UPDATE retry_count++; >=MAX_RETRY_COUNT -> status='abandoned'
reset_stale() -> processing > threshold seconds -> pendingCircuit breaker: three consecutive mark_failed calls trip the breaker
for 60 s; while open, claim_next returns None so callers short-
circuit without hammering an unreachable cloud. Any successful
confirm resets the consecutive-failure counter.
Idempotency contract: claim_next deliberately self-heals stale
processing rows after DEFAULT_STALE_SECONDS. A very slow upload can
therefore be retried by a later drain pass. Every cloud endpoint reached
from this queue must treat duplicate payloads as idempotent, keyed by
the event id / request signature carried in the payload. The queue
chooses at-least-once delivery over permanent local data loss.
Modules§
- kind
- Supported outbox payload kinds. Stored as TEXT in
cloud_outbox.kind; thedrain_outboxdispatcher matches on these to pick the right POST route. Keep the string literals stable — changing one means abandoning every row in the queue at upgrade time.
Structs§
- Accepted
Edit Attribution Summary - Drain
Summary - Result of a
drain_abandoned_older_thancall (dry-run or real). - Outbox
Counts - Summary row for
difflore doctor/ diagnostics. - Outbox
Drain Report - Outbox
Item - A row in
cloud_outboxthat has been claimed for processing. - Outbox
Queue - Queue handle. Cheap to clone; all state is either on disk or inside
an
Arc<Atomic*>so multiple callers inside the same process observe the same breaker state.
Enums§
- Circuit
State - Current state of the breaker.
Openmeans callers should short- circuit until theuntil_unix_mstimestamp has passed.
Constants§
- CIRCUIT_
FAILURE_ THRESHOLD - How many consecutive
mark_failedcalls trip the circuit breaker. - CIRCUIT_
OPEN_ DURATION_ MS - How long (ms) the circuit stays open before
claim_nextstarts returning rows again. - DEFAULT_
STALE_ SECONDS - How long a processing row is allowed to sit before
reset_stalewill recover it. Anything claimed by a crashed / hung drain pass falls back topendingafter this many seconds. - MAX_
RETRY_ COUNT - Maximum delivery attempts per outbox item. After this many failures,
the item is marked
abandonedand is no longer claimed.
Functions§
- drain_
outbox - Drain at most
max_itemsoutbox rows. For each claimed row, invoke the appropriateCloudClientmethod, thenconfirmon success ormark_failedon HTTP / network failure. Returns(attempted, confirmed). - drain_
outbox_ kind - drain_
outbox_ kind_ report - drain_
outbox_ report