{
  "version": 2,
  "name": "codeflash-internal-psycopg-serialization",
  "description": "sync_to_async with thread_sensitive=True serializes all concurrent DB calls through one thread and one Postgres connection, making TaskGroup parallelism a no-op.",
  "eval_type": "async",
  "repo": "codeflash-ai/codeflash-internal",
  "commit": "cc4eaf4392eba26206820d7106f681f8bbfccff4",
  "fix_commit": "5972dc2e03bc4a362a88f95f4819d27eb1679d02",
  "prompt": "Concurrent DB calls in log_features are fully serialized — calling multiple aexists() in a TaskGroup shows no speedup vs sequential. Profile or diagnose why, and fix the connection-level bottleneck.",
  "bugs": [
    {
      "id": "sync-to-async-thread-sensitive",
      "file": "django/aiservice/core/log_features/log_features.py",
      "function": "log_features",
      "description": "sync_to_async defaults to thread_sensitive=True, routing all calls to a single shared thread. Under ASGI, this means one Postgres connection for all concurrent operations.",
      "domain": "async"
    },
    {
      "id": "psycopg2-no-pooling",
      "file": "django/aiservice/aiservice/settings.py",
      "description": "psycopg2 has no native connection pooling. Combined with thread_sensitive=True, every concurrent call shares one connection.",
      "domain": "async"
    }
  ],
  "rubric": {
    "criteria": {
      "diagnosed_serialization": 3,
      "identified_root_cause": 3,
      "correct_fix": 2,
      "tests_pass": 2
    },
    "total": 10,
    "notes": {
      "diagnosed_serialization": "Agent discovered that concurrent DB calls are serialized. Evidence: profiling, asyncio debug mode, pg_backend_pid check, or source-reading that identifies thread_sensitive behavior.",
      "identified_root_cause": "Agent identified thread_sensitive=True and/or single-connection sharing as the bottleneck, not a surface symptom like 'slow queries'.",
      "correct_fix": "Agent implemented a fix that enables parallel DB connections: thread_sensitive=False, driver migration with pooling, or connection pool configuration.",
      "tests_pass": "All tests pass after the fix."
    }
  }
}
