fix(author bootstrap): resolve allocator session ownership, authority alignment, and test coverage (#943)
This commit is contained in:
@@ -196,6 +196,58 @@ def _verify_assignment_and_lease_ids(
|
||||
# Some lease rows may not yet have an assignment join; still require
|
||||
# the lease itself to exist and bind to the claimed session/issue.
|
||||
pass
|
||||
# #943 review 622 B2: a lease that is no longer live confers no ownership.
|
||||
# Existence alone previously satisfied this gate, so a released or expired
|
||||
# lease could still authorize a bootstrap for a claim its session had given
|
||||
# up. Checked before the session comparison so the reason names the real
|
||||
# problem rather than reporting a mismatch.
|
||||
from datetime import datetime, timezone
|
||||
|
||||
lease_status = str(lease.get("status") or "").strip().lower()
|
||||
if lease_status and lease_status != "active":
|
||||
return {
|
||||
"success": False,
|
||||
"reason_code": "lease_not_live",
|
||||
"message": (
|
||||
f"lease_id '{lid}' is '{lease_status}', not active; a lease that "
|
||||
"is not live confers no ownership (fail closed)."
|
||||
),
|
||||
"exact_next_action": (
|
||||
"Re-allocate the work item and pass the live assignment/lease pair."
|
||||
),
|
||||
}
|
||||
expires_raw = str(lease.get("expires_at") or "").strip()
|
||||
if expires_raw:
|
||||
try:
|
||||
expires_at = datetime.fromisoformat(expires_raw.replace("Z", "+00:00"))
|
||||
except ValueError:
|
||||
return {
|
||||
"success": False,
|
||||
"reason_code": "lease_not_live",
|
||||
"message": (
|
||||
f"lease_id '{lid}' records an unparseable expiry "
|
||||
f"'{expires_raw}' (fail closed)."
|
||||
),
|
||||
"exact_next_action": (
|
||||
"Re-allocate the work item and pass the live "
|
||||
"assignment/lease pair."
|
||||
),
|
||||
}
|
||||
if expires_at.tzinfo is None:
|
||||
expires_at = expires_at.replace(tzinfo=timezone.utc)
|
||||
if expires_at <= datetime.now(timezone.utc):
|
||||
return {
|
||||
"success": False,
|
||||
"reason_code": "lease_not_live",
|
||||
"message": (
|
||||
f"lease_id '{lid}' expired at {expires_raw}; an expired lease "
|
||||
"confers no ownership (fail closed)."
|
||||
),
|
||||
"exact_next_action": (
|
||||
"Reclaim or re-allocate the lease, then retry with the live pair."
|
||||
),
|
||||
}
|
||||
|
||||
lease_session = str(lease.get("session_id") or "").strip()
|
||||
if lease_session and lease_session != owner_session:
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user