Skip to content

Expose per-device save sync attribution and origin device#3479

Merged
gantoine merged 3 commits into
rommapp:masterfrom
tmgast:fix/save-device-attribution
Jun 5, 2026
Merged

Expose per-device save sync attribution and origin device#3479
gantoine merged 3 commits into
rommapp:masterfrom
tmgast:fix/save-device-attribution

Conversation

@tmgast

@tmgast tmgast commented Jun 5, 2026

Copy link
Copy Markdown
Member

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_syncs list. Device-scoped saves responses (list and
    single-save: get, upload, update, download-confirm, track/untrack) now
    return one entry per device that has synced the save, each with its own
    is_current and is_untracked, caller's entry first. A new
    get_syncs_for_saves handler fetches them for a page in one joined
    query. Requests without device_id are unchanged.

  • origin_device_id. New nullable column (migration 0082, FK
    devices ON DELETE SET NULL, indexed) recording the device that
    created a save, set on initial upload only and exposed on the save
    schema. Existing saves remain NULL.

Tests

  • Multi-device device_syncs content and caller-first ordering;
    device_syncs omitted without device_id.
  • origin_device_id set on creation, preserved across updates and
    downloads, nulled when its device is deleted.
  • get_syncs_for_saves handler coverage.

AI Disclosure
Planning and review assisted by Claude Code.

Checklist

  • I've tested the changes locally
  • I've updated relevant comments
  • I've assigned reviewers for this PR
  • I've added unit tests that cover the changes

Copilot AI review requested due to automatic review settings June 5, 2026 11:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_id to Save (DB + API schema) with FK behavior ON 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_syncs across 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.

Comment thread backend/handler/database/device_save_sync_handler.py
Comment thread backend/alembic/versions/0082_save_origin_device.py
Comment thread backend/endpoints/saves.py
tmgast added 2 commits June 5, 2026 20:25
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
tmgast force-pushed the fix/save-device-attribution branch from 5e478f9 to 96534ad Compare June 5, 2026 11:30
@gantoine
gantoine merged commit 031fb57 into rommapp:master Jun 5, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants