One pull at a time: the run is claimed in the database and its marker rides in each batch

A second pull (schedule, Run button, `app job pull` in another process) could
start while one was fetching and overwrite the stored run marker, so the first
run's boards failed their stamp check or a settle closed on the other run's id
lists. `claim_run` sets `pull:run` in one conditional statement, only while it
equals `pull:settled` or is older than an hour; a refused `pull` job queues no
stage and says so in its result and a notice, and the CLI exits 1. Batches
carry the marker in their payload, the plugins stamp with it, and the settle
reads it off its own batches' payloads before releasing the run.

Co-Authored-By: Claude Opus <noreply@anthropic.com>
This commit is contained in:
WolfandClaude Opus committed 2026-09-29 14:12:17 +02:00
1 parent c7da12b93d
commit b43fc54565
11 files changed
+328 -70

No files matched your search

+13
View File
@@ -1237,6 +1237,19 @@ class Store:
"SELECT key, value FROM state WHERE substr(key, 1, ?) = ? ORDER BY key",
(len(prefix), prefix))}
def claim_state(self, key: str, value: str, *, released: str, stale: str) -> bool:
"""Set `key` to `value` only while it is free: unset, equal to the
value under `released` (the claim last let go of), or no later than
`stale`. Returns whether it was set. One statement, so of two
processes claiming at once exactly one wins."""
return self._write(
"""INSERT INTO state (key, value) VALUES (?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value
WHERE state.value <= ?
OR state.value = COALESCE(
(SELECT r.value FROM state AS r WHERE r.key = ?), '')""",
(key, value, stale, released)) > 0
def _check_status(status: str) -> None:
if status not in STATUSES: