It is well settled that where, as here, the defendant’s factual plea allocution casts doubt upon her guilt by negating an essential element of the crime or by raising a defense, the court may not accept the plea without making further inquiry into whether, in fact, the defendant is guilty and apprising her of the availability of any defense implicated by her allocution (People v Thomas, 159 AD2d 529, 530; People v Zeth, 148 AD2d 960, 961; People v Benton, 143 AD2d 526). If, in pleading, the defendant’s allocution casts doubt upon her guilt, she must be given an opportunity to withdraw her plea and she "shall not be permitted to plead guilty under such circumstances until the court ascertains that the defendant is aware of what [s]he is doing” (People v Nixon, 21 NY2d 338, 344, cert denied sub nom. Robinson v New York, 393 US 1067). In the instant case, the defendant, in pleading guilty to a charge of criminal sale of a controlled substance in the fifth degree, stated facts which established the existence of a possible agency defense. Because the court did not explain to the defendant the existence of this possible agency defense, her guilty plea was not knowing, intelligent and voluntary (cf., People v Pelaccio, 141 AD2d 772). Accordingly, the court should not have denied her motion to withdraw her plea (see, People v Flihan, 166 AD2d 927).
As the defendant’s plea was not knowingly, intelligently and voluntarily entered, her waiver of her right to appeal was similarly deficient (see, People v Bray, 154 AD2d 692, 693). Therefore, this ineffective waiver does not preclude review of the denial of the defendant’s motion to withdraw her plea, as the right to challenge the voluntariness of the plea is a right that the defendant always retains (see, People v Seaberg, 74 NY2d 1, 10; cf., People v Hall, 176 AD2d 960; People v Stephens, 175 AD2d 272). Kunzeman, J. P., Balletta, Miller and Ritter, JJ., concur.