Skip to content

fix(scanner): keep a book restored with its old modification time during a scan - #4514

Merged
Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/4266-restored-book-missing
Nov 18, 2026
Merged

Quick104 merged 4 commits into
Silo-Server:mainfrom
Rhainland:fix/4266-restored-book-missing

Conversation

@Rhainland

@Rhainland Rhainland commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Closes #4266
Related issue: N/A
Validation tasks: reaches #1254 C1; the removed-book behavior it checks is unchanged (rechecked locally)

Other clients: N/A (no client-visible change)

A book removed from an ebook, manga, or audiobook library and put back during a library scan could still be marked missing. It had to come back with its old size and modification time, for example after mv on the same filesystem, cp -p, rsync -a, or a remount. The library scan then removed the book from the library and deleted its item, even though the file was on disk. The book stayed hidden until a later scan found it again.

The single-file scan that saw the book again, from real-time monitoring or autoscan, found its row unchanged and skipped it without writing anything. The library scan's missing-file pass leaves alone only rows written since it started walking (#4253, #4265), so it still marked the book. The single-file path for a vanished file had a narrower form of the same race: it checked that the file was gone, then marked the row unconditionally, so a file put back in between was marked missing.

Approach

A scoped scan (a subtree or one file) of a book library now updates updated_at on the rows of a book it skips as unchanged. The library scan's missing-file pass then treats the book as another scan's and leaves it. If a row was marked missing before that write, the write matches nothing and the scoped scan indexes the book again instead of skipping it. Full library scans still skip without writing: only one runs per library on a server, and a write for every unchanged book would slow every library scan.

The single-file path now reads the database time before it checks the disk and marks only a row written before then. If the mark matches nothing because the row was written in between, the path checks the disk again with a new time. A file that is back is scanned normally. A file still gone is marked, so an unrelated write to the row, such as a metadata update, can't keep a deleted file listed. If the row is written again before that second mark too, the scan fails with an error instead of reporting success with the file still listed. This path is shared with movie and series libraries; for them, behavior is the same as before except for that check.

A reviewer may ask why the missing-file pass doesn't stat each file right before marking it. The walk deliberately leaves out files that exist on disk: ignored files, skipped folder names, and duplicate symlinked paths. A stat would keep those rows forever.

Validation

  • New database tests: a library scan of an ebook, manga, or audiobook library keeps a book that a single-file scan saw unchanged after it was restored with its old modification time. A single-file scan of a vanished ebook keeps it when it comes back before the mark, and marks it when it is still gone after another write to its row. Each fails on main and passes here.
  • go test for internal/scanner, internal/scanqueue, and internal/libraryingest against a migrated Postgres: pass.
  • make test-go: pass. Four packages first failed only because the shell's umask made test temp directories group-writable; they pass with umask 022.
  • make test-db-contracts: all listed tests pass. The backup tests skip because pg_dump isn't installed on the test machine.
  • go build, gofmt, go mod tidy -diff, go vet ./internal/scanner/..., make lint-changed, and make lint-router-recovery (0 issues); verify-local-paths, verify-case-collisions, verify-size-ratchet, and verify-bidi: pass.
  • Web checks were not run: no web files change.

Evidence

Checked on a local build with a 40,000-book synthetic EPUB library. Real-time monitoring was off, so Silo did not hear about the removal, as with an autoscan setup that only reports new files. Steps: change every other book so the library scan reindexes them and takes about 25 seconds, move one book out, start a library scan, move the book back with mv (same size and modification time) five seconds in, then request a scan of that file.

Before (main):

ebook scan: starting candidates=39999
ebook scan: completed processed=1 skipped=1          <- the file scan skips the restored book
ebook scan: completed processed=39999 skipped=0
ebook scan: reconciled missing files missing=1 memberships_removed=1 items_deleted=1
GET /api/v2/catalog/items/<book> -> 404               <- the book is on disk

After (this branch, same data and steps):

