{"record":{"id":"a5ffba3b722db16c","repo":"Significant-Gravitas/AutoGPT","slug":"nightly-batch-scheduling-failed-type-exc-name","errorCode":null,"errorMessage":"Nightly batch scheduling failed: {type(exc).__name__}: {exc}","messagePattern":"Nightly batch scheduling failed: (.+?): (.+?)","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/admin/memory_admin_routes.py","lineNumber":897,"sourceCode":"    except ValueError as exc:\n        raise HTTPException(status_code=400, detail=str(exc))\n\n    job_id = str(_uuid.uuid4())\n    status = await write_initial_status(kind=\"nightly\", job_id=job_id, user_id=target)\n\n    try:\n        await get_scheduler_client().schedule_immediate_nightly_batch(\n            user_id=target, job_id=job_id\n        )\n    except Exception as exc:\n        logger.warning(\n            \"Failed to schedule nightly batch %s for user %s: %s\",\n            job_id[:12],\n            target[:12],\n            exc,\n        )\n        await _mark_schedule_failed(\"nightly\", job_id, exc)\n        raise HTTPException(\n            status_code=500,\n            detail=f\"Nightly batch scheduling failed: {type(exc).__name__}: {exc}\",\n        )\n\n    payload = JobTriggerResponse(\n        job_id=status.job_id,\n        user_id=status.user_id,\n        kind=status.kind,\n        state=status.state,\n        started_at=status.started_at,\n    )\n    return JSONResponse(status_code=202, content=payload.model_dump(mode=\"json\"))\n\n\n@router.get(\n    \"/{user_id}/nightly/{job_id}\",\n    response_model=NightlyJobStatus,\n)","sourceCodeStart":879,"sourceCodeEnd":915,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/admin/memory_admin_routes.py#L879-L915","documentation":"HTTP 500 raised when the nightly batch trigger is accepted (202 flow started, initial status written) but get_scheduler_client().schedule_immediate_nightly_batch raises. The job row is marked failed via _mark_schedule_failed and the exception type and message are included in the response detail.","triggerScenarios":"POST /{user_id}/nightly where scheduling enqueue fails: scheduler/broker down, credential or network mismatch between API and scheduler, or an exception inside the scheduler client. The response is 500 and the stored job state transitions to failed.","commonSituations":"Scheduler process not started in dev; RabbitMQ/Redis container stopped or restarting at the moment of the call; env var drift after config changes; scheduler overloaded rejecting connections.","solutions":["Check the 'Failed to schedule nightly batch' warning in API logs for the underlying exception","Ensure scheduler and broker services are healthy and the API can connect (docker compose ps, network settings)","Poll GET /{user_id}/nightly/{job_id}/status to confirm the failed state, then re-trigger to get a fresh job","Align API and scheduler versions/config if a deploy left them inconsistent"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"# Before triggering, confirm broker/scheduler reachable from ops dashboard or healthcheck","typeGuard":null,"tryCatchPattern":"except httpx.HTTPStatusError as e:\n    if e.response.status_code == 500 and \"Nightly batch scheduling failed\" in e.response.json()[\"detail\"]:\n        await backoff_and_retry_once()  # job row already marked failed; new POST issues new job_id\n    raise","preventionTips":["Run scheduler/broker as supervised services with restart policies","On 500, always fetch the failed job status before retrying to confirm cause","Don't reuse the job_id from a failed trigger"],"tags":["http-500","scheduler","nightly-batch","broker"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}