Skip to content

feat(autoscan): pluggable scan-source autoscan category (Sonarr/Radarr) - #44

Merged
Quick104 merged 118 commits into
Silo-Server:mainfrom
fluxis:feat/autoscan-scan-source-host
Jun 6, 2026
Merged

Quick104 merged 118 commits into
Silo-Server:mainfrom
fluxis:feat/autoscan-scan-source-host

Conversation

@fluxis

@fluxis fluxis commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Adds Autoscan: a standalone admin category that watches Sonarr/Radarr (and, in future, any provider) for imports + renames and triggers targeted library rescans, so new media appears without waiting for a full scan.

Change-detection is pluggable via the new scan_source.v1 capability (merged in silo-plugin-sdk #2). The host owns the timer, marker storage, path rewrites, scan enqueueing, and the admin UI; an out-of-process plugin (the Sonarr/Radarr provider, separate repo) just polls arr and returns raw changed paths. This PR is the host half (silo-server).

Note on history/diff size: this branch is based on a local main that carried an earlier in-process autoscan, which this work replaced. The commit history therefore shows v1 added-then-removed churn — but the net diff vs origin/main is the clean v2 feature (review the Files changed tab). Recommend squash-merge.

Architecture

Operator installs the Sonarr/Radarr plugin via /admin/plugins
        │ (auto-discovered as an available scan source)
        ▼
/admin/autoscan: create a Source per arr (bind a Connection + path rewrites + enable)
        │
host poll loop (per enabled source, every N s):
  resolve Connection → {base_url, api_key}
  → plugin.PollChanges(marker, connection)         # plugin polls arr /history
  → raw source_paths + next_marker
  → apply this source's path rewrites (host-owned)
  → resolve to a MediaFolder → suppress dupes → enqueue rescan
  → store marker (only after work is consumed)
  • Connections — an arr server the host can reach: enter your own URL+key, or reuse a Requests integration (live link). Test-connection button.
  • Sources — one per installed scan_source capability × connection (many per plugin). Per-source rewrites with a "Sync from arr" suggester (matches arr root folders to Silo media folders). Auto-discovered; enable requires a bound connection.
  • Opaque marker — host stores it verbatim; never regresses; advances only after work is consumed.

What's in this PR (host)

  • internal/autoscan/ — engine (poll → rewrite → resolve → suppress → enqueue → marker), repository, connection resolver, provider seam, discovery, host-side rewrite suggester, connection probe.
  • internal/pluginhost + internal/plugins — scan_source.v1 client wrapper + service resolver.
  • internal/api/handlers/autoscan.go + autoscan_wiring.go + router.go — admin API (settings, connections, sources, scan-source-plugins, trigger, status, connection-test, rewrite-suggestions).
  • migrations/171_autoscan.up.sql — single clean v2 schema (the prior in-process autoscan never shipped to main, so its migration was collapsed, not migrated).
  • web/src/pages/AdminAutoscan.tsx + pages/admin/autoscan/* + hooks/types — the Autoscan admin category.
  • cmd/silo/main.go — poll task wiring.
  • go.mod — depends on the merged silo-plugin-sdk (scan_source.v1) via pseudo-version; bump to a tagged release when one is cut.

Dependencies / multi-repo

  • silo-plugin-sdk — scan_source.v1 is merged (Add online recap and preview marker support #2). This PR consumes it.
  • Sonarr/Radarr plugin — separate repo (the provider). Needs a canonical Silo-Server/silo-plugin-autoscan-arr repo + a silo-plugins catalog entry. Without an installed scan-source plugin, the Autoscan page shows an empty "install a plugin" state — the host degrades gracefully.
  • Client repos (android/apple): admin-only surface, no client changes.

Known follow-up (intentionally out of scope)

Arr API keys are stored plaintext at rest in autoscan_connections.api_key_ref — consistent with the existing request_integrations pattern (Requests stores its arr keys plaintext too; silo-server has no Fernet/secret store). This is a repo-wide property, not an autoscan regression. Encrypting arr credentials at rest (a shared secret store for both Requests and autoscan) is tracked as a separate cross-cutting security item.

Test plan

  • go build ./... + go test ./... green (run in a libvips-equipped env — internal/api/* link libvips via CGO).
  • web builds; no new frontend test failures vs baseline.
  • Plugin↔host contract validated by a live go-plugin e2e test (in the plugin repo).
  • Verified live on a real deployment: 4 arr sources poll successfully (markers advance, zero errors), Sync-from-arr applies rewrites, connection-test works.
  • Hardened by three rounds of adversarial /code-review max (credential dead-seam, unbind no-op, marker data-loss, history truncation, migration backfill, +more — all fixed).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • New “Autoscan” admin area (sidebar link): Settings, Sources, Connections, Activity (events & scans) and “Run now” trigger.
    • Manage/test connections, create/manage scan sources with per-source intervals, enable/disable, path rewrites, and “Sync from arr” rewrite suggestions.
    • Background polling that enqueues targeted folder scans with debouncing and per-source status.
  • Documentation

    • Multiple design/plan/spec docs for Autoscan, plugin capability, host/backend, and UI.
  • Tests

    • Extensive unit and integration test coverage across autoscan, handlers, provider, rewrites, and UI.

fluxis and others added 30 commits June 2, 2026 17:53
Periodic poller over autoscan-enabled Radarr/Sonarr instances (reusing
request_integrations) that maps import paths to Silo media folders and
enqueues targeted scans via the existing scantrigger + scanqueue. Lean
single-service model: no cross-node fan-out guard or retry queue.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Adds ErrIntegrationNotFound sentinel (errors.Is) instead of string matching.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…ure trigger on interval change; skip source on key-resolution error

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…p, boundary-safe rewrites, GREATEST cursor guard, async trigger, quiet unresolved-path skip, FK->404

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…rs, re-seed source editor on save

Addresses minor code-review findings: Windows backslash paths now normalized
before rewrite/dedupe; HandleStatus returns repository errors instead of 200;
the per-source editor re-seeds from server data after a save.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add suggestRewrites / commonSuffixLen for Task 1 of the autoscan
arr-polling feature. Pure function: matches arr root-folder paths to
Silo media folder paths by longest common trailing segment count,
adjusted for depth-delta so coincidental same-named segments at
different structural levels don't inflate confidence. Categorises
each arr root as Proposed, Ambiguous, Unmatched, or Covered by an
existing PathRewrite rule. TDD: test file written first, verified
failing, then implementation added.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Add GET /autoscan/sources/{id}/rewrite-suggestions admin endpoint: extend
the autoscanTriggerer interface with SuggestRewrites, wire SetRewriteResolvers
in the router, and add handler + test.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
…p no-op suggestions

Addresses final-review edge cases: coveredBy normalizes the existing rewrite's
From (so a stored Windows/dup-slash rule still covers a root); duplicate arr
roots and duplicate Silo folder paths are de-duplicated; an arr path that already
equals its Silo path is not proposed as a no-op rewrite.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
fluxis and others added 12 commits June 5, 2026 15:57
Replace the sourceNames Map plumbing in ActivityPanel with SourceLabelLookups
and delegate both name functions to resolveEventSourceName from @/lib/autoscanLabels,
enabling the full label chain (operator label → connection name → manifest display_name
→ capability_id) for all Scan History and Poll log rows.
Final-review follow-ups: add the label field to the autoscanStatusSource
response (and AutoscanStatusSource type) so the status view matches the
source response per spec, and give pollSourceName a non-empty fallback for
symmetry with scanSourceName.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Replace the legacy capability-only sourceLabel() helper with resolveSourceName()
(operator label -> connection -> display_name -> capability). Row controls now
announce the row's resolvedLabel (reflecting in-progress edits) and the delete
dialog announces the resolved name, so screen readers hear "4K Movies" instead
of "arr (plugin Silo-Server#4)".

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Replace the card/table hybrid and 200-row "Load more" cap on the autoscan
Activity panel with proper tables and real pagination.

Backend: add offset + total-count to the scans/events list endpoints so
history pages through the full set instead of a capped window. Extract
shared event/scan WHERE-clause builders so list and count filter
identically, and add CountEvents / CountAutoscanScans.

Frontend: add a reusable TablePagination component (rows-per-page,
"showing X-Y of Z", numbered window with ellipses, responsive) and reuse
it for the server-paginated history (scans + polls) and the
client-paginated live queue. Unify all three tables behind one DataTable
shell so they read as one family.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Quick104
Quick104 merged commit d169b52 into Silo-Server:main Jun 6, 2026
1 check passed