ebook scan: starting candidates=39999
ebook scan: completed processed=1 skipped=1
ebook scan: completed processed=39999 skipped=0
GET /api/v2/catalog/items/<book> -> 200

Also checked on this branch: a book really removed before a library scan is still marked missing and its item deleted (404). With real-time monitoring on, a removed book disappears (404) and comes back when it is moved back (200). A library scan of unchanged books still skips all 39,999 in under a second.

Risks

A scoped scan's write also protects a book that is deleted after that scan saw it but before a running library scan's walk reaches it. That book stays listed until real-time monitoring reports the deletion or the next library scan runs. As with #4253 and #4265, mistakes go toward keeping a book visible.

A restore with no scoped scan at all (real-time monitoring off and no autoscan request) is still marked missing by a library scan that walked without the book. The next scan finds it again.

Scoped book scans make one small UPDATE per unchanged book they skip, and a single-file scan of a vanished file makes one or two extra SELECT now() queries.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.
  • Each test this pull request adds meets "Decide what to test" in CONTRIBUTING.md.
  • The Evidence section shows every change a user can see, or how I checked a change nobody sees.

AI Disclosure

  • Harness: Claude Code (via T3 Code); Codex CLI for code review
  • Tool(s): Claude Code; Codex CLI
  • Model(s): claude-opus-5-5; gpt-6.2-sol, gpt-6.2-astra, claude-fable-5-2 (code review)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Four independent reviews of the branch diff at medium effort (gpt-6.2-sol and gpt-6.2-astra through Codex CLI, claude-opus-5-5 and Claude Fable 5.2 as subagents), on correctness, standards, and spec, then reconciled and checked against the code. They found one real defect, now fixed: the single-file path's conditional mark could leave a deleted file listed when an unrelated write or an earlier scoped scan touched its row first. It now checks the disk again and marks a file that is still gone, with a test. A second round on that fix found no defects; an outcome name was changed on its advice. Kept as known limits and listed under Risks: a library scan without any scoped scan still marks a restored book, and a scoped scan's write can keep a book deleted moments later listed until the next scan. A suggestion to batch the scoped-scan writes was left out, since scoped scans are usually small.

Note

Fix scanner to keep restored files with old modification time indexed

  • Prevents single-file scans from skipping a file as "unchanged" when the library scan has just marked it missing. Non-full scans now mark their context via withScopedScan, and unchanged-file skip decisions in audiobook, ebook, and manga scans call the new Scanner.confirmUnchangedFiles first (scan_presence.go).
  • Adds FileRepository.ConfirmPresent, which bumps updated_at on matching non-missing rows and reports failure when any row is missing or the count does not match.
  • Reworks vanished-file handling in reconcileVanishedFileIfNeeded: restored files and uncataloged paths return early instead of entering the missing-file sweep, and markVanishedFile retries the row mark up to two times against a captured inventory time (scanner.go).
  • Adds database-backed concurrency tests for audiobook, ebook, and manga restore-with-old-mtime cases, plus vanished-file reconciliation tests. Registers them in db-contracts.txt.
  • Risk: single-file scans on unchanged files now issue an extra ConfirmPresent UPDATE per file; the two-attempt limit in markVanishedFile returns an error when the catalog row keeps changing.

Macroscope summarized 7eb6208.

…ing a scan

A book removed before a library scan's walk and put back with its old size
and modification time during the scan was still marked missing, and its
item deleted. The single-file scan that saw the book again skipped it as
unchanged and wrote nothing, so the library scan's missing-file pass, which
leaves alone only rows written since its walk, still marked it.

A scoped scan (a subtree or one file) of an ebook, manga, or audiobook
library now records that it saw an unchanged book by touching its rows'
updated_at before skipping it. If a row was marked missing meanwhile, the
book is indexed again instead. A full library scan skips without writing,
as before.

The single-file path that marks a vanished file missing now marks only a
row last written before it checked the disk, so a file restored and seen
by another single-file scan before the mark stays present.

