Skip to content

fix(scan): emit a client update for ROMs that are no longer missing#3903

Merged
gantoine merged 1 commit into
masterfrom
fix/emit-restored-roms-during-platform-scan
Jul 23, 2026
Merged

fix(scan): emit a client update for ROMs that are no longer missing#3903
gantoine merged 1 commit into
masterfrom
fix/emit-restored-roms-during-platform-scan

Conversation

@gantoine

Copy link
Copy Markdown
Member

Description
Explain the changes or enhancements you are proposing with this pull request.

Reported on Discord: re-adding a game's file only clears the "missing" badge when you quick/hash scan that game, never when you scan the platform. It looks like a platform scan skips missing games.

The database was actually being repaired correctly all along. _identify_platform syncs missing_from_fs against the filesystem before the identify loop, and bulk_mark_present clears it again for skipped entries. What was missing is the client-facing signal: a ROM that already exists is skipped by should_scan_rom on a quick scan, and only ROMs that go through _identify_rom emit scan:scanning_rom. So an open gallery kept showing the stale badge until a refetch, while a single-game scan (which forces the ROM through the scan path via roms_ids) visibly fixed it.

Changes:

  • get_missing_rom_ids(platform_id) in roms_handler returns the ids currently flagged missing.
  • _identify_platform snapshots those ids before the pre-loop mark_missing_roms sync clears them. Without the snapshot there's nothing left to detect: by the time the batch loop loads the ROM, the flag is already False.
  • After bulk_mark_present, each restored entry is logged and re-emitted over scan:scanning_rom, reloaded via get_rom so the schema has its relationships hydrated (the scan-loop lookup deliberately only eager-loads platform).

The frontend already merges scan:scanning_rom into the gallery and stores, so the badge now clears live during a platform scan and the restored ROM shows up in the scan progress list.

Deliberately out of scope: restored ROMs still don't get their RomFile rows and hashes rebuilt on a quick scan. Doing that would rehash the whole library in the common "NAS unmounted, then remounted" case. A complete or hash scan still rebuilds them.

Checklist
Please check all that apply.

  • 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

Tests: TestIdentifyPlatformEmitsRestoredRoms (emits for a restored ROM, stays silent for one that was already present) and test_get_missing_rom_ids. tests/endpoints/sockets/test_scan.py 49 passed, the missing/bulk-mark DB handler tests 17 passed, trunk fmt && trunk check clean.

Screenshots (if applicable)

N/A, backend only.


AI assistance disclosure: this change was written with AI assistance (Claude Code). The investigation, the patch, and the tests were AI-generated, then reviewed and verified locally by me.

A platform scan already clears `missing_from_fs` for an entry whose file
came back under the same name, but the ROM is skipped by `should_scan_rom`
so nothing emits `scan:scanning_rom` for it. An open gallery keeps showing
the stale "missing" badge until a refetch, which reads as the platform scan
ignoring missing games (a single-game scan does emit, and looks fixed).

Snapshot the flagged ids before the pre-loop sync clears them, then emit for
the restored entries after `bulk_mark_present`.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 23, 2026 13:40

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Updates platform scans to notify connected clients when previously missing ROMs reappear.

  • Adds a platform-scoped database query for missing ROM IDs.
  • Snapshots missing IDs before filesystem synchronization and emits hydrated restored ROMs through scan:scanning_rom.
  • Adds socket-scan and database-handler tests for restored-ROM notifications and missing-ID filtering.

Confidence Score: 5/5

The PR appears safe to merge with no actionable defects identified.

The restored-ROM path snapshots state before synchronization, updates persisted presence before reloading, and emits the same hydrated payload shape already used by existing scan notifications.

Important Files Changed

Filename Overview
backend/endpoints/sockets/scan.py Correctly snapshots missing ROM IDs before synchronization and emits restored skipped ROMs using the established hydrated socket payload path.
backend/handler/database/roms_handler.py Adds a platform-scoped, dialect-portable query returning IDs currently marked missing.
backend/tests/endpoints/sockets/test_scan.py Covers notification behavior for restored ROMs and verifies already-present ROMs remain silent.
backend/tests/handler/test_db_handler.py Verifies missing-ROM ID filtering is limited to flagged ROMs on the requested platform.

Reviews (1): Last reviewed commit: "fix(scan): emit a client update for ROMs..." | Re-trigger Greptile

@gantoine
gantoine merged commit c99154a into master Jul 23, 2026
11 checks passed
@gantoine
gantoine deleted the fix/emit-restored-roms-during-platform-scan branch July 23, 2026 16:48
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.

2 participants