I've struggled with this in the past, and every time I work on a project with a custom FAPI form that involves multiple elements and submit buttons to either add another, or do some other fun AJAXy goodness it seems to rear its head again. In the past I've found various messy ways to resolve the problem, but I think I've finally discovered the real "clean" way.
What's the problem I'm talking about?
Suppose you have three instances of a custom compound field, each with an ajax button to go perform some action and update another element in the "field" ... Initial testing seems to be working fine, until you actually add multiple instances and realize that no matter which button you click it's behaving as if the LAST instance of that button was clicked. Furthermore, I can never seem to find the solution documented anywhere. Infuriating! Surely I'm not the ONLY person who struggles with this.