Introducing a new way to review your PRs.

Read the announcement

rommapp / romm

A beautiful, powerful, self-hosted ROM manager and player.

View on GitHub

22 documents · Updated Nov 23, 2026

docs / remote-library-sync

Remote library sync

Remote library sync keeps a RomM user's save files aligned with a registered remote client. A device can exchange save state through the client API, a shared sync folder, an SSH/SFTP connection, or RetroArch Cloud Sync over WebDAV. Each run records a sync session, compares the two sides, and reports work, conflicts, and errors to the user.

Sync modes

The sync mode defines how a device presents save files to RomM. All modes use the same device record and save history, but they differ in who starts the transfer and where the file exchange takes place.

ModeMain actorFile exchangeTypical use
apiRemote clientClient sends save metadata to the sync API and executes the returned planClients that can call RomM directly
file_transferRomM watcherClient places files in an incoming folder and reads files from an outgoing folderDevices that use a mounted or shared folder
push_pullRomM taskRomM connects to the device and transfers files over SSH/SFTPDevices that expose configured save directories

Sync must be enabled on the device. A device registration can also supply mode-specific settings, such as remote directories for SSH/SFTP or a device folder layout for file transfer.

References: backend/…/device.py• L18-22 backend/…/device.py• L42-73 backend/…/device.py• L22-34

Sync sessions

A sync session is the user-visible record of one synchronization attempt for one device. It ties planned work to a device and user, stores progress counts, and ends with a completed, failed, or cancelled result.

The session lifecycle is:

flowchart LR
    A[Sync request or detected files] --> B[PENDING session]
    B --> C[IN_PROGRESS session]
    C --> D[COMPLETED session]
    C --> E[FAILED session]
    B --> F[CANCELLED session]
    C --> F

An API negotiation creates a session for that launch. It does not cancel another active session for the same device, because one device can have more than one game open at the same time. Cleanup handles a session that no owner closes. The API and worker paths complete their own sessions after the client or worker finishes its operations.

The session record exposes the device, start and end times, planned operations, completed operations, failed operations, and an error message when a run fails. Progress and result events use the user's socket room and carry the device and session identifiers so a client can update the correct run. Conflict notices from negotiation are sent after the response under a short deadline, so a slow broker does not block the client. A completion request can still report an expired session, but it cannot complete a session that was closed on purpose.

References: backend/…/sync_session.py• L17-53 backend/…/sync_sessions_handler.py• L14-30 backend/…/sync_sessions_handler.py• L43-64 backend/…/sync_sessions_handler.py• L100-172 backend/…/__init__.py• L160-216 backend/…/__init__.py• L219-526 backend/…/__init__.py• L529-599 backend/…/sync.py• L25-117

Save pairing and comparison

Save comparison decides whether RomM should accept the client file, send the server file, stop, delete a server-side copy, or ask for conflict handling. API clients pair a save by (rom_id, slot), while file-transfer and push-pull paths first identify the platform and then match a slot-bound server save by file name.

For API, file-transfer, and push-pull device sync, only slot-bound saves take part in pairing. A save with a null slot is an archival or manual-upload item for those paths. RetroArch WebDAV can also expose unslotted assets, including PSP save bundles, because that transport maps client file paths directly to library assets. For API clients, a stable non-null slot keeps a save paired across runs. RomM uses the newest server row for each ROM and slot unless a save channel supplies the current version for that slot. An emulator and core scope can further limit which saved versions the client can pair.

The comparison gives content hashes first priority. If both hashes match, it returns no_op. If the slot belongs to a save channel, the channel history can identify a version that moved forward or became a branch before ordinary timestamp comparison runs. For normal device history, the last-sync time shows which side changed. If both changed, the result is conflict. If only the client changed, it is upload; if only the server changed, it is download. Without sync history, the newer timestamp wins. Equal timestamps with different or missing content produce a conflict. A deletion record prevents an older client copy from undoing a server-side deletion.

