fix(scan): emit a client update for ROMs that are no longer missing#3903
Merged
Conversation
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>
Contributor
Greptile SummaryUpdates platform scans to notify connected clients when previously missing ROMs reappear.
Confidence Score: 5/5The 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
Reviews (1): Last reviewed commit: "fix(scan): emit a client update for ROMs..." | Re-trigger Greptile |
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
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_platformsyncsmissing_from_fsagainst the filesystem before the identify loop, andbulk_mark_presentclears it again for skipped entries. What was missing is the client-facing signal: a ROM that already exists is skipped byshould_scan_romon a quick scan, and only ROMs that go through_identify_romemitscan: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 viaroms_ids) visibly fixed it.Changes:
get_missing_rom_ids(platform_id)inroms_handlerreturns the ids currently flagged missing._identify_platformsnapshots those ids before the pre-loopmark_missing_romssync clears them. Without the snapshot there's nothing left to detect: by the time the batch loop loads the ROM, the flag is alreadyFalse.bulk_mark_present, each restored entry is logged and re-emitted overscan:scanning_rom, reloaded viaget_romso the schema has its relationships hydrated (the scan-loop lookup deliberately only eager-loadsplatform).The frontend already merges
scan:scanning_rominto 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
RomFilerows 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.
Tests:
TestIdentifyPlatformEmitsRestoredRoms(emits for a restored ROM, stays silent for one that was already present) andtest_get_missing_rom_ids.tests/endpoints/sockets/test_scan.py49 passed, the missing/bulk-mark DB handler tests 17 passed,trunk fmt && trunk checkclean.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.