fix: exclude foreign-claimed work from allocation instead of blockading the queue (Closes #765)

Recovered preserved candidate d06198b onto current master 0c2f45a via clean
cherry-pick. Active foreign leases are excluded before allocator ranking;
controller_instance_id ownership is persisted; dashboard matches allocator
exclusion. Stable patch-id bacafc5f… preserved.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This commit is contained in:
2026-07-20 13:52:39 -05:00
co-authored by Claude Opus 4.8
parent 0c2f45abb7
commit ad13d872df
5 changed files with 735 additions and 22 deletions
+16
View File
@@ -19211,6 +19211,7 @@ def gitea_allocate_next_work(
apply=bool(apply),
profile_name=profile_name,
username=username,
controller_instance_id=allocator_service.resolve_controller_instance_id(),
)
if inv_reasons:
result.setdefault("inventory_warnings", inv_reasons)
@@ -19378,6 +19379,7 @@ def gitea_workflow_dashboard(
leases: list[dict] = []
terminal_pr: int | None = None
terminal_lock: dict | None = None
claims: dict = {}
db, db_errs = _control_plane_db_or_error()
if db is None:
inv_reasons.extend(db_errs or ["control-plane DB unavailable"])
@@ -19416,6 +19418,18 @@ def gitea_workflow_dashboard(
inv_reasons.append(
f"terminal lock lookup failed: {_redact(str(exc))}"
)
try:
# #765: live claims so the dashboard never advertises another
# controller's active task as safe next work.
claims = db.list_active_claims(
remote=remote if remote in REMOTES else remote,
org=o,
repo=r,
)
except Exception as exc: # noqa: BLE001
inv_reasons.append(
f"active claim lookup failed: {_redact(str(exc))}"
)
snap = workflow_dashboard.build_workflow_dashboard(
candidates=candidates,
@@ -19427,6 +19441,8 @@ def gitea_workflow_dashboard(
terminal_lock=terminal_lock,
inventory_complete=inventory_complete,
inventory_reasons=inv_reasons,
claims=claims,
controller_instance_id=allocator_service.resolve_controller_instance_id(),
)
payload = snap.as_dict()
payload["inventory_source"] = (