ActionMeaning for the client or worker
uploadMove the client save into RomM
downloadMove the RomM save to the client
deleteRemove the server save because the client deletion is known
conflictKeep both changes for review instead of choosing one
no_opDo not move file data because the states are already aligned

This comparison uses hashes as identity evidence and timestamps as change evidence. It does not merge save-file contents. A save held by a sync channel is not overwritten in place; a newer device copy becomes a conflict or a separate version according to the transport.

References: backend/…/comparison.py• L9-110 backend/…/comparison.py• L113-219 backend/…/__init__.py• L269-477 backend/…/sync.py• L9-55 backend/…/assets.py• L86-108

API negotiation

API negotiation is a plan-building exchange between a client and RomM. The client sends its current save metadata and can send the ROM IDs and emulator or core capabilities available on the device. RomM returns a session ID and one operation per relevant save so the client can perform the transfers with clear reasons and server metadata.

An installed-ROM scope limits downloads to ROMs that the client can use. RomM also includes any ROM for which the client sent a save, even if that ROM was not in the scope. Emulator and core scopes limit pairing and downloads to saves that the client can load. These scopes are read-only: omitting a ROM, emulator, or core does not delete or unlink server saves.

The exchange follows this sequence:

sequenceDiagram
    participant C as Remote client
    participant R as RomM API
    participant S as Save store
    C->>R: Save states and optional device scopes
    R->>R: Create a session for this launch
    R->>S: Find current slot saves and channel heads in scope
    R->>R: Compare paired and missing saves
    R-->>C: Session ID and operation plan
    C->>R: Complete session with counts
    R->>R: Record save sync times
    R-->>C: Completed session

A client-only save becomes an upload operation. A server-only save becomes a download unless the device has already synced it and the server has not changed since that sync; that case is treated as an intentional client deletion. Clients that cannot intentionally delete saves can set restore_unlisted to request those missing saves again. A known server deletion can instead produce a delete operation for a stale client copy. An untracked save is returned as no_op, which lets the device opt out of that save without deleting the server copy. After the client performs the plan, it reports success and failure counts through the session completion endpoint.

The same completion request can include play-session records from the client. RomM ingests those records after it marks the sync session complete, which links play activity to the device and sync run. See play sessions and saves for the wider save and play-session model.

References: backend/…/__init__.py• L72-158 backend/…/__init__.py• L219-526 backend/…/__init__.py• L529-599 frontend/…/SyncNegotiatePayload.ts• L6-18

RetroArch WebDAV transport

RetroArch Cloud Sync uses a WebDAV surface as a separate remote-client transport. It gives RetroArch a manifest and a stable file view for saves, states, screenshots, and support data, then accepts client uploads and deletions so RomM can update the matching library assets.

The manifest is derived from current server data. It exposes visible, addressable saves and the newest state for each ROM, core folder, disc-named state, and load slot. RomM maps each emulator ID to its RetroArch core folder and treats all IDs that share that folder as one sync view. The core also supplies a platform scope for ROM lookup, which keeps the same file name on different platforms tied to the ROM that the core can run. If no platform-specific match exists, RomM can resolve a name through a ROM-owned file. For saves, a slotted .srm path represents the newest autosave version, while other save files remain at their own path. For states, a file that still exists on disk takes priority over a newer database row whose file is missing. State screenshots follow their state. RetroArch configuration, thumbnail, and system data use opaque user-scoped paths. Hashes let the client detect changes without RomM merging file contents.

The client addresses a ROM through its file name and optional emulator folder. RomM resolves that path against ROMs the user can see, first using the platform set for the core and then the file-name fallback. A path is advertised only when the same ROM would receive the request. State names map to load slots. A state named after a ROM file keeps a separate slot so multi-disc files do not overwrite one another. This lets a client keep using a stable RetroArch name even when the stored state file has another name. Uploads update an existing unslotted asset or add one when the path does not exist. Slotted save uploads create a new autosave version when the content changes. Repeated content does not create another version. State uploads keep stream captures as history rather than overwriting them. Deletes remove all versions covered by the path, so an older copy does not reappear on the next manifest. Missing files are excluded until the manifest can expose the next valid asset at that path. A save or state held by a sync channel is protected from an in-place WebDAV overwrite.

