Merge two strikes for boards swept across pulls (wp-b-strikes)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
19401cfc7a
5 files changed
+373
-11
No files matched your search
+52
-1
@@ -24,6 +24,13 @@ filtered read, or one of a reader that declares `empty="suspect"`, that lists
|
||||
under a tenth of what the same read listed last time is recorded by the
|
||||
runner as a failure, not as a list to close against.
|
||||
|
||||
A board swept across pulls (`ats:swept:<target>`, a complete read that finished
|
||||
a sweep an earlier pull began) closes a role only when two finished sweeps in a
|
||||
row missed it (`_close_swept`): offset paging drifts when roles close between
|
||||
pulls, so one sweep can miss a role that is still open. The ids a finished
|
||||
sweep missed are kept in `ats:missing:<target>`, and a complete read that was
|
||||
not swept clears them.
|
||||
|
||||
A read narrowed by the agents' fetch terms (`ats:narrowed:<target>`) lists
|
||||
the roles matching a word, which says nothing of the roles it did not list,
|
||||
so it closes nothing; only an unfiltered or a place-filtered complete read
|
||||
@@ -282,7 +289,12 @@ def close_boards(config: Config, store: Store, tally: Tally, *,
|
||||
if store.state.get(f"{source}:narrowed:{sub.target}", ""):
|
||||
continue
|
||||
seen_ids = json.loads(store.state.get(f"{source}:ids:{sub.target}", "[]"))
|
||||
if store.state.get(f"{source}:filtered:{sub.target}", ""):
|
||||
is_filtered = bool(store.state.get(f"{source}:filtered:{sub.target}", ""))
|
||||
if store.state.get(f"{source}:swept:{sub.target}", ""):
|
||||
closed += _close_swept(store, source, sub, seen_ids, is_filtered)
|
||||
continue
|
||||
store.state.pop(f"{source}:missing:{sub.target}", None)
|
||||
if is_filtered:
|
||||
closed += _close_unlisted(store, source, seen_ids, sub.id)
|
||||
else:
|
||||
closed += store.mark_closed(source, seen_ids, sub.id)
|
||||
@@ -313,6 +325,45 @@ def _close_unlisted(store: Store, source: str, seen_ids: list[str], subscription
|
||||
(store.now(), source, subscription_id, json.dumps(list(seen_ids)))).rowcount
|
||||
|
||||
|
||||
def _close_swept(store: Store, source: str, sub: Any, seen_ids: list[str],
|
||||
filtered: bool) -> int:
|
||||
"""The close of a board whose complete read finished a sweep across
|
||||
pulls: its open roles missing from `seen_ids` that also are in
|
||||
`<source>:missing:<target>`, the ones the previous finished sweep missed.
|
||||
The ones missing now are kept there for the next sweep. A role one sweep
|
||||
missed may only have shifted back past the cursor when roles closed
|
||||
between pulls, so one sweep is not evidence that it is gone. A filtered
|
||||
read keeps its exceptions as `_close_unlisted` does: a role acted on
|
||||
stays open, and stays in `missing`."""
|
||||
key = f"{source}:missing:{sub.target}"
|
||||
try:
|
||||
earlier = {str(i) for i in json.loads(store.state.get(key) or "[]")}
|
||||
except (TypeError, ValueError):
|
||||
earlier = set()
|
||||
acted_on = """ AND uid NOT IN (SELECT uid FROM role_votes)
|
||||
AND uid NOT IN (SELECT role_uid FROM applications
|
||||
WHERE role_uid IS NOT NULL)""" if filtered else ""
|
||||
with store.transaction() as conn:
|
||||
missed = [row[0] for row in conn.execute(
|
||||
"""SELECT source_id FROM roles
|
||||
WHERE source = ? AND subscription_id = ? AND closed_at IS NULL
|
||||
AND source_id NOT IN (SELECT value FROM json_each(?))""",
|
||||
(source, sub.id, json.dumps(list(seen_ids))))]
|
||||
closing = [row[0] for row in conn.execute(
|
||||
f"""SELECT source_id FROM roles
|
||||
WHERE source = ? AND subscription_id = ? AND closed_at IS NULL
|
||||
AND source_id IN (SELECT value FROM json_each(?))
|
||||
AND source_id IN (SELECT value FROM json_each(?)){acted_on}""",
|
||||
(source, sub.id, json.dumps(sorted(earlier)), json.dumps(missed)))]
|
||||
count = conn.execute(
|
||||
"""UPDATE roles SET closed_at = ?
|
||||
WHERE source = ? AND subscription_id = ? AND closed_at IS NULL
|
||||
AND source_id IN (SELECT value FROM json_each(?))""",
|
||||
(store.now(), source, sub.id, json.dumps(closing))).rowcount
|
||||
store.state[key] = json.dumps(sorted(set(missed) - set(closing)))
|
||||
return count
|
||||
|
||||
|
||||
def failing_boards(store: Store) -> dict[str, tuple[str, str]]:
|
||||
"""`target -> (since, reason)` for every `ats` board whose last fetch
|
||||
failed: when the failures began, and what the latest one said."""
|
||||
|
||||
Reference in new issue
Block a user