I think what you have right is that taxable income is irrelevant. Forgetting anything about foreign income, if someone earns $4000 (in taxable compensation*) in the US they can contribute $4000 to an IRA even if their standard deduction is greater than $4000 and their taxable income is zero.
As you note (and so sayeth the IRS):
Compensation does not include any of the following items.
Any amounts (other than combat pay) you exclude from income, such as foreign earned income and housing costs.
There is not a separate Roth limit in the sense that you can contribute $5000 total to either one or the other or both, e.g., $3000 traditional and $2000 Roth.
Contributions on your behalf to a traditional IRA reduce your limit for contributions to a Roth IRA.
If contributions are made to both Roth IRAs and traditional IRAs established for your benefit, your contribution limit for Roth IRAs generally is the same as your limit would be if contributions were made only to Roth IRAs, but then reduced by all contributions for the year to all IRAs other than Roth IRAs. Employer contributions under a SEP or SIMPLE IRA plan do not affect this limit.
This means that your contribution limit is the lesser of:
$5,000 ($6,000 if you are age 50 or older) minus all contributions (other than employer contributions under a SEP or SIMPLE IRA plan) for the year to all IRAs other than Roth IRAs, or
Your taxable compensation minus all contributions (other than employer contributions under a SEP or SIMPLE IRA plan) for the year to all IRAs other than Roth IRAs.
However, for determining your MAGI for reducing your Roth contribution limits:
Add the following deductions and exclusions:
Traditional IRA deduction,
Foreign earned income exclusion,
Foreign housing exclusion or deduction,
If you file Form 1040, refigure the amount on the page 1 “adjusted gross income” line without taking into account any of the following amounts.
Foreign earned income exclusion.
Foreign housing exclusion or deduction.
This is your modified AGI.
See pub 590 for information on IRAs. 401(k) contributions don't show up on your 1040.