phacility/phabricator · error · Exception
Trying to activate a lease which has the wrong status: statu
Error message
Trying to activate a lease which has the wrong status: status must be "%s", actually "%s".
What it means
DrydockLease::activateOnResource() performs the ACQUIRED → ACTIVE transition, so it hard-requires the lease to currently be in STATUS_ACQUIRED. If the lease is still PENDING (acquisition never happened or has not committed), already ACTIVE, or RELEASED/BROKEN, activation refuses with this Exception. Like the acquisition precondition, this is a state-machine invariant — retrying the identical call cannot succeed; the lease's real status must be reconciled first.
Source
Thrown at src/applications/drydock/storage/DrydockLease.php:333
$this->logEvent(DrydockLeaseAcquiredLogType::LOGCONST);
if ($new_status == DrydockLeaseStatus::STATUS_ACTIVE) {
$this->didActivate();
}
return $this;
}
public function isAcquiredLease() {
return $this->isAcquired;
}
public function activateOnResource(DrydockResource $resource) {
$expect_status = DrydockLeaseStatus::STATUS_ACQUIRED;
$actual_status = $this->getStatus();
if ($actual_status != $expect_status) {
throw new Exception(
pht(
'Trying to activate a lease which has the wrong status: status '.
'must be "%s", actually "%s".',
$expect_status,
$actual_status));
}
if ($resource->getStatus() == DrydockResourceStatus::STATUS_PENDING) {
// TODO: Be stricter about this?
throw new Exception(
pht(
'Trying to activate a lease on a pending resource.'));
}
$this->openTransaction();
try {
DrydockSlotLock::acquireLocks($this->getPHID(), $this->slotLocks);View on GitHub (pinned to 5720a38cfe)
Solutions
- Follow the canonical order: acquireOnResource() first, then activateOnResource() — see DrydockWorkingCopyBlueprintImplementation::executeCommand lease handling
- Reload the lease before activating and assert status is STATUS_ACQUIRED; skip if another worker already advanced it
- If the lease is still PENDING, queue it for normal processing (lease update worker) instead of forcing activation
- If RELEASED/BROKEN, discard and create a new lease
Example fix
// before
$lease->activateOnResource($resource);
// Exception: Trying to activate a lease which has the wrong status: status must be "acquired", actually "pending".
// after
$lease = id(new DrydockLeaseQuery())
->setViewer($viewer)
->withPHIDs(array($lease->getPHID()))
->executeOne();
if ($lease->getStatus() !== DrydockLeaseStatus::STATUS_ACQUIRED) {
return; // not ready or already advanced
}
$lease->activateOnResource($resource); Defensive patterns
Strategy: validation
Validate before calling
// Assert ACQUIRED status before activating:
$lease = id(new DrydockLeaseQuery())
->setViewer($viewer)
->withPHIDs(array($lease->getPHID()))
->executeOne();
if ($lease->getStatus() !== DrydockLeaseStatus::STATUS_ACQUIRED) {
// not acquired yet (or already advanced): reconcile instead of activating
}
$lease->activateOnResource($resource); Try / catch
catch (Exception $ex) { on 'must be "acquired"', reload the lease and branch: PENDING → run acquisition first; ACTIVE → nothing to do; RELEASED/BROKEN → create a new lease } Prevention
- Enforce the acquire → activate order in custom blueprint code; stock example is DrydockWorkingCopyBlueprintImplementation
- Idempotency-check with a fresh load before every lifecycle call
- Let the lease update worker drive transitions where possible instead of forcing them inline
When it happens
Trigger: Calling activateOnResource() on a freshly-created PENDING lease without calling acquireOnResource() first; double activation from two workers; activating a lease object whose in-memory status predates another daemon's transition.
Common situations: Custom blueprints implementing their own activation step (the stock path is in DrydockWorkingCopyBlueprintImplementation, which calls activateOnResource after acquiring); retry wrappers that re-enter activation after a partial failure; manual state poking during debugging.
Related errors
- Trying to acquire a lease on a resource which is in the wron
- Trying to acquire an active lease on a pending resource. You
- Trying to activate a lease on a pending resource.
- Working copy lease is missing required attribute "%s". Attr
- Use "--lease" to specify a lease.
AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21).
Data as JSON: /api/errors/f050f4888f066c44.
Report an issue: GitHub.