Skip to content

fix(autoscan): advance marker past paths outside any library folder - #314

Merged
Quick104 merged 3 commits into
Silo-Server:mainfrom
uffcd:fix/autoscan-advance-on-unresolved-paths
Jul 6, 2026
Merged

Quick104 merged 3 commits into
Silo-Server:mainfrom
uffcd:fix/autoscan-advance-on-unresolved-paths

Conversation

@uffcd

@uffcd uffcd commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

A filesystem-watcher scan source (e.g. the CephFS plugin) observes the entire volume, so it legitimately returns changes for paths that live in folders which are not registered as Silo libraries (unregistered decade buckets, 4k-dv, anime-dub, download/recycle dirs, etc.).

Previously, when a poll returned paths but none resolved to a library folder, PollOnce recorded an "unresolved" error and refused to advance the marker, on the assumption this only happens for a freshly-enabled source with unconfigured path rewrites. For a whole-volume watcher that assumption is wrong: a single change under an unregistered folder pins the journal marker in place, so every subsequent poll re-reads the same window and autoscan stalls permanently. Real imports pile up behind the stuck marker and are never scanned until the next full library scan.

Treat "paths returned but none resolved" as a benign, expected condition: log a warning (so an operator can still investigate a genuinely misconfigured source) and advance the marker so the queue keeps moving. Partial resolution was already handled correctly — the unresolved subset is simply outside Silo's libraries.

Observed in production: one file added under movies/4k-dv (not a library path) froze the CephFS source for ~18 days; ~42k journal changes had accumulated behind it. With this change the marker advances and the backlog drains on the next poll.

Summary by CodeRabbit

  • Bug Fixes
    • Refined autoscan polling marker behavior and event outcomes when provider-reported changes don’t match any library folder.
    • Autoscan now advances with an unresolved warning for non-library-related misses, while holding the marker and reporting an error when failures appear transient/internal, reducing unintended stalls and improving status accuracy.
  • Tests
    • Expanded autoscan poll tests to cover marker-advance vs marker-hold for transient/internal resolution failures and updated existing expectations accordingly.

A filesystem-watcher scan source (e.g. the CephFS plugin) observes the
entire volume, so it legitimately returns changes for paths that live in
folders which are not registered as Silo libraries (unregistered decade
buckets, 4k-dv, anime-dub, download/recycle dirs, etc.).

Previously, when a poll returned paths but none resolved to a library
folder, PollOnce recorded an "unresolved" error and refused to advance
the marker, on the assumption this only happens for a freshly-enabled
source with unconfigured path rewrites. For a whole-volume watcher that
assumption is wrong: a single change under an unregistered folder pins
the journal marker in place, so every subsequent poll re-reads the same
window and autoscan stalls permanently. Real imports pile up behind the
stuck marker and are never scanned until the next full library scan.

Treat "paths returned but none resolved" as a benign, expected condition:
log a warning (so an operator can still investigate a genuinely
misconfigured source) and advance the marker so the queue keeps moving.
Partial resolution was already handled correctly — the unresolved subset
is simply outside Silo's libraries.

Observed in production: one file added under movies/4k-dv (not a library
path) froze the CephFS source for ~18 days; ~42k journal changes had
accumulated behind it. With this change the marker advances and the
backlog drains on the next poll.
@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5ac76c03-b277-4620-a6d8-3477f99290f7

📥 Commits

Reviewing files that changed from the base of the PR and between 730b880 and d0be9a5.

📒 Files selected for processing (2)
  • internal/autoscan/service.go
  • internal/autoscan/service_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • internal/autoscan/service.go

📝 Walkthrough

Walkthrough

Autoscan now advances the marker when returned paths do not match any Silo library, unless resolution encounters transient internal failures. Event completion, marker handling, and test coverage were updated to reflect the two outcomes.

Changes

Marker advancement on unresolved autoscan results

Layer / File(s) Summary
PollOnce resolution and marker handling
internal/autoscan/service.go, internal/autoscan/repository.go
resolveStats tracks transient resolution failures, PollOnce now distinguishes transient errors from unresolved paths outside Silo libraries, and the marker-advance comment was updated to match the new timing.
Marker behavior tests
internal/autoscan/service_test.go
The unresolved-path test now expects marker advancement, no recorded source error, and an unresolved event with the next marker and updated message; new resolver fakes and transient-failure tests cover the marker-hold path.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Provider
  participant Service
  participant Store

  Provider->>Service: return changes
  Service->>Service: resolve paths and count transient errors
  alt transient internal errors occurred
    Service->>Store: finish event (EventStatusError)
    Service->>Service: keep marker
  else paths matched no Silo library folder
    Service->>Store: finish event (EventStatusUnresolved)
    Service->>Store: advance marker
  end
Loading

