The bug
When I give myself extra max health with an attribute, then gain health, log out and log back in there are empty hearts but not the health.
Steps to Reproduce:
Give yourself a diamond sword that grants double health and hold it in your main hand.
/give @s diamond_sword[attribute_modifiers={modifiers:[{type:"generic.max_health",amount:20.0,slot:mainhand,id:"extra_max_hp_from_sword",operation:add_value}]}]
Give yourself some regeneration.
/effect give @s minecraft:regeneration 3 3 false
Take note of the health you currently have.
Reload into the world and once again, take note of the health that you now have.
Observed Behavior:
Additional health granted with items that have attributes is lost upon reloading the world.
Expected Behavior:
Additional health granted with items that have attributes would not be lost upon reloading the world.
Related issues
is duplicated by
Attachments
Comments

I can confirm this in 13w24b

Confirmed.
Still present in 13w15a
@up You mean 13w25a?
@Dominik, Yes I meant 13w25a.
Also just confirmed with the 1.6 pre-release you don't even have to log out to lose the extra health. I gave myself the Health boost effect x 4, healed up and then the health just vanished and I was left with 10 empty hearts. Was in survival mode and the character body shuddered like I was taking damage but with not hurt sound. And that left me with an empty health boost.
I've just tested with the long regen potion. Every time the Health Boost Effect hits a 30 second mark the additional health is removed.
Oh and the health now remains after login, as long as it's within that 30 second window.

@Pete Frisky: That's MC-18976
@Kumasasa Thanks for the heads up that it is a separate issue now.
confirment
Still an issue in 1.6.2.
Still an issue in 14w10c. Ran into this with a diamond chestplate with an Attrubute Modifier to give me 35 hearts (70 total max health). Healing back the extra 25 hearts at the start of every session is costly (but then I use cheats to give myself a stack of instant health potions).

Cannot Reproduce in 1.8.1 Pre3, assuming it is Fixed
Still an issue in 1.9.0. Have a chestplate that gives me 3 extra hearts (26 health in total). Relogging changes me back to a current health of 20 and costs me saturation to heal back the 3 extra hearts.
Note: max health is 20 instead of 26 until the world finishes loading in. The chestplate only appears on me a good 2-3 seconds after the world starts. Same deal with chests and any other "entities" that look like blocks.
EDIT: just occurred to me that you'll want confirmation for either the latest release version or the latest snapshot, rather than the outdated 1.9.0. Just started a new world in 1.9.3pre1 to test it, and the bug is still present.
To reproduce: use this command in a command block to create the armor: /give @p diamond_chestplate 1 0 {AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:6,Operation:0,UUIDLeast:894654,UUIDMost:2872}]}
Put it on and allow yourself to finish healing back the extra hearts. Then save and quit, and re-enter the world. You will be back down to 10 full hearts and 3 empty ones. This wastes saturation healing each time.
I can reproduce this in 1.10.2.
Note that extra hearts from the Health Boost effect persists over a relog, but extra health from AttributeModifiers does not.

Affects 1.13-pre6. Please keep the issue updated accordingly.
Also, change the example command to:
/give @p diamond_sword{AttributeModifiers:[{AttributeName:"generic.maxHealth",Name:"generic.maxHealth",Amount:20d,Operation:0,UUIDLeast:111113,UUIDMost:1111,Slot:"mainhand"}]}
as that is proper format for 1.13.
Affects 1.14.2-Pre-Release 3
Can confirm in 20w51a.
Can confirm in 21w03a.
Can confirm in 21w05b.
Can confirm in 21w06a.
Can confirm in 21w07a. Video attached.
Can confirm in 1.16.5 and 21w08b.
Can confirm in 21w11a.
Can confirm in 21w15a.
Can confirm in 1.17.
Can confirm in 1.17.1.
Can confirm this behavior in 21w39a. Here are some extra details regarding this problem.
The Bug:
Additional health granted with items that have attributes is lost upon reloading the world.
Steps to Reproduce:
Give yourself a diamond sword that grants double health and hold it in your main hand.
/give @s minecraft:diamond_sword{AttributeModifiers:[{AttributeName:"minecraft:generic.max_health",Amount:20,UUID:[I;1,2,3,4],Slot:"mainhand"}]}
Give yourself some regeneration.
/effect give @s minecraft:regeneration 3 3 false
Take note of the health you currently have.
Reload into the world and once again, take note of the health that you now have.
Observed Behavior:
Additional health granted with items that have attributes is lost upon reloading the world.
Expected Behavior:
Additional health granted with items that have attributes would not be lost upon reloading the world.
Can confirm in 1.18.2.
Can confirm in 1.19.

Can confirm for 23w33a.
(Approximate) expected behavior: On the first tick where a LivingEntity is being deserialized, don't run the check comparing health with LivingEntity.getMaxHealth() until the underlying field has been initialized to account for Attributes.
(Please. It's been 10 years.)
Can confirm for 1.21, also for Custom Enchantments using said perk (/Attribute one works however)