openloops.receiver_tick#
One tick of the board-receiver job: check for work without a model, then hand over.
ADR-011. A launchd StartInterval job runs this every few minutes. Starting a Claude
session on every tick would cost money while nothing is pending, so the tick first asks
the board store, with plain HTTP and no model, whether anything needs the receiver.
Only if something does (or the question cannot be answered) does it replace itself with
the real command, claude -p <the receiver prompt>.
Liveness. Every successful check writes the board’s meta/receiver heartbeat
(the receiver’s own document, under the session name from board/board.json), so an
idle board stays green and a dead job turns it amber after 20 minutes. It also touches a
local board-receiver.lastcheck stamp, which ol receiver-job-status reports as
“last check”, separately from “last work” (the log, written only by ticks with work).
Fail closed on configuration, open on anything else. A configuration error (no credentials file, a missing key, a cleartext origin, a refused sign-in, a 403 from the store) cannot be fixed by a session, so the tick starts none and says so in the log on every tick; the stale heartbeat turns the board amber. Any other failure (the store down, a malformed answer, a bug here) starts the session anyway, because a check that silently suppressed the receiver would be the failure this package exists to prevent. Repeated failures back off exponentially: one hour, then two, four, capped at six.
This is the one module that talks to the network, to the owner’s own board store (the
HTTP API of ADR-009). Nothing imports it; import openloops never loads it.
The work set is the one references/receiver.md defines: events with no receipt,
processing receipts older than 15 minutes, and queued receipts and failed
receipts marked transient. Those last two are retried only once they are an hour old
(RETRY_AFTER): a receipt that waits on another machine, a busy worker or a
lasting GitHub error would otherwise start a paid session every tick, all day, to change
nothing. The sign-in is the one in references/receiver-http.md.
Module Attributes
A |
|
A |
|
After a failed check starts a session, the next one waits this long, doubling with each further failure up to |
Functions
|
Ask the store whether anything needs the receiver. |
|
What needs the receiver, from the store's two collections ( |
|
|
|
|
Classes
|
The reasons the receiver is needed; empty means nothing to do. |
Exceptions
The check cannot run as configured, and a session could not fix that either. |
- exception openloops.receiver_tick.ConfigError[source]#
Bases:
RuntimeErrorThe check cannot run as configured, and a session could not fix that either.
- openloops.receiver_tick.FAIL_OPEN_BACKOFF = datetime.timedelta(seconds=3600)#
After a failed check starts a session, the next one waits this long, doubling with each further failure up to
FAIL_OPEN_CAP: a lasting fault must not start a paid session every tick, all day.
- class openloops.receiver_tick.Pending(iterable=(), /)[source]#
Bases:
listThe reasons the receiver is needed; empty means nothing to do.
totalcounts the items behind those reasons (the heartbeat’spending);heartbeatsays whatcheck()did with the heartbeat.
- openloops.receiver_tick.RETRY_AFTER = datetime.timedelta(seconds=3600)#
A
queuedor transientlyfailedreceipt is retried only once it is this old.
- openloops.receiver_tick.STALE_CLAIM = datetime.timedelta(seconds=900)#
A
processingreceipt older than this is a sweep that died (receiver.md, section 0).
- openloops.receiver_tick.check(env_file=PosixPath('~/.config/openloops/board-receiver.env'), *, heartbeat_by=None, now=None)[source]#
Ask the store whether anything needs the receiver. Raises if it cannot ask:
ConfigErrorwhen no session could fix it, anything else otherwise.With heartbeat_by (the board’s session name) it also writes the
meta/receiverheartbeat, and says what happened in the result’sheartbeat. A failed heartbeat never fails the check: the board turning amber is how that shows.- Return type:
- openloops.receiver_tick.main(argv=None)[source]#
python -m openloops.receiver_tick [--check-only] [--env-file F] [-- CMD ...].- Return type:
- openloops.receiver_tick.pending_work(outbox, receipts, *, now=None, retry_after=datetime.timedelta(seconds=3600))[source]#
What needs the receiver, from the store’s two collections (
id -> data).queuedand transientlyfailedreceipts count only once theirat(or, lacking one,claimedAt) is older than retry_after; one with neither counts.>>> pending_work({'e1': {}}, {}) ['1 event(s) without a receipt'] >>> pending_work({'e1': {}}, {'e1': {'status': 'posted'}}) []
- Return type:
- openloops.receiver_tick.read_env_file(path)[source]#
KEY=VALUE/export KEY=VALUElines of an env file, parsed, never executed.>>> import tempfile, pathlib >>> f = pathlib.Path(tempfile.mkdtemp()) / 'e' >>> _ = f.write_text("# c\nexport A='x y'\nB=2\n\nbad line\n") >>> read_env_file(f) {'A': 'x y', 'B': '2'}