Play sessions and saves
Play-session and asset services preserve a player's activity and game progress. They record durable play time, expose short-lived live activity, and move saves, emulator states, memory cards, and screenshots between players, devices, and play environments. This page is a child of Play and client services and relates to Remote library sync, Netplay and streaming, and Save snapshots and channels.
Player data boundary
The service separates a record of play from the data that helps a player resume a game. A play session records time. A save or state records game progress. A memory card preserves emulator media across sessions. A screenshot shows that progress or acts as a gallery image.
| Data | Main purpose | Sharing model |
|---|---|---|
| Play session | Record when and how long a player used a ROM | Durable history for the owner |
| Active activity | Show who is playing now | Short-lived live view |
| Save | Preserve game or emulator progress | Private by default; public items can be shared |
| State | Preserve a full emulator checkpoint | Private by default; public items can be shared |
| Memory card | Preserve emulator media across play containers | Private by default; public cards can be read |
| Screenshot | Show progress or add a gallery image | Private by default |
Ownership and visibility
Durable play and asset records belong to a user. Normal queries therefore stay within the user's data, while public saves, states, memory cards, and gallery screenshots can appear in shared ROM views. ROM and platform visibility rules still apply to those shared results. References: backend/…/assets.py• L95-170, backend/…/assets.py• L173-310, backend/…/assets.py• L311-377, backend/…/snapshot.py• L36-101, backend/…/channel.py• L17-59
Play records
Play tracking has two forms with different lifetimes. Durable sessions support history and time totals. Active activity supports a live “now playing” view and is not the source of durable history.
Durable play sessions
The play-session service accepts a single session or a batch and stores the user's relationship to a ROM and device. It validates the time range, ignores retries that identify the same session, and returns the result for each submitted item. Clients can query or delete their own history through the play-session API.
Accepted sessions also update the user's latest-played progress for the ROM. This update moves forward only when the session is newer, so backfilled history does not make current progress look older. References: backend/…/play_session.py• L26-60, backend/…/play_sessions.py• L25-139, backend/…/play_session_handler.py• L41-169
Live activity
Live activity is a temporary view keyed by user and device. A client starts or refreshes it with a heartbeat, and the service broadcasts changes to connected clients. A stop, disconnect, or expired heartbeat removes the entry.
The live view can show all active players or only players using one ROM. It includes the ROM, platform, device, start time, cover, and a current gameplay screenshot. Hidden ROMs and platforms are removed before the result is returned. References: backend/…/activity.py• L23-126, backend/…/activity.py• L9-15, backend/…/activity.py• L116-155, backend/…/activity_handler.py• L18-63
Play-page lifecycle
Player pages start durable recording only after playback is ready. They flush the session when playback ends or the page closes, so a route change or tab close can preserve the final duration. A failed launch does not become play history. References: frontend/…/EmulatorJS.vue• L201-210, frontend/…/EmulatorJS.vue• L651-681, frontend/…/Stream.vue• L774-780, frontend/…/Stream.vue• L1007-1012, frontend/…/Stream.vue• L1327-1361
Streaming claims and admin desktop claims protect a running resource. They are not ROM play records and do not provide save or resume data. References: frontend/…/Desktop.vue• L1-9, frontend/…/Desktop.vue• L58-71, frontend/…/Stream.vue• L674-714
This diagram shows how a client play signal becomes durable history or temporary live activity.
flowchart LR
C[Client or device] --> H[Play lifecycle]
H -->|exit or page close| D[(Durable play history)]
H -->|start and heartbeat| A[(Live activity)]
A --> V[REST and Socket.IO views]
C -->|stop or disconnect| X[Activity expiry or clear]
X --> V
References: backend/…/activity_handler.py• L1-63 backend/…/activity.py• L39-126 backend/…/activity.py• L158-246 frontend/…/EmulatorJS.vue• L651-659 frontend/…/Stream.vue• L491-519
Game data assets
Saves and states expose a common player-data model. This lets clients list, download, update, share, and delete progress in a consistent way. Memory cards use a separate identity and version history because one card can hold media for many games.
Save records
A save represents a user's progress file for a ROM. It carries the emulator context, optional slot, content identity, source device, sharing state, and owner annotations. An optional screenshot gives the save a visual preview.
The /api/saves interface supports upload, replacement, listing, download, sharing, rename, labels, favorites, deletion, and device tracking. Clients can scope lists to one ROM or a set of ROMs, and a device context adds sync results without changing the save set. Slot uploads can retain a bounded history. Repeated content can reuse an existing slot version instead of creating a duplicate. References: backend/…/assets.py• L173-242, backend/…/saves.py• L258-524, backend/…/saves.py• L527-598, backend/…/saves.py• L1024-1283
Save downloads can also adapt a save for the emulator that will use it. The endpoint can return the original file or a restored set of files for a target core, and it can merge those files into a supplied container. This keeps a stored save independent from the layout required by a specific player. References: backend/…/saves.py• L692-737, backend/…/saves.py• L826-920, backend/…/saves.py• L932-988
Emulator states
An emulator state is a full checkpoint rather than a normal game save. It can include the emulator and core context, a mounted disc reference, an origin device, a public flag, and a matching preview screenshot. State routes provide the same broad lifecycle as save routes, including list, content access, sharing, and deletion. References: backend/…/assets.py• L244-309, backend/…/states.py• L25-205, backend/…/states.py• L228-284
Resume choices
The player treats saves and states as alternative resume sources. A state restores the emulator checkpoint, while a save restores game data. The default choice is the newest compatible item, and the player warns when a selected item is older than newer progress. The player sends only the chosen asset or slot into the launch flow. References: frontend/…/resumeSelection.ts• L1-64, frontend/…/EmulatorJS.vue• L498-545, frontend/…/Stream.vue• L299-410, frontend/…/launchIntent.ts• L1-83
Memory cards
A memory card is a named user asset scoped to an emulator rather than to one ROM. Each upload creates a new version. The newest version is the card used by the next play container, while older versions remain available as history.
The memory-card interface lets an owner create, upload, download, rename, share, inspect history, and delete cards. Other users can browse and download public cards, but only the owner can change their versions. References: backend/…/assets.py• L311-386, backend/…/memory_cards.py• L39-158, backend/…/memory_cards.py• L198-434, frontend/…/MemoryCardManager.vue• L43-313
Screenshot assets
Screenshots serve two related purposes. An automatic screenshot can preview a save or state, while a gallery screenshot is an intentional image attached to a ROM view. The is_gallery and is_public flags separate those purposes and their sharing rules.
Save and state previews are matched to the related user's ROM asset by file name or file-name stem. Gallery uploads use a direct screenshot route instead. Public asset changes also update the preview's visibility so a shared item does not lose its expected image. References: backend/…/assets.py• L143-170, backend/…/assets.py• L226-241, backend/…/assets.py• L297-308, backend/…/screenshots.py• L36-162, backend/…/saves.py• L1099-1130, backend/…/screenshots_handler.py• L17-45
Save synchronization
Device synchronization adds per-device knowledge to a shared save. A device marker records when a device received a version and whether it has stopped tracking that save; it does not create a second logical save.
Device sync markers
Save uploads, downloads, and explicit download confirmations update the marker for the authenticated device. Device-scoped save responses report all known devices and place the caller's device first. A device with no marker receives an unsynced result, while requests without device context omit per-device markers.
Device-bound tokens cannot act on another device's save data. This keeps tracking, download confirmation, and sync-session accounting tied to the device that owns the token. References: backend/…/device_save_sync.py• L16-34, backend/…/saves.py• L110-169, backend/…/saves.py• L180-191, backend/…/saves.py• L991-1021, backend/…/auth.py• L22-73
Save conflict boundary
An upload from a known device is rejected when the server has newer progress than the device has seen, unless the client explicitly overwrites it. Slotted uploads compare the current slot version. Unslotted uploads compare the selected save. The autosave slot represents automatic progress, while an unslotted save remains an archival upload. References: backend/…/assets.py• L29-33, backend/…/saves.py• L194-228, backend/…/saves.py• L341-363
The browser can send a small final save during page close. It uses overwrite because the close path cannot wait for a conflict round trip, and it skips files above the browser keepalive limit. References: frontend/…/save.ts• L22-47, frontend/…/save.ts• L121-175
Channel snapshots
A channel is a named playthrough for one ROM or target file. It points to its current snapshot, while snapshots preserve fixed checkpoints that can contain one save and a bank of emulator states. This model extends save synchronization from a single file to a coherent set of game data.
Snapshots can be channel checkpoints, standalone archival items, or branches created when concurrent progress cannot replace the expected channel state. A device-channel record stores the snapshot a device last applied and the latest channel version it knows. This gives synchronization a base for detecting moved progress and gives shared channels a clear current state. References: backend/…/channel.py• L12-59, backend/…/snapshot.py• L21-123, backend/…/device_channel_sync.py• L12-40, backend/…/assets.py• L109-140
Snapshot access follows ownership and sharing boundaries. Owners can read their snapshots. Other users can read snapshots in a public channel or public archival snapshots. Snapshot pins preserve a readable checkpoint from pruning. References: backend/…/snapshot.py• L93-101, backend/…/snapshot.py• L126-141
This diagram shows how a channel groups the current checkpoint and how device sync records relate to it.
flowchart LR
D[Device] --> DS[Device-channel sync]
DS -->|base and latest known| C[Channel]
C -->|current pointer| S[Current snapshot]
S --> P[Save]
S --> ST[State bank]
S --> B[Branch or archival history]
References: backend/…/channel.py• L35-59 backend/…/device_channel_sync.py• L23-40 backend/…/snapshot.py• L36-123
Player-facing interfaces
The API exposes activity, history, and game data through focused routes and ROM responses. Protected routes enforce user or asset access, while content routes also check that the parent ROM and platform are visible.
Activity and history interfaces
Activity routes serve the live player board. Play-session routes serve durable history. ROM-facing views can use the latest save preview and related screenshots to show where a player last stopped. References: backend/…/activity.py• L23-126, backend/…/play_sessions.py• L25-139, backend/…/screenshots.py• L1-23, backend/…/__init__.py• L830-855
ROM data interfaces
ROM detail responses combine the user's private data with other users' public saves, states, and screenshots. Community entries include their owner identity for display, and recent updates appear first so launch and browsing views can focus on current progress. References: backend/…/rom.py• L565-571, backend/…/rom.py• L648-705, backend/…/assets.py• L11-125
Save data workspace
The save-data view gives each ROM one place to browse saves and emulator states. It separates owned data from community data, lets owners change their own items, and keeps community items read-only apart from download. Player views use the same data to present launch and resume choices. References: frontend/…/SaveDataTab.vue• L53-121, frontend/…/SaveDataTab.vue• L130-597, frontend/…/EmulatorJS.vue• L860-987, frontend/…/Stream.vue• L843-913
Change checklist
When these files or sections are changed, remember to consider these:
- Keep play-session validation, retry identity, batch results, and sync completion aligned across both ingestion paths.
- Keep player start and close-flush points aligned with the boundary for durable history.
- Keep save and state visibility changes coupled to their automatic preview screenshots.
- Keep save slot meaning consistent between upload, conflict checks, and the browser autosave path.
- Keep device-bound token checks aligned with save reads, writes, downloads, tracking, and sync-session counts.
- Keep caller-first ordering and the unsynced-device result stable in device-scoped save responses.
- Keep ROM scope intersection and empty-scope behavior aligned for save and state lists.
- Keep channel current pointers, snapshot parent links, device bases, and branch conflict reasons consistent when synchronization rules change.
- Keep snapshot visibility rules aligned for owned, public-channel, and public-archival reads.
- Keep the newest memory-card version as the current play input while retaining older versions as history.
- Keep memory-card public reads separate from owner-only writes and keep emulator scoping stable.
- Keep screenshot matching stable for both exact file names and file-name stems.
- Keep save restoration output compatible with the target emulator or core and its container path.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
| A client retries a session with the same identity | Duplicate history is not created | Session identity checks and database uniqueness |
| Playback fails before the runtime is ready | Failed starts do not become play history | Start recording only after playback is active |
| A heartbeat stops or a client disconnects | Live activity expires or clears | Heartbeat lifetime and disconnect cleanup |
| A device uploads over newer server progress | The upload is rejected and newer data remains | Per-device sync comparison unless overwrite is explicit |
| A device-bound token names another device | The action cannot access that device's data | Shared token-to-device validation |
| A save or state is private to another user | The content is returned as not found | Owner-or-public and ROM visibility checks |
| A save or state file is missing from storage | Metadata may remain but content download fails | Stored-path and file checks |
| A slotted upload repeats existing content | A second copy is not kept | Content matching within the user's ROM and slot |
| A page closes with an oversized save | The keepalive path cannot send the final data | Client-side size limit before unload upload |
| A memory-card archive is unsafe or too large | The new card version is rejected | Archive safety and size validation |
| A channel moves before a device pushes its progress | The push becomes a branch or conflict result | Snapshot base and current-version comparison |
| A public snapshot is requested without a public channel or archival flag | Another user cannot read it | Snapshot ownership and visibility rules |
| A selected resume item is removed or no longer compatible | The player cannot restore that selection | Resolve selections against current compatible data |
Key files
| File | Why to read it |
|---|---|
| backend/…/play_sessions.py | Main contract for durable play history |
| backend/…/play_session_handler.py | Session validation, retry handling, and progress effects |
| backend/…/activity.py | REST live activity and heartbeat interface |
| backend/…/activity.py | Realtime activity updates |
| backend/…/assets.py | Shared save, state, screenshot, and memory-card model |
| backend/…/saves.py | Save lifecycle, restoration, visibility, and device sync |
| backend/…/channel.py | Named playthrough and current snapshot model |
| backend/…/snapshot.py | Checkpoint, branch, archival, and state-bank model |
| backend/…/device_channel_sync.py | Device knowledge of channel snapshots |
| backend/…/device_save_sync.py | Device knowledge of save versions |
| backend/…/states.py | Emulator-state lifecycle and sharing |
| backend/…/memory_cards.py | Memory-card versions and access rules |
| backend/…/screenshots.py | Player gallery screenshot lifecycle |
| backend/…/rom.py | ROM responses that combine personal and public game data |
| frontend/…/EmulatorJS.vue | Browser play lifecycle and resume choices |
| frontend/…/Stream.vue | Streaming resume, memory-card, and claim-aware play flow |
| frontend/…/resumeSelection.ts | Default resume and newer-progress rules |
| frontend/…/SaveDataTab.vue | Save and state browsing workspace |
| frontend/…/MemoryCardManager.vue | Player memory-card controls |