Before RetroArch overwrites or deletes an existing save, state, screenshot, or user blob, RomM can preserve the old file as a timestamped backup. Valid backup paths refer only to supported sync paths, and RomM stores them in a user-owned namespace with separate ROM and non-ROM areas. Retention follows the configured save-version limit, so backup history does not grow without bound. Upload target resolution is shared with normal writes, which keeps a backup tied to the exact file that the request would replace. A versioned slotted save has no overwrite target because its changed content becomes a new autosave version.

PSP save folders are handled as one logical save because their files only work as a set. RomM resolves the folder by its serial mapping or its PARAM.SFO title, using the PPSSPP platform scope for the mapping, stores the folder as a bundle, and exposes each bundle member as a separate RetroArch path. If a folder arrives before RomM can identify its ROM, RomM holds the files until the folder can be resolved. An empty bundle is removed when its last member is deleted. PSP bundle input is limited to a bounded number of members and total uncompressed size. A PARAM.SFO title is also size-limited before RomM uses it for a ROM search. These limits keep malformed or oversized folders from consuming unbounded memory or search work. When a PSP bundle is written, the shared archive-write safeguard makes the ZIP writer safe even when the archive reader extension is active.

The same surface exposes a read-only roms/ tree for generic WebDAV clients; RetroArch itself does not browse this tree. It presents non-empty visible platforms and ROMs as browsable files, uses absolute mount-relative WebDAV links, and redirects ROM content requests to the normal ROM content service. Each ROM appears as one file, including a ZIP view for multi-file ROMs. The browse tree follows the authenticated user's ROM and platform permissions. This path does not use the device sync-session negotiation flow.

References: backend/…/sync_handler.py• L63-189 backend/…/sync_handler.py• L194-377 backend/…/sync_handler.py• L386-577 backend/…/sync_handler.py• L588-748 backend/…/sync_handler.py• L762-847 backend/…/sync_handler.py• L893-1243 backend/…/psp.py• L45-104 backend/…/psp.py• L237-274 backend/…/psp.py• L276-329 backend/…/psp.py• L363-517 backend/…/psp.py• L533-678 backend/…/retroarch.py• L238-464 backend/…/retroarch.py• L467-643 backend/…/retroarch.py• L715-822

SSH and SFTP transport

Push-pull mode makes RomM the active transfer side. A background task connects to the device over SSH, uses SFTP to inspect configured save directories, and then pulls or pushes each matched file according to the comparison result.

SSH trust comes from an administrator-controlled known_hosts file. RomM checks the requested host and port against that allowlist before it opens a network connection, including an exact host-and-port entry for non-default ports. Authentication uses the mounted key named for the device when present, or a configured password when no key is available. A device-provided private-key path is ignored so one device cannot select another device's mounted key. The transport is created only when it is first used, so an unconfigured push-pull setup does not block application startup.

Remote directory settings identify a platform, its directory, and an optional file extension filter. RomM ignores missing directories and non-regular entries. It records each candidate's file name, size, modification time, platform, and remote path. A download also computes a content hash before comparison. Uploads create the target directory when needed and replace the remote file.

References: backend/…/ssh_handler.py• L43-61 backend/…/ssh_handler.py• L64-89 backend/…/ssh_handler.py• L91-150 backend/…/ssh_handler.py• L152-203 backend/…/ssh_handler.py• L205-240 backend/…/__init__.py• L428-445

Push-pull task execution

The push-pull task runs for enabled devices in push_pull mode. It can run for all such devices on its periodic schedule or for one device after a manual trigger. A manual trigger creates the session first and places the task on the high-priority queue.

