Skip to content

fix(web): stop the Autoscan tab crashing when opened directly - #1927

Merged
Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/autoscan-direct-load-crash
Oct 5, 2026
Merged

Quick104 merged 2 commits into
Silo-Server:mainfrom
Rhainland:fix/autoscan-direct-load-crash

Conversation

@Rhainland

@Rhainland Rhainland commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

Related issue: #1230
Validation tasks: changes #1232 C1

Opening the Autoscan tab directly crashes the admin page with "Something went wrong" (React error #185). That covers a refresh of /admin/libraries?tab=autoscan, a bookmark, and the old /admin/autoscan link the dashboard widgets still use. Clicking the tab from the Libraries tab works, so the crash only shows up when the page loads straight into it.

While the libraries query is loading, AdminLibraries falls back to a new [] on every render. The effect that copies libraries into the drag-and-drop reorder state depends on that array, so it runs and sets state on every render until the query resolves. On the Libraries tab that only wastes renders. On the Autoscan tab, the header switch (Radix) sets state from a ref during each commit, and the endless re-renders push it past React's nested-update limit.

Approach

Use one stable empty array as the fallback, so the effect only runs when the libraries actually change.

Validation

  • A new AdminLibraries test re-renders the page while libraries are still loading; before the fix it fails with a render-loop error instead of hanging the worker, after it the page renders once.
  • On a local Docker build, a direct load of the Autoscan tab crashed 3 times out of 3 before the fix and rendered 3 out of 3 after it; the old /admin/autoscan link and ?view=activity also render.
  • Full gate from CONTRIBUTING.md on a branch combining all eleven [v1] Autoscan #1230 PRs: build, gofmt, go vet, make lint-changed (0 issues), web lint, format check, build and budget, every verify-* target and the router artifact test pass. DB-backed tests for the touched packages (autoscan, scanqueue, scanner, libraryingest, taskmanager, scantrigger, adminjob) pass against a freshly migrated database.
  • make test-go fails only in playback, jellycompat, transcodenode, api/handlers and apiv2 tests that also fail on unmodified main on this macOS host: hardware-probe tests whose fake ffmpeg is killed, transcode-session timing under full-suite load, and TestAdminResourceCapabilitiesAndScope. None of them exercise changed code. make test-web had one failure under full-suite load (AdminUsers row actions) that passes on its own. Linux CI is the authority for these.
  • Each PR on its own builds and passes go vet and the tests of the packages it changes (apart from TestAdminResourceCapabilitiesAndScope above); web PRs also pass the typecheck and the autoscan web tests. Every pair of the eleven PRs merges cleanly into main in either order.

Risks

None identified.

Checklist

  • I read and can explain the complete diff.
  • This pull request addresses one concern.

AI Disclosure

  • Harness: Claude Code (running in T3 Code)
  • Tool(s): Claude Code (Bash, Read, Edit, Write, sub-agents, Playwright browser automation, T3 Code device control), OpenAI Codex CLI (review only), GitHub CLI, Docker, Sonarr, Radarr
  • Model(s): claude-opus-5-5; review: gpt-6.1-sol and gpt-6-astra (Codex CLI)
  • Involvement: Fully AI-generated, human verified
  • Adversarial review: Three independent reviews of the combined [v1] Autoscan #1230 diff against main at medium effort (a Claude Code review agent on claude-opus-5-5, and Codex CLI with gpt-6.1-sol and gpt-6-astra) checked correctness, React state/effect behavior, stale-request guards and docs. No findings for this change.

Note

Fix Autoscan tab crash when opened directly in AdminLibraries

  • Adds a regression test in AdminLibraries.test.tsx that mocks the libraries query as continuously loading and limits hook calls to catch render loops
  • The test rerenders the page after an unrelated update and verifies the loading message stays visible with exactly one libraries-hook call
  • Refactors the test render setup to use a shared query-client factory and one shared provider wrapper for both static and interactive renders

Macroscope summarized a56f710.

Opening /admin/libraries?tab=autoscan directly (a refresh, a bookmark or
the old /admin/autoscan link) crashed with React error Silo-Server#185. While the
libraries query loaded, the page fell back to a new empty array on every
render, so the effect that copies libraries into the reorder state ran on
every render. The Autoscan header switch updates state from a ref during
commit, and the endless re-renders pushed it past React's nested update
limit.

Use a stable empty array as the fallback.
@silo-kody

silo-kody Bot commented Oct 4, 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 ❌

@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: e98bb52d-6184-4b1d-b292-f6c9fd136b9b
📥 Commits

Reviewing files that changed from the base of the PR and between 90e2683 and a56f710.

📒 Files selected for processing (2)
  • web/src/pages/AdminLibraries.test.tsx
  • web/src/pages/AdminLibraries.tsx

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


📝 Walkthrough

Walkthrough

AdminLibraries uses stable empty-array fallbacks when library and active-scan query data is unavailable. Its tests share a QueryClient-and-router wrapper and check that loading continues after rerendering.

Changes

Admin Libraries Loading

Layer / File(s) Summary
Stable fallbacks and loading regression test
web/src/pages/AdminLibraries.tsx, web/src/pages/AdminLibraries.test.tsx
AdminLibraries uses stable empty arrays when library or active-scan query data is missing. The test helpers share a QueryClient-and-router wrapper. A regression test checks that the loading state remains visible after rerendering and that useAdminLibraries is called once after the rerender.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: quick104

Merge Risk: ⚪ Minimal · up to a56f7

No actionable current-head risk remains. The loading fix and its regression check support merging after normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly states the primary change: fixing the Autoscan tab crash when opened directly.
Description check ✅ Passed The description explains the direct-load crash, its cause, the stable-array fix, and the regression test.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@macroscopeapp

macroscopeapp Bot commented Oct 4, 2026

Copy link
Copy Markdown

#1232 C1 currently says Not run, with no failed/blocked result or linked blocker, so this PR does not unblock a recorded case. The diff stabilizes direct loading into the Autoscan panel C1 exercises; its source, connection, mapping, and activity workflows are unchanged. This is a minor entry-point change, and C1 still needs its first validation on a published build.

Suggested fix: Replace the PR line with:
Validation tasks: changes #1232 C1

Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed.

Posted via Macroscope — v1 validation impact

@Rhainland

Copy link
Copy Markdown
Contributor Author

Right, both cases are still recorded as Not run, so there is nothing to unblock. Updated the line to Validation tasks: changes #1232 C1.

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

The fix is correct. The stable fallback stops the reorder-state effect from setting state on every render, and every route onto the Autoscan tab goes through line 177. AdminLibraries.test.tsx passes on this head (16/16). The inline comments cover the regression test, which hangs instead of failing when the fix is reverted, the remaining copy of libraries into state, and two nits.

Two older issues in the reorder state, outside this diff (lines 217 and 246). Both predate this PR and share the repair in the line 177 comment:

  • Low: a refetch during a reorder snaps the dragged row back. If a scan finishes while the reorder request is in flight, the scans event invalidates the libraries query. The refetch returns the old order as a new array, and the effect at line 217 overwrites the dragged order. The row jumps back, then forward again when the reorder succeeds. A second drag in that window sends an order built from the reverted list.
  • Low: a failed reorder can restore a stale list. onError: () => setOrderedLibraries(prev) (line 246) restores the list from drag time even if a refetch landed in between, for example after a library was deleted. useReorderLibraries doesn't invalidate on error, and libraries hasn't changed since that refetch, so the stale rows stay until the next invalidation.

Both come from reading the code; I didn't reproduce them in a browser.

Needs your call: #1232 C1 is recorded as Not run. CLAUDE.md asks the Validation tasks: line to list the passed cases a change could reach, which would make it Validation tasks: none. The current wording follows the Macroscope suggestion, so this is a question of maintainer convention.

AI disclosure: review by claude-opus-5-5 (with claude-sonnet-5-5 subagents) in Claude Code via T3 Code, /silo code-review.

Comment thread web/src/pages/AdminLibraries.test.tsx Outdated
Comment on lines +399 to +406
const view = render(page());
mocks.useAdminLibraries.mockClear();

// Any unrelated update (another query resolving) re-renders the page.
view.rerender(page());

expect(screen.getByText("Loading libraries...")).toBeInTheDocument();
expect(mocks.useAdminLibraries.mock.calls.length).toBeLessThan(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.

Medium: this test hangs instead of failing if the fix regresses.

With line 177 reverted to data: libraries = [], the render loop starts inside the first render(page()), so render never returns. I ran this test against that revert: no output after about three minutes, memory past 2.8 GB, and the worker had to be killed. Vitest's per-test timeout can't interrupt a synchronous loop, so CI would show a stuck or out-of-memory job instead of a failure that names this test. On the fixed code, toBeLessThan(5) passes trivially (the hook is called once per rerender), and it would still pass with up to four extra renders.

Suggested repair: make a loop fail fast inside the first render. For example, count calls in a mockImplementation and throw once the count passes a small bound, or wrap the page in a React.Profiler and fail on too many commits. Then tighten the last check to toHaveBeenCalledTimes(1). Please confirm the new version fails, rather than hangs, with the fix reverted.

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.

Fixed in a56f710: the mocked hook now throws once the page renders more than 20 times, so with the fix reverted the test fails in about 20 ms with "AdminLibraries re-rendered in a loop while loading" instead of hanging, and the rerender check is now toHaveBeenCalledTimes(1).

}

const { data: libraries = [], isLoading } = useAdminLibraries();
const { data: libraries = NO_LIBRARIES, isLoading } = useAdminLibraries();

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.

Low, needs your call (this PR or a follow-up): the fix depends on libraries keeping the same reference.

This line is now the only thing preventing the #185 loop. The underlying pattern is still there: orderedLibraries copies libraries into state (line 210), and the effect at lines 217–219 calls setOrderedLibraries(libraries) whenever the reference changes. Any later change that hands the effect a new array on each render brings the crash back: a select in useAdminLibraries, a ?? [] here, or a filter or sort before the effect. The new test mocks the hook, so it wouldn't catch the select case.

Suggested repair: stop copying the query data into state. Keep only a pending order (useState<Library[] | null>(null)), render pendingOrder ?? libraries, and clear it when the reorder mutation settles. Or apply the reorder optimistically in useReorderLibraries (cancelQueries and setQueryData in onMutate, restore in onError). Either one removes the effect, and with it the two reorder races in the review summary. It's a larger change than this crash fix, so a follow-up issue seems reasonable.

Comment thread web/src/pages/AdminLibraries.test.tsx Outdated
Comment on lines +391 to +398
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const page = () => (
<QueryClientProvider client={client}>
<MemoryRouter>
<AdminLibraries />
</MemoryRouter>
</QueryClientProvider>
);

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.

Nit: third copy of the page's provider tree.

renderPage and renderInteractivePage (lines 131–151) already build this QueryClient → QueryClientProvider → MemoryRouter → AdminLibraries tree. They can't be reused here as written, because rerender needs the element and they don't expose it. A shared element factory, such as const page = (client: QueryClient) => (...), used by both helpers and this test, would keep a future provider change in one place.

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.

Fixed in a56f710: page(client) builds the provider tree once, and renderPage, renderInteractivePage and this test all use it.

Comment thread web/src/pages/AdminLibraries.tsx Outdated
const { data: libraries = [], isLoading } = useAdminLibraries();
const { data: libraries = NO_LIBRARIES, isLoading } = useAdminLibraries();
const { data: libraryCapabilities } = useLibraryCapabilities();
const { data: activeScans = [] } = useActiveScans();

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.

Nit, optional: the same = [] default one line down.

activeScans gets a new array on every render until useActiveScans resolves. It only feeds the useMemos at lines 271 and 283, with no effect, and the query resolves almost immediately, so the cost is negligible. A NO_ACTIVE_SCANS constant next to NO_LIBRARIES would keep the two defaults consistent.

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.

Done in a56f710: activeScans falls back to a stable NO_ACTIVE_SCANS next to NO_LIBRARIES.

The regression test now throws from the mocked hook once the page renders
in a loop, so a reverted fix fails the test in milliseconds instead of
exhausting the worker, and the rerender check expects exactly one call.
The three tests share one provider-tree factory, and the active-scans
fallback uses a stable empty array like the libraries one.
@silo-kody

silo-kody Bot commented Oct 5, 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 ❌

@Quick104
Quick104 merged commit c8ca429 into Silo-Server:main Oct 5, 2026
21 checks passed
Quick104 added a commit to Rhainland/silo-server that referenced this pull request Oct 5, 2026
Brings in main's fix for the Autoscan tab crash on direct open (Silo-Server#1927).
SourcesPanel.tsx keeps this branch's version: main's copy is Silo-Server#1928's
head, which this branch already contains.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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