{
  "db_name": "PostgreSQL",
  "query": "\n            UPDATE requests\n            SET\n                state = 'pending',\n                daemon_id = NULL,\n                claimed_at = NULL,\n                started_at = NULL\n            WHERE id IN (\n                SELECT id FROM (\n                    -- Time-based fallback: request stuck too long regardless of daemon state\n                    SELECT r.id FROM requests r\n                    WHERE\n                        (r.state = 'claimed' AND r.claimed_at < NOW() - ($1 || ' milliseconds')::INTERVAL)\n                        OR\n                        (r.state = 'processing' AND r.started_at < NOW() - ($2 || ' milliseconds')::INTERVAL)\n                    UNION\n                    -- Daemon-aware reclaim: daemon is dead or its heartbeat went stale\n                    SELECT r.id FROM requests r\n                    WHERE\n                        r.state IN ('claimed', 'processing')\n                        AND r.daemon_id IN (\n                            SELECT d.id FROM daemons d\n                            WHERE d.status = 'dead'\n                               OR d.last_heartbeat < NOW() - ($3 || ' milliseconds')::INTERVAL\n                        )\n                ) sub\n                LIMIT $4\n            )\n            ",
  "describe": {
    "columns": [],
    "parameters": {
      "Left": [
        "Text",
        "Text",
        "Text",
        "Int8"
      ]
    },
    "nullable": []
  },
  "hash": "bfa80538e264dcb78b0283db917f7501a3eda66d1d38fc410f41a3a1310ad026"
}