Closes Silo-Server#4266
…rite

The conditional mark in the single-file vanish path also skipped a file
that was still gone when its row was written for another reason, such as
a metadata write or an earlier observation by a scoped scan. The path now
checks the disk once more with a new time and marks the file if it is
still gone.
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Walkthrough

Scoped scans now confirm unchanged file paths before skipping reconciliation. Vanished-file handling rechecks disk and catalog state before marking rows missing. Scanner tests cover restored files with their original modification times and files that remain absent.

Changes: Scanner race handling

Layer / File(s) Summary
Confirm unchanged files during scoped scans
internal/scanner/scan_presence.go, internal/scanner/audiobook_scan.go, internal/scanner/ebook_scan.go, internal/scanner/manga_scan.go, internal/scanner/audiobook_concurrent_scan_test.go, internal/scanner/ebook_concurrent_scan_test.go, scripts/ci/db-contracts.txt
Scoped scans confirm that unchanged paths still have present rows before skipping them. If confirmation fails, audiobook, ebook, and manga scans continue reconciliation. Tests cover restored files with their original modification times.
Recheck vanished files before marking
internal/scanner/scanner.go, internal/scanner/ebook_concurrent_scan_test.go
Vanished-file handling rechecks the file and catalog row before marking. It retries when a concurrent row change prevents marking. Tests verify that a restored file remains present and a file that remains absent is marked missing.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: quick104, blurbery

Merge Risk: Low · up to 7eb62

Scoped scans now keep a restored book from being marked missing, and single-file vanished-file handling is more robust. One narrow audiobook ordering could still let a stale transaction lower the confirmation timestamp, so a restored audiobook could occasionally be marked missing until the next scan. This is low risk and worth tracking, but it should not block the merge.

Security architecture risk: Minimal · up to 7eb62

The change reduces the chance of restored books being hidden or removed during overlapping scans. The inspected changes preserve library boundaries and do not establish a new security or failure-containment risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • observed — The relevant sensitive outcome is catalog visibility and downstream membership or item cleanup. After a successful or already-existing missing mark, the existing sweep is folder-wide, not restricted to the requested file. It remains bounded by folder identity, protected roots, and the configured trash-removal policy; the PR does not broaden that sweep.

Trust Boundaries and Controls

  • observed — Filesystem paths enter through existing scoped scan entrypoints, which retain configured-root containment checks. The new confirmation write uses bound SQL parameters and folder-plus-exact-path predicates. Vanished-file marking rejects a loaded row belonging to another library before mutation. These controls constrain filesystem-driven presence changes without adding a new identity or authority input.

Resilience and Maintainability Implications

  • inferred — The confirmation is a database statement, not a transaction spanning the filesystem and cleanup. Repetition refreshes the timestamp without creating a reservation requiring release. If execution stops after confirmation, the durable effect is a later timestamp that can defer an older scan's missing mark; a later scan with a fresh cutoff can reassess the row. This favors retaining visibility over stale destructive reconciliation.
Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: a book restored with its old modification time is kept during a scan. The changeset adds scoped-scan confirmation and reworks the vanished-file path in the scanner to …
Linked Issues check Passed Directly linked issue #4266 has one coding objective: a book on disk when the missing-file pass reaches it stays present. The reproduced race is covered. (1) Scoped scans (subtree or single file) of e…
Out of Scope Changes check Passed All changed code serves the #4266 fix. Changes: ConfirmPresent, withScopedScan, and confirmUnchangedFiles in scan_presence.go; confirmation gates in audiobook_scan.go, ebook_scan.go, and manga_scan.go…
Description check Passed The description is directly related to the changeset. It explains the race where a restored book is marked missing during a library scan, names the scoped-scan write and the vanished-file mark changes…
Full details: Title check

Explanation

The title names the main change: a book restored with its old modification time is kept during a scan. The changeset adds scoped-scan confirmation and reworks the vanished-file path in the scanner to match that fix, so the title fits the primary change.

