fix: release reserved L2 agent when AMI redirect fails during escalation
deploy / deploy (push) Successful in 32s
deploy / deploy (push) Successful in 32s
Found during production smoke test: if the AMI Redirect call in create_escalation() raises (channel gone, AMI hiccup), the agent stays RESERVED forever with no owning call — orphaned out of the pool until someone fixes it by hand. Now releases the agent and marks the escalation failed before re-raising as a 502.
This commit is contained in:
@@ -721,15 +721,25 @@ def create_escalation(call_id: str, body: EscalationRequestIn, actor: dict) -> E
|
|||||||
session.commit()
|
session.commit()
|
||||||
raise HTTPException(status_code=409, detail=f"No available {body.target_level} agent right now")
|
raise HTTPException(status_code=409, detail=f"No available {body.target_level} agent right now")
|
||||||
|
|
||||||
bridge._ami_action(
|
try:
|
||||||
"Redirect",
|
bridge._ami_action(
|
||||||
{
|
"Redirect",
|
||||||
"Channel": channel,
|
{
|
||||||
"Context": bridge._transfer_context(),
|
"Channel": channel,
|
||||||
"Exten": reserved_extension,
|
"Context": bridge._transfer_context(),
|
||||||
"Priority": 1,
|
"Exten": reserved_extension,
|
||||||
},
|
"Priority": 1,
|
||||||
)
|
},
|
||||||
|
)
|
||||||
|
except Exception as exc:
|
||||||
|
try:
|
||||||
|
bridge._release_routing_agent(call_id)
|
||||||
|
except Exception:
|
||||||
|
LOGGER.warning("bridge.escalation_release_agent_failed call_id=%s", call_id)
|
||||||
|
escalation.status = "failed"
|
||||||
|
escalation.completed_at = utc_now_iso()
|
||||||
|
session.commit()
|
||||||
|
raise HTTPException(status_code=502, detail=f"Failed to redirect call to agent: {exc}") from exc
|
||||||
|
|
||||||
escalation.status = "ringing"
|
escalation.status = "ringing"
|
||||||
escalation.assigned_agent_id = reserved_extension
|
escalation.assigned_agent_id = reserved_extension
|
||||||
|
|||||||
Reference in New Issue
Block a user