From 5063fcb469a7ba8ad233a90e484eb5add13d549c Mon Sep 17 00:00:00 2001 From: operator Date: Sun, 4 Oct 2026 16:47:36 +0000 Subject: [PATCH] fix(cdp_queue): auto-purge stale queue tickets older than 2x acquire timeout --- bin/cdp_queue.py | 13 +++++++++++-- job-sidechats.json | 5 +++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/cdp_queue.py b/bin/cdp_queue.py index eda98be..82bf711 100644 --- a/bin/cdp_queue.py +++ b/bin/cdp_queue.py @@ -89,9 +89,10 @@ def _ensure_dirs(node): def _read_tickets(node): - """Return sorted list of (priority, timestamp, ticket_name).""" + """Return sorted list of (priority, timestamp, ticket_name), purging stale tickets.""" tdir = _tickets_dir(node) out = [] + now = time.time() try: for name in os.listdir(tdir): if not name.endswith(".ticket"): @@ -100,7 +101,15 @@ def _read_tickets(node): # ticket name: "--.ticket" parts = name[:-7].split("-") prio_s, ts_s = parts[0], parts[1] - out.append((int(prio_s), float(ts_s), name)) + ts = float(ts_s) + # Purge stale ticket if process crashed or timed out ungracefully + if now - ts > (ACQUIRE_TIMEOUT * 2): + try: + os.unlink(os.path.join(tdir, name)) + except Exception: + pass + continue + out.append((int(prio_s), ts, name)) except (ValueError, IndexError): continue except FileNotFoundError: diff --git a/job-sidechats.json b/job-sidechats.json index 1ce871f..c7c5656 100644 --- a/job-sidechats.json +++ b/job-sidechats.json @@ -17,5 +17,10 @@ "thread_uuid": "da55b05c-19c6-4bdb-8f8b-e507d7430ca2", "agent": "opm", "created_at": "2026-10-04T16:39:34.721269+00:00" + }, + "pipe-9735f2": { + "thread_uuid": "0077e918-9ac8-40ba-b0ad-65f9f78037c4", + "agent": "opm", + "created_at": "2026-10-04T16:43:03.587214+00:00" } } \ No newline at end of file