For each device, the task creates or adopts a session, emits a start event, opens SSH, and scans the configured remote directories. It then processes each remote file. A pull writes a newer client save into RomM. A push writes the newer server save to the remote path. A conflict emits a conflict event and leaves the file unresolved. Files with unknown platforms or no matching slot-bound server save are skipped.

After remote files are processed, the task checks server saves that are absent from the remote listing. It pushes missing saves unless their device-save record marks them as untracked. The task then closes the connection, completes or fails the session, updates the device's last-seen time, and emits the final result.

References: backend/…/__init__.py• L629-667 backend/…/sync_push_pull_task.py• L32-63 backend/…/sync_push_pull_task.py• L66-222 backend/…/sync_push_pull_task.py• L225-339 backend/…/sync_push_pull_task.py• L342-435

File-transfer execution

File-transfer mode uses a RomM-owned sync area instead of a live remote connection. Each device has incoming, outgoing, and conflicts areas with platform subdirectories. A client places changed files in incoming; RomM places server-newer files in outgoing for the client to collect.

The folder watcher accepts added or changed files under the expected device and platform path. It groups files by device, checks that the device uses file-transfer mode and has sync enabled, then creates one session for the batch. It removes an already-synced incoming file, stores a client-newer file in the RomM asset store, writes a server-newer file to outgoing, or moves a conflict to conflicts and emits a conflict event. Unknown devices, platforms, and unmatched saves do not become server saves.

The manual folder scan is a recovery path for events lost during a restart or on a file system that does not report changes reliably. It lists remaining incoming files and sends them through the same device processing path.

References: backend/…/sync_handler.py• L12-113 backend/sync_watcher.py• L46-107 backend/sync_watcher.py• L110-203 backend/sync_watcher.py• L206-337 backend/…/sync_folder_scan.py• L18-63 backend/…/__init__.py• L428-435

Device-save tracking

Device-save tracking is the memory that lets RomM tell a new change from an intentional deletion. Each record joins one device to one server save and stores the last successful sync time. It also has an is_untracked flag for a save that the device should not receive or report as work.

The record is created or refreshed after a successful pull or push. Push-pull also refreshes it for a no-op, and API negotiation records matching content when it confirms that both sides already hold the same save. A refresh clears is_untracked, because a successful sync puts the save back under active tracking. Marking a save untracked creates a record when needed. The flag excludes the save from API work and from push-pull missing-save pushes. Clearing that flag does not create a new record for an unknown pair. Resetting a registered device's sync state removes all of its device-save records, so the next run treats its server saves as unseen.

This state is separate from the save itself. Deleting a device removes its tracking rows, while a save can remain in RomM and still be associated with the device that created it through its origin metadata.

References: backend/…/device_save_sync.py• L16-34 backend/…/device_save_sync_handler.py• L14-155 backend/…/device.py• L62-89 backend/…/__init__.py• L325-417 backend/…/assets.py• L86-108

Sync event delivery

Sync event delivery gives the user's live client a view of work that may run in an API request, a folder watcher, or a background task. Workers use a write-only socket manager for the same event path, so a failed emit is logged instead of raised.

The event contract identifies the device and session on every event. Start events identify the mode. Progress events carry planned and completed operation counts and may name the current file. Completion events carry completed and failed counts. Conflict events identify the file and ROM, while error events carry the failure message.

References: backend/…/sync.py• L1-117

Scheduled progress synchronization

Scheduled RetroAchievements progress synchronization is a separate progress flow that updates each user's game status from the latest remote achievement data. It matters to the broader client-service view because it changes RomM's per-game progress after an external service reports new awards, but it does not transfer save files or participate in sync sessions.

For each user with a RetroAchievements account, the task incrementally refreshes stored progression and maps the highest known award to a RomM game status. Mastered or completed games become COMPLETED_100, beaten games become FINISHED, and games with no award become INCOMPLETE. The same RetroAchievements game ID can identify several regional ROM rows, so the status applies to each matching row. A separate job can refresh one user's progress after play. The scheduled task skips the run when the service is disabled and continues with other users when one update fails.

