Expose per-device save sync attribution and origin device#3479
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds origin-device attribution for saves and expands save responses to include sync state for all devices (with device names) when a caller provides a device_id.
Changes:
- Add
origin_device_idtoSave(DB + API schema) with FK behaviorON DELETE SET NULL. - Add DB query helper to fetch all device syncs for a set of saves, including device names.
- Update saves endpoints to return
device_syncsacross all devices for device-scoped requests; add/extend tests.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| backend/models/assets.py | Adds origin_device_id column to Save ORM model. |
| backend/alembic/versions/0081_save_origin_device.py | Introduces migration adding column + index + FK for origin device tracking. |
| backend/handler/database/device_save_sync_handler.py | Adds get_syncs_for_saves() to fetch syncs + device names in bulk. |
| backend/endpoints/saves.py | Returns full per-device sync lists (with stable caller-first ordering) and sets origin_device_id on create. |
| backend/endpoints/responses/assets.py | Exposes origin_device_id on SaveSchema. |
| backend/tests/handler/database/test_device_save_sync_handler.py | Tests new sync-fetch grouping and origin-device FK cascade behavior. |
| backend/tests/endpoints/test_saves.py | Tests endpoint behavior for multi-device syncs and origin-device persistence. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
saves responses now include one device_syncs entry per device that has synced a save, not just the caller's, so clients can tell which devices hold a save. is_current is computed per entry and the caller's own entry is ordered first for backward compatibility. add a saves.origin_device_id column (migration 0081) recording the device that created a save, set on initial upload only, surfaced as origin_device_id on the save schema.
tmgast
force-pushed
the
fix/save-device-attribution
branch
from
June 5, 2026 11:30
5e478f9 to
96534ad
Compare
gantoine
approved these changes
Jun 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Saves sync per device, but the saves endpoints only ever returned the
caller's own sync row, so a client couldn't tell which devices hold a
save or which one created it. This enhancement exposes full per-device
sync attribution and records each save's creating device.
Changes
Full
device_syncslist. Device-scoped saves responses (list andsingle-save: get, upload, update, download-confirm, track/untrack) now
return one entry per device that has synced the save, each with its own
is_currentandis_untracked, caller's entry first. A newget_syncs_for_saveshandler fetches them for a page in one joinedquery. Requests without
device_idare unchanged.origin_device_id. New nullable column (migration 0082, FKdevicesON DELETE SET NULL, indexed) recording the device thatcreated a save, set on initial upload only and exposed on the save
schema. Existing saves remain NULL.
Tests
device_syncscontent and caller-first ordering;device_syncsomitted withoutdevice_id.origin_device_idset on creation, preserved across updates anddownloads, nulled when its device is deleted.
get_syncs_for_saveshandler coverage.Checklist