OK here is the reason this messes up. The nested hypotheticals confuse it.
The first time IGG is played, when gainCopperPriority is invoked:
Coins is $3.
A hypothetical state is created to determine the coin gain margin.
In this hypothetical state, the first time IGG is played, in gainCopperPriority:
Coins is $4.
A hypothetical state is created to determine the coin gain margin.
In this hypothetical state:
A recursion-avoidance check changes the phase from treasure to buy.
(This means we don't play the IGG we have in hand, in this hypothetical.)
Therefore the amount of coins is $4.
We want a Duchy, so the coin gain margin is $1. We have one IGG in hand, so
we gain the copper.
In this hypothetical state, the second time IGG is played, in gainCopperPriority:
Coins is $6 (since we gained a copper with the previous IGG, played it, then
played this IGG).
A hypothetical state is created to determine the coin gain margin.
In this hypothetical state:
A recursion-avoidance check changes the phase from treasure to buy.
(This doesn't matter since we have no treasure remaining in hand.)
Therefore the amount of coins is $5.
So the coin gain margin is $3, since hypothetically we can afford a duchy and
the next step up is province. We have no IGGs in hand, so we don't gain a copper.
Therefore the coin gain margin will be $2, since we ended the hypothetical state
with $6, and we would like to bump up our buy to province. We have 2 IGGs in hand,
so therefore we decide to gain a copper.
The second time IGG is played, when gainCopperPriority is invoked:
Coins is $5.
A hypothetical state is created to determine the coin gain margin.
In this hypothetical state, when IGG is played, in gainCopperPriority:
Coins is $6.
A hypothetical state is created to determine the coin gain margin.
In this hypothetical state:
A recursion-avoidance check changes the phase from treasure to buy.
(This doesn't matter since we have no treasure remaining in hand.)
Therefore the amount of coins is $6.
We want a province, so the coin gain margin is $2. We have no IGGs in hand, so
we do not gain a copper.
Therefore the coin gain margin will be $2, since we ended the hypothetical state
with $6, and we would like to bump up our buy to province. We have 1 IGG in hand,
so therefore we decide to NOT gain a copper.
So that explains why it gains copper with the first IGG and not the second IGG.