My answer pertains to Washington, which has a similar law. The circumstances where it is legal for one person to intentionally kill another are highly limited in all states: using Washington terminology, you must be justified, and "because he asked me to" is not an legal justification. "Death with dignity" does not allow a doctor to kill a patient, it allows them to assist a person in killing themselves. Suicide is not illegal in Washington, or generally, in the US (see this question), but it is still a crime if another "knowingly causes or aids another person to attempt suicide" (RCW 9a.36.060).
A terminally-ill patient may request medication to end his life, and the physician can under specified conditions prescribe appropriate medication. Pursuant to RCW 70.245.190, a person who has acted in accordance with this chapter is not criminally or civilly liable for participating in this act: but they have to follow the rules. I can't at this point ferret out the civil liability laws that say that a doctor cannot knowingly prescribe a fatal overdose (it's about doctors, patients, and prescriptions), but I am confident that they exist in Washington. This law states a very narrow exception to that law, as well as the criminal law against helping a person kill himself. The only sense in which the patient "grants immunity" is by voluntarily and informedly making a request, which the doctor can grant, thereby acting according to law. Most importantly: it is the patient who kills himself.
Setting aside special liabilities that doctors are subject to, the general definition of homicide is RCW 9a.32.10
Homicide is the killing of a human being by the act, procurement, or
omission of another, death occurring at any time, and is either (1)
murder, (2) homicide by abuse, (3) manslaughter, (4) excusable
homicide, or (5) justifiable homicide.
Any killing of another by act, procurement, or omission is homicide (nb: "killing" is not statutorily defined). The first 3 kinds of killings are punishable, the last two are not. Excusable homicide is "when committed by accident or misfortune in doing any lawful act by lawful means, without criminal negligence, or without any unlawful intent", meaning at minimum that the act be unintended – not the described situation. Justifiable homicide divides into the "officer" case which is very lengthy (about police in the performance of their duty), and the case of "others", where it comes down to "defense of self or others". If B kills A, and the killing is not justifiable, then it is a punishable offense. There is no defense "he asked me to;" the allowed defenses are only "excusable" and "justifiable".