Full details: Linked Issues check

Explanation

Directly linked issue #4266 has one coding objective: a book on disk when the missing-file pass reaches it stays present. The reproduced race is covered. (1) Scoped scans (subtree or single file) of ebook, manga, and audiobook libraries now call withScopedScan and confirmUnchangedFiles before skipping an unchanged book. That path calls FileRepository.ConfirmPresent (internal/scanner/scan_presence.go), which runs UPDATE media_files SET updated_at = NOW() on present rows. The library scan's written-before-scan pass then leaves those rows alone. If any row is missing or not updated, the book is indexed again. Full scans skip without writing, as the PR states. (2) The single-file vanished-file path (scanner.go markVanishedFile) reads the inventory time before the disk check, marks only rows written before that time (MarkMissingWrittenBefore), and retries once with a new time if the mark matches nothing. A file that is back returns without a sweep. Database tests are named in the PR and in scripts/ci/db-contracts.txt; I did not read the test bodies. Residual limit: a restore with no scoped scan at all is still marked missing. The PR discloses this under Risks, and the issue's reproduction step 3 requires a single-file scan, so the reproduced scenario is covered.

Full details: Out of Scope Changes check

Explanation

All changed code serves the #4266 fix. Changes: ConfirmPresent, withScopedScan, and confirmUnchangedFiles in scan_presence.go; confirmation gates in audiobook_scan.go, ebook_scan.go, and manga_scan.go; the markVanishedFile and mediaFileGone refactor in scanner.go, which replaces the unconditional MarkMissing with a conditional mark; new concurrency tests in audiobook_concurrent_scan_test.go and ebook_concurrent_scan_test.go; and the db-contracts.txt registration. The scanner.go refactor is needed to split the stat check from the row mark. No unrelated files or behavior changes were found in the diff I read.

Full details: Description check

Explanation

The description is directly related to the changeset. It explains the race where a restored book is marked missing during a library scan, names the scoped-scan write and the vanished-file mark changes that the diff implements, and lists the tests and validation performed. It is specific, so it is neither off-topic nor vague.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@silo-triage silo-triage Bot added the size/L 200–499 added + deleted lines (all files); change volume, not priority. label Nov 18, 2026
@silo-kody

silo-kody Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌

@silo-triage silo-triage Bot added bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish labels Nov 18, 2026
Comment on lines +2997 to +3004
err = s.fileRepo.MarkMissingWrittenBefore(ctx, file.ID, file.FilePath, time.Now().UTC(), checkedAt)
if errors.Is(err, ErrFileNotFound) && attempt < 2 {
continue
}
if err != nil && !errors.Is(err, ErrFileNotFound) {
return vanishedFileNeedsSweep, fmt.Errorf("marking vanished media file %s missing: %w", filePath, err)
}
return vanishedFileNeedsSweep, nil

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

kody code-review Bug high

A second concurrent row update leaves a vanished file present

If another operation updates the row during both attempts, the second ErrFileNotFound is ignored, leaving the missing file visible in the catalog after a successful scan. Retry with a fresh disk check until the mark succeeds, or return an error when the retry limit is reached.

Prompt for LLM
File internal/scanner/scanner.go, lines 2997-3004:

A second concurrent row update leaves a vanished file present

If another operation updates the row during both attempts, the second `ErrFileNotFound` is ignored even though the file remains absent, leaving it visible in the catalog after a successful scan. Retry with a fresh disk check until the mark succeeds or return an error when the retry limit is reached.

Talk to Kody by mentioning @kody

Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.

​

​

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.

Confirmed. When the row is written again before the second conditional mark, markVanishedFile returns as if it had marked the file, and ScanFile reports success while the deleted file stays listed until the next library scan. Movie and series libraries go through this path too. A local test that writes the row before every mark showed ScanFile returning nil with the file still present.

