{"record":{"id":"0dbf4994c7d3c16b","repo":"Significant-Gravitas/AutoGPT","slug":"chat-read-path-unhealthy-session-not-found-after","errorCode":null,"errorMessage":"Chat read path unhealthy: session not found after create","messagePattern":"Chat read path unhealthy: session not found after create","errorType":"http","errorClass":"HTTPException","httpStatus":503,"severity":"critical","filePath":"autogpt_platform/backend/backend/api/features/chat/routes.py","lineNumber":1986,"sourceCode":"\n    \"\"\"\n    from backend.data.user import get_or_create_user\n\n    # Ensure health check user exists (required for FK constraint)\n    health_check_user_id = \"health-check-user\"\n    await get_or_create_user(\n        {\n            \"sub\": health_check_user_id,\n            \"email\": \"health-check@system.local\",\n            \"user_metadata\": {\"name\": \"Health Check User\"},\n        }\n    )\n\n    # Create and retrieve session to verify full data layer\n    session = await create_chat_session(health_check_user_id, dry_run=False)\n    fetched = await get_chat_session_metadata(session.session_id, health_check_user_id)\n    if fetched is None:\n        raise HTTPException(\n            status_code=503,\n            detail=\"Chat read path unhealthy: session not found after create\",\n        )\n\n    return {\n        \"status\": \"healthy\",\n        \"service\": \"chat\",\n        \"version\": \"0.1.0\",\n    }\n\n\n# ========== Schema Export (for OpenAPI / Orval codegen) ==========\n\nToolResponseUnion = (\n    AgentsFoundResponse\n    | NoResultsResponse\n    | AgentDetailsResponse\n    | SetupRequirementsResponse","sourceCodeStart":1968,"sourceCodeEnd":2004,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/chat/routes.py#L1968-L2004","documentation":"HTTP 503 from the chat health-check endpoint (routes.py:1986). The probe creates a synthetic user and a real chat session (dry_run=False), then reads it back via get_chat_session_metadata. If the freshly created session cannot be found, the read path is declared unhealthy and the endpoint returns 503 'Chat read path unhealthy: session not found after create'.","triggerScenarios":"Hitting the chat health check while the database (Prisma/Postgres) is failing reads, in a split-brain state, or when the create committed to a different store than the read (e.g. read replica lag or misrouted connections).","commonSituations":"Load balancer health probes going red during DB incidents; Postgres restart/failover; replica lag after a burst of writes; a misconfigured DATABASE_URL pointing writes and reads at different instances.","solutions":["Check Postgres health and the backend DB connection (Prisma logs, DATABASE_URL) — the write succeeded but the read didn't.","If using read replicas, verify replication lag and that the health check reads from the primary.","Ops: this failing means the load balancer should pull the instance; investigate the DB before user-facing debugging.","Rule out test-env flakiness where the health-check user/session fixtures collide."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { await get('/chat/health'); } catch (e) {\n  if (e.status === 503) { markInstanceUnhealthy(); pageOut(); alertOps('chat DB read path broken'); return; }\n  throw e;\n}","preventionTips":["Wire this endpoint into load-balancer probes: 503 should pull the instance","Check read-replica lag and DATABASE_URL routing when it fires — write succeeded, read didn't","Treat failure as a database incident, not an app bug; investigate Postgres first"],"tags":["http","health-check","database","postgres","availability","fastapi"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}