References: backend/…/sync_retroachievements_progress.py• L18-76 backend/…/sync_retroachievements_progress.py• L79-113 backend/…/sync_retroachievements_progress.py• L116-153

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the five comparison actions aligned across compare_save_state, channel history, missing-save and deletion handling, the negotiation response, and each transport's file action.
  • Preserve the non-null slot rule in API pairing and in filename-based file-transfer and push-pull matching. Archival saves must not become device targets.
  • Keep the optional rom_ids, restore_unlisted, emulators, and cores scopes aligned between the negotiation payload, generated client types, server-side planning, and the rule that omitted items are not deletion signals.
  • If channel or snapshot selection changes, check current-version serving, branch and removal comparison, device base records, held-save protection, and WebDAV version creation together.
  • If session states or counters change, update both worker completion paths and the API completion response. Socket event payloads must still identify the same session.
  • If socket event fields change, update the user-room consumers and every producer, including background workers that publish through Redis.
  • If device registration or sync configuration changes, check SSH key lookup, known-host validation, remote directory discovery, and file-transfer directory creation together.
  • If device-save tracking changes, review intentional deletion handling, untracked saves, identical-content recording, device re-registration reset behavior, and missing-save pushes as one contract.
  • If the WebDAV manifest, upload targets, or backup rules change, check RetroArch reads, COPY and MOVE backups, uploads, deletes, retention, access scopes, generic WebDAV browsing, state-slot and screenshot pairing, and the rule that the manifest is server-derived.
  • If RetroArch emulator aliases or core-platform resolution changes, check shared core-folder views, same-name ROM selection, file-name fallback, canonical slot names, and screenshot pairing together.
  • If state selection changes, check ROM-file-named states and separate disc slots as well as the shared core-folder slot.
  • If PSP folder handling changes, check serial and title resolution, PPSSPP platform selection, pending files, bundle limits, member-level manifest paths, and empty-bundle deletion together.
  • If PSP archive writing changes, check the shared archive-write safeguard and every code path that rewrites or creates a bundle while the archive reader extension is loaded.
  • If RetroAchievements award mapping changes, check incremental progression storage, status updates for all ROM rows sharing an RA ID, and service-disabled or per-user failure handling.

Important failure modes