Rather than retrying until the mark lands, I'm returning an error after the second lost mark, so the scan run shows the failure. Each extra attempt needs another write to land in a window of a few milliseconds, so two attempts are enough. I'm fixing this in a commit on this branch, so there's no need to change it yourself.

🤖 Claude Code (claude-opus-5-5)

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.

Fixed in 7eb6208. markVanishedFile now returns an error ("its row changed during each of 2 attempts") when both conditional marks lose, instead of reporting the file as handled. The same local test now gets that error from ScanFile, and on the previous head it got nil with the file still listed. go test for internal/scanner, internal/scanqueue, and internal/libraryingest against a migrated Postgres, and make lint-changed, pass.

🤖 Claude Code (claude-opus-5-5)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for the update. Returning an error after both conditional marks fail addresses the reported issue: the scan no longer reports success while leaving the vanished file listed.

The tests and lint checks you reported provide useful validation. I haven’t independently verified commit 7eb6208e7b.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for confirming and testing the race. Returning an error after the second lost mark is a reasonable bounded approach: it avoids reporting a successful scan when the file may still be incorrectly listed.

I’ll leave the fix to you.

markVanishedFile retries its conditional mark once. When the row was
written again before the second mark too, it returned as if it had
marked the file, so ScanFile reported success while the deleted file
stayed listed. Return an error instead, so the scan run shows the
failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@silo-kody

silo-kody Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Silo Kody — review complete

Review finished. Check the inline comments for findings and verify each suggestion against the code and tests.

Reviewing changes in Silo
  • Include the related issue, expected behavior, and validation steps in the PR description.
  • For API changes, describe the effect on Apple and Android clients and Jellyfin compatibility.
  • For plugin changes, identify the affected SDK contract, plugin, and catalog entry.
  • Follow this repository's AGENTS.md and CONTRIBUTING.md.
  • Request another review with @kody start-review in a PR comment.
  • React with 👍 or 👎 to give feedback on individual suggestions.
Review settings
Review Options

The following review options are enabled or disabled:

Options Enabled
Bug ✅
Performance ✅
Security ✅
Business Logic ❌
⚠️ 5 Kody Rule(s) were not evaluated

These rules declare that they need repository context beyond this diff, and the review could not retrieve it, so they were not judged on this pull request:

  • Preserve optional store capabilities through production wrappers
  • Detach mandatory cleanup from request cancellation and bound its lifetime
  • Preserve durable media identity and share identity-evidence precedence
  • Bound decoder throughput trades and share direct-play eligibility
  • Retain distributed firing claims through their own validity windows

@Quick104

Copy link
Copy Markdown
Contributor

Maintainer review (reviewed 7eb6208)

Fit: 9/10 · Readiness: 9/10 — ready (assuming CI is green)

This fixes a real scanner bug. A book that was removed and put back with its old size and modification time during a library scan was still marked missing, and its item was deleted. The fix builds on the existing "written before the scan started" check from #4253 and #4265 instead of adding a second mechanism. It adds no setting and no API surface. Its cost is one small UPDATE for each unchanged book that a subtree or single-file scan skips. Full library scans don't pay it.

