Well, you're using Jamba, so have you made sure you don't have master switches on window change enabled? If Jamba is switching your master, then party1 may be the slave on some occasions.

Can't speak to AHK, but your master is physically targeting the NPC first? If you are trying to select a target on the main at the same time as telling the slave to assist and target, the slave might not yet "see" the target in order to assist.