Possibly related PRs

  • Silo-Server/silo-server#312: Also changes the internal/autoscan/service.go resolution path around resolveAndClaim/resolveChange and the resulting unresolved-path behavior in PollOnce.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title matches the main change: autoscan now advances the marker when returned paths are outside any library folder.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: cac98e72a1

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment on lines 252 to +254
if len(changes) > 0 && !resolvedAny {
msg := fmt.Sprintf("returned %d path(s) but none matched a Silo library folder — check this source's path rewrites", len(changes))
if rerr := s.store.RecordError(ctx, src.ID, msg); rerr != nil {
slog.WarnContext(ctx, "autoscan: record error failed", "source_id", src.ID, "err", rerr)
}
s.finishEvent(ctx, eventID, EventFinish{
Status: EventStatusUnresolved,
ChangesReturned: len(changes),
ErrorMessage: msg,
MarkerAfter: marker,
})
continue // do NOT advance marker
slog.WarnContext(ctx, "autoscan: returned paths matched no library folder — advancing marker",
"source_id", src.ID, "changes", len(changes))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep markers when connection-backed sources resolve nothing

This branch now advances the marker for every source whose returned paths fail to resolve, but that case is still a setup/error signal for Sonarr/Radarr-style sources with missing or wrong path_rewrites. In that scenario the provider has returned real imported media paths, no scans are enqueued, and the following AdvanceMarker consumes the provider marker and clears last_error, so the same imports will not be retried after the operator fixes the rewrite. Please limit the benign advance to known whole-volume filesystem watchers, or keep the marker for connection-backed sources when none of the returned paths map to a library.

Useful? React with 👍 / 👎.

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

🧹 Nitpick comments (1)
internal/autoscan/service.go (1)

242-255: 🩺 Stability & Availability | 🔵 Trivial | ⚖️ Poor tradeoff

Consider surfacing repeated unresolved-paths warnings for operators.

Logic correctly matches the PR intent: warn and advance instead of stalling. One gap: since no error is recorded anymore, persistent misconfiguration (e.g., a bad path-rewrite rule silently causing every path to miss resolution) will now only show up in logs, with events reporting EventStatusSuccess indefinitely. Consider tracking a metric/counter or surfacing "N consecutive unresolved polls" so operators can still notice a persistently misconfigured source, without reverting to hard error state.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@internal/autoscan/service.go` around lines 242 - 255, The autoscan warning in
the unresolved-paths branch now advances correctly, but persistent unresolved
polls are only logged and never surfaced elsewhere. Update the autoscan flow
around the changes/resolvedAny check in service.go to track repeated unresolved
polls for a source, such as a counter for consecutive unresolved scans or a
metric on the warning path. Keep the existing warning-and-advance behavior, but
add operator-visible telemetry so a misconfigured source can still be detected
even when EventStatusSuccess is reported.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@internal/autoscan/service.go`:
- Around line 242-255: The autoscan warning in the unresolved-paths branch now
advances correctly, but persistent unresolved polls are only logged and never
surfaced elsewhere. Update the autoscan flow around the changes/resolvedAny
check in service.go to track repeated unresolved polls for a source, such as a
counter for consecutive unresolved scans or a metric on the warning path. Keep
the existing warning-and-advance behavior, but add operator-visible telemetry so
a misconfigured source can still be detected even when EventStatusSuccess is
reported.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: cacb6b94-9efe-4846-be20-8df6302fffda

📥 Commits

Reviewing files that changed from the base of the PR and between 82675eb and cac98e7.

📒 Files selected for processing (2)
  • internal/autoscan/service.go
  • internal/autoscan/service_test.go

…lved events visible

Review follow-up: advancing past a window where nothing resolved is only
safe when every path is genuinely outside Silo's libraries (RequestError).
When resolve attempts fail internally (resolver/database fault), the same
resolvedAny=false state now holds the marker and records the error so the
window is retried once the fault clears, instead of silently skipping
imports until the next full library scan.

The benign outside-libraries case still advances, but finishes its poll
event as "unresolved" (with an explaining message) instead of "success",
so the condition stays visible in poll history and the existing
unresolved status filter in the API/admin UI keeps working. Stale doc
comments on PollOnce and AdvanceMarker updated to match the new behavior.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Quick104

Quick104 commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Maintainer follow-up pushed in 730b880 after review. The stall diagnosis and the direction here are right — thanks for the detailed writeup. Two things the flat "always advance" flip gave up, now restored:

1. Transient resolver failures no longer advance the marker. resolvedAny == false conflated two very different states: "every path is outside Silo's libraries" (scantrigger.RequestError — advancing is correct, this is the CephFS whole-volume case) and "resolve attempts failed internally" (DB timeout / resolver fault — advancing silently skips real imports until the next full library scan). resolveAndClaim already distinguished these internally, so it now counts internal failures (resolveStats.TransientErrors), and PollOnce holds the marker + records the error only in that case. The window is retried once the fault clears.

2. The all-outside case stays observable. It still advances (the fix this PR is for), but the poll event now finishes as unresolved with an explaining message instead of success. That keeps the condition visible in poll history and keeps the existing unresolved status filter in the API and admin Activity panel meaningful — after the original change nothing wrote that status anymore. No source-level last_error is recorded, so the source itself still reads healthy.

Also refreshed the stale doc comments on PollOnce and AdvanceMarker ("Called only after a successful enqueue") that described the pre-PR contract, and added a regression test (TestPollOnceHoldsMarkerOnTransientResolveFailure) alongside the updated advance test.

AI-use disclosure: review and follow-up commit were done with Claude Code (Claude Fable 5), maintainer-verified; go test ./internal/autoscan/, go vet, and gofmt are clean.

@coderabbitai coderabbitai Bot added the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 6, 2026

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@internal/autoscan/service.go`:
- Around line 266-278: The autoscan marker advance logic in autoscan/service.go
only holds the marker when no paths were resolved, so mixed results can still
advance past a transient failure. Update the event handling branch around the
existing `stats.TransientErrors` and `resolvedAny` checks in `service.go` so any
internal resolve failure keeps the current marker and records the error before
advancing. Use the existing `RecordError`, `finishEvent`, and `AdvanceMarker`
flow to ensure the mixed resolved + transient-failed case does not skip the
failed path, and add a regression test for that scenario.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1cb33fa8-dd2d-4e3d-9e49-61464fd6b70e

📥 Commits

Reviewing files that changed from the base of the PR and between cac98e7 and 730b880.

📒 Files selected for processing (3)
  • internal/autoscan/repository.go
  • internal/autoscan/service.go
  • internal/autoscan/service_test.go
✅ Files skipped from review due to trivial changes (1)
  • internal/autoscan/repository.go

Comment thread internal/autoscan/service.go Resolved
…, not only when all do

The transient-failure hold was gated inside the nothing-resolved branch, so
a mixed window (some paths resolved+enqueued, others failed on an internal
resolver fault) still advanced the marker past the failed paths. Hoist the
gate: any internal resolve failure now records the error and holds the
marker regardless of how many paths resolved. The resolved targets were
already enqueued; re-reading the window at worst re-scans them, which is
safe. Adds a mixed-window regression test.

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai coderabbitai Bot removed the v1.0 Silo v1 scope - auto-adds to the Silo v1 project label Jul 6, 2026
@Quick104
Quick104 merged commit f5329e1 into Silo-Server:main Jul 6, 2026
1 check passed
Quick104 added a commit that referenced this pull request Jul 10, 2026
…314)

* fix(autoscan): advance marker past paths outside any library folder

A filesystem-watcher scan source (e.g. the CephFS plugin) observes the
entire volume, so it legitimately returns changes for paths that live in
folders which are not registered as Silo libraries (unregistered decade
buckets, 4k-dv, anime-dub, download/recycle dirs, etc.).

Previously, when a poll returned paths but none resolved to a library
folder, PollOnce recorded an "unresolved" error and refused to advance
the marker, on the assumption this only happens for a freshly-enabled
source with unconfigured path rewrites. For a whole-volume watcher that
assumption is wrong: a single change under an unregistered folder pins
the journal marker in place, so every subsequent poll re-reads the same
window and autoscan stalls permanently. Real imports pile up behind the
stuck marker and are never scanned until the next full library scan.

Treat "paths returned but none resolved" as a benign, expected condition:
log a warning (so an operator can still investigate a genuinely
misconfigured source) and advance the marker so the queue keeps moving.
Partial resolution was already handled correctly — the unresolved subset
is simply outside Silo's libraries.

Observed in production: one file added under movies/4k-dv (not a library
path) froze the CephFS source for ~18 days; ~42k journal changes had
accumulated behind it. With this change the marker advances and the
backlog drains on the next poll.

* fix(autoscan): hold marker on transient resolve failures, keep unresolved events visible

Review follow-up: advancing past a window where nothing resolved is only
safe when every path is genuinely outside Silo's libraries (RequestError).
When resolve attempts fail internally (resolver/database fault), the same
resolvedAny=false state now holds the marker and records the error so the
window is retried once the fault clears, instead of silently skipping
imports until the next full library scan.

The benign outside-libraries case still advances, but finishes its poll
event as "unresolved" (with an explaining message) instead of "success",
so the condition stays visible in poll history and the existing
unresolved status filter in the API/admin UI keeps working. Stale doc
comments on PollOnce and AdvanceMarker updated to match the new behavior.

Co-Authored-By: Claude Fable 5 <[email protected]>

* fix(autoscan): hold marker when any resolve attempt fails transiently, not only when all do

The transient-failure hold was gated inside the nothing-resolved branch, so
a mixed window (some paths resolved+enqueued, others failed on an internal
resolver fault) still advanced the marker past the failed paths. Hoist the
gate: any internal resolve failure now records the error and holds the
marker regardless of how many paths resolved. The resolved targets were
already enqueued; re-reading the window at worst re-scans them, which is
safe. Adds a mixed-window regression test.

Co-Authored-By: Claude Fable 5 <[email protected]>

---------
Co-authored-by: Quick <[email protected]>
Co-authored-by: Claude Fable 5 <[email protected]>
@zZebrahz zZebrahz mentioned this pull request Sep 26, 2026
12 tasks done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants