activity-core/workplans/ADHOC-2026-10-19.md
tegwick 42347da012 feat(ops-runs): expire claims that keep losing their lease
Lapsed claims were reopened with no attempt ceiling, so a run whose worker
lost its lease (including a 409 before dispatch) could cycle forever.
Activity Core now reopens a lapsed claim below OPS_RUN_MAX_ATTEMPTS and sets
terminal 'expired' at the ceiling. The owner is kept for audit, and
/ops-runs/expire-leases reports reopened and expired counts. Answers the
REINAH-WP-0003-T05 open point on thread 27cd4c47 (ACTIVITY-WP-ADHOC-2026-10-19).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Assistant: claude-code
Assistant-Model: opus
Assistant-Process: 244572@bnt-lap001
Assistant-Session: 3b235e1a-ae45-4d0f-ae70-17a9bd78ece8
2026-10-19 15:30:29 +02:00

48 lines
1.6 KiB
Markdown

---
id: ACTIVITY-WP-ADHOC-2026-10-19
type: workplan
title: Activity Core owns recovery of lapsed ops_run leases
domain: infotech
repo: activity-core
status: active
owner: claude-activity-core
created: "2026-10-19"
updated: "2026-10-19"
related: [REINAH-WP-0003]
---
Origin: rein-aharness REINAH-WP-0003-T05 open point on thread 27cd4c47. When
the worker's first heartbeat gets a 409 before dispatch, the run stays
`claimed`, because a worker must not close a lease it has lost. Activity
Core's position: that is correct, and recovery is Activity Core's job.
## Expire claims that keep losing their lease
```task
id: ACTIVITY-WP-ADHOC-2026-10-19-T01
status: done
priority: high
```
`reopen_stale_claims` returned every lapsed claim to `open` with no attempt
ceiling, so a row that kept losing its lease could cycle forever. New
`expire_stale_claims` in `ops_run_queue.py`, which runs before each claim and
behind `POST /ops-runs/expire-leases`, now reopens lapsed claims below
`OPS_RUN_MAX_ATTEMPTS`. At the ceiling it sets terminal `expired`, keeps the
owner for audit and records `result.error`. A late close on an expired row is
refused as `state_conflict`. The endpoint returns
`{"reopened": n, "expired": m}`. Contract documented in
`docs/ops-run-queue.md`, with three new tests in `tests/test_ops_run_queue.py`.
## Release the expiry change to production
```task
id: ACTIVITY-WP-ADHOC-2026-10-19-T02
status: wait
blocked_on: human-gate:image-release
priority: medium
```
Wait: this ships with the next image release through the normal GitOps path,
the same release that carries repository grant v2 (ACTIVITY-WP-0046-T03). No
rollout from this session.