Skip to content

Commit d87e7d8

Browse files
committed
fix: remove cancelled jobs from queue to prevent orphaned runners
1 parent 1b4033c commit d87e7d8

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

app.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,19 @@ async def github_webhook(request: Request):
459459

460460
# Handle cancellation - terminate sandbox
461461
if conclusion == "cancelled":
462-
# Check if job was in active jobs
462+
removed_from_queue = False
463+
464+
# Check if job was in the queue - remove it if found
465+
if run_id in _run_configs:
466+
queue = _run_configs[run_id].queue
467+
for i, queued_job in enumerate(queue):
468+
if queued_job.job_id == job_id:
469+
del queue[i]
470+
logger.info(f"Removed cancelled job {job_id} from queue")
471+
removed_from_queue = True
472+
break
473+
474+
# Check if job was in active jobs - terminate sandbox
463475
if job_id in _active_jobs:
464476
try:
465477
_active_jobs[job_id].sandbox.terminate()
@@ -479,7 +491,7 @@ async def github_webhook(request: Request):
479491
await _try_process_queue(run_id)
480492

481493
# Fallback: also check by tag for robustness
482-
else:
494+
elif not removed_from_queue:
483495
for sb in modal.Sandbox.list(
484496
app_id=app.app_id, tags={"job_id": job_id}
485497
):

0 commit comments

Comments
 (0)