Addressed

  • A vanished file could stay listed after a "successful" scan (Kody's thread on markVanishedFile). If the row was written again before the second conditional mark, the scan returned without marking the file. Movie and series libraries share this path. I pushed 7eb6208, which returns an error in that case so the scan run shows the failure. Details are in the thread.

Verification

  • The three new database tests (TestScanBookFolderKeepsBookIndexedByConcurrentScanDB restored-unchanged subtests, TestScanAudiobookFolderKeepsBookRestoredUnchangedDB, TestScanFileReconcilesVanishedBookDB/restored_unchanged_before_the_mark) fail on main because the restored book is not present, and pass on this branch. row_written_while_still_gone passes on both, as expected, because it guards this PR's own retry.
  • A local test that writes the row before every mark returned nil from ScanFile with the file still listed on 6f3d169, and returns the new error on 7eb6208. It isn't committed.
  • go test for internal/scanner, internal/scanqueue, and internal/libraryingest against a migrated Postgres, plus make lint-changed, pass. I didn't reproduce the race on a running server; the author's before/after is in the Evidence section.
  • The earlier Go test failure was an apt-install timeout during Go setup, not a test failure.

Remaining limits for maintainers

These were traced from the code. None is new in this PR, and all of them can only keep a book visible or let the next scan correct it:

  • A full library scan still skips unchanged books without writing anything. So a scoped scan's missing-file pass, or a pending single-file mark, can still mark a book that a concurrent full scan saw restored. This already happens on main, and it's the same "restore with no later scoped scan" case the PR lists under Risks. Closing it would mean a write per book on every library scan, or a separate "last seen" column.
  • A scoped scan's confirmation can keep a book listed if the book is deleted right after that scan saw it. This is disclosed under Risks.
  • A subtree scan at the root of a large book library pays one UPDATE per unchanged book. This is disclosed and not measured.

Checks

  • Validated features: no passed case is affected. Audiobooks — Server #1254 (Audiobooks — Server) has no recorded results yet.
  • User manual: unaffected. This is a fix toward the behavior users already expect.
  • Other clients: none affected. This is a server-only scanner change.
  • Second opinion: one adversarial round with gpt-6.2-sol on 6f3d169. It raised the limits above and nothing else that this PR introduced.

🤖 Claude Code (claude-opus-5-5)

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

Review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d9f28c20-9e32-44bd-8909-9518aa59603d
Commits

Reviewing files that changed from the base of the PR and between e8de111 and 7eb6208.

Files selected for processing: 8

  • internal/scanner/audiobook_concurrent_scan_test.go
  • internal/scanner/audiobook_scan.go
  • internal/scanner/ebook_concurrent_scan_test.go
  • internal/scanner/ebook_scan.go
  • internal/scanner/manga_scan.go
  • internal/scanner/scan_presence.go
  • internal/scanner/scanner.go
  • scripts/ci/db-contracts.txt

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

if len(paths) == 0 {
return true, nil
}
tag, err := r.pool.Exec(ctx, `UPDATE media_files SET updated_at = NOW()

@coderabbitai coderabbitai Bot Nov 18, 2026 •

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.

Minor · Data Integrity & Integration · Heavy lift

Keep a confirmed timestamp from being lowered by an older audiobook transaction.

The audiobook upsert sets updated_at = NOW() on conflict. NOW() is the start time of its transaction, which can be earlier than a confirmation committed by ConfirmPresent. When that happens, the restored row's updated_at falls below the inventory cutoff. A full scan can then mark the restored file missing, which is the race this change is meant to prevent.

The required behavior: a confirmation must stay newer than the cutoff until the full-scan missing pass reads it, including when an older audiobook transaction upserts the same row afterward. ConfirmPresent currently runs outside lockAudiobookRoot and does not coordinate with the stale-inventory check. Choose the synchronization or timestamp rule that enforces this behavior.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This race isn't new to this PR. It is the same limit #4265's MarkMissingWrittenBefore cutoff already has. The audiobook upsert stamps updated_at with its transaction's start time. So an audiobook transaction that started before a library scan's cutoff, and writes the row after that scan's walk began, already lands below the cutoff on main, with or without ConfirmPresent. Closing it means changing how scan writes are timed (for example clock_timestamp() or GREATEST on every scanner write that counts as presence), which belongs in its own change. It is also narrow here: it needs a second audiobook transaction for the same book that started before the cutoff and writes after the confirmation commits.

@Quick104
Quick104 merged commit 6af631a into Silo-Server:main Nov 18, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working go Pull requests that update go code impact: usability Core flow broken or severely blocked priority: P2 Limited scope, workaround exists, or polish size/L 200–499 added + deleted lines (all files); change volume, not priority.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] A book restored with its old modification time during a scan is still marked missing

2 participants