fix(snapshots): record the pushing device on a snapshot's states (#5720)

A push stored its save with origin_device_id and its states with none.
The web player counts a state with no origin_device_id as its own and
prefers a state on a tie, so after a console pushed a save and states in
the same snapshot, the web player booted the console's state instead of
its save, though that state may be another core's or older than the save.

A pushed state now carries the same origin_device_id as the save beside
it.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
MMagTech
2026-11-22 10:01:19 -05:00
committed by GitHub
parent ac9f5ab505
commit 23ea65e2fe
2 changed files with 14 additions and 1 deletions

View File

@@ -493,6 +493,7 @@ async def _store_part(
"user_id": plan.owner.id,
"emulator": write.manifest.emulator,
"emulator_version": write.manifest.emulator_version,
"origin_device_id": write.origin_device_id or write.device_id,
}
row: Save | State
if is_save:
@@ -507,7 +508,6 @@ async def _store_part(
),
shape=entry.shape,
format=entry.format,
origin_device_id=write.origin_device_id or write.device_id,
core=write.manifest.core,
core_version=write.manifest.core_version,
)

View File

@@ -82,6 +82,19 @@ async def test_the_first_push_creates_the_channel_and_points_it_at_the_snapshot(
assert sync.base_snapshot_id == snapshot.id
async def test_the_pushed_save_and_states_carry_the_device_that_wrote_them(
admin_user: User, rom: Rom, hashed_file: RomFile, device: Device
):
result = await first_push(admin_user, rom, hashed_file, device_id=device.id)
with sync_session() as session:
save = session.get_one(Save, result.snapshot.save_id)
state = session.get_one(State, result.snapshot.states[0].state_id)
assert result.snapshot.origin_device_id == device.id
assert save.origin_device_id == device.id
assert state.origin_device_id == device.id
async def test_a_client_supplied_channel_id_creates_that_channel(
admin_user: User, rom: Rom, hashed_file: RomFile
):