TriggerConsequenceGuard
SSH known_hosts file is absentPush-pull cannot establish a trusted connection and the session failsMount the configured known_hosts file before enabling SSH sync
SSH host or non-default port is not in the administrator's allowlistRomM rejects the connection before opening a network connectionAdd the exact host and port to the configured known_hosts file
No SSH key or password is availableThe device cannot authenticate and no remote files are processedMount the key named for the device, or provide ssh_password in sync configuration
A device tries to select a private key through sync configurationThe configured path is ignored and authentication can failMount the device key at the server's device-key path
Both client and server changed after the last syncRomM reports a conflict instead of overwriting either sideReview the conflict file or event and choose the desired save
A client omits a previously synced unchanged saveRomM treats the omission as an intentional client deletion unless restore_unlisted is setSet restore_unlisted for clients whose storage can lose files without an intentional delete
A client sends an incomplete ROM, emulator, or core scopeRomM does not offer downloads outside that scope in the negotiationSend the ROM IDs and capabilities the client can use; omission does not delete server saves
A save channel moved on from the client's versionRomM downloads the current version or reports a branch conflict instead of accepting stale dataKeep channel history and device base records available during comparison
A RetroArch core name is missing or mapped to the wrong platform setA same-named save or state can resolve to the wrong ROM, or a valid asset stays hidden from the manifestKeep core-folder aliases and their supported platform sets aligned with the client
A file has no matching platform or slot-bound server saveThe file is skipped and does not create or overwrite an archival saveUse the configured platform slug, file name, and stable slot pairing
A server deletion is not represented in the client stateA stale client copy can be offered back as an uploadPreserve deletion records and send stable slot metadata
A sync session is completed twiceThe second completion is rejected because the session is no longer activeKeep one owner for session completion and use the returned session state
A socket event omits the device or session identifierThe client cannot map live progress to the correct sync runPreserve both identifiers in every sync event payload
A WebDAV path has no visible ROM owner or uses an unsupported slotThe manifest omits the asset, or the client upload is rejectedUse a visible ROM file name and a supported save or state path
A WebDAV overwrite or delete cannot resolve an existing targetThe old file is not preserved as a backup, or the request cannot safely completeResolve the same upload target used by the write path before creating the backup
WebDAV backup retention is set incorrectly or backup paths are not validBackup history can grow without bound or unrelated user files can be addressedKeep backup names timestamped, user-scoped, path-validated, and subject to the configured retention limit
A WebDAV state screenshot has no matching stateRomM does not advertise or attach the screenshot to a stateKeep the screenshot beside the matching state and slot
A PSP save folder cannot be resolved to a visible ROMIts files remain pending and do not appear as syncable save membersProvide a matching serial mapping or a readable PARAM.SFO title
A PSP bundle is corrupt or exceeds its member or size limitRomM cannot read or merge the folder as a saveRepair the bundle or reduce the folder to a valid save set
A PSP PARAM.SFO is malformed or its title is too largeRomM cannot use that title to resolve the folder and files can remain pendingSend a valid small PARAM.SFO or configure a serial mapping
A WebDAV upload cannot be read for hashingRomM omits that asset from the manifest until it can read the fileRestore the asset file and let the next manifest request rebuild its hash
A generic WebDAV client lacks ROM read permissionThe ROM tree is denied even when the mount endpoint is reachableGrant ROM read access to the authenticated client
A RetroAchievements award kind is unknownProgression is stored but no RomM game status is changed for that resultKeep the award mapping aligned with the external service's defined kinds
RetroAchievements is disabled or a user update failsThe scheduled progress run returns without that user's new statusEnable the service and review the task log for the affected user

Key files

FileWhy to read it
backend/…/__init__.pyShows the API negotiation contract, ROM and capability scopes, session completion, conflict notification, and manual push-pull trigger
backend/…/retroarch.pyShows the WebDAV manifest, ROM browsing, remote file access, and save or state upload, COPY backup, and delete flow
backend/…/sync_handler.pyShows how RetroArch paths, manifests, state slots, screenshots, support blobs, backups, emulator aliases, core-platform ROM selection, and file hashes map to RomM assets
backend/…/emulator_names.pyShows the mapping between RomM emulator IDs, shared RetroArch core folders, and core platform sets
backend/…/psp.pyShows how PSP save-folder files become one syncable save bundle, how folders resolve to ROMs, and how safe bundle writes support the WebDAV path
backend/…/browser.pyShows how generic WebDAV clients browse visible platforms and ROMs as a read-only file tree; RetroArch itself does not browse this tree
frontend/…/SyncNegotiatePayload.tsShows the client-facing negotiation shape, including installed-ROM, restore, emulator, and core scopes
backend/…/sync_push_pull_task.pyShows the SSH-driven scan and bidirectional task flow
backend/sync_watcher.pyShows the shared-folder flow and conflict handling
backend/…/comparison.pyDefines the single decision rule used by the sync paths and save channels
backend/…/ssh_handler.pyDefines SSH allowlist checks, device-key authentication, remote listing, and SFTP file movement
backend/…/sync_session.pyDefines the durable run state and operation counters
backend/…/device_save_sync.pyDefines the per-device save history used to detect changes and deletions
backend/…/device_save_sync_handler.pyShows how tracking records are refreshed, marked untracked, and reset
backend/…/sync_handler.pyDefines the incoming, outgoing, and conflict folder boundaries
backend/…/sync.pyDefines the live progress, completion, conflict, and error signals
backend/…/sync_retroachievements_progress.pyDefines the scheduled external-progress update and its game-status mapping

For the parent view, see Play and client services. Related behavior is described in Play sessions and saves, Netplay and streaming, and Save snapshots and channels.