<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.4.1">Jekyll</generator><link href="https://mcgarrah.org/feed.xml" rel="self" type="application/atom+xml" /><link href="https://mcgarrah.org/" rel="alternate" type="text/html" hreflang="en" /><updated>2026-11-13T17:32:23+00:00</updated><id>https://mcgarrah.org/feed.xml</id><title type="html">McGarrah Technical Blog</title><subtitle>Engineering deep dives on infrastructure, distributed systems, and AI/ML — from homelab experiments to enterprise architecture.</subtitle><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><entry><title type="html">Rescuing a Landline Number: Migrating Out of Google Fiber and Into Google Voice</title><link href="https://mcgarrah.org/rescuing-landline-number-google-fiber-to-google-voice/" rel="alternate" type="text/html" title="Rescuing a Landline Number: Migrating Out of Google Fiber and Into Google Voice" /><published>2026-09-14T00:00:00+00:00</published><updated>2026-09-14T00:00:00+00:00</updated><id>https://mcgarrah.org/rescuing-landline-number-google-fiber-to-google-voice</id><content type="html" xml:base="https://mcgarrah.org/rescuing-landline-number-google-fiber-to-google-voice/"><![CDATA[<p>Losing a primary phone number tied to decades of professional history, resumes, and account recovery flows is a technical emergency, not a mild inconvenience. It’s the number on file with banks, with two-factor recovery paths, with people who haven’t updated their contacts since a job I left years ago. When Google Fiber changed its home phone backend and quietly dropped SMS support – and a backend glitch forced an unwanted random number reassignment on top of it – my number, <code class="language-plaintext highlighter-rouge">919-807-1057</code>, ended up stranded on a deprecated VoIP endpoint with no straightforward way off it.</p>

<!-- excerpt-end -->

<p>Google Voice won’t accept a direct port from a landline or fixed VoIP provider. That restriction turned what should have been a five-minute porting form into a multi-step migration across three different carrier systems.</p>

<h2 id="the-technical-roadblock-voip-vs-mobile-classification">The Technical Roadblock: VoIP vs. Mobile Classification</h2>

<p>Google Fiber phone numbers live on a traditional VoIP carrier network. Google Voice’s porting pipeline checks the number’s carrier-type classification in the Local Number Portability (LNP) database, and it only accepts inbound ports from numbers classified under a mobile carrier block. Submit a port request straight from a landline or fixed VoIP number, and it gets rejected immediately on carrier type – no amount of retrying the form changes that outcome.</p>

<p>To get the number in front of Google Voice at all, it first had to exist on real mobile infrastructure. That meant introducing an intermediate carrier hop: land the number on a mobile network first, let the LNP database catch up, then port from there.</p>

<h2 id="the-migration-path">The Migration Path</h2>

<p><strong>1. Secure the account parameters.</strong> Before touching anything, I logged into the Google Fiber account portal to pull the exact account number and generate a valid port-out PIN. The service has to stay active through this step – cancelling early releases the number back into the pool and closes the window for good.</p>

<p><strong>2. Bridge through a mobile eSIM.</strong> I had a spare eSIM slot on a Galaxy S23 Ultra, so I activated a low-cost line with Tello, a mobile carrier riding on major cellular infrastructure. Instead of keeping Tello’s assigned placeholder number, I immediately filed a port-in request against it using the Fiber account number and PIN, moving <code class="language-plaintext highlighter-rouge">919-807-1057</code> onto Tello.</p>

<p><strong>3. Wait for LNP propagation.</strong> Once the carrier-to-carrier port cleared, the number’s record in the LNP database now showed a mobile carrier block. That’s the only thing Google Voice’s porting form actually checks – it doesn’t care that the line spent all of ten minutes on Tello before moving again.</p>

<p><strong>4. Port into Google Voice.</strong> With the classification fixed, I submitted the port request through <a href="https://voice.google.com/porting">voice.google.com/porting</a>, paid the one-time $20 porting fee, and anchored the Voice account to a separate mobile number for verification (Google Voice requires a working number to receive porting status updates and as a fallback contact during the transition). The port cleared a few hours later once NPAC (Number Portability Administration Center) finished routing synchronization.</p>

<h2 id="the-takeaway">The Takeaway</h2>

<p>The eSIM bridge is the whole trick: it’s not a real carrier relationship, just a brief stop that changes the number’s classification in the LNP database so the next port is one Google Voice will actually accept. The number is back on modern infrastructure now, with full SMS, call history, and voicemail – and none of the professional contacts or account-recovery flows built around it over the years had to change.</p>

<p>If you’re stuck in the same spot – a landline or fixed VoIP number Google Voice won’t take directly – the fix isn’t a support ticket, it’s routing around the carrier-type check with a throwaway mobile line you control long enough to make the classification stick.</p>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="personal" /><category term="technical" /><category term="google" /><category term="google-fiber" /><category term="google-voice" /><category term="esim" /><category term="number-porting" /><category term="voip" /><category term="telecom" /><category term="tello" /><summary type="html"><![CDATA[How I recovered a 15-year-old phone number after Google Fiber changed its telephony backend and broke SMS -- using a temporary Tello eSIM as a mobile bridge to satisfy Google Voice's carrier-type porting requirements.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/rescuing-landline-number-google-fiber-to-google-voice.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/rescuing-landline-number-google-fiber-to-google-voice.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Kiro IDE + WSL2: Fixing the Agent Shell Execution Layer</title><link href="https://mcgarrah.org/kiro-ide-wsl2-integration/" rel="alternate" type="text/html" title="Kiro IDE + WSL2: Fixing the Agent Shell Execution Layer" /><published>2026-08-21T00:00:00+00:00</published><updated>2026-08-21T00:00:00+00:00</updated><id>https://mcgarrah.org/kiro-ide-wsl2-integration</id><content type="html" xml:base="https://mcgarrah.org/kiro-ide-wsl2-integration/"><![CDATA[<p>Kiro is AWS’s AI-native IDE — a Code OSS fork with agentic coding capabilities baked in. Unlike VS Code, it doesn’t ship with Microsoft’s proprietary Remote - WSL extension. Instead, WSL2 connectivity relies on the community-maintained <a href="https://open-vsx.org/extension/jeanp413/open-remote-wsl">Open Remote - WSL</a> extension (<code class="language-plaintext highlighter-rouge">jeanp413.open-remote-wsl</code>), which is available on Open VSX. I covered the full setup — installation, <code class="language-plaintext highlighter-rouge">argv.json</code> configuration, the update breakage cycle, and recovery — in a <a href="/kiro-ide-wsl2-support-open-remote-extension/">previous article</a>.</p>

<p>This article tackles what happens <em>after</em> WSL2 connectivity is working: the agent’s shell execution layer still misbehaves. Kiro’s AI agent can run terminal commands inside your WSL2 environment, but without explicit Linux terminal profiles and shell integration, the results are garbled, unreliable, and frustrating.</p>

<!-- excerpt-end -->

<p>I hit this after migrating from VS Code to Kiro. Every shell command the agent tried to run came back with double-echoed output, <code class="language-plaintext highlighter-rouge">Exit Code: 1</code>, and Windows-style path escaping — despite the commands actually executing successfully inside my WSL2 Ubuntu 24.04 environment. This article documents the fixes.</p>

<h2 id="the-trigger-im-clearly-stuck-in-a-loop">The Trigger: “I’m Clearly Stuck in a Loop”</h2>

<p>The moment that sent me down this rabbit hole was Kiro’s agent announcing:</p>

<blockquote>
  <p>“I’ve been trying to use <code class="language-plaintext highlighter-rouge">execute_pwsh</code> but it’s failed 7 times in a row. I’m clearly stuck in a loop. What would you like me to do?”</p>
</blockquote>

<p>My immediate reaction: <em>why is it using PowerShell?</em> I’m in WSL2 running Ubuntu 24.04 with zsh. There is no PowerShell here. I told the agent — repeatedly across multiple sessions — that it cannot use PowerShell in this environment, and each time it acknowledged the constraint but kept invoking the same <code class="language-plaintext highlighter-rouge">execute_pwsh</code> tool.</p>

<p>The confusion is understandable. The tool is <em>named</em> <code class="language-plaintext highlighter-rouge">execute_pwsh</code>. If you’re a developer who sees “pwsh” in a tool name, you think PowerShell. The agent thinks PowerShell. Everyone assumes the wrong thing.</p>

<p>Here’s the reality: <code class="language-plaintext highlighter-rouge">execute_pwsh</code> is just the name of Kiro’s <em>only</em> shell execution tool. It’s not actually calling PowerShell — it dispatches commands to whatever terminal backend the IDE is configured to use. In a WSL Remote context, that terminal <em>should</em> be your Linux shell. The name is a misnomer inherited from the tool’s original Windows-first design.</p>

<p>The real problem isn’t that PowerShell is being invoked. It’s that the terminal backend, despite reaching your Linux shell, is misconfigured — the path escaping, echo handling, and exit code parsing are all broken because Kiro doesn’t have explicit Linux terminal profiles telling it how to behave in this context.</p>

<p>Once I understood that distinction — <code class="language-plaintext highlighter-rouge">execute_pwsh</code> ≠ PowerShell, it’s just a badly-named shell dispatch tool — the fix became obvious: tell Kiro what shell to actually use on the Linux side.</p>

<p><strong>Prerequisites:</strong> You should already have <code class="language-plaintext highlighter-rouge">jeanp413.open-remote-wsl</code> installed and configured with the <code class="language-plaintext highlighter-rouge">enable-proposed-api</code> entry in <code class="language-plaintext highlighter-rouge">~/.kiro/argv.json</code>. If you haven’t done that yet, start with <a href="/kiro-ide-wsl2-support-open-remote-extension/">Kiro IDE on Windows: WSL2 Support via Open Remote Extension</a>.</p>

<h2 id="the-problem">The Problem</h2>

<p>When Kiro’s agent executes terminal commands via its <code class="language-plaintext highlighter-rouge">execute_pwsh</code> tool (yes, the name is hardcoded regardless of your actual shell), it does the following in a WSL Remote context:</p>

<ol>
  <li><strong>Mangles the <code class="language-plaintext highlighter-rouge">cwd</code> parameter</strong> — Converts Linux paths to Windows UNC notation before passing them, causing <code class="language-plaintext highlighter-rouge">cd</code> failures.</li>
  <li><strong>Double-echoes commands</strong> — Every command appears twice in the output, garbled with character insertions.</li>
  <li><strong>Reports false exit codes</strong> — Commands succeed but the tool reports <code class="language-plaintext highlighter-rouge">Exit Code: 1</code>.</li>
  <li><strong>Treats paths as Windows</strong> — Backslash escaping and quoting patterns break Linux commands.</li>
</ol>

<p>The commands actually execute — <code class="language-plaintext highlighter-rouge">git pull</code> succeeds, files get modified — but the agent can’t reliably parse its own output, leading to confusion, retries, and a frustrating developer experience.</p>

<h2 id="why-this-worked-in-vs-code">Why This Worked in VS Code</h2>

<p>VS Code extensions like GitHub Copilot, Amazon Q, and Continue dispatch shell commands through the <code class="language-plaintext highlighter-rouge">terminal.integrated.automationProfile</code> settings. When you’re connected to WSL2 via Remote WSL, VS Code correctly uses the Linux automation profile for command execution.</p>

<p>Kiro’s agent tool (<code class="language-plaintext highlighter-rouge">execute_pwsh</code>) appears to bypass or ignore this setting chain in certain configurations. The fix is to explicitly declare Linux terminal profiles so there’s no ambiguity.</p>

<p>Note: VS Code uses Microsoft’s proprietary Remote - WSL extension, which is not available on Open VSX and cannot be used in Kiro. Kiro uses <code class="language-plaintext highlighter-rouge">jeanp413.open-remote-wsl</code> — a community-built alternative that provides the same WSL2 filesystem and terminal bridging. The terminal profile fix below applies regardless of which remote extension provides the WSL2 connection.</p>

<h2 id="the-fix-three-parts">The Fix: Three Parts</h2>

<h3 id="1-kiro-user-settings-settingsjson">1. Kiro User Settings (settings.json)</h3>

<p>Location on the Windows filesystem: <code class="language-plaintext highlighter-rouge">%APPDATA%\Kiro\User\settings.json</code></p>

<p>From WSL: <code class="language-plaintext highlighter-rouge">/mnt/c/Users/&lt;username&gt;/AppData/Roaming/Kiro/User/settings.json</code></p>

<p>Add these settings:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"terminal.integrated.defaultProfile.linux"</span><span class="p">:</span><span class="w"> </span><span class="s2">"zsh"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"terminal.integrated.automationProfile.linux"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="nl">"path"</span><span class="p">:</span><span class="w"> </span><span class="s2">"/bin/zsh"</span><span class="w">
  </span><span class="p">},</span><span class="w">
  </span><span class="nl">"terminal.integrated.profiles.linux"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="nl">"zsh"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nl">"path"</span><span class="p">:</span><span class="w"> </span><span class="s2">"/bin/zsh"</span><span class="w"> </span><span class="p">},</span><span class="w">
    </span><span class="nl">"bash"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="nl">"path"</span><span class="p">:</span><span class="w"> </span><span class="s2">"/bin/bash"</span><span class="w"> </span><span class="p">}</span><span class="w">
  </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>The key insight: even though <code class="language-plaintext highlighter-rouge">terminal.integrated.defaultProfile.windows</code> was already set to a WSL profile, the <strong>Linux-side profiles</strong> were never declared. When Kiro’s Remote WSL connection needs to execute commands inside the Linux environment, it looks for <code class="language-plaintext highlighter-rouge">*.linux</code> settings — and without them, falls back to behavior that doesn’t match your environment.</p>

<p>You should also have the Windows-side WSL profile configured:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"terminal.integrated.defaultProfile.windows"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Ubuntu-24.04 (WSL)"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"terminal.integrated.profiles.windows"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="nl">"Ubuntu-24.04 (WSL)"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
      </span><span class="nl">"path"</span><span class="p">:</span><span class="w"> </span><span class="s2">"C:</span><span class="se">\\</span><span class="s2">WINDOWS</span><span class="se">\\</span><span class="s2">System32</span><span class="se">\\</span><span class="s2">wsl.exe"</span><span class="p">,</span><span class="w">
      </span><span class="nl">"args"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="s2">"-d"</span><span class="p">,</span><span class="w"> </span><span class="s2">"Ubuntu-24.04"</span><span class="p">]</span><span class="w">
    </span><span class="p">}</span><span class="w">
  </span><span class="p">}</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<h3 id="2-shell-integration-scripts">2. Shell Integration Scripts</h3>

<p>Kiro provides shell integration that improves command tracking, exit code detection, and working directory awareness. Without these, the agent has to infer results from raw terminal output — which is where the garbling and false errors come from.</p>

<p><strong>For zsh</strong> — add to the end of <code class="language-plaintext highlighter-rouge">~/.zshrc</code>:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Kiro shell integration</span>
<span class="o">[[</span> <span class="s2">"</span><span class="nv">$TERM_PROGRAM</span><span class="s2">"</span> <span class="o">==</span> <span class="s2">"kiro"</span> <span class="o">]]</span> <span class="o">&amp;&amp;</span> <span class="nb">.</span> <span class="s2">"</span><span class="si">$(</span>kiro <span class="nt">--locate-shell-integration-path</span> zsh<span class="si">)</span><span class="s2">"</span>
</code></pre></div></div>

<p><strong>For bash</strong> — add to the end of <code class="language-plaintext highlighter-rouge">~/.bashrc</code>:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Kiro shell integration</span>
<span class="o">[[</span> <span class="s2">"</span><span class="nv">$TERM_PROGRAM</span><span class="s2">"</span> <span class="o">==</span> <span class="s2">"kiro"</span> <span class="o">]]</span> <span class="o">&amp;&amp;</span> <span class="nb">.</span> <span class="s2">"</span><span class="si">$(</span>kiro <span class="nt">--locate-shell-integration-path</span> bash<span class="si">)</span><span class="s2">"</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">[[ "$TERM_PROGRAM" == "kiro" ]]</code> guard ensures these only activate when running inside Kiro — no impact on your regular terminal sessions.</p>

<h3 id="3-reload-kiro">3. Reload Kiro</h3>

<p>After making these changes:</p>

<ol>
  <li>Close and reopen Kiro, <strong>or</strong> use Command Palette → “Developer: Reload Window”</li>
  <li>Open a new agent session to test</li>
</ol>

<p>The shell integration loads at terminal startup, so existing sessions won’t pick up the changes.</p>

<h2 id="bonus-wsl-launcher-function">Bonus: WSL Launcher Function</h2>

<p>If you want to launch Kiro from your WSL terminal (like <code class="language-plaintext highlighter-rouge">code .</code> opens VS Code), add this to <code class="language-plaintext highlighter-rouge">~/.zshrc</code>:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>kiro<span class="o">()</span> <span class="o">{</span>
    <span class="nb">local </span><span class="nv">KIRO_BIN</span><span class="o">=</span><span class="s2">"/mnt/c/Users/&lt;username&gt;/AppData/Local/Programs/Kiro/Kiro.exe"</span>
    <span class="nb">env</span> <span class="nt">-i</span> /init <span class="s2">"</span><span class="nv">$KIRO_BIN</span><span class="s2">"</span> <span class="s2">"</span><span class="si">$(</span>wslpath <span class="nt">-w</span> <span class="s2">"</span><span class="k">${</span><span class="nv">1</span><span class="k">:-</span><span class="p">.</span><span class="k">}</span><span class="s2">"</span><span class="si">)</span><span class="s2">"</span> <span class="o">&gt;</span> /dev/null 2&gt;&amp;1 &amp;
<span class="o">}</span>
</code></pre></div></div>

<p>Usage:</p>
<ul>
  <li><code class="language-plaintext highlighter-rouge">kiro .</code> — Open current directory in Kiro</li>
  <li><code class="language-plaintext highlighter-rouge">kiro ~/github/myproject</code> — Open a specific project</li>
</ul>

<p>The <code class="language-plaintext highlighter-rouge">env -i /init</code> pattern is key — it uses the WSL interop bridge (<code class="language-plaintext highlighter-rouge">/init</code>) to launch the Windows binary while cleaning the environment so Linux environment variables don’t leak into the Windows process. The <code class="language-plaintext highlighter-rouge">&amp;</code> backgrounds it so your terminal stays usable.</p>

<h2 id="kiro-steering-files">Kiro Steering Files</h2>

<p>If you’re using Kiro’s steering system (<code class="language-plaintext highlighter-rouge">.kiro/steering/*.md</code>) to provide project context to the agent, add a note about the shell environment. I keep this at the user level (<code class="language-plaintext highlighter-rouge">~/.kiro/steering/shell-environment.md</code>) so it applies across all workspaces:</p>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nn">---</span>
<span class="na">inclusion</span><span class="pi">:</span> <span class="s">auto</span>
<span class="nn">---</span>

<span class="gh"># Shell &amp; Platform Environment</span>
<span class="p">
-</span> <span class="gs">**Execution environment:**</span> WSL2 running Ubuntu 24.04 LTS
<span class="p">-</span> <span class="gs">**Shell:**</span> zsh with Oh My Zsh (omz)
<span class="p">-</span> <span class="gs">**This is a Linux environment.**</span> Always use Linux commands, paths, and tooling.
<span class="p">-</span> Do NOT use PowerShell, <span class="sb">`cmd.exe`</span>, or Windows-style paths in shell commands.
<span class="p">-</span> Native paths use <span class="sb">`/home/&lt;username&gt;/...`</span> format, not Windows UNC paths.
</code></pre></div></div>

<p>This gives the agent explicit context about the execution environment, reducing the chance it tries to use Windows-style commands or paths.</p>

<h2 id="phantom-diffs-in-the-source-control-panel">Phantom Diffs in the Source Control Panel</h2>

<p>After getting shell execution working, you may notice another oddity: Kiro’s Source Control panel shows files as “modified” even when <code class="language-plaintext highlighter-rouge">git status</code> from the terminal reports a clean working tree. The phantom diffs almost always affect shell scripts (<code class="language-plaintext highlighter-rouge">.sh</code> files) — specifically those with the executable bit (<code class="language-plaintext highlighter-rouge">chmod +x</code>) set.</p>

<p><strong>Root cause:</strong> Kiro’s built-in git SCM extension reads file metadata through the <code class="language-plaintext highlighter-rouge">\\wsl$\</code> UNC path (the 9P filesystem bridge between Windows and WSL2). The 9P bridge does not faithfully translate Unix file permissions — Windows sees all files without the executable bit. Git’s index stores these files as <code class="language-plaintext highlighter-rouge">100755</code> (executable), but when the SCM extension stats them through the UNC path, it sees <code class="language-plaintext highlighter-rouge">100644</code> (non-executable). That permission mismatch registers as a modification.</p>

<p>You can confirm this is a phantom diff by running:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git status          <span class="c"># Clean — nothing to commit</span>
git ls-files <span class="nt">-m</span>     <span class="c"># Empty — no modifications</span>
git diff            <span class="c"># Empty — no content changes</span>
git ls-tree HEAD jekyll-caddy.sh  <span class="c"># Shows 100755 — executable in index</span>
<span class="nb">ls</span> <span class="nt">-la</span> jekyll-caddy.sh            <span class="c"># Shows -rwxr-xr-x — executable on disk</span>
</code></pre></div></div>

<p>If all of those are clean but the SCM panel still shows “M”, the issue is filemode detection through the 9P bridge.</p>

<h3 id="what-doesnt-work">What Doesn’t Work</h3>

<p>I tried several approaches before finding the solution:</p>

<ul>
  <li><strong><code class="language-plaintext highlighter-rouge">.gitattributes</code> with <code class="language-plaintext highlighter-rouge">eol=lf</code></strong> — This fixes line-ending phantom diffs but has no effect on permission/filemode diffs. The problem isn’t line endings.</li>
  <li><strong><code class="language-plaintext highlighter-rouge">git.path</code> pointing to a wrapper script</strong> — I created <code class="language-plaintext highlighter-rouge">~/.local/bin/git-kiro</code> that injected <code class="language-plaintext highlighter-rouge">-c core.fileMode=false</code> and set <code class="language-plaintext highlighter-rouge">"git.path"</code> in both the Kiro user settings and workspace <code class="language-plaintext highlighter-rouge">.vscode/settings.json</code>. The SCM extension ignored it entirely — it appears to use its own git integration that doesn’t honor <code class="language-plaintext highlighter-rouge">git.path</code> when connected via WSL Remote.</li>
  <li><strong>Global git attributes</strong> (<code class="language-plaintext highlighter-rouge">~/.config/git/attributes</code>) — Same story. Attributes control line-ending normalization, not filemode comparison.</li>
</ul>

<h3 id="the-fix-corefilemodefalse-per-repository">The Fix: <code class="language-plaintext highlighter-rouge">core.fileMode=false</code> Per Repository</h3>

<p>The only approach that works is setting <code class="language-plaintext highlighter-rouge">core.fileMode=false</code> directly in each repository’s <code class="language-plaintext highlighter-rouge">.git/config</code>:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git config core.fileMode <span class="nb">false</span>
</code></pre></div></div>

<p>This tells git to stop comparing the executable bit between the index and the working tree. Files already committed as <code class="language-plaintext highlighter-rouge">100755</code> remain <code class="language-plaintext highlighter-rouge">100755</code> in the repository — this setting only affects the working-tree comparison.</p>

<p>Apply to all affected repos:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git <span class="nt">-C</span> ~/github/mcgarrah.github.io config core.fileMode <span class="nb">false
</span>git <span class="nt">-C</span> ~/github/jellyfin-plugin-media-integrity-scanner config core.fileMode <span class="nb">false
</span>git <span class="nt">-C</span> ~/github/k8s-proxmox config core.fileMode <span class="nb">false
</span>git <span class="nt">-C</span> ~/github/resume config core.fileMode <span class="nb">false</span>
</code></pre></div></div>

<p>For new clones, add it after cloning:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone &lt;url&gt; <span class="o">&amp;&amp;</span> git <span class="nt">-C</span> &lt;repo&gt; config core.fileMode <span class="nb">false</span>
</code></pre></div></div>

<h3 id="why-not-set-it-globally">Why Not Set It Globally?</h3>

<p>You could run <code class="language-plaintext highlighter-rouge">git config --global core.fileMode false</code> to apply it everywhere, but that affects all tools on the system — Claude Code, Antigravity (Gemini), terminal git, CI scripts. The per-repo approach isolates the workaround to just the repositories open in Kiro.</p>

<p>The tradeoff is minor: if you add a new shell script with <code class="language-plaintext highlighter-rouge">chmod +x</code>, git won’t automatically detect the permission change. You’ll need to explicitly tell git:</p>
<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git update-index <span class="nt">--chmod</span><span class="o">=</span>+x newscript.sh
</code></pre></div></div>

<p>Since this only matters when adding <em>new</em> executable files (not editing existing ones), it’s rarely an issue in practice.</p>

<h3 id="why-this-happens">Why This Happens</h3>

<p>The chain of events:</p>

<ol>
  <li>Kiro connects to WSL2 via <code class="language-plaintext highlighter-rouge">jeanp413.open-remote-wsl</code></li>
  <li>The built-in git SCM extension runs on the remote side</li>
  <li>But it reads file stats through a code path that goes via the 9P bridge (<code class="language-plaintext highlighter-rouge">\\wsl$\</code>)</li>
  <li>The 9P bridge strips Unix permission bits — all files appear as <code class="language-plaintext highlighter-rouge">644</code></li>
  <li>Git’s index says <code class="language-plaintext highlighter-rouge">755</code> for shell scripts</li>
  <li>The SCM extension sees <code class="language-plaintext highlighter-rouge">755 → 644</code> = modified</li>
</ol>

<p>The Linux-native git binary doesn’t have this problem because it reads permissions directly from the ext4 filesystem. The SCM extension’s internal git implementation takes a different code path that hits the 9P translation layer.</p>

<h3 id="supplementary-gitattributes-for-line-endings">Supplementary: <code class="language-plaintext highlighter-rouge">.gitattributes</code> for Line Endings</h3>

<p>While <code class="language-plaintext highlighter-rouge">.gitattributes</code> doesn’t fix the permission issue, it’s still worth adding for line-ending normalization — a separate class of phantom diffs that can occur with other file types:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code># .gitattributes — normalize line endings for cross-platform sanity
*.sh text eol=lf
*.md text eol=lf
*.yml text eol=lf
*.json text eol=lf
*.py text eol=lf
*.html text eol=lf
*.svg text eol=lf
*.png binary
*.jpg binary
*.pdf binary
</code></pre></div></div>

<p>This handles the case where a file is committed with LF but the 9P bridge serves it with CRLF (less common, but possible depending on mount options).</p>

<h2 id="known-remaining-limitations">Known Remaining Limitations</h2>

<p>Even with these fixes, some quirks persist:</p>

<ul>
  <li><strong>The tool is still named <code class="language-plaintext highlighter-rouge">execute_pwsh</code></strong> — This is cosmetic but confusing in logs. The name doesn’t change the actual shell used.</li>
  <li><strong>File read/write tools use Windows UNC paths</strong> — Kiro’s file tools resolve paths as <code class="language-plaintext highlighter-rouge">\\wsl$\Ubuntu-24.04\...</code>. Shell commands must use native Linux paths. The agent needs to handle both.</li>
  <li><strong>The <code class="language-plaintext highlighter-rouge">cwd</code> parameter may still be unreliable</strong> — For git operations, using <code class="language-plaintext highlighter-rouge">git -C /path/to/repo</code> is more reliable than depending on the <code class="language-plaintext highlighter-rouge">cwd</code> parameter.</li>
  <li><strong>Exit code reporting</strong> — Even after fixes, the tool may still report non-zero exit codes for successful commands. This is a Kiro-side issue worth tracking.</li>
</ul>

<h2 id="filing-a-bug">Filing a Bug</h2>

<p>If you’re still experiencing issues after these changes, file a bug at the <a href="https://github.com/kirodotdev/kiro/issues">Kiro GitHub repository</a>. The <a href="https://github.com/kirodotdev/kiro/issues/17">tracking issue #17</a> covers WSL2 support broadly. For agent-specific shell execution problems, a separate issue may be warranted. Include:</p>

<ul>
  <li>Your OS (Windows 11 + WSL2 distribution and version)</li>
  <li>Kiro version (Help → About)</li>
  <li>Open Remote - WSL extension version (<code class="language-plaintext highlighter-rouge">jeanp413.open-remote-wsl</code>)</li>
  <li>The terminal settings from your <code class="language-plaintext highlighter-rouge">settings.json</code></li>
  <li>Example of garbled output from the agent</li>
</ul>

<h2 id="summary">Summary</h2>

<p>The fix boils down to: <strong>explicitly declare Linux terminal profiles</strong> in Kiro’s settings and <strong>enable shell integration</strong> in your RC files. VS Code inferred this correctly; Kiro (as of mid-2026) needs the explicit configuration.</p>

<table>
  <thead>
    <tr>
      <th>Component</th>
      <th>File</th>
      <th>Change</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Terminal profiles</td>
      <td><code class="language-plaintext highlighter-rouge">%APPDATA%\Kiro\User\settings.json</code></td>
      <td>Add <code class="language-plaintext highlighter-rouge">automationProfile.linux</code> and <code class="language-plaintext highlighter-rouge">profiles.linux</code></td>
    </tr>
    <tr>
      <td>Shell integration (zsh)</td>
      <td><code class="language-plaintext highlighter-rouge">~/.zshrc</code></td>
      <td>Source Kiro integration when <code class="language-plaintext highlighter-rouge">TERM_PROGRAM == kiro</code></td>
    </tr>
    <tr>
      <td>Shell integration (bash)</td>
      <td><code class="language-plaintext highlighter-rouge">~/.bashrc</code></td>
      <td>Source Kiro integration when <code class="language-plaintext highlighter-rouge">TERM_PROGRAM == kiro</code></td>
    </tr>
    <tr>
      <td>Agent context</td>
      <td><code class="language-plaintext highlighter-rouge">~/.kiro/steering/shell-environment.md</code></td>
      <td>Tell agent it’s in Linux/zsh</td>
    </tr>
    <tr>
      <td>Phantom SCM diffs</td>
      <td>Each repo’s <code class="language-plaintext highlighter-rouge">.git/config</code></td>
      <td><code class="language-plaintext highlighter-rouge">core.fileMode=false</code> to suppress permission phantom diffs</td>
    </tr>
    <tr>
      <td>Line-ending normalization</td>
      <td><code class="language-plaintext highlighter-rouge">.gitattributes</code> (per-repo) or <code class="language-plaintext highlighter-rouge">~/.config/git/attributes</code> (global)</td>
      <td><code class="language-plaintext highlighter-rouge">eol=lf</code> declarations for text files</td>
    </tr>
  </tbody>
</table>

<p>Once configured, Kiro’s agent can reliably execute shell commands in your WSL2 environment — making the agentic coding experience actually functional for Linux-first developers on Windows hardware.</p>

<h2 id="related">Related</h2>

<ul>
  <li><a href="/kiro-ide-wsl2-support-open-remote-extension/">Kiro IDE on Windows: WSL2 Support via Open Remote Extension</a> — The prerequisite setup: installing <code class="language-plaintext highlighter-rouge">jeanp413.open-remote-wsl</code>, the <code class="language-plaintext highlighter-rouge">argv.json</code> requirement, the update breakage cycle, and recovery procedures.</li>
  <li><a href="https://open-vsx.org/extension/jeanp413/open-remote-wsl">Open Remote - WSL on Open VSX</a></li>
  <li><a href="https://github.com/jeanp413/open-remote-wsl">jeanp413/open-remote-wsl on GitHub</a></li>
  <li><a href="https://github.com/kirodotdev/kiro/issues/17">Kiro GitHub Issue #17</a> — WSL support tracking issue</li>
  <li><a href="https://kiro.dev/docs/">Kiro IDE Documentation</a></li>
</ul>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="development" /><category term="tools" /><category term="kiro" /><category term="wsl2" /><category term="ubuntu" /><category term="ide" /><category term="ai-coding" /><category term="zsh" /><category term="shell-integration" /><category term="open-remote-wsl" /><summary type="html"><![CDATA[A practical guide to fixing Kiro IDE's agent shell execution in WSL2 — adding Linux terminal profiles, shell integration scripts, and steering context for reliable AI agent interactions on Ubuntu 24.04.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/kiro-ide-wsl2-integration.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/kiro-ide-wsl2-integration.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Jellyfin Media Integrity Scanner: v0.1.1 Release — Update Checker and Auto-Update</title><link href="https://mcgarrah.org/jellyfin-media-integrity-release-and-updates/" rel="alternate" type="text/html" title="Jellyfin Media Integrity Scanner: v0.1.1 Release — Update Checker and Auto-Update" /><published>2026-08-19T00:00:00+00:00</published><updated>2026-08-19T00:00:00+00:00</updated><id>https://mcgarrah.org/jellyfin-media-integrity-release-and-updates</id><content type="html" xml:base="https://mcgarrah.org/jellyfin-media-integrity-release-and-updates/"><![CDATA[<p>The first five articles in this series documented the development path from problem statement through operational deployment of the Media Integrity Scanner plugin. By the end of that arc (2026-07-31), the plugin was functionally complete — two-phase scanning, SQLite persistence, REST API, dashboard, and event-driven library monitoring all shipping and tested.</p>

<p>But “functionally complete” and “production-ready” are different things. Between v0.1.0 and the v0.1.1 stable release (2026-08-02), the plugin gained automatic update checking, session-aware restart logic, comprehensive end-to-end testing, and critical packaging fixes. This article covers what changed and why.</p>

<!-- excerpt-end -->

<p>No plan survives contact with real data. The first five articles designed a scanner, a dashboard, and a release pipeline that all looked correct on paper — and every one of them still had a gap that only showed up once something real got involved: a real installed release instead of five hand-copied DLLs, a real dashboard response parsed by real browser JavaScript, a real Jellyfin server that has no idea whether anyone’s mid-episode when a restart gets triggered. This article is that reckoning, not a sixth increment of new features.</p>

<h2 id="the-v010--v011-journey">The v0.1.0 → v0.1.1 Journey</h2>

<p>The path from the initial v0.1.0 release to v0.1.1 stable involved:</p>

<ol>
  <li><strong>Development channel releases</strong> — Three pre-releases (v0.1.0-dev.1 through dev.4) to test fixes before marking them stable</li>
  <li><strong>Critical packaging bugs</strong> — Discovered and fixed two issues that broke cross-platform installation</li>
  <li><strong>Testing infrastructure</strong> — Added Playwright E2E suite and media corruption matrix to validate real-world behavior</li>
  <li><strong>Update mechanism</strong> — Implemented automatic update checking with smart restart logic to prevent scan interruption</li>
  <li><strong>Documentation</strong> — Created ARCHITECTURE.md with event-flow diagrams, complementing the blog series</li>
</ol>

<p>This article is Part 6 of the <a href="/jellyfin-media-integrity-scanner-introduction/">Jellyfin Media Integrity Scanner</a> development series. Unlike the previous five parts, it’s not required reading before deploying v0.1.0 — those articles describe a complete, working plugin. This is a “what came next” article for users interested in how production release engineering shaped the project after initial functionality shipped.</p>

<h2 id="feature-1-update-checker-with-stabledevelopment-channels">Feature 1: Update Checker with Stable/Development Channels</h2>

<p>Users installing the plugin via <code class="language-plaintext highlighter-rouge">manifest.json</code> could see updates listed in Jellyfin’s own Plugins → Catalog page, but nothing surfaced that from <em>inside</em> the plugin — no dashboard banner, no way to trigger an install without going through Jellyfin’s generic catalog UI. The natural fix leans on machinery Jellyfin already has rather than reinventing it: <code class="language-plaintext highlighter-rouge">IInstallationManager</code>, the same DI-registered service the Catalog page itself uses to list and install plugin versions.</p>

<p>That interface only ever returns versions from plugin repositories an admin has <strong>already registered</strong> under Dashboard → Plugins → Repositories — a plugin has no way to discover its own updates from a manifest Jellyfin doesn’t know about, and this plugin deliberately doesn’t register one on the admin’s behalf, since that’s global server config, not this plugin’s own. Registering <code class="language-plaintext highlighter-rouge">manifest.json</code> (stable) and, optionally, <code class="language-plaintext highlighter-rouge">manifest-unstable.json</code> (development) is a one-time, explicit setup step, documented on the settings page rather than done silently.</p>

<pre><code class="language-mermaid">%%{init: {"theme": "base", "themeVariables": {
  "primaryColor": "#17221f",
  "primaryTextColor": "#e7ede9",
  "primaryBorderColor": "#3e6e67",
  "lineColor": "#7c93a3",
  "secondaryColor": "#1d2b27",
  "tertiaryColor": "#101a18",
  "fontFamily": "monospace",
  "fontSize": "14px"
}}}%%
flowchart TD
    subgraph DAILY["CheckForUpdatesTask — daily, 04:00"]
        A["RefreshAsync"]:::act --&gt; B["IInstallationManager&lt;br/&gt;.GetAvailablePackages"]:::act
        B --&gt; C{"classify each version&lt;br/&gt;by RepositoryUrl"}:::gate
        C --&gt;|"manifest.json"| D["Stable"]:::pipe
        C --&gt;|"manifest-unstable.json"| E["Development"]:::pipe
        D --&gt; F[("cached UpdateStatus")]:::db
        E --&gt; F
    end

    subgraph WEEKLY["AutoUpdateTask — weekly, Sunday 04:00"]
        G{"EnableAutoUpdate?"}:::gate
        G --&gt;|"no"| SKIP1["skip"]:::stop
        G --&gt;|"yes"| H{"update available for&lt;br/&gt;configured channel?"}:::gate
        H --&gt;|"no"| SKIP2["skip"]:::stop
        H --&gt;|"yes"| I["InstallPackage via&lt;br/&gt;IInstallationManager"]:::act
        I --&gt; J{"AutoRestartAfterUpdate?"}:::gate
        J --&gt;|"no"| STAGED["leave staged,&lt;br/&gt;admin restarts manually"]:::pipe
        J --&gt;|"yes"| K["wait for zero active&lt;br/&gt;playback sessions"]:::wait
        K --&gt; L["ISystemManager.Restart()"]:::pipe
    end

    F -.-&gt;|"read by"| H

    classDef gate fill:#2a2013,stroke:#e3a857,color:#f4d9a8
    classDef wait fill:#2a2013,stroke:#e3a857,color:#f4d9a8,stroke-dasharray: 3 3
    classDef act fill:#16332c,stroke:#5fa88f,color:#cfefe2
    classDef db fill:#17221f,stroke:#7c93a3,color:#e7ede9
    classDef pipe fill:#101a18,stroke:#e3a857,color:#e3a857,stroke-width:2px
    classDef stop fill:#331c1a,stroke:#d96c5d,color:#f3c8c2
</code></pre>

<p><code class="language-plaintext highlighter-rouge">UpdateStatus</code> — the cached object both tasks and the dashboard read — tracks <code class="language-plaintext highlighter-rouge">CurrentVersion</code>, <code class="language-plaintext highlighter-rouge">LatestStableVersion</code>, <code class="language-plaintext highlighter-rouge">LatestDevVersion</code>, <code class="language-plaintext highlighter-rouge">UpdateAvailable</code>, <code class="language-plaintext highlighter-rouge">AvailableVersion</code>, and which <code class="language-plaintext highlighter-rouge">Channel</code> it was computed against. Splitting the check (daily, cheap, read-only) from the install-and-maybe-restart step (weekly, and off by default) means opening the dashboard never triggers a live network call or an unexpected install — it just reads whatever the last scheduled check found.</p>

<h3 id="channel-selection">Channel Selection</h3>

<p>Since a single registered repository can list many versions and Jellyfin has no first-class idea of “channels,” this plugin publishes two separate manifests and classifies each <code class="language-plaintext highlighter-rouge">VersionInfo</code> Jellyfin returns by which registered repository URL it came from — not by a repository’s free-text display name, which an admin could label anything:</p>

<table>
  <thead>
    <tr>
      <th>Setting</th>
      <th>Default</th>
      <th>Effect</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">UpdateChannel</code></td>
      <td><code class="language-plaintext highlighter-rouge">Stable</code></td>
      <td><code class="language-plaintext highlighter-rouge">Stable</code> or <code class="language-plaintext highlighter-rouge">Development</code> — which channel counts as “available”</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">StableManifestUrl</code></td>
      <td>this repo’s <code class="language-plaintext highlighter-rouge">manifest.json</code></td>
      <td>Advanced override; rarely touched</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">DevManifestUrl</code></td>
      <td>this repo’s <code class="language-plaintext highlighter-rouge">manifest-unstable.json</code></td>
      <td>Advanced override; rarely touched</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">EnableAutoUpdate</code></td>
      <td><code class="language-plaintext highlighter-rouge">false</code></td>
      <td>Weekly task installs (stages) a newer version automatically</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">AutoRestartAfterUpdate</code></td>
      <td><code class="language-plaintext highlighter-rouge">false</code></td>
      <td>After an automatic install, also restart once nobody’s watching</td>
    </tr>
  </tbody>
</table>

<p>All four update-related settings default to off — a conservative install only ever sees update notifications and clicks “Update Now” on the dashboard by hand. <code class="language-plaintext highlighter-rouge">EnableAutoUpdate</code> and <code class="language-plaintext highlighter-rouge">AutoRestartAfterUpdate</code> are deliberately separate toggles: the first lets the plugin stage a newer version without touching the running process at all, the second is what actually restarts Jellyfin to load it, covered next.</p>

<p>Full source: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/Updates/UpdateChecker.cs"><code class="language-plaintext highlighter-rouge">Updates/UpdateChecker.cs</code></a>, <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/ScheduledTasks/CheckForUpdatesTask.cs"><code class="language-plaintext highlighter-rouge">ScheduledTasks/CheckForUpdatesTask.cs</code></a>.</p>

<h2 id="feature-2-session-aware-auto-restart">Feature 2: Session-Aware Auto-Restart</h2>

<p>Automatic updates are only useful if they actually apply, but blindly restarting Jellyfin the moment a new version installs is a terrible user experience: an in-progress scan gets cut off mid-file, and anyone mid-episode loses playback outright. <code class="language-plaintext highlighter-rouge">AutoUpdateTask</code> — the same weekly task that performs the install — handles this by refusing to restart until it’s actually safe:</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="k">async</span> <span class="n">Task</span> <span class="nf">ExecuteAsync</span><span class="p">(</span><span class="n">IProgress</span><span class="p">&lt;</span><span class="kt">double</span><span class="p">&gt;</span> <span class="n">progress</span><span class="p">,</span> <span class="n">CancellationToken</span> <span class="n">cancellationToken</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(!</span><span class="n">config</span><span class="p">.</span><span class="n">EnableAutoUpdate</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span>

    <span class="kt">var</span> <span class="n">status</span> <span class="p">=</span> <span class="k">await</span> <span class="n">_updateChecker</span><span class="p">.</span><span class="nf">RefreshAsync</span><span class="p">(</span><span class="n">cancellationToken</span><span class="p">);</span>
    <span class="k">if</span> <span class="p">(!</span><span class="n">status</span><span class="p">.</span><span class="n">UpdateAvailable</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span>

    <span class="k">await</span> <span class="n">_updateChecker</span><span class="p">.</span><span class="nf">InstallAsync</span><span class="p">(</span><span class="n">status</span><span class="p">.</span><span class="n">Channel</span><span class="p">,</span> <span class="n">cancellationToken</span><span class="p">);</span>

    <span class="k">if</span> <span class="p">(</span><span class="n">config</span><span class="p">.</span><span class="n">AutoRestartAfterUpdate</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">await</span> <span class="nf">WaitForNoActivePlaybackAsync</span><span class="p">(</span><span class="n">cancellationToken</span><span class="p">);</span>
        <span class="n">_systemManager</span><span class="p">.</span><span class="nf">Restart</span><span class="p">();</span>
    <span class="p">}</span>
<span class="p">}</span>

<span class="k">private</span> <span class="k">async</span> <span class="n">Task</span> <span class="nf">WaitForNoActivePlaybackAsync</span><span class="p">(</span><span class="n">CancellationToken</span> <span class="n">cancellationToken</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">while</span> <span class="p">(</span><span class="n">_sessions</span><span class="p">.</span><span class="n">Sessions</span><span class="p">.</span><span class="nf">Any</span><span class="p">(</span><span class="n">s</span> <span class="p">=&gt;</span> <span class="n">s</span><span class="p">.</span><span class="n">NowPlayingItem</span> <span class="p">!=</span> <span class="k">null</span><span class="p">)</span> <span class="p">&amp;&amp;</span> <span class="p">!</span><span class="n">cancellationToken</span><span class="p">.</span><span class="n">IsCancellationRequested</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">await</span> <span class="n">Task</span><span class="p">.</span><span class="nf">Delay</span><span class="p">(</span><span class="n">TimeSpan</span><span class="p">.</span><span class="nf">FromSeconds</span><span class="p">(</span><span class="m">30</span><span class="p">),</span> <span class="n">cancellationToken</span><span class="p">);</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Notice what’s <em>not</em> there: no forced restart after some maximum wait. That was a deliberate call, not an oversight — <code class="language-plaintext highlighter-rouge">ISystemManager.Restart()</code> is a one-way door with no way to defer or cancel it once called (confirmed by decompiling Jellyfin’s own implementation rather than assuming), so there’s no safe way to “restart soon anyway” without risking the exact scenario this feature exists to prevent. If playback never stops, the update simply stays installed-but-not-loaded until an admin restarts manually — which is also exactly why <code class="language-plaintext highlighter-rouge">EnableAutoUpdate</code> and <code class="language-plaintext highlighter-rouge">AutoRestartAfterUpdate</code> are two separate settings: an install with no restart is a strictly safer default than an install that eventually forces one.</p>

<h3 id="what-triggers-a-restart">What Triggers a Restart</h3>

<p>Restarts only ever come from this one path:</p>

<ul>
  <li><code class="language-plaintext highlighter-rouge">EnableAutoUpdate</code> is on, a newer version exists for the configured channel, <strong>and</strong> <code class="language-plaintext highlighter-rouge">AutoRestartAfterUpdate</code> is also on.</li>
</ul>

<p>Scanning, API requests, and dashboard access never trigger a restart under any circumstances — and the wait loop above re-checks playback every 30 seconds indefinitely, so a scan or a movie that’s still running an hour after the update installed simply delays the restart by that same hour.</p>

<p>Full source: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/ScheduledTasks/AutoUpdateTask.cs"><code class="language-plaintext highlighter-rouge">ScheduledTasks/AutoUpdateTask.cs</code></a>.</p>

<h2 id="critical-fixes-packaging-and-cross-platform-support">Critical Fixes: Packaging and Cross-Platform Support</h2>

<p>Two packaging bugs surfaced during testing and needed to be fixed before calling the release stable.</p>

<h3 id="issue-1-shipping-redundant-assemblies">Issue 1: Shipping Redundant Assemblies</h3>

<p>The initial plugin package included:</p>

<ul>
  <li>Every Jellyfin assembly (even though the host already provides them)</li>
  <li>Platform-specific native SQLite libraries for Windows, Linux, and macOS (all bundled together)</li>
</ul>

<p>This bloated the plugin zip to ~40MB, most of it unused. Windows installs included Linux binaries and vice versa. Worse, the duplicate Jellyfin assemblies sometimes shadowed the host versions, causing unpredictable binding-redirect behavior.</p>

<p><strong>Fix (PR #29):</strong> Removed all redundant assemblies and platform-specific natives from the package. The plugin now:</p>

<ul>
  <li>Declares Jellyfin assemblies as <code class="language-plaintext highlighter-rouge">&lt;FrameworkReference&gt;</code> (the server provides them)</li>
  <li>Declares <code class="language-plaintext highlighter-rouge">Microsoft.Data.Sqlite</code> as a NuGet dependency (the runtime installs the right native library for the target platform)</li>
  <li>Publishes only the plugin’s own code and essential cross-platform dependencies</li>
</ul>

<p><strong>Result:</strong> Package size dropped from ~40MB to ~3MB. Installation is faster, and cross-platform conflicts disappeared.</p>

<h3 id="issue-2-assembly-whitelist-for-cross-platform-loading">Issue 2: Assembly Whitelist for Cross-Platform Loading</h3>

<p>Trimming the package down to just <code class="language-plaintext highlighter-rouge">linux-x64</code>’s native SQLite binary (Issue 1’s fix) stopped the install crash, but it meant Windows, macOS, and every other Linux architecture would have shipped with no working native SQLite library at all. Restoring real cross-platform support meant bundling <em>every</em> server platform’s native binary back in — which reintroduced the original crash, just for a different set of files.</p>

<p>The actual mechanism, found by decompiling Jellyfin’s own <code class="language-plaintext highlighter-rouge">PluginManager</code> (<code class="language-plaintext highlighter-rouge">Emby.Server.Implementations.dll</code>, pulled from a real 10.11.11 server image) rather than guessing: a plugin can ship its own <code class="language-plaintext highlighter-rouge">meta.json</code> with a populated <code class="language-plaintext highlighter-rouge">assemblies</code> list, and Jellyfin uses <strong>only that whitelist</strong> to decide what to load as a managed .NET assembly — instead of its default fallback of recursively loading every <code class="language-plaintext highlighter-rouge">.dll</code> under the plugin folder, which is what choked on a bundled native binary that merely <em>looked</em> like a managed assembly by extension.</p>

<p><strong>Fix (PR #30):</strong> a flat <code class="language-plaintext highlighter-rouge">assemblies</code> whitelist in the plugin’s own bundled <code class="language-plaintext highlighter-rouge">meta.json</code> (not the repository-level <code class="language-plaintext highlighter-rouge">manifest.json</code> used earlier in this article — a different file, at a different layer):</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"guid"</span><span class="p">:</span><span class="w"> </span><span class="s2">"c8f4a3b2-1d5e-4f6a-9b7c-2e8d0f1a3b5c"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"assemblies"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
    </span><span class="s2">"Jellyfin.Plugin.MediaIntegrityScanner.dll"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"Microsoft.Data.Sqlite.dll"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"SQLitePCLRaw.batteries_v2.dll"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"SQLitePCLRaw.core.dll"</span><span class="p">,</span><span class="w">
    </span><span class="s2">"SQLitePCLRaw.provider.e_sqlite3.dll"</span><span class="w">
  </span><span class="p">]</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>With the whitelist in place, native runtime binaries for every platform (win-x64/arm64, linux-x64/arm/arm64/musl variants, osx-x64/arm64) never reach Jellyfin’s assembly loader at all, regardless of filename — so the package can safely bundle all of them in one universal zip. Verified against a real demo instance: staged a build containing every platform’s native binary (including the exact <code class="language-plaintext highlighter-rouge">win-x64</code> DLL that crashed the previous attempt) and confirmed via the server’s own logs that it loaded only the five whitelisted managed assemblies and never touched a native runtime file.</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/meta.json"><code class="language-plaintext highlighter-rouge">meta.json</code></a>.</p>

<h2 id="testing-infrastructure-playwright-e2e-and-corruption-matrix">Testing Infrastructure: Playwright E2E and Corruption Matrix</h2>

<p>Between commits, two major testing initiatives shipped to reduce post-release surprises.</p>

<h3 id="playwright-end-to-end-testing-pr-24">Playwright End-to-End Testing (PR #24)</h3>

<p>The unit test suite (141 tests) covers the core logic: scan engine decisions, database queries, API responses, concurrency safety. But unit tests can’t catch everything — particularly UI integration bugs and Jellyfin API version mismatches.</p>

<p>The plugin now includes a <strong>Playwright E2E test suite</strong> that:</p>

<ol>
  <li>Launches a real Jellyfin instance in Docker</li>
  <li>Automates a real web browser (headless Chrome)</li>
  <li>Logs in as admin</li>
  <li>Navigates to the plugin dashboard</li>
  <li>Triggers a scan</li>
  <li>Verifies results appear in the dashboard</li>
  <li>Edits settings</li>
  <li>Confirms the UI reflects the changes</li>
</ol>

<p>This caught a real bug that slipped past unit tests: the dashboard JSON response was using wrong casing for some fields, causing the UI JavaScript to fail silently. The E2E suite caught it immediately by actually rendering the page.</p>

<h3 id="media-corruption-test-matrix-pr-23">Media Corruption Test Matrix (PR #23)</h3>

<p>The plugin’s core value is detecting corrupt media files. But how do you verify the detection logic works? You need actual corrupt files to scan.</p>

<p>The project now includes a <strong>test fixture generator</strong> that creates good and bad video files:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Good files (valid containers, playable streams)</span>
ffmpeg <span class="nt">-f</span> lavfi <span class="nt">-i</span> <span class="nv">testsrc</span><span class="o">=</span><span class="nv">size</span><span class="o">=</span>320x240:duration<span class="o">=</span>1 <span class="nt">-f</span> lavfi <span class="nt">-i</span> <span class="nv">sine</span><span class="o">=</span><span class="nv">f</span><span class="o">=</span>1000:d<span class="o">=</span>1 good_video.mp4
ffmpeg <span class="nt">-f</span> lavfi <span class="nt">-i</span> <span class="nv">testsrc</span><span class="o">=</span><span class="nv">size</span><span class="o">=</span>320x240:duration<span class="o">=</span>1 good_video.mkv

<span class="c"># Bad files (truncated, corrupt headers, invalid codecs)</span>
<span class="nb">truncate</span> <span class="nt">-s</span> 1M good_video.mp4        <span class="c"># Truncated file</span>
<span class="nb">dd </span><span class="k">if</span><span class="o">=</span>/dev/zero <span class="nv">of</span><span class="o">=</span>corrupt.mp4 <span class="nv">bs</span><span class="o">=</span>1 <span class="nv">count</span><span class="o">=</span>1024 <span class="nv">seek</span><span class="o">=</span>65536 <span class="nv">conv</span><span class="o">=</span>notrunc  <span class="c"># Corrupt middle</span>
<span class="nb">dd </span><span class="k">if</span><span class="o">=</span>/dev/urandom <span class="nv">of</span><span class="o">=</span>badheader.mp4 <span class="nv">bs</span><span class="o">=</span>1 <span class="nv">count</span><span class="o">=</span>100  <span class="c"># Corrupt header</span>
</code></pre></div></div>

<p>The matrix validates that:</p>
<ul>
  <li><strong>Phase 1 (ffprobe)</strong> catches truncated files, corrupt containers, invalid codecs</li>
  <li><strong>Phase 2 (ffmpeg decode)</strong> catches mid-file corruption and encoding errors</li>
  <li><strong>False positives</strong> don’t occur on actually valid files</li>
</ul>

<p>This gives confidence that the plugin’s detection logic matches what real ffmpeg does, not what the developer <em>thinks</em> ffmpeg does.</p>

<h2 id="documentation-architecturemd">Documentation: ARCHITECTURE.md</h2>

<p>The first five articles in this series cover the design, but operators and developers need to understand <strong>every single code path</strong> that can trigger a scan — Jellyfin events, scheduled tasks, manual API calls. A single diagram that shows all of these helps immensely.</p>

<p><a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/ARCHITECTURE.md">ARCHITECTURE.md</a> includes:</p>

<ol>
  <li><strong>Event-flow diagram</strong> — Every Jellyfin event that feeds into the scan engine:
    <ul>
      <li>Library item added/removed</li>
      <li>Scheduled tasks (header scan, deep scan)</li>
      <li>REST API calls (manual triggers)</li>
      <li>Settings changes that affect throttling</li>
    </ul>
  </li>
  <li><strong>Gate pipeline diagram</strong> — Every decision the scan engine makes before actually starting a scan:
    <ul>
      <li>Is it quiet hours? Stop.</li>
      <li>Is playback active? Pause.</li>
      <li>Are we at concurrency limit? Queue.</li>
      <li>Does Phase 1 pass? Skip Phase 2 (unless configured otherwise).</li>
    </ul>
  </li>
  <li><strong>Two worked scenarios</strong>:
    <ul>
      <li>Scenario 1: User adds a new file to the library while deep scan is running</li>
      <li>Scenario 2: User manually triggers a deep scan from the dashboard during active playback</li>
    </ul>
  </li>
</ol>

<p>These diagrams live in the repository, not in the blog series, because they update as the code evolves. The blog articles describe <em>why</em> the design works; ARCHITECTURE.md documents <em>how</em> it works in real code.</p>

<h2 id="the-release-checklist">The Release Checklist</h2>

<p>Getting from v0.1.0-dev to v0.1.1 stable required a formal checklist:</p>

<ul>
  <li>✅ Unit tests passing (141 tests)</li>
  <li>✅ Integration tests passing (Docker + real Jellyfin instance)</li>
  <li>✅ E2E tests passing (Playwright browser automation)</li>
  <li>✅ Media corruption matrix validated</li>
  <li>✅ Cross-platform packaging verified (Windows, Linux, macOS)</li>
  <li>✅ Update checker tested and working</li>
  <li>✅ Session-aware restart logic verified</li>
  <li>✅ Documentation complete (README.md, ARCHITECTURE.md, INSTALL.md, RELEASE.md)</li>
  <li>✅ GitHub releases API workflow automated (manifest.json version bumps on tagged release)</li>
  <li>✅ Both stable and development channel builds working</li>
</ul>

<p>The development channel (<code class="language-plaintext highlighter-rouge">v0.1.0-dev.1</code> through <code class="language-plaintext highlighter-rouge">dev.4</code>) provided a staging ground for the fixes. Each dev release was a stepping stone toward stability.</p>

<h2 id="for-users-what-changed">For Users: What Changed</h2>

<p>If you’re running v0.1.0 and upgrading to v0.1.1:</p>

<ol>
  <li><strong>Installation is easier</strong> — Package is 13x smaller (3MB vs 40MB)</li>
  <li><strong>Cross-platform works now</strong> — If you’re on Windows or macOS, the plugin now works reliably</li>
  <li><strong>Auto-update is optional</strong> — Disabled by default. Enable in <strong>Dashboard → Plugins → Media Integrity Scanner → Settings</strong> if you want automatic updates</li>
  <li><strong>Scans never interrupted by restarts</strong> — Even if you enable auto-update, restarts wait for idle periods</li>
  <li><strong>Everything else is the same</strong> — The scanning logic, throttling, database schema, and API are unchanged</li>
</ol>

<p>No action required. The upgrade is transparent.</p>

<h2 id="for-developers-what-matters">For Developers: What Matters</h2>

<p>If you’re using this plugin as a reference for Jellyfin plugin development:</p>

<ol>
  <li><strong>Platform-specific artifacts belong in manifest.json, not the package</strong> — Declare them and let the plugin loader sort out what to install where</li>
  <li><strong>Update checking is worth doing</strong> — GitHub releases API is free and reliable. Users expect to see “Update available” notifications</li>
  <li><strong>Session awareness prevents disasters</strong> — Check playback sessions and scan state before auto-restarting</li>
  <li><strong>E2E testing catches what unit tests miss</strong> — Browser automation finds UI bugs, casing bugs, and integration mismatches</li>
  <li><strong>Test fixture generation validates detection logic</strong> — Create the edge cases you’re trying to detect</li>
  <li><strong>Architectural diagrams live in code, not blog articles</strong> — Blog articles explain <em>why</em>; diagrams document <em>what</em></li>
</ol>

<h2 id="series-recap">Series Recap</h2>

<p>The six-part series now covers:</p>

<table>
  <thead>
    <tr>
      <th>#</th>
      <th>Article</th>
      <th>Focus</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>1</td>
      <td><a href="/jellyfin-media-integrity-scanner-introduction/">Introduction</a></td>
      <td>Problem statement, project scope, architecture overview</td>
    </tr>
    <tr>
      <td>2</td>
      <td><a href="/jellyfin-media-integrity-architecture-design/">Architecture &amp; Design Decisions</a></td>
      <td>Plugin vs. script, two-phase scanning, I/O throttling, SQLite</td>
    </tr>
    <tr>
      <td>3</td>
      <td><a href="/jellyfin-media-integrity-scanner-core/">Building the Scanner Core</a></td>
      <td>FFmpeg integration, plugin structure, scan engine</td>
    </tr>
    <tr>
      <td>4</td>
      <td><a href="/jellyfin-media-integrity-dashboard-api/">The Dashboard &amp; API</a></td>
      <td>Admin UI, REST API, real-time status</td>
    </tr>
    <tr>
      <td>5</td>
      <td><a href="/jellyfin-media-integrity-deployment-operations/">Deployment &amp; Operations</a></td>
      <td>Proxmox/CephFS setup, monitoring, CI/CD pipeline</td>
    </tr>
    <tr>
      <td>6</td>
      <td><strong>v0.1.1 Release</strong> (this post)</td>
      <td>Update checker, auto-update, testing, packaging</td>
    </tr>
  </tbody>
</table>

<p>Together, these articles document a complete development and release cycle: from identifying a problem, designing a solution, implementing it, shipping it, and then hardening it for production use based on real-world feedback.</p>

<h2 id="future-work">Future Work</h2>

<p>The plugin is stable and production-ready, but v0.1.1 is the end of the <em>development series</em>, not the end of the plugin’s evolution. Some of these are old ideas that never got past a bullet point; others came out of specifically sitting down and asking hard questions about parts of the design that had started to feel too convenient to be true. None of it is scheduled — this is the honest state of “things worth doing,” not a roadmap with dates.</p>

<h3 id="operational-improvements">Operational improvements</h3>

<ul>
  <li><strong>A CLI mode.</strong> Right now every interaction goes through the dashboard or the REST API — there’s no way to, say, initialize the database or kick off a scan from a script after a fresh install. The catch: a Jellyfin plugin has no <code class="language-plaintext highlighter-rouge">Main()</code> and depends entirely on Jellyfin’s own DI container, so this only works cleanly if it turns out to mean “a thin CLI wrapper over the existing API,” not “run the plugin binary standalone.”</li>
  <li><strong>Database size and maintenance visibility.</strong> The SQLite cache has no size reporting and no exposed way to <code class="language-plaintext highlighter-rouge">VACUUM</code> or run an integrity check — currently that’s a manual <code class="language-plaintext highlighter-rouge">sqlite3</code> shell session. A dashboard stat plus a manual “run maintenance now” button would close that gap, assuming <code class="language-plaintext highlighter-rouge">VACUUM</code> really is safe to run against the live WAL-mode database without stopping Jellyfin, which needs confirming for real rather than assumed from documentation.</li>
  <li><strong>Prometheus metrics export</strong> — a native <code class="language-plaintext highlighter-rouge">/metrics</code> endpoint instead of the polling script from the <a href="/jellyfin-media-integrity-deployment-operations/#monitoring--alerting">deployment article</a>.</li>
  <li><strong>Scan result export</strong> (CSV, for analysis or archival) and <strong>bulk rescan operations</strong> (scan everything matching a media type, library, or date range).</li>
  <li><strong>Storage-level integrations</strong> — alerts when CephFS/RAID health itself degrades, not just when a file fails a scan.</li>
  <li><strong>Webhook notifications</strong> to Discord/Slack/ntfy on failures, and <strong>repair automation</strong> that attempts an <code class="language-plaintext highlighter-rouge">ffmpeg -c copy</code> remux on the subset of failures that kind of fix can actually help.</li>
</ul>

<h3 id="under-the-hood">Under the hood</h3>

<ul>
  <li><strong>The throttling model is more naive than it looks.</strong> <code class="language-plaintext highlighter-rouge">MaxConcurrentScans</code> is a flat, manually-set number with no relationship to the host’s actual CPU count, and <code class="language-plaintext highlighter-rouge">MaxReadRateMbPerSec</code> is enforced <em>per file</em>, not system-wide — run more concurrent scans and the real aggregate read rate off storage can exceed the configured cap by a multiple of however many scans are running at once. Worth a real redesign: a vCPU-aware default for concurrency, and a shared rate limiter every scan draws from instead of each one pacing itself in isolation.</li>
  <li><strong>The scan-results database is add-and-remove, but only while something’s listening.</strong> A removed library item does get purged — confirmed by reading the real code, not assumed — but only if the plugin happens to be running at the exact moment Jellyfin reports the removal. There’s no periodic reconciliation pass that catches whatever that missed. Jellyfin’s own <code class="language-plaintext highlighter-rouge">ILibraryManager.GetItemIds()</code> is exactly the primitive a “diff the database against what’s actually in the library” task would need; nothing’s built against it yet.</li>
  <li><strong>A per-library throttle profile and a scan-priority queue</strong> (recently-added files first) — both straightforward extensions of the existing throttling model, just not built.</li>
  <li><strong>Live-reload of Jellyfin’s own ffmpeg path.</strong> The resolver already checks Jellyfin’s global transcoding ffmpeg override, which is nice — but it’s only read once, at plugin startup, and cached from then on. Change that setting in Jellyfin’s own dashboard later and this plugin won’t notice until a restart.</li>
</ul>

<h3 id="testing-and-platform-coverage">Testing and platform coverage</h3>

<ul>
  <li><strong>Every CI check runs on Linux only.</strong> The unit tests, integration suite, and Playwright suite all execute on <code class="language-plaintext highlighter-rouge">ubuntu-latest</code> — nothing runs on Windows or macOS, despite the plugin explicitly shipping and claiming support for both. One test file even says so directly in a code comment: the Windows/macOS branches of the ffmpeg path resolver “are not covered.” Real proof of cross-platform support means actually running somewhere other than Linux, not just packaging correctly for it.</li>
</ul>

<h3 id="an-idea-that-hit-a-real-wall">An idea that hit a real wall</h3>

<p>The one genuinely appealing idea that turned out not to be buildable, at least not yet: using Jellyfin’s own playback-failure signal to trigger an immediate follow-up scan on whatever file a client just reported trouble with, instead of waiting for the next scheduled sweep. Jellyfin’s client-facing API <em>does</em> carry a <code class="language-plaintext highlighter-rouge">Failed</code> flag when a session stops — but reading the real, decompiled <code class="language-plaintext highlighter-rouge">SessionManager</code> source shows that flag gets read internally to decide whether to update watch state, and is never copied onto the event a plugin actually receives. A playback that failed and a playback someone simply stopped early look identical from the one hook a plugin can subscribe to. This isn’t a plugin design problem to solve — it’s a gap in what Jellyfin exposes, and the honest next step is raising it upstream rather than working around something that isn’t there.</p>

<hr />

<p><strong>Related Articles:</strong></p>
<ul>
  <li><a href="/managing-cross-ai-agent-context/">Managing Context and Rules Across Multiple AI Coding Assistants</a> — Bonus: how this plugin was built</li>
  <li><a href="/ai-coding-agent-context-files-reference/">AI Coding Agent Context Files: A Reference Guide</a> — The methodology behind coordinating multiple AI agents on the project</li>
  <li><a href="/ai-agent-context-files-in-practice/">AI Agent Context Files in Practice: One Repo, Five Agents</a> — The same plugin as a case study in cross-agent collaboration</li>
</ul>

<p><strong>Project Links:</strong></p>
<ul>
  <li><a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner">Repository</a></li>
  <li><a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/ARCHITECTURE.md">ARCHITECTURE.md</a> — Event-flow and gate-pipeline diagrams</li>
  <li><a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/releases">Releases</a> — Stable and development channel</li>
</ul>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="homelab" /><category term="media-server" /><category term="jellyfin" /><category term="media-integrity" /><category term="release-management" /><category term="auto-update" /><category term="testing" /><category term="plugin-development" /><category term="dotnet" /><summary type="html"><![CDATA[v0.1.1 release article for the Jellyfin Media Integrity Scanner. Covers update checker architecture, session-aware auto-restart, package bloat fixes, Playwright E2E testing, media corruption test matrix, and architectural documentation. Part 6 of a 6-part development series.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-release-and-updates.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-release-and-updates.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Jellyfin Media Integrity Scanner: Deployment &amp;amp; Operations</title><link href="https://mcgarrah.org/jellyfin-media-integrity-deployment-operations/" rel="alternate" type="text/html" title="Jellyfin Media Integrity Scanner: Deployment &amp;amp; Operations" /><published>2026-08-17T00:00:00+00:00</published><updated>2026-08-17T00:00:00+00:00</updated><id>https://mcgarrah.org/jellyfin-media-integrity-deployment-operations</id><content type="html" xml:base="https://mcgarrah.org/jellyfin-media-integrity-deployment-operations/"><![CDATA[<p>The plugin is built — scanner core, SQLite persistence, REST API, admin dashboard. Now it needs to run reliably in production without causing problems. This article covers the deployment story: installing the plugin, configuring it for shared storage, monitoring its operation, and automating the release pipeline.</p>

<!-- excerpt-end -->

<p>This is Part 5 of the <a href="/jellyfin-media-integrity-scanner-introduction/">Jellyfin Media Integrity Scanner</a> development series. The build pipeline, release pipeline, and Proxmox LXC provisioning described below are all live and operational, and <code class="language-plaintext highlighter-rouge">MaxReadRateMbPerSec</code> and the quiet-hours settings in the CephFS/NFS tuning tables are genuinely enforced (see <a href="#cephfs-specific-configuration">CephFS-Specific Configuration</a> for the mechanism). The CI/CD section reflects the real, current workflows — automated <code class="language-plaintext highlighter-rouge">manifest.json</code> version bumps on tagged releases, plus a unit test suite and a Docker-based integration suite gating every build (see <a href="#cicd-pipeline">CI/CD Pipeline</a> for what that testing found). There’s also a real in-app settings page now (see the <a href="/jellyfin-media-integrity-dashboard-api/#update-a-real-settings-page">dashboard article</a>), so the “Configure throttling settings” step in the <a href="#operational-runbook">Operational Runbook</a> no longer means hand-editing an XML file. CephFS OSD-level tuning and Prometheus/Grafana monitoring remain aspirational — see the <a href="/jellyfin-media-integrity-release-and-updates/#future-work">final article’s Future Work section</a> for where those stand.</p>

<h2 id="installation-methods">Installation Methods</h2>

<h3 id="method-1-plugin-repository-recommended">Method 1: Plugin Repository (Recommended)</h3>

<p>Add the custom repository to Jellyfin:</p>

<ol>
  <li><strong>Dashboard → Plugins → Repositories → Add</strong></li>
  <li><strong>Name:</strong> <code class="language-plaintext highlighter-rouge">mcgarrah-plugins</code></li>
  <li><strong>URL:</strong> <code class="language-plaintext highlighter-rouge">https://raw.githubusercontent.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/main/manifest.json</code></li>
  <li><strong>Save</strong> → Go to <strong>Catalog</strong> → Install <strong>Media Integrity Scanner</strong></li>
  <li><strong>Restart Jellyfin</strong></li>
</ol>

<p><strong>If the plugin doesn’t appear in the Catalog after adding the repository, this is almost always the web client, not the server.</strong> Hit exactly this standing up a second test instance: the repository saved correctly, the manifest was reachable (confirmed both from a browser and with <code class="language-plaintext highlighter-rouge">curl</code> from inside the container), and querying the server’s own <code class="language-plaintext highlighter-rouge">/Packages</code> API directly with an authenticated request showed the plugin present in the catalog data all along — correct GUID, correctly tagged with the repository name. The web UI was just holding a stale, cached view of the catalog fetched before the repository was added. A hard refresh of the Catalog page (Ctrl+Shift+R / Cmd+Shift+R, not a normal reload) resolved it immediately. If that doesn’t do it, a full logout/login or a private-browsing window rules out cached session state, and it’s worth checking the Catalog page’s category filter dropdown hasn’t been left on something other than “General” from a previous session.</p>

<h3 id="method-2-manual-dll-installation">Method 2: Manual DLL Installation</h3>

<p>For development or airgapped environments:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Download the latest release</span>
wget https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/releases/latest/download/media-integrity-scanner.zip

<span class="c"># Extract to plugin directory</span>
unzip media-integrity-scanner.zip <span class="nt">-d</span> <span class="se">\</span>
  /var/lib/jellyfin/plugins/MediaIntegrityScanner

<span class="c"># Restart Jellyfin</span>
systemctl restart jellyfin
</code></pre></div></div>

<h3 id="method-3-build-from-source">Method 3: Build from Source</h3>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>git clone https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner.git
<span class="nb">cd </span>jellyfin-plugin-media-integrity-scanner

dotnet build <span class="nt">--configuration</span> Release
dotnet publish <span class="nt">--configuration</span> Release <span class="nt">--output</span> ./publish

<span class="c"># Copy to plugins directory</span>
<span class="nb">cp</span> <span class="nt">-r</span> ./publish /var/lib/jellyfin/plugins/MediaIntegrityScanner

systemctl restart jellyfin
</code></pre></div></div>

<h2 id="proxmox-lxc-configuration">Proxmox LXC Configuration</h2>

<p>My Jellyfin runs in an unprivileged Proxmox LXC container. Key considerations:</p>

<h3 id="ffmpeg-availability">FFmpeg Availability</h3>

<p>The <code class="language-plaintext highlighter-rouge">jellyfin-ffmpeg</code> package bundles a compatible ffmpeg build:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Inside the LXC container</span>
apt <span class="nb">install </span>jellyfin-ffmpeg6

<span class="c"># Verify</span>
/usr/lib/jellyfin-ffmpeg/ffmpeg <span class="nt">-version</span>
</code></pre></div></div>

<p>The plugin auto-detects this path. No configuration needed.</p>

<h3 id="resource-limits">Resource Limits</h3>

<p>The LXC container should have adequate resources for background scanning:</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># /etc/pve/lxc/XXX.conf additions for scan workload
</span><span class="na">lxc.cgroup2.cpu.max:</span><span class="w"> </span><span class="na">200000</span><span class="w"> </span><span class="na">100000</span><span class="w">  </span><span class="c"># 2 cores max
</span><span class="na">lxc.cgroup2.memory.max:</span><span class="w"> </span><span class="na">4G</span><span class="w">
</span><span class="na">lxc.cgroup2.io.max:</span><span class="w"> </span><span class="na">/dev/sdX</span><span class="w"> </span><span class="py">rbps</span><span class="p">=</span><span class="s">10485760  # 10MB/s read limit</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">io.max</code> cgroup limit provides a hard ceiling on disk I/O at the container level, complementing the plugin’s application-level throttling.</p>

<h3 id="storage-mount">Storage Mount</h3>

<p>CephFS media storage mounted into the container:</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># /etc/pve/lxc/XXX.conf
</span><span class="na">mp0:</span><span class="w"> </span><span class="na">/mnt/cephfs/media,</span><span class="py">mp</span><span class="p">=</span><span class="s">/media,ro=0</span>
</code></pre></div></div>

<p>For integrity scanning, read-only access is sufficient. Consider mounting as read-only to prevent any accidental writes:</p>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="na">mp0:</span><span class="w"> </span><span class="na">/mnt/cephfs/media,</span><span class="py">mp</span><span class="p">=</span><span class="s">/media,ro=1</span>
</code></pre></div></div>

<h2 id="cephfs-specific-configuration">CephFS-Specific Configuration</h2>

<p>CephFS distributed storage requires careful throttling to avoid impacting other clients:</p>

<h3 id="recommended-plugin-settings-for-cephfs">Recommended Plugin Settings for CephFS</h3>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"MaxConcurrentScans"</span><span class="p">:</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w">
  </span><span class="nl">"DelayBetweenFilesMs"</span><span class="p">:</span><span class="w"> </span><span class="mi">10000</span><span class="p">,</span><span class="w">
  </span><span class="nl">"MaxReadRateMbPerSec"</span><span class="p">:</span><span class="w"> </span><span class="mi">5</span><span class="p">,</span><span class="w">
  </span><span class="nl">"PauseDuringPlayback"</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w">
  </span><span class="nl">"UseQuietHoursOnly"</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w">
  </span><span class="nl">"QuietHoursStart"</span><span class="p">:</span><span class="w"> </span><span class="s2">"01:00"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"QuietHoursEnd"</span><span class="p">:</span><span class="w"> </span><span class="s2">"07:00"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<h3 id="why-these-values">Why These Values</h3>

<ul>
  <li><strong>10-second inter-file delay</strong> — Allows CephFS OSD recovery between reads</li>
  <li><strong>5 MB/s read cap</strong> — Well below typical OSD throughput, leaves headroom for playback</li>
  <li><strong>Quiet hours only</strong> — Scanning happens when nobody is watching</li>
  <li><strong>Single file at a time</strong> — Prevents MDS metadata load spikes</li>
</ul>

<blockquote>
  <p><strong>Update (July 31, 2026) — how the read-rate cap and quiet hours actually work:</strong> For a while, <code class="language-plaintext highlighter-rouge">MaxReadRateMbPerSec</code> and the quiet-hours settings were config fields that did nothing — a gap found during a later review. They’re enforced now, but worth understanding the mechanism:</p>

  <ul>
    <li><strong><code class="language-plaintext highlighter-rouge">MaxReadRateMbPerSec</code> is an average-rate pacer, not a literal in-flight byte cap.</strong> After each file scan, the plugin computes how long the file <em>should</em> have taken at the configured rate (<code class="language-plaintext highlighter-rouge">fileSizeMB ÷ maxReadRateMbPerSec</code>) and pads the wall-clock gap before the next file if the scan finished faster than that. This was a deliberate choice over piping the file through ffmpeg’s stdin for precise byte-level control: stdin piping breaks seekability, and many MP4/MOV files store the <code class="language-plaintext highlighter-rouge">moov</code> atom at the end of the file — probing them over a non-seekable pipe produces a false <code class="language-plaintext highlighter-rouge">"moov atom not found"</code> failure, which is exactly the corruption signature this plugin exists to catch. The padding approach has zero risk to decode correctness and still bounds the long-run average throughput pulled from CephFS.</li>
    <li><strong><code class="language-plaintext highlighter-rouge">UseQuietHoursOnly</code> gates every scan through <code class="language-plaintext highlighter-rouge">ScanEngine</code></strong>, the same choke point all scan paths (manual, event-driven, and scheduled) already go through — mirroring the existing playback-pause mechanism. If the toggle is on and the current time falls outside the window, the scan waits (polling every 5 minutes) rather than skipping outright, so a manual “scan now” from the dashboard still eventually runs instead of silently no-op’ing.</li>
  </ul>

  <p>The OS-level <code class="language-plaintext highlighter-rouge">lxc.cgroup2.io.max</code> limit from the <a href="#resource-limits">Resource Limits</a> section above is still the harder guarantee — the plugin’s pacing is a cooperative, application-level complement to it, not a replacement.</p>
</blockquote>

<h3 id="monitoring-cephfs-impact">Monitoring CephFS Impact</h3>

<p>Watch OSD utilization during scanning:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># On Proxmox host</span>
ceph osd perf

<span class="c"># Per-OSD bandwidth</span>
ceph daemon osd.X perf dump | jq <span class="s1">'.osd.op_r_out_bytes'</span>

<span class="c"># Client I/O from the Jellyfin container</span>
ceph daemon mds.X session <span class="nb">ls</span> | jq <span class="s1">'.[].inst'</span>
</code></pre></div></div>

<h2 id="nfs-storage-configuration">NFS Storage Configuration</h2>

<p>For NFS-backed media libraries:</p>

<div class="language-json highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">{</span><span class="w">
  </span><span class="nl">"MaxConcurrentScans"</span><span class="p">:</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w">
  </span><span class="nl">"DelayBetweenFilesMs"</span><span class="p">:</span><span class="w"> </span><span class="mi">5000</span><span class="p">,</span><span class="w">
  </span><span class="nl">"MaxReadRateMbPerSec"</span><span class="p">:</span><span class="w"> </span><span class="mi">20</span><span class="p">,</span><span class="w">
  </span><span class="nl">"PauseDuringPlayback"</span><span class="p">:</span><span class="w"> </span><span class="kc">true</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div></div>

<p>NFS is more tolerant of sequential reads than CephFS, so the rate limit can be higher. Monitor with <code class="language-plaintext highlighter-rouge">nfsstat</code> on the server side.</p>

<h2 id="monitoring--alerting">Monitoring &amp; Alerting</h2>

<h3 id="prometheus-metrics-future-enhancement">Prometheus Metrics (Future Enhancement)</h3>

<p>The API endpoint provides data suitable for Prometheus scraping:</p>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># prometheus.yml scrape config</span>
<span class="pi">-</span> <span class="na">job_name</span><span class="pi">:</span> <span class="s1">'</span><span class="s">jellyfin-media-integrity'</span>
  <span class="na">metrics_path</span><span class="pi">:</span> <span class="s1">'</span><span class="s">/MediaIntegrity/Status'</span>
  <span class="na">static_configs</span><span class="pi">:</span>
    <span class="pi">-</span> <span class="na">targets</span><span class="pi">:</span> <span class="pi">[</span><span class="s1">'</span><span class="s">jellyfin-host:8096'</span><span class="pi">]</span>
  <span class="c1"># Custom relabeling to extract metrics from JSON response</span>
</code></pre></div></div>

<h3 id="simple-health-check-script">Simple Health Check Script</h3>

<p>Until native Prometheus support is added:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c">#!/bin/bash</span>
<span class="c"># /usr/local/bin/check-media-integrity.sh</span>

<span class="nv">API_KEY</span><span class="o">=</span><span class="s2">"your-api-key"</span>
<span class="nv">JELLYFIN_URL</span><span class="o">=</span><span class="s2">"http://localhost:8096"</span>

<span class="nv">STATUS</span><span class="o">=</span><span class="si">$(</span>curl <span class="nt">-s</span> <span class="s2">"</span><span class="k">${</span><span class="nv">JELLYFIN_URL</span><span class="k">}</span><span class="s2">/MediaIntegrity/Status"</span> <span class="se">\</span>
  <span class="nt">-H</span> <span class="s2">"X-Emby-Token: </span><span class="k">${</span><span class="nv">API_KEY</span><span class="k">}</span><span class="s2">"</span><span class="si">)</span>

<span class="nv">FAILED</span><span class="o">=</span><span class="si">$(</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$STATUS</span><span class="s2">"</span> | jq <span class="s1">'.failedFiles'</span><span class="si">)</span>
<span class="nv">HEALTH</span><span class="o">=</span><span class="si">$(</span><span class="nb">echo</span> <span class="s2">"</span><span class="nv">$STATUS</span><span class="s2">"</span> | jq <span class="s1">'.healthPercentage'</span><span class="si">)</span>

<span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$FAILED</span><span class="s2">"</span> <span class="nt">-gt</span> 0 <span class="o">]</span><span class="p">;</span> <span class="k">then
    </span><span class="nb">echo</span> <span class="s2">"WARNING: </span><span class="nv">$FAILED</span><span class="s2"> media files failed integrity check"</span>
    <span class="nb">echo</span> <span class="s2">"Library health: </span><span class="k">${</span><span class="nv">HEALTH</span><span class="k">}</span><span class="s2">%"</span>
    <span class="c"># Send notification (adapt to your alerting system)</span>
    <span class="c"># curl -d "Media integrity: $FAILED failed files" ntfy.sh/your-topic</span>
    <span class="nb">exit </span>1
<span class="k">fi

</span><span class="nb">echo</span> <span class="s2">"OK: Library health </span><span class="k">${</span><span class="nv">HEALTH</span><span class="k">}</span><span class="s2">%"</span>
<span class="nb">exit </span>0
</code></pre></div></div>

<h3 id="systemd-timer-for-health-checks">Systemd Timer for Health Checks</h3>

<div class="language-ini highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># /etc/systemd/system/media-integrity-check.timer
</span><span class="nn">[Unit]</span><span class="w">
</span><span class="py">Description</span><span class="p">=</span><span class="s">Check media integrity scan results</span>
<span class="w">
</span><span class="nn">[Timer]</span><span class="w">
</span><span class="py">OnCalendar</span><span class="p">=</span><span class="s">*-*-* 08:00:00</span>
<span class="py">Persistent</span><span class="p">=</span><span class="s">true</span>
<span class="w">
</span><span class="nn">[Install]</span><span class="w">
</span><span class="py">WantedBy</span><span class="p">=</span><span class="s">timers.target</span>
</code></pre></div></div>

<h2 id="cicd-pipeline">CI/CD Pipeline</h2>

<blockquote>
  <p><strong>Build environment note (updated July 31, 2026):</strong> The Proxmox LXC build/integration-test container is operational (.NET 9 SDK, <code class="language-plaintext highlighter-rouge">jellyfin-ffmpeg</code>, test Jellyfin instance, sample media). GitHub-hosted Ubuntu runners remain the primary CI path; the LXC is used for local/manual verification.</p>

  <p><strong>Update:</strong> The workflows below are the real, current ones — including two things that were missing for a while: a wired-up unit test suite (<code class="language-plaintext highlighter-rouge">tests/Jellyfin.Plugin.MediaIntegrityScanner.Tests</code>, covering the quiet-hours/read-rate pacing logic from the <a href="/jellyfin-media-integrity-scanner-core/#update-quiet-hours-and-read-rate-throttling">scanner core article</a>), and a real <code class="language-plaintext highlighter-rouge">scripts/update-manifest.py</code> wired into the release workflow (the script existed only as an unimplemented reference in this article before). Note that <code class="language-plaintext highlighter-rouge">dotnet build</code>/<code class="language-plaintext highlighter-rouge">dotnet publish</code> target the plugin’s <code class="language-plaintext highlighter-rouge">.csproj</code> explicitly rather than the solution file — once the test project joined the <code class="language-plaintext highlighter-rouge">.sln</code>, publishing the whole solution would have bundled test binaries into the release artifact.</p>

  <p><strong>Update (August 1, 2026) — the test suite grew a lot, and it found real bugs:</strong> The unit test project grew from 20 tests to 113 across 8 files, covering the database layer, the ffmpeg process wrapper, the API controller, and <code class="language-plaintext highlighter-rouge">ScanEngine</code> itself with mocked dependencies. Separately, the Docker-based integration suite (<code class="language-plaintext highlighter-rouge">tests/run-integration-tests.sh</code> and <code class="language-plaintext highlighter-rouge">integration-test.yml</code>, kept in sync with each other) grew from a basic “plugin loads, config endpoint responds” smoke check into something that actually exercises the scanning pipeline: a settings-page configuration round-trip, both web pages being served, a full scan-and-verify flow (trigger → poll → assert results), item-detail lookups, an item-scoped deep scan, and the cancel endpoint.</p>

  <p>Two things surfaced along the way that are worth knowing about if you’re troubleshooting a similar setup:</p>
  <ul>
    <li><strong>The “Verify FFmpeg is available in container” CI step was silently passing without checking anything</strong>, for a long time. It ran <code class="language-plaintext highlighter-rouge">docker exec jellyfin-test ffmpeg -version | head -5</code> — since <code class="language-plaintext highlighter-rouge">jellyfin-ffmpeg</code> isn’t symlinked onto <code class="language-plaintext highlighter-rouge">PATH</code> in the <code class="language-plaintext highlighter-rouge">jellyfin/jellyfin</code> image (it only lives at <code class="language-plaintext highlighter-rouge">/usr/lib/jellyfin-ffmpeg/ffmpeg</code>), that command actually fails, but piping into <code class="language-plaintext highlighter-rouge">head</code> without <code class="language-plaintext highlighter-rouge">pipefail</code> means the pipeline’s reported exit code is <code class="language-plaintext highlighter-rouge">head</code>’s, not <code class="language-plaintext highlighter-rouge">ffmpeg</code>’s — so the step went green anyway. Fixed by checking the real path and adding <code class="language-plaintext highlighter-rouge">set -euo pipefail</code>, a good reminder that any <code class="language-plaintext highlighter-rouge">cmd | head</code>/<code class="language-plaintext highlighter-rouge">| tail</code> in CI is worth a second look for whether it’s masking the thing you actually meant to check.</li>
    <li><strong>Writing that integration suite found two real, previously-undetected bugs in the plugin itself</strong> — the dashboard was reading JSON field names in the wrong casing (see the <a href="/jellyfin-media-integrity-dashboard-api/#update-the-dashboard-was-reading-the-wrong-json-casing">dashboard article</a>), and the deep-scan “skip if already scanned” check never looked at scan phase (see the <a href="/jellyfin-media-integrity-scanner-core/#update-the-skip-check-didnt-know-about-scan-phase">scanner core article</a>). Both had shipped silently for a while; both were only caught because the integration tests started actually asserting on real response data instead of just HTTP status codes.</li>
  </ul>

  <p><strong>Update (August 2, 2026) — a real corruption matrix, and a real-browser test suite:</strong> The integration suite’s test media was, until now, a single always-valid clip — every scan test proved the scanner <em>ran</em>, but none proved it actually <em>detected</em> anything. <code class="language-plaintext highlighter-rouge">tests/generate-test-media.sh</code> now generates seven files: two valid (different container/codec pairs) and five corrupted in distinct, verified-for-real ways — an empty file, random bytes with a video extension, a zeroed header, a truncated copy, and a file with a few KB zeroed out mid-stream. The last two are the interesting pair: both pass a header-only <code class="language-plaintext highlighter-rouge">ffprobe</code> scan (the corruption doesn’t touch <code class="language-plaintext highlighter-rouge">moov</code>/<code class="language-plaintext highlighter-rouge">ftyp</code>) but fail a full <code class="language-plaintext highlighter-rouge">ffmpeg</code> decode — the first automated proof that this plugin’s two-phase scanning design actually does what it claims, rather than just running twice for show.</p>

  <p>Building on top of that, a <a href="https://playwright.dev/">Playwright</a> suite now drives the dashboard and settings pages through a real Chromium session — logging in via the actual web form, triggering a real scan, and asserting the UI reflects it — instead of the integration suite’s curl+grep, which never executes a page’s own JavaScript or its real <code class="language-plaintext highlighter-rouge">ApiClient</code>-backed session. That gap is exactly what caught the dashboard-was-never-reachable bug described in the <a href="/jellyfin-media-integrity-dashboard-api/#update-the-dashboard-was-never-actually-reachable-in-a-real-browser">dashboard article’s update</a>. It runs in its own <code class="language-plaintext highlighter-rouge">playwright-e2e.yml</code> workflow, deliberately kept separate from <code class="language-plaintext highlighter-rouge">build.yml</code>/<code class="language-plaintext highlighter-rouge">integration-test.yml</code> — a real-browser suite is slower and more prone to environmental flakiness than a curl-based check, so its result is independent rather than blocking those other checks.</p>

  <p>One operational gotcha worth keeping in mind for any script that starts a Jellyfin container and installs a plugin into it in the same breath: <strong>the plugin DLL has to land in the bind-mounted config directory <em>before</em> the container’s first boot, not after.</strong> Jellyfin loads plugins once, early in its own startup; copying a DLL in after that point is a no-op until the container is restarted. This is a genuine race, not a hypothetical — reproduced locally by starting the container and copying the DLL in immediately after, which intermittently lost the race and left every <code class="language-plaintext highlighter-rouge">/MediaIntegrity/*</code> route 404ing until an explicit restart. Both CI workflows now copy the plugin in before <code class="language-plaintext highlighter-rouge">docker run</code>/<code class="language-plaintext highlighter-rouge">docker compose up</code>, not after.</p>
</blockquote>

<h2 id="update-automated-development-releases">Update: Automated Development Releases</h2>

<p>Adding an <a href="/jellyfin-media-integrity-dashboard-api/#update-an-in-plugin-update-checker">in-plugin update checker</a> that can offer a Development channel meant that channel needed something real to point at — a plugin repository manifest that actually gets newer entries as work lands on <code class="language-plaintext highlighter-rouge">main</code>, not just at tagged milestones.</p>

<p>A second workflow, <code class="language-plaintext highlighter-rouge">release-dev.yml</code>, now runs on every push to <code class="language-plaintext highlighter-rouge">main</code> and cuts a real GitHub <strong>pre-release</strong> plus a new <code class="language-plaintext highlighter-rouge">manifest-unstable.json</code>, parallel to the existing tagged-release path but never touching the stable <code class="language-plaintext highlighter-rouge">manifest.json</code>. The tricky part was version numbering: Jellyfin manifest versions have to be a clean 4-part numeric <code class="language-plaintext highlighter-rouge">System.Version</code> — no semver <code class="language-plaintext highlighter-rouge">-dev</code>/<code class="language-plaintext highlighter-rouge">-rc</code> suffix survives round-tripping through it — so the dev workflow keeps Major.Minor.Build from the current stable base and bumps only the fourth (Revision) component using the run’s own unique, ever-increasing run number (<code class="language-plaintext highlighter-rouge">0.1.0.147</code>, say). The human-friendly <code class="language-plaintext highlighter-rouge">v0.1.0-dev.147</code> form still shows up in the GitHub release title and changelog text, just not in the version Jellyfin actually compares against.</p>

<p>One thing deliberately <em>not</em> done: bumping <code class="language-plaintext highlighter-rouge">Directory.Build.props</code> on every single dev push and committing it back. That’s fine for a build artifact (the compiled DLL needs the real version baked in to compare correctly against what’s installed), but committing it every push would spam the repo and collide with the stable release workflow’s own version-bump commits to the same file — so the dev workflow bumps it locally within the CI run only, discards that change, and commits just the manifest update.</p>

<p>Also fixed while wiring this up: the existing stable <code class="language-plaintext highlighter-rouge">release.yml</code> updated <code class="language-plaintext highlighter-rouge">manifest.json</code>’s version on every tag but never actually bumped <code class="language-plaintext highlighter-rouge">Directory.Build.props</code> — meaning the <em>built assembly’s own</em> version number never moved past <code class="language-plaintext highlighter-rouge">0.1.0.0</code>, tag after tag. Harmless before there was any code that cared about the plugin’s own version, but a real problem for an update checker: it would report “update available” forever, even seconds after actually installing one, since the thing it’s comparing against never changes. Both workflows now agree on the version story.</p>

<p>No safe way to dry-run a workflow whose only trigger is “push to main” without literally pushing to main first, so the real test was the first real merge. It worked cleanly on the first attempt: a genuine <code class="language-plaintext highlighter-rouge">v0.1.0-dev.1</code> pre-release appeared with the built zip attached, and <code class="language-plaintext highlighter-rouge">manifest-unstable.json</code> picked up a matching <code class="language-plaintext highlighter-rouge">0.1.0.1</code> entry with the right checksum and source URL, no fix-forward required.</p>

<h3 id="github-actions-build--test">GitHub Actions: Build &amp; Test</h3>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># .github/workflows/build.yml</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">Build Plugin</span>

<span class="na">on</span><span class="pi">:</span>
  <span class="na">push</span><span class="pi">:</span>
    <span class="na">branches</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">main</span><span class="pi">,</span> <span class="nv">dev</span><span class="pi">]</span>
  <span class="na">pull_request</span><span class="pi">:</span>
    <span class="na">branches</span><span class="pi">:</span> <span class="pi">[</span><span class="nv">main</span><span class="pi">]</span>

<span class="na">jobs</span><span class="pi">:</span>
  <span class="na">build</span><span class="pi">:</span>
    <span class="na">runs-on</span><span class="pi">:</span> <span class="s">ubuntu-latest</span>

    <span class="na">steps</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Checkout</span>
        <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/checkout@v7</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Setup .NET </span><span class="m">9</span>
        <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/setup-dotnet@v6</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">dotnet-version</span><span class="pi">:</span> <span class="s1">'</span><span class="s">9.0.x'</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Restore dependencies</span>
        <span class="na">run</span><span class="pi">:</span> <span class="s">dotnet restore --verbosity normal</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Build</span>
        <span class="na">run</span><span class="pi">:</span> <span class="s">dotnet build --configuration Release --no-restore --verbosity normal</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Test</span>
        <span class="na">run</span><span class="pi">:</span> <span class="s">dotnet test --configuration Release --no-restore --no-build --verbosity normal</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Publish</span>
        <span class="na">run</span><span class="pi">:</span> <span class="s">dotnet publish Jellyfin.Plugin.MediaIntegrityScanner/Jellyfin.Plugin.MediaIntegrityScanner.csproj --configuration Release --output ./artifacts --no-build</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">List artifacts</span>
        <span class="na">run</span><span class="pi">:</span> <span class="s">ls -la ./artifacts/</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Upload build artifact</span>
        <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/upload-artifact@v7</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">name</span><span class="pi">:</span> <span class="s">media-integrity-scanner</span>
          <span class="na">path</span><span class="pi">:</span> <span class="s">./artifacts/</span>
          <span class="na">retention-days</span><span class="pi">:</span> <span class="m">30</span>
</code></pre></div></div>

<h3 id="github-actions-release">GitHub Actions: Release</h3>

<div class="language-yaml highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1"># .github/workflows/release.yml</span>
<span class="na">name</span><span class="pi">:</span> <span class="s">Release Plugin</span>

<span class="na">on</span><span class="pi">:</span>
  <span class="na">push</span><span class="pi">:</span>
    <span class="na">tags</span><span class="pi">:</span> <span class="pi">[</span><span class="s1">'</span><span class="s">v*'</span><span class="pi">]</span>

<span class="na">jobs</span><span class="pi">:</span>
  <span class="na">release</span><span class="pi">:</span>
    <span class="na">runs-on</span><span class="pi">:</span> <span class="s">ubuntu-latest</span>
    <span class="na">permissions</span><span class="pi">:</span>
      <span class="na">contents</span><span class="pi">:</span> <span class="s">write</span>

    <span class="na">steps</span><span class="pi">:</span>
      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Checkout</span>
        <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/checkout@v7</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Setup .NET </span><span class="m">9</span>
        <span class="na">uses</span><span class="pi">:</span> <span class="s">actions/setup-dotnet@v6</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">dotnet-version</span><span class="pi">:</span> <span class="s1">'</span><span class="s">9.0.x'</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Restore dependencies</span>
        <span class="na">run</span><span class="pi">:</span> <span class="s">dotnet restore Jellyfin.Plugin.MediaIntegrityScanner/Jellyfin.Plugin.MediaIntegrityScanner.csproj</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Build Release</span>
        <span class="na">run</span><span class="pi">:</span> <span class="s">dotnet publish Jellyfin.Plugin.MediaIntegrityScanner/Jellyfin.Plugin.MediaIntegrityScanner.csproj --configuration Release --output ./publish</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Package</span>
        <span class="na">run</span><span class="pi">:</span> <span class="pi">|</span>
          <span class="s">cd publish</span>
          <span class="s">zip -r ../media-integrity-scanner-$.zip .</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Create GitHub Release</span>
        <span class="na">uses</span><span class="pi">:</span> <span class="s">softprops/action-gh-release@v3</span>
        <span class="na">with</span><span class="pi">:</span>
          <span class="na">files</span><span class="pi">:</span> <span class="s">media-integrity-scanner-$.zip</span>
          <span class="na">generate_release_notes</span><span class="pi">:</span> <span class="kc">true</span>

      <span class="pi">-</span> <span class="na">name</span><span class="pi">:</span> <span class="s">Update manifest.json</span>
        <span class="na">run</span><span class="pi">:</span> <span class="pi">|</span>
          <span class="s">python3 scripts/update-manifest.py "$" "media-integrity-scanner-$.zip"</span>
          <span class="s">git config user.name "github-actions[bot]"</span>
          <span class="s">git config user.email "github-actions[bot]@users.noreply.github.com"</span>
          <span class="s">git add manifest.json</span>
          <span class="s">git commit -m "chore: update manifest.json for $"</span>
          <span class="s"># Assumes the tag was created from the current tip of main.</span>
          <span class="s">git push origin HEAD:main</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">scripts/update-manifest.py</code> normalizes the git tag (<code class="language-plaintext highlighter-rouge">v0.2.0</code> → <code class="language-plaintext highlighter-rouge">0.2.0.0</code>), computes the MD5 checksum of the release zip (the convention Jellyfin plugin manifests use), derives <code class="language-plaintext highlighter-rouge">targetAbi</code> from the <code class="language-plaintext highlighter-rouge">Jellyfin.Controller</code> package reference in the <code class="language-plaintext highlighter-rouge">.csproj</code>, and prepends a new version entry to <code class="language-plaintext highlighter-rouge">manifest.json</code> — replacing any existing entry for the same version, so re-running for the same tag is idempotent.</p>

<h2 id="operational-runbook">Operational Runbook</h2>

<h3 id="first-time-setup">First-Time Setup</h3>

<ol>
  <li>Install plugin via repository or manual DLL</li>
  <li>Restart Jellyfin</li>
  <li>Navigate to <strong>Dashboard → Plugins → Media Integrity Scanner</strong></li>
  <li>Configure throttling settings for your storage backend</li>
  <li>Optionally enable “Scan on Item Added” for new file validation</li>
  <li>Run initial header scan from the dashboard (this may take hours for large libraries)</li>
</ol>

<h3 id="handling-failed-files">Handling Failed Files</h3>

<p>When files are flagged as failed:</p>

<ol>
  <li>Check the error output in the dashboard detail view</li>
  <li>Common failures:
    <ul>
      <li><code class="language-plaintext highlighter-rouge">"Invalid data found when processing input"</code> → Corrupt container</li>
      <li><code class="language-plaintext highlighter-rouge">"moov atom not found"</code> → Truncated MP4/MOV</li>
      <li><code class="language-plaintext highlighter-rouge">"Error while decoding stream"</code> → Corrupt video frames</li>
    </ul>
  </li>
  <li>Attempt repair: <code class="language-plaintext highlighter-rouge">ffmpeg -i broken.mkv -c copy repaired.mkv</code></li>
  <li>If repair fails: re-download or re-rip the source</li>
  <li>After fix: trigger a rescan from the dashboard</li>
</ol>

<h3 id="database-maintenance">Database Maintenance</h3>

<p>The SQLite database grows slowly. Occasional maintenance:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Location</span>
<span class="nb">ls</span> /var/lib/jellyfin/plugins/MediaIntegrityScanner/data/

<span class="c"># Vacuum to reclaim space (while Jellyfin is stopped)</span>
sqlite3 media-integrity.db <span class="s2">"VACUUM;"</span>

<span class="c"># Check database integrity</span>
sqlite3 media-integrity.db <span class="s2">"PRAGMA integrity_check;"</span>
</code></pre></div></div>

<h3 id="upgrading-the-plugin">Upgrading the Plugin</h3>

<ol>
  <li>Check the repository for new releases</li>
  <li>Jellyfin’s plugin auto-update handles it if installed via repository</li>
  <li>For manual installs: replace the DLL files and restart</li>
</ol>

<h2 id="whats-next">What’s Next</h2>

<p>The plugin is deployed, monitored, and releasing on a real CI/CD pipeline — but v0.1.0 wasn’t the end of the story. The <a href="/jellyfin-media-integrity-release-and-updates/">final article</a> covers what production use and real testing turned up afterward: an update checker, session-aware auto-restart, a packaging bug that broke non-Linux installs, and a full future-work list of what’s still being evaluated.</p>

<h2 id="resources">Resources</h2>

<ul>
  <li><strong>Repository:</strong> <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner">github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner</a></li>
  <li><strong>Issues &amp; Feature Requests:</strong> <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/issues">GitHub Issues</a></li>
  <li><strong>Jellyfin Plugin Template:</strong> <a href="https://github.com/jellyfin/jellyfin-plugin-template">github.com/jellyfin/jellyfin-plugin-template</a></li>
  <li><strong>CephFS Performance Tuning:</strong> <a href="https://docs.ceph.com/en/latest/cephfs/">docs.ceph.com/en/latest/cephfs/</a></li>
  <li><strong>Jellyfin API Docs:</strong> <a href="https://api.jellyfin.org/">api.jellyfin.org</a></li>
</ul>

<h2 id="series-navigation">Series Navigation</h2>

<ol>
  <li><a href="/jellyfin-media-integrity-scanner-introduction/">Introduction &amp; Problem Statement</a></li>
  <li><a href="/jellyfin-media-integrity-architecture-design/">Architecture &amp; Design Decisions</a></li>
  <li><a href="/jellyfin-media-integrity-scanner-core/">Building the Scanner Core</a></li>
  <li><a href="/jellyfin-media-integrity-dashboard-api/">The Dashboard &amp; API</a></li>
  <li><strong>Deployment &amp; Operations</strong> (this post)</li>
  <li><a href="/jellyfin-media-integrity-release-and-updates/">v0.1.1 Release: Update Checker &amp; Auto-Update</a></li>
</ol>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="homelab" /><category term="media-server" /><category term="jellyfin" /><category term="media-integrity" /><category term="proxmox" /><category term="ceph" /><category term="deployment" /><category term="ci-cd" /><category term="monitoring" /><category term="github-actions" /><summary type="html"><![CDATA[Deploying and operating the Jellyfin Media Integrity Scanner plugin in a production homelab. Covers Proxmox LXC installation, CephFS/NFS storage configuration, monitoring with Prometheus/Grafana, alerting on failures, and GitHub Actions CI/CD for automated builds and releases. Part 5 of a 6-part development series.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-deployment-operations.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-deployment-operations.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">AI Agent Context Files in Practice: One Repo, Five Agents</title><link href="https://mcgarrah.org/ai-agent-context-files-in-practice/" rel="alternate" type="text/html" title="AI Agent Context Files in Practice: One Repo, Five Agents" /><published>2026-08-14T00:00:00+00:00</published><updated>2026-08-14T00:00:00+00:00</updated><id>https://mcgarrah.org/ai-agent-context-files-in-practice</id><content type="html" xml:base="https://mcgarrah.org/ai-agent-context-files-in-practice/"><![CDATA[<p>Two months ago I wrote about <a href="/managing-cross-ai-agent-context/">managing context across multiple AI coding assistants</a> and documented the <a href="/ai-coding-agent-context-files-reference/">reference guide for every agent’s file format</a>. The theory was straightforward: maintain a single source of truth and let each agent’s config file be a thin pointer.</p>

<p>This week I put that into practice on <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner">jellyfin-plugin-media-integrity-scanner</a> — and discovered what actually matters when you stop thinking about it abstractly and start shipping code with multiple agents hitting the same repo.</p>

<!-- excerpt-end -->

<h2 id="the-problem-that-triggered-this">The Problem That Triggered This</h2>

<p>I was implementing the plugin’s core components with Kiro (Amazon’s new agent-native IDE) and ran into a cascade of build failures. The Jellyfin 10.11 API had removed <code class="language-plaintext highlighter-rouge">IServerEntryPoint</code>, changed where <code class="language-plaintext highlighter-rouge">MediaType</code> lives, and renamed the <code class="language-plaintext highlighter-rouge">TaskTriggerInfo</code> trigger constants. Every time I fixed one issue and pushed, CI failed on the next.</p>

<p>The frustrating part: I’d already figured out these API changes. But without persistent context, each new session started from zero. Worse, when I switched between agents (Kiro for implementation, Claude Code for investigation, Copilot for quick completions), none of them knew what the others had learned.</p>

<p>That’s when the articles I’d written stopped being theoretical. I needed exactly the pattern I’d described: one canonical context file that every agent reads.</p>

<h2 id="the-implementation">The Implementation</h2>

<p>Here’s what the repository looks like now:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>jellyfin-plugin-media-integrity-scanner/
├── AGENTS.md                           # Single source of truth
├── CLAUDE.md                           # "Read AGENTS.md"
├── .github/copilot-instructions.md     # "Read AGENTS.md"
├── .gemini/styleguide.md               # "Read AGENTS.md"
├── .kiro/steering/project-context.md   # Pulls in AGENTS.md via inclusion
└── ...
</code></pre></div></div>

<p>Five files. One has content. Four are one-liners.</p>

<h3 id="why-agentsmd">Why AGENTS.md</h3>

<p>The name matters for exactly one reason: OpenAI Codex auto-discovers <code class="language-plaintext highlighter-rouge">AGENTS.md</code> by convention, which means one fewer stub file to maintain. Every other agent needs its own config file regardless of what you name the canonical source, so you might as well pick the name that gives you one free discovery.</p>

<p>I considered <code class="language-plaintext highlighter-rouge">CONTEXT.md</code> (more neutral) and <code class="language-plaintext highlighter-rouge">CONVENTIONS.md</code> (from my earlier article), but <code class="language-plaintext highlighter-rouge">AGENTS.md</code> is self-documenting — a human browsing the repo immediately understands what it’s for and who it’s for.</p>

<h3 id="the-agents-covered">The Agents Covered</h3>

<table>
  <thead>
    <tr>
      <th>Agent</th>
      <th>Discovery File</th>
      <th>Notes</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><strong>Kiro</strong> (IDE + CLI)</td>
      <td><code class="language-plaintext highlighter-rouge">.kiro/steering/project-context.md</code></td>
      <td>File inclusion directive loads full content</td>
    </tr>
    <tr>
      <td><strong>Claude Code</strong></td>
      <td><code class="language-plaintext highlighter-rouge">CLAUDE.md</code></td>
      <td>Reliably follows file references</td>
    </tr>
    <tr>
      <td><strong>GitHub Copilot</strong></td>
      <td><code class="language-plaintext highlighter-rouge">.github/copilot-instructions.md</code></td>
      <td>Workspace indexing picks up AGENTS.md</td>
    </tr>
    <tr>
      <td><strong>Gemini</strong> (<code class="language-plaintext highlighter-rouge">agy</code> CLI)</td>
      <td><code class="language-plaintext highlighter-rouge">.gemini/styleguide.md</code></td>
      <td>Google’s Antigravity/Gemini Code Assist</td>
    </tr>
    <tr>
      <td><strong>Codex</strong> (OpenAI)</td>
      <td><code class="language-plaintext highlighter-rouge">AGENTS.md</code> directly</td>
      <td>Auto-discovers by convention</td>
    </tr>
  </tbody>
</table>

<p>I deliberately dropped Amazon Q Developer support. Amazon shifted their AI developer tooling strategy toward Kiro, and Q Developer’s rules system (<code class="language-plaintext highlighter-rouge">.amazonq/rules/</code>) is headed for deprecation or irrelevance. Maintaining config files for abandoned tooling is exactly the kind of drift I’m trying to avoid.</p>

<h3 id="the-stub-files">The Stub Files</h3>

<p>Each agent file is exactly one line:</p>

<p><strong>CLAUDE.md:</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Read AGENTS.md for all project context.
</code></pre></div></div>

<p><strong>.github/copilot-instructions.md:</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Read AGENTS.md at the repository root for all project context and coding guidelines.
</code></pre></div></div>

<p><strong>.gemini/styleguide.md:</strong></p>
<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Read AGENTS.md at the repository root for all project context.
</code></pre></div></div>

<p>No duplicated details. Nothing that can go stale. If the agent can follow a file reference (Claude Code can, reliably), it gets the full context. If it can’t, the stub at least tells it where to look, and most modern agents will read the referenced file.</p>

<h3 id="kiros-special-case">Kiro’s Special Case</h3>

<p>Kiro (both the IDE and the forthcoming <code class="language-plaintext highlighter-rouge">kiro-cli</code>) has a genuinely useful feature here. Its steering files support a file inclusion directive:</p>

<p><strong>.kiro/steering/project-context.md:</strong></p>
<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nn">---</span>
<span class="na">inclusion</span><span class="pi">:</span> <span class="s">auto</span>
<span class="nn">---</span>

<span class="gh">#[[file:AGENTS.md]]</span>
</code></pre></div></div>

<p>The <code class="language-plaintext highlighter-rouge">inclusion: auto</code> frontmatter means this loads on every session. The <code class="language-plaintext highlighter-rouge">#[[file:AGENTS.md]]</code> directive injects the full content of AGENTS.md directly into Kiro’s context — no cross-referencing, no hoping the agent follows a pointer. The content is there, guaranteed, every time.</p>

<p>This is the closest any agent comes to solving the problem cleanly. The <code class="language-plaintext highlighter-rouge">.kiro/steering/</code> directory is shared between the IDE and CLI, so the same context file works for both. The others still rely on the agent being smart enough to read a referenced file.</p>

<h2 id="what-goes-in-agentsmd">What Goes in AGENTS.md</h2>

<p>The content matters as much as the structure. After iterating on this during real implementation work, here’s what proved essential:</p>

<h3 id="1-environment-details-that-prevent-wasted-cycles">1. Environment Details That Prevent Wasted Cycles</h3>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gu">### Important: Shell Execution</span>
<span class="p">-</span> Shell commands must run in a Linux context (bash/zsh), not PowerShell
<span class="p">-</span> <span class="sb">`dotnet`</span> is not available locally — do not attempt local builds
<span class="p">-</span> Use <span class="sb">`gh`</span> CLI for GitHub API access (runs, PRs, issues)
</code></pre></div></div>

<p>This saved me repeated failures. Kiro’s shell execution was trying to run <code class="language-plaintext highlighter-rouge">dotnet build</code> in a context where the SDK wasn’t installed, and it took multiple sessions to diagnose because the context reset each time. Once this was in AGENTS.md, every agent knew immediately: don’t try local builds, push and check CI instead.</p>

<h3 id="2-api-specific-gotchas">2. API-Specific Gotchas</h3>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="gu">### Removed/Changed APIs</span>
<span class="p">-</span> <span class="gs">**`IServerEntryPoint`**</span> — Removed in 10.11. Use <span class="sb">`IHostedService`</span> instead.
<span class="p">-</span> <span class="gs">**`MediaType`**</span> — Now in <span class="sb">`MediaBrowser.Model.Entities`</span>.
<span class="p">-</span> <span class="gs">**`TaskTriggerInfo.TriggerDaily`**</span> — Use the string <span class="sb">`"DailyTrigger"`</span>.
</code></pre></div></div>

<p>This is the highest-value content in the file. Without it, every agent independently discovers these breaking changes by writing code that fails CI, reading the error, and fixing it — three round-trips per issue, per session. With it, the agent writes correct code on the first attempt.</p>

<h3 id="3-correct-patterns-not-just-whats-wrong">3. Correct Patterns (Not Just What’s Wrong)</h3>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c1">// Scheduled task triggers</span>
<span class="k">new</span> <span class="n">TaskTriggerInfo</span> <span class="p">{</span> <span class="n">Type</span> <span class="p">=</span> <span class="s">"DailyTrigger"</span><span class="p">,</span> <span class="n">TimeOfDayTicks</span> <span class="p">=</span> <span class="n">TimeSpan</span><span class="p">.</span><span class="nf">FromHours</span><span class="p">(</span><span class="m">3</span><span class="p">).</span><span class="n">Ticks</span> <span class="p">}</span>
</code></pre></div></div>

<p>Don’t just say what’s broken — show what’s correct. Agents are better at copying patterns than inferring fixes from error descriptions.</p>

<h3 id="4-build-verification-workflow">4. Build Verification Workflow</h3>

<div class="language-markdown highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Since <span class="sb">`dotnet`</span> is not installed locally, all build verification happens via CI:
<span class="p">1.</span> Push changes to GitHub
<span class="p">2.</span> Check workflow status: <span class="sb">`GH_PAGER=cat gh run list --limit 3`</span>
<span class="p">3.</span> View errors: <span class="sb">`GH_PAGER=cat gh run view &lt;run-id&gt; --log-failed 2&gt;&amp;1 | grep "error CS"`</span>
</code></pre></div></div>

<p>This tells the agent how to close the feedback loop. Without it, the agent pushes code and considers the task done. With it, the agent knows to check CI and iterate.</p>

<h2 id="what-i-left-out">What I Left Out</h2>

<p>Equally important: the stub files contain zero details that could go stale. My earlier article suggested keeping a “quick reference” in CLAUDE.md with build commands and key conventions. I tried that initially and removed it within a day.</p>

<p>The problem: when you update AGENTS.md (adding a new API note, fixing a path), you forget to update the duplicated snippets in CLAUDE.md. Now Claude Code has stale context that contradicts the canonical source. The whole point of centralization is defeated the moment you duplicate anything.</p>

<p>One line. One reference. No details in the stubs.</p>

<h2 id="does-cross-referencing-actually-work">Does Cross-Referencing Actually Work?</h2>

<p>In my earlier article, I was skeptical about cross-referencing — telling one agent to read a competitor’s files. Two months later, the landscape has improved:</p>

<ul>
  <li><strong>Claude Code</strong>: Reliably reads referenced files. <code class="language-plaintext highlighter-rouge">CLAUDE.md</code> saying “read AGENTS.md” works.</li>
  <li><strong>Kiro</strong>: File inclusion directive guarantees the content is loaded. Best solution of any agent.</li>
  <li><strong>GitHub Copilot</strong>: Reads <code class="language-plaintext highlighter-rouge">.github/copilot-instructions.md</code> content but does not follow file references within it. However, since AGENTS.md is in the repo, Copilot’s workspace indexing picks it up for chat context.</li>
  <li><strong>Gemini</strong> (<code class="language-plaintext highlighter-rouge">agy</code> CLI): Reads <code class="language-plaintext highlighter-rouge">.gemini/styleguide.md</code> and follows file references. Google’s tooling respects the pointer pattern.</li>
  <li><strong>Codex</strong>: Auto-discovers AGENTS.md by convention. No pointer needed.</li>
</ul>

<p>The pattern works today in mid-2026 in a way it wouldn’t have six months ago. Agents are better at following references, and workspace-level indexing means the canonical file gets picked up even without explicit inclusion.</p>

<h2 id="lessons-learned">Lessons Learned</h2>

<p><strong>1. Context persistence is the real problem, not context format.</strong></p>

<p>I spent time in my earlier articles comparing file formats (MDC vs Markdown, YAML vs prose). That doesn’t matter. What matters is: does the agent have the right information when it starts working? AGENTS.md solves that regardless of format differences.</p>

<p><strong>2. API breakage documentation is the highest-ROI content.</strong></p>

<p>Of everything in AGENTS.md, the Jellyfin 10.11 API notes save the most time. Environment details are a close second. General coding standards (XML docs, ConfigureAwait) are nice-to-have but agents mostly infer those from existing code.</p>

<p><strong>3. One file, one truth, no duplication.</strong></p>

<p>Every time I was tempted to put “just a few key points” in a stub file, I reminded myself: that’s how drift starts. The stubs are pointers, not summaries.</p>

<p><strong>4. The name <code class="language-plaintext highlighter-rouge">AGENTS.md</code> is a pragmatic choice, not a standard.</strong></p>

<p>There is still no cross-agent standard. <code class="language-plaintext highlighter-rouge">AGENTS.md</code> works because Codex reads it natively and the name is self-documenting. But if the ecosystem converges on something else tomorrow, the migration is trivial — rename one file, update four one-liners.</p>

<h2 id="the-repository">The Repository</h2>

<p>The full implementation is at <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner">github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner</a>. The <code class="language-plaintext highlighter-rouge">feat/agent-context-files</code> branch contains the agent context setup described here.</p>

<h2 id="reality-check-kiro-cli-is-broken-for-enterprise-auth">Reality Check: Kiro CLI Is Broken for Enterprise Auth</h2>

<p>While the <code class="language-plaintext highlighter-rouge">.kiro/steering/</code> file inclusion works beautifully in the Kiro IDE, <code class="language-plaintext highlighter-rouge">kiro-cli</code> — the terminal-based agent — is currently unusable with IAM Identity Center (organization-managed) authentication. I spent hours debugging this and <a href="https://github.com/kirodotdev/Kiro/issues/10587">filed the issue</a>.</p>

<p>The symptoms: <code class="language-plaintext highlighter-rouge">kiro-cli chat</code> exits silently. No error, no output, exit code 0. Authentication works (<code class="language-plaintext highlighter-rouge">whoami</code> succeeds, <code class="language-plaintext highlighter-rouge">chat --list-models</code> returns models), but the chat subprocess never starts. Debug output reveals the problem:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>no social token found
no idp token found
launching q chat binary
</code></pre></div></div>

<p>The chat subprocess only accepts “social” tokens (Google/GitHub login) or “idp” tokens (Okta/Entra). IAM Identity Center SSO tokens — the enterprise auth path — are simply not handled. The Kiro IDE works fine with the same credentials because it handles auth internally rather than delegating to a subprocess.</p>

<p>This is frustrating for two reasons:</p>

<p><strong>1. The CLI was closed-source in the transition.</strong> Amazon Q Developer CLI was open source on GitHub. When it was rebranded to Kiro CLI, the repository was archived and the new codebase is proprietary. I can’t look at the token-passing code to understand the issue or propose a fix. The debug output (<code class="language-plaintext highlighter-rouge">q_cli::cli</code>, <code class="language-plaintext highlighter-rouge">launching q chat binary</code>) reveals the old Q Developer internals are still under the hood — this is a rebrand, not a rewrite — but I can’t inspect them anymore.</p>

<p><strong>2. Builder ID works, enterprise auth doesn’t.</strong> The irony of a tool marketed for enterprise adoption failing on the enterprise authentication path while working fine with personal Builder ID login is not lost on me. If you’re evaluating Kiro CLI for an organization that uses IAM Identity Center, be aware that chat functionality doesn’t work as of version 2.15.2.</p>

<p>For now, my <code class="language-plaintext highlighter-rouge">.kiro/steering/project-context.md</code> file delivers value through the Kiro IDE (where it works as designed) and awaits a fix for the CLI. The context file pattern is correct — the tooling has a gap.</p>

<h2 id="related-articles">Related Articles</h2>

<ul>
  <li><a href="/managing-cross-ai-agent-context/">Managing Context and Rules Across Multiple AI Coding Assistants</a> — The strategy article that preceded this implementation</li>
  <li><a href="/ai-coding-agent-context-files-reference/">AI Coding Agent Context Files: A Reference Guide</a> — Detailed reference for each agent’s file format and conventions</li>
</ul>

<h2 id="series-context">Series Context</h2>

<p>This article is part of the <a href="/jellyfin-media-integrity-scanner-introduction/">Jellyfin Media Integrity Scanner</a> development series, though it stands alone as a practical guide to AI agent context management applicable to any project.</p>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="technical" /><category term="development" /><category term="ai" /><category term="claude-code" /><category term="github-copilot" /><category term="kiro" /><category term="gemini" /><category term="productivity" /><category term="tooling" /><category term="plugin-development" /><summary type="html"><![CDATA[A practical case study of implementing centralized AI agent context management in a real .NET plugin repository. Demonstrates the AGENTS.md pattern with minimal per-tool stubs for Kiro, Claude Code, GitHub Copilot, Gemini CLI, and OpenAI Codex.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/ai-agent-context-files-in-practice.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/ai-agent-context-files-in-practice.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Jellyfin Media Integrity Scanner: The Dashboard &amp;amp; API</title><link href="https://mcgarrah.org/jellyfin-media-integrity-dashboard-api/" rel="alternate" type="text/html" title="Jellyfin Media Integrity Scanner: The Dashboard &amp;amp; API" /><published>2026-08-12T00:00:00+00:00</published><updated>2026-08-12T00:00:00+00:00</updated><id>https://mcgarrah.org/jellyfin-media-integrity-dashboard-api</id><content type="html" xml:base="https://mcgarrah.org/jellyfin-media-integrity-dashboard-api/"><![CDATA[<p>The <a href="/jellyfin-media-integrity-scanner-core/">scanner core</a> handles the detection work — finding corrupt files and recording results in SQLite. But a scanner that runs silently in the background is only half the solution. Admins need to see what’s broken, when it was scanned, and have the ability to trigger scans on demand.</p>

<!-- excerpt-end -->

<p>This is Part 4 of the <a href="/jellyfin-media-integrity-scanner-introduction/">Jellyfin Media Integrity Scanner</a> development series. The REST API controller and dashboard below are fully implemented and shipping, though two accuracy bugs surfaced during a later review: <code class="language-plaintext highlighter-rouge">GetStatus</code> originally reported <code class="language-plaintext highlighter-rouge">TotalFiles</code>/<code class="language-plaintext highlighter-rouge">PendingFiles</code> straight from the scan-results table, which never reflected the real library size and double-counted items scanned in both phases, and <code class="language-plaintext highlighter-rouge">libraryId</code> on <code class="language-plaintext highlighter-rouge">GET /Results</code> was accepted but silently ignored. Both are covered in the <a href="#update-status-accuracy-and-library-filtering">Status Accuracy and Library Filtering update</a> further down.</p>

<h2 id="rest-api-controller">REST API Controller</h2>

<p><code class="language-plaintext highlighter-rouge">MediaIntegrityController</code> exposes the scan engine over Jellyfin’s own ASP.NET Core pipeline. Every route requires the <code class="language-plaintext highlighter-rouge">RequiresElevation</code> policy (admin-only), and the controller itself stays thin — it wires HTTP verbs to <code class="language-plaintext highlighter-rouge">IScanEngine</code>/database calls without implementing any scanning logic of its own:</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">[</span><span class="n">ApiController</span><span class="p">]</span>
<span class="p">[</span><span class="nf">Route</span><span class="p">(</span><span class="s">"MediaIntegrity"</span><span class="p">)]</span>
<span class="p">[</span><span class="nf">Authorize</span><span class="p">(</span><span class="n">Policy</span> <span class="p">=</span> <span class="s">"RequiresElevation"</span><span class="p">)]</span>
<span class="k">public</span> <span class="k">class</span> <span class="nc">MediaIntegrityController</span> <span class="p">:</span> <span class="n">ControllerBase</span>
<span class="p">{</span>
    <span class="p">[</span><span class="nf">HttpGet</span><span class="p">(</span><span class="s">"Status"</span><span class="p">)]</span>
    <span class="k">public</span> <span class="k">async</span> <span class="n">Task</span><span class="p">&lt;</span><span class="n">ActionResult</span><span class="p">&lt;</span><span class="n">ScanStatusResponse</span><span class="p">&gt;&gt;</span> <span class="nf">GetStatus</span><span class="p">()</span> <span class="p">{</span> <span class="cm">/* ... */</span> <span class="p">}</span>

    <span class="p">[</span><span class="nf">HttpGet</span><span class="p">(</span><span class="s">"Results"</span><span class="p">)]</span>
    <span class="k">public</span> <span class="k">async</span> <span class="n">Task</span><span class="p">&lt;</span><span class="n">ActionResult</span><span class="p">&lt;</span><span class="n">PagedResultResponse</span><span class="p">&gt;&gt;</span> <span class="nf">GetResults</span><span class="p">(</span>
        <span class="n">ScanStatus</span><span class="p">?</span> <span class="n">status</span><span class="p">,</span> <span class="kt">int</span> <span class="n">page</span> <span class="p">=</span> <span class="m">1</span><span class="p">,</span> <span class="kt">int</span> <span class="n">pageSize</span> <span class="p">=</span> <span class="m">50</span><span class="p">,</span> <span class="kt">string</span><span class="p">?</span> <span class="n">libraryId</span> <span class="p">=</span> <span class="k">null</span><span class="p">)</span> <span class="p">{</span> <span class="cm">/* ... */</span> <span class="p">}</span>

    <span class="p">[</span><span class="nf">HttpGet</span><span class="p">(</span><span class="s">"Results/{itemId}"</span><span class="p">)]</span>
    <span class="k">public</span> <span class="k">async</span> <span class="n">Task</span><span class="p">&lt;</span><span class="n">ActionResult</span><span class="p">&lt;</span><span class="n">ItemScanDetail</span><span class="p">&gt;&gt;</span> <span class="nf">GetItemDetail</span><span class="p">(</span><span class="kt">string</span> <span class="n">itemId</span><span class="p">)</span> <span class="p">{</span> <span class="cm">/* ... */</span> <span class="p">}</span>

    <span class="p">[</span><span class="nf">HttpPost</span><span class="p">(</span><span class="s">"Scan"</span><span class="p">)]</span>
    <span class="k">public</span> <span class="k">async</span> <span class="n">Task</span><span class="p">&lt;</span><span class="n">ActionResult</span><span class="p">&gt;</span> <span class="nf">TriggerScan</span><span class="p">([</span><span class="n">FromBody</span><span class="p">]</span> <span class="n">ScanRequest</span> <span class="n">request</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="n">_scanner</span><span class="p">.</span><span class="n">IsScanning</span><span class="p">)</span>
        <span class="p">{</span>
            <span class="k">return</span> <span class="nf">Conflict</span><span class="p">(</span><span class="s">"A scan is already in progress."</span><span class="p">);</span>
        <span class="p">}</span>

        <span class="c1">// Fire-and-forget: the request returns immediately and the caller</span>
        <span class="c1">// polls GetStatus/GetResults, rather than holding a connection open</span>
        <span class="c1">// for a scan that can take hours on a large library.</span>
        <span class="n">_</span> <span class="p">=</span> <span class="n">Task</span><span class="p">.</span><span class="nf">Run</span><span class="p">(()</span> <span class="p">=&gt;</span> <span class="n">request</span><span class="p">.</span><span class="n">ItemId</span> <span class="p">!=</span> <span class="k">null</span>
            <span class="p">?</span> <span class="n">_scanner</span><span class="p">.</span><span class="nf">ScanItemAsync</span><span class="p">(</span><span class="n">_library</span><span class="p">.</span><span class="nf">GetItemById</span><span class="p">(</span><span class="n">Guid</span><span class="p">.</span><span class="nf">Parse</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="n">ItemId</span><span class="p">)),</span>
                <span class="n">request</span><span class="p">.</span><span class="n">DeepScan</span> <span class="p">?</span> <span class="n">ScanPhase</span><span class="p">.</span><span class="n">FullDecode</span> <span class="p">:</span> <span class="n">ScanPhase</span><span class="p">.</span><span class="n">Header</span><span class="p">,</span> <span class="n">CancellationToken</span><span class="p">.</span><span class="n">None</span><span class="p">)</span>
            <span class="p">:</span> <span class="n">_scanner</span><span class="p">.</span><span class="nf">ScanLibraryAsync</span><span class="p">(</span><span class="n">request</span><span class="p">.</span><span class="n">LibraryId</span><span class="p">,</span>
                <span class="n">request</span><span class="p">.</span><span class="n">DeepScan</span> <span class="p">?</span> <span class="n">ScanPhase</span><span class="p">.</span><span class="n">FullDecode</span> <span class="p">:</span> <span class="n">ScanPhase</span><span class="p">.</span><span class="n">Header</span><span class="p">,</span> <span class="n">CancellationToken</span><span class="p">.</span><span class="n">None</span><span class="p">));</span>

        <span class="k">return</span> <span class="nf">Accepted</span><span class="p">();</span>
    <span class="p">}</span>

    <span class="p">[</span><span class="nf">HttpPost</span><span class="p">(</span><span class="s">"Cancel"</span><span class="p">)]</span>
    <span class="k">public</span> <span class="n">ActionResult</span> <span class="nf">CancelScan</span><span class="p">()</span> <span class="p">{</span> <span class="n">_scanner</span><span class="p">.</span><span class="nf">Cancel</span><span class="p">();</span> <span class="k">return</span> <span class="nf">Ok</span><span class="p">();</span> <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">TriggerScan</code>’s early <code class="language-plaintext highlighter-rouge">Conflict</code> return is the API-level half of the same single-scan-at-a-time guarantee <code class="language-plaintext highlighter-rouge">ScanEngine</code>’s semaphore already enforces internally (see the <a href="/jellyfin-media-integrity-scanner-core/#the-scan-engine">scanner core article</a>) — rejecting a second request at the HTTP layer gives an admin an immediate, meaningful <code class="language-plaintext highlighter-rouge">409</code> instead of a call that silently queues behind the running scan.</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/Api/MediaIntegrityController.cs"><code class="language-plaintext highlighter-rouge">Api/MediaIntegrityController.cs</code></a>.</p>

<h3 id="requestresponse-models">Request/Response Models</h3>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="k">class</span> <span class="nc">ScanStatusResponse</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="kt">bool</span> <span class="n">IsScanning</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
    <span class="k">public</span> <span class="kt">int</span> <span class="n">TotalFiles</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
    <span class="k">public</span> <span class="kt">int</span> <span class="n">PassedFiles</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
    <span class="k">public</span> <span class="kt">int</span> <span class="n">FailedFiles</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
    <span class="k">public</span> <span class="kt">double</span> <span class="n">HealthPercentage</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
<span class="p">}</span>

<span class="k">public</span> <span class="k">class</span> <span class="nc">ScanRequest</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="kt">string</span><span class="p">?</span> <span class="n">ItemId</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
    <span class="k">public</span> <span class="kt">string</span><span class="p">?</span> <span class="n">LibraryId</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
    <span class="k">public</span> <span class="kt">bool</span> <span class="n">DeepScan</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="k">false</span><span class="p">;</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Plain DTOs — no behavior, just the shape the dashboard’s JavaScript reads and writes. That shape is exactly what’s wrong in the <a href="#update-the-dashboard-was-reading-the-wrong-json-casing">JSON casing bug</a> further down.</p>

<h2 id="admin-dashboard">Admin Dashboard</h2>

<p>The dashboard is a single embedded HTML page: CSS for a stat-card grid and results table, then vanilla JavaScript that polls the API above and renders it. No framework, no build step — Jellyfin serves the file exactly as committed, via <code class="language-plaintext highlighter-rouge">GetPages()</code>.</p>

<div class="language-html highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"stats-grid"</span> <span class="na">id=</span><span class="s">"stats-grid"</span><span class="nt">&gt;</span>
    <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"stat-card"</span><span class="nt">&gt;</span>
        <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"stat-label"</span><span class="nt">&gt;</span>Library Health<span class="nt">&lt;/div&gt;</span>
        <span class="nt">&lt;div</span> <span class="na">class=</span><span class="s">"stat-value status-pass"</span> <span class="na">id=</span><span class="s">"health-pct"</span><span class="nt">&gt;</span>—<span class="nt">&lt;/div&gt;</span>
    <span class="nt">&lt;/div&gt;</span>
    <span class="c">&lt;!-- Total Files / Passed / Failed / Pending / Status cards follow the same pattern --&gt;</span>
<span class="nt">&lt;/div&gt;</span>

<span class="nt">&lt;script&gt;</span>
    <span class="kd">const</span> <span class="nx">API_BASE</span> <span class="o">=</span> <span class="nx">ApiClient</span><span class="p">.</span><span class="nf">getUrl</span><span class="p">(</span><span class="dl">'</span><span class="s1">MediaIntegrity</span><span class="dl">'</span><span class="p">);</span>

    <span class="k">async</span> <span class="kd">function</span> <span class="nf">loadStatus</span><span class="p">()</span> <span class="p">{</span>
        <span class="kd">const</span> <span class="nx">resp</span> <span class="o">=</span> <span class="k">await</span> <span class="nx">ApiClient</span><span class="p">.</span><span class="nf">fetch</span><span class="p">({</span> <span class="na">url</span><span class="p">:</span> <span class="nx">API_BASE</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">/Status</span><span class="dl">'</span><span class="p">,</span> <span class="na">type</span><span class="p">:</span> <span class="dl">'</span><span class="s1">GET</span><span class="dl">'</span> <span class="p">});</span>
        <span class="kd">const</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">JSON</span><span class="p">.</span><span class="nf">parse</span><span class="p">(</span><span class="nx">resp</span><span class="p">);</span>
        <span class="nb">document</span><span class="p">.</span><span class="nf">getElementById</span><span class="p">(</span><span class="dl">'</span><span class="s1">health-pct</span><span class="dl">'</span><span class="p">).</span><span class="nx">textContent</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">healthPercentage</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">%</span><span class="dl">'</span><span class="p">;</span>
        <span class="nb">document</span><span class="p">.</span><span class="nf">getElementById</span><span class="p">(</span><span class="dl">'</span><span class="s1">scan-status</span><span class="dl">'</span><span class="p">).</span><span class="nx">textContent</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">isScanning</span> <span class="p">?</span> <span class="dl">'</span><span class="s1">Scanning...</span><span class="dl">'</span> <span class="p">:</span> <span class="dl">'</span><span class="s1">Idle</span><span class="dl">'</span><span class="p">;</span>
        <span class="c1">// ...remaining stat cards set the same way</span>
    <span class="p">}</span>

    <span class="k">async</span> <span class="kd">function</span> <span class="nf">triggerScan</span><span class="p">(</span><span class="nx">deep</span><span class="p">)</span> <span class="p">{</span>
        <span class="k">await</span> <span class="nx">ApiClient</span><span class="p">.</span><span class="nf">fetch</span><span class="p">({</span>
            <span class="na">url</span><span class="p">:</span> <span class="nx">API_BASE</span> <span class="o">+</span> <span class="dl">'</span><span class="s1">/Scan</span><span class="dl">'</span><span class="p">,</span> <span class="na">type</span><span class="p">:</span> <span class="dl">'</span><span class="s1">POST</span><span class="dl">'</span><span class="p">,</span>
            <span class="na">data</span><span class="p">:</span> <span class="nx">JSON</span><span class="p">.</span><span class="nf">stringify</span><span class="p">({</span> <span class="na">deepScan</span><span class="p">:</span> <span class="nx">deep</span> <span class="p">}),</span> <span class="na">contentType</span><span class="p">:</span> <span class="dl">'</span><span class="s1">application/json</span><span class="dl">'</span>
        <span class="p">});</span>
        <span class="nf">setTimeout</span><span class="p">(</span><span class="nx">loadStatus</span><span class="p">,</span> <span class="mi">1000</span><span class="p">);</span>
    <span class="p">}</span>

    <span class="nf">loadStatus</span><span class="p">();</span>
    <span class="nf">loadResults</span><span class="p">();</span>
    <span class="nf">setInterval</span><span class="p">(</span><span class="nx">loadStatus</span><span class="p">,</span> <span class="mi">10000</span><span class="p">);</span>
<span class="nt">&lt;/script&gt;</span>
</code></pre></div></div>

<p>Two things worth calling out that aren’t obvious from the excerpt above. First, <code class="language-plaintext highlighter-rouge">ApiClient</code> is a global object <em>Jellyfin’s own admin dashboard</em> injects into the page — this plugin never defines it, which turns out to matter a lot (see <a href="#update-the-dashboard-was-never-actually-reachable-in-a-real-browser">how classic Jellyfin pages actually load</a> further down). Second, the full file’s <code class="language-plaintext highlighter-rouge">renderResults</code> (not shown) builds the results table with one template-literal row per item, keyed off small <code class="language-plaintext highlighter-rouge">getStatusClass</code>/<code class="language-plaintext highlighter-rouge">getStatusLabel</code> helpers that map the numeric <code class="language-plaintext highlighter-rouge">ScanStatus</code> enum to a CSS class and label.</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/Web/integrity_dashboard.html"><code class="language-plaintext highlighter-rouge">Web/integrity_dashboard.html</code></a>.</p>

<p>That <code class="language-plaintext highlighter-rouge">setInterval(loadStatus, 10000)</code> at the bottom is doing more work than it looks like. A new file landing in a watched folder while someone’s mid-episode doesn’t show up as a quick blip — the scan sits waiting for playback to end before it ever touches ffmpeg, and the dashboard keeps polling <code class="language-plaintext highlighter-rouge">IsScanning</code> through the whole wait:</p>

<pre><code class="language-mermaid">%%{init: {"theme": "base", "themeVariables": {
  "actorBkg": "#17221f",
  "actorBorder": "#3e6e67",
  "actorTextColor": "#e7ede9",
  "actorLineColor": "#3e6e67",
  "signalColor": "#5c6b75",
  "signalTextColor": "#2a2a2a",
  "labelBoxBkgColor": "#2a2013",
  "labelBoxBorderColor": "#e3a857",
  "labelTextColor": "#f4d9a8",
  "loopTextColor": "#2a2a2a",
  "noteBkgColor": "#1d2b27",
  "noteBorderColor": "#3e6e67",
  "noteTextColor": "#e7ede9",
  "activationBorderColor": "#5fa88f",
  "activationBkgColor": "#16332c",
  "sequenceNumberColor": "#101a18",
  "fontFamily": "monospace",
  "fontSize": "13px"
}}}%%
sequenceDiagram
    participant JF as Jellyfin Core
    participant LM as LibraryMonitor
    participant SE as ScanEngine
    participant SM as SessionManager
    participant DB as scan_results

    JF-&gt;&gt;LM: ItemAdded (new episode copied in)
    activate LM
    LM-&gt;&gt;LM: ScanOnItemAdded == true?
    LM-&gt;&gt;SE: ScanItemAsync(item, Header)
    deactivate LM
    activate SE
    SE-&gt;&gt;SE: acquire concurrency slot
    SE-&gt;&gt;SM: any session with NowPlayingItem?
    SM--&gt;&gt;SE: yes, someone is watching
    loop every 30 seconds
        SE-&gt;&gt;SM: still playing?
        SM--&gt;&gt;SE: yes
    end
    Note over SE: playback ends
    SM--&gt;&gt;SE: no
    SE-&gt;&gt;SE: apply DelayBetweenFilesMs
    SE-&gt;&gt;SE: ffprobe the file
    SE-&gt;&gt;DB: SaveResultAsync(Pass, Header)
    deactivate SE
    Note over DB: the dashboard's next&lt;br/&gt;GET /Status reflects the new file
</code></pre>

<p>None of that shows up as a distinct dashboard state — <code class="language-plaintext highlighter-rouge">IsScanning</code> is just <code class="language-plaintext highlighter-rouge">true</code> for however long the wait plus the actual scan takes, which is why the “Status” card can sit on “Scanning…” for a lot longer than the file itself would ever take to check.</p>

<h2 id="api-usage-examples">API Usage Examples</h2>

<h3 id="check-library-health-from-the-command-line">Check library health from the command line</h3>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Get overall status</span>
curl <span class="nt">-s</span> http://localhost:8096/MediaIntegrity/Status <span class="se">\</span>
  <span class="nt">-H</span> <span class="s2">"X-Emby-Token: YOUR_API_KEY"</span> | jq <span class="nb">.</span>

<span class="c"># Get failed files only</span>
curl <span class="nt">-s</span> <span class="s2">"http://localhost:8096/MediaIntegrity/Results?status=2"</span> <span class="se">\</span>
  <span class="nt">-H</span> <span class="s2">"X-Emby-Token: YOUR_API_KEY"</span> | jq <span class="s1">'.items[].filePath'</span>

<span class="c"># Trigger a header scan</span>
curl <span class="nt">-X</span> POST http://localhost:8096/MediaIntegrity/Scan <span class="se">\</span>
  <span class="nt">-H</span> <span class="s2">"X-Emby-Token: YOUR_API_KEY"</span> <span class="se">\</span>
  <span class="nt">-H</span> <span class="s2">"Content-Type: application/json"</span> <span class="se">\</span>
  <span class="nt">-d</span> <span class="s1">'{"deepScan": false}'</span>
</code></pre></div></div>

<h2 id="update-status-accuracy-and-library-filtering">Update: Status Accuracy and Library Filtering</h2>

<p>Two things in the original <code class="language-plaintext highlighter-rouge">GetStatus</code>/<code class="language-plaintext highlighter-rouge">GetResults</code> design didn’t hold up once real libraries were scanned:</p>

<p><strong><code class="language-plaintext highlighter-rouge">TotalFiles</code>/<code class="language-plaintext highlighter-rouge">PendingFiles</code> were derived entirely from the <code class="language-plaintext highlighter-rouge">scan_results</code> table</strong> — <code class="language-plaintext highlighter-rouge">COUNT(*)</code> over rows that are only ever written as Pass/Fail/Error (nothing ever inserts a “Pending” row), so <code class="language-plaintext highlighter-rouge">PendingFiles</code> was always <code class="language-plaintext highlighter-rouge">0</code>, and <code class="language-plaintext highlighter-rouge">TotalFiles</code> always equaled <code class="language-plaintext highlighter-rouge">ScannedFiles</code>, even on a freshly-installed library with thousands of files that hadn’t been scanned yet. Worse, an item scanned in both phases (header + deep) produced two rows in <code class="language-plaintext highlighter-rouge">scan_results</code>, so <code class="language-plaintext highlighter-rouge">COUNT(*)</code> double-counted it.</p>

<p>The fix: <code class="language-plaintext highlighter-rouge">GetStatisticsAsync</code> now dedupes by <code class="language-plaintext highlighter-rouge">item_id</code>, keeping only the highest-<code class="language-plaintext highlighter-rouge">scan_phase</code> (most authoritative) row per item via a <code class="language-plaintext highlighter-rouge">ROW_NUMBER() OVER (PARTITION BY item_id ...)</code> window query, and adds a distinct <code class="language-plaintext highlighter-rouge">ErroredFiles</code> bucket (previously errors counted toward the total but vanished from the pass/fail breakdown). The controller then derives the real <code class="language-plaintext highlighter-rouge">TotalFiles</code> from <code class="language-plaintext highlighter-rouge">ILibraryManager.GetItemList(...)</code> — the same query shape <code class="language-plaintext highlighter-rouge">ScanEngine</code> and the scheduled tasks already use — and computes <code class="language-plaintext highlighter-rouge">PendingFiles = TotalFiles - ScannedFiles</code>. The dashboard grew an “Errored” stat card to match.</p>

<p><strong><code class="language-plaintext highlighter-rouge">libraryId</code> on <code class="language-plaintext highlighter-rouge">GET /Results</code> was a no-op.</strong> The API accepted the parameter, the XML doc even said “not yet implemented,” and the SQL query never touched it. Fixed by resolving <code class="language-plaintext highlighter-rouge">libraryId</code> to the set of item IDs currently in that library (via the same <code class="language-plaintext highlighter-rouge">ILibraryManager</code> query, scoped with <code class="language-plaintext highlighter-rouge">ParentId</code>) in the controller, then passing that set down to a parameterized <code class="language-plaintext highlighter-rouge">item_id IN (...)</code> clause — keeping the database layer free of any dependency on Jellyfin’s library structure.</p>

<h2 id="update-a-real-settings-page">Update: A Real Settings Page</h2>

<p>Every field in <code class="language-plaintext highlighter-rouge">PluginConfiguration</code> — throttling, quiet hours, ffmpeg path overrides, the on-add/on-remove toggles — could originally only be changed by hand-editing the plugin’s XML config file on disk. There was no in-app way to configure it at all, which meant Jellyfin’s admin dashboard technically listed the plugin as “configurable” without actually offering a working configuration UI.</p>

<p>Fixed with a second web page (<code class="language-plaintext highlighter-rouge">integrity_settings.html</code>), registered alongside the dashboard via a second <code class="language-plaintext highlighter-rouge">PluginPageInfo</code> entry in <code class="language-plaintext highlighter-rouge">GetPages()</code>. It’s a straightforward form over all twelve config properties, using the same <code class="language-plaintext highlighter-rouge">ApiClient.getPluginConfiguration</code>/<code class="language-plaintext highlighter-rouge">updatePluginConfiguration</code> JS calls Jellyfin’s own plugin pages use to load and save. One gotcha worth flagging: the settings page’s JS has to address the plugin by its <strong>dashless</strong> GUID (<code class="language-plaintext highlighter-rouge">c8f4a3b21d5e4f6a9b7c2e8d0f1a3b5c</code>, no hyphens) — Jellyfin 10.11.11’s <code class="language-plaintext highlighter-rouge">/Plugins/{id}/Configuration</code> routes 404 on the canonical hyphenated form. The dashboard and settings pages now cross-link to each other via <code class="language-plaintext highlighter-rouge">configurationpage?name=...</code>.</p>

<h2 id="update-the-dashboard-was-reading-the-wrong-json-casing">Update: The Dashboard Was Reading the Wrong JSON Casing</h2>

<p>This one is worth calling out plainly: <strong>the dashboard likely never rendered real data in any live browser session.</strong> Its JS reads <code class="language-plaintext highlighter-rouge">data.isScanning</code>, <code class="language-plaintext highlighter-rouge">data.totalFiles</code>, <code class="language-plaintext highlighter-rouge">item.filePath</code>, and so on — camelCase, which is the ASP.NET Core default for JSON responses. But Jellyfin’s host doesn’t apply that default to controller output; it serializes using the raw C# property names, so a real <code class="language-plaintext highlighter-rouge">/MediaIntegrity/Status</code> response looks like <code class="language-plaintext highlighter-rouge">{"IsScanning":false,"TotalFiles":1,...}</code> — PascalCase. Every field read in <code class="language-plaintext highlighter-rouge">loadStatus</code>, <code class="language-plaintext highlighter-rouge">renderResults</code>, and <code class="language-plaintext highlighter-rouge">renderPagination</code> was silently reading <code class="language-plaintext highlighter-rouge">undefined</code>.</p>

<p>This surfaced only once an integration test piped a real response through <code class="language-plaintext highlighter-rouge">jq</code> and the PascalCase keys were staring back. Worth noting the asymmetry: incoming request bodies deserialize case-<em>insensitively</em> (the dashboard’s own <code class="language-plaintext highlighter-rouge">triggerScan()</code> already sent <code class="language-plaintext highlighter-rouge">{ deepScan: deep }</code> and it correctly bound to <code class="language-plaintext highlighter-rouge">ScanRequest.DeepScan</code>), so only the outgoing side needed the fix. The settings page above was unaffected, since its JS was written by copying the C# <code class="language-plaintext highlighter-rouge">PluginConfiguration</code> property names directly — which happened to already be PascalCase.</p>

<p>Every <code class="language-plaintext highlighter-rouge">data.</code>/<code class="language-plaintext highlighter-rouge">item.</code> field access in the dashboard is now PascalCase, verified against a real Jellyfin 10.11.11 instance end-to-end (trigger a scan, poll status, render results) rather than just by reading the diff.</p>

<h2 id="update-the-dashboard-was-never-actually-reachable-in-a-real-browser">Update: The Dashboard Was Never Actually Reachable in a Real Browser</h2>

<p>The PascalCase fix above turned out not to be the whole story. Building a Playwright suite to drive this plugin’s pages through an actual browser — not curl+grep, not a REST call — surfaced something more fundamental: <strong>both config pages had likely never rendered at all in a genuine admin session.</strong></p>

<p>Jellyfin’s classic (non-React) admin dashboard doesn’t navigate to a plugin’s config page the way a browser normally would. It fetches the page’s HTML via AJAX through an internal <code class="language-plaintext highlighter-rouge">loadView</code>/<code class="language-plaintext highlighter-rouge">ViewManager</code> mechanism and injects the result as a <em>fragment</em> into the already-running single-page app — which is what supplies the global <code class="language-plaintext highlighter-rouge">ApiClient</code>/<code class="language-plaintext highlighter-rouge">Dashboard</code> objects this page’s own JS depends on. Both <code class="language-plaintext highlighter-rouge">integrity_dashboard.html</code> and <code class="language-plaintext highlighter-rouge">integrity_settings.html</code> were written as full standalone documents (<code class="language-plaintext highlighter-rouge">&lt;!DOCTYPE html&gt;&lt;html&gt;&lt;head&gt;...&lt;body&gt;</code>), and that structural mismatch broke two different ways depending on how you reached the page:</p>

<ul>
  <li>A direct URL (<code class="language-plaintext highlighter-rouge">.../configurationpage?name=...</code>) forces a real top-level page load, which never gets <code class="language-plaintext highlighter-rouge">ApiClient</code> injected: <code class="language-plaintext highlighter-rouge">ReferenceError: ApiClient is not defined</code>.</li>
  <li>A genuine in-app click on the plugin’s own auto-generated “Settings” link instead throws inside <em>Jellyfin’s own bundled code</em> — <code class="language-plaintext highlighter-rouge">Cannot read properties of undefined (reading 'classList')</code> in <code class="language-plaintext highlighter-rouge">Object.loadView</code> — because it’s trying to graft a full document into the DOM where it expects a content fragment.</li>
</ul>

<p>Both are the same root cause, confirmed via two distinct real stack traces, not two separate bugs. There’s no public documentation for the expected fragment shape (this plugin ships with no external API access during development), so it was reverse-engineered by inspecting a real rendered session: wrap the content in <code class="language-plaintext highlighter-rouge">&lt;div id="...Page" data-role="page" class="page type-interior pluginConfigurationPage"&gt;&lt;div data-role="content" class="content-primary"&gt;...&lt;/div&gt;&lt;/div&gt;</code>, with no <code class="language-plaintext highlighter-rouge">&lt;!DOCTYPE&gt;</code>/<code class="language-plaintext highlighter-rouge">&lt;html&gt;</code>/<code class="language-plaintext highlighter-rouge">&lt;head&gt;</code>/<code class="language-plaintext highlighter-rouge">&lt;body&gt;</code>/<code class="language-plaintext highlighter-rouge">&lt;title&gt;</code> wrapper.</p>

<p>Fixing the structure surfaced two smaller, related issues in the same pass:</p>
<ul>
  <li>The pages’ own internal cross-links (dashboard’s “Settings »”, settings’ “« Back to Dashboard”) used plain relative <code class="language-plaintext highlighter-rouge">href</code>s with no SPA hash prefix — clicking either one forced the exact same full-page-load path and reproduced <code class="language-plaintext highlighter-rouge">ApiClient is not defined</code>, even after the fragment fix. Jellyfin’s own auto-generated links use <code class="language-plaintext highlighter-rouge">href="#/configurationpage?name=..."</code>; ours needed the same <code class="language-plaintext highlighter-rouge">#/</code> prefix.</li>
  <li>Those same nav links, positioned with <code class="language-plaintext highlighter-rouge">float: right</code>, sat directly underneath Jellyfin’s fixed app-bar header on this Jellyfin version’s React-based chrome — a real click-target problem for actual users, confirmed by bounding-box inspection, not just a browser-automation artifact. Fixed with more top padding on the page container.</li>
</ul>

<p>Worth flagging as expected behavior rather than a bug: Jellyfin’s <code class="language-plaintext highlighter-rouge">ViewManager</code> hides a previously-visited page (<code class="language-plaintext highlighter-rouge">display:none</code>) instead of removing it from the DOM when you navigate back to it, re-injecting a fresh copy — including a fresh copy of the page’s own <code class="language-plaintext highlighter-rouge">&lt;script&gt;</code> block — on every visit. Each visit’s <code class="language-plaintext highlighter-rouge">setInterval(loadStatus, 10000)</code> polling loop keeps running on the hidden, stale copy too. Harmless for a user (only the visible copy is ever read), but worth knowing if you’re writing your own plugin-page tests against a classic Jellyfin dashboard page: scope element lookups to the visible page rather than a bare <code class="language-plaintext highlighter-rouge">#id</code>, since Jellyfin doesn’t guarantee that ID stays unique for long.</p>

<h2 id="update-an-in-plugin-update-checker">Update: An In-Plugin Update Checker</h2>

<p>Running a demo instance on an LXC surfaced an obvious gap: nothing told an admin a newer build existed, and updating meant manually rebuilding and redeploying the DLL by hand. The fix leans on Jellyfin’s own machinery rather than reinventing it — the same <code class="language-plaintext highlighter-rouge">IInstallationManager</code> interface Dashboard &gt; Plugins &gt; Catalog uses internally to list and install plugin versions, injected into a new plugin service exactly the way <code class="language-plaintext highlighter-rouge">ILibraryManager</code> already is in the controller. Its shape (confirmed by reflecting against the real Jellyfin 10.11.11 server assemblies rather than guessing from memory, since this plugin has no live internet access during development) is close to what you’d expect: <code class="language-plaintext highlighter-rouge">GetAvailablePackages</code> returns everything Jellyfin currently knows about across every registered plugin repository, <code class="language-plaintext highlighter-rouge">FilterPackages</code> narrows that down to one plugin by GUID, and <code class="language-plaintext highlighter-rouge">InstallPackage</code> triggers a real install using the exact same code path the Catalog page’s own “Update” button does.</p>

<p><strong>The one hard constraint this whole feature sits on top of</strong>: <code class="language-plaintext highlighter-rouge">IInstallationManager</code> only ever sees packages from repositories an admin has <em>already registered</em> under Dashboard &gt; Plugins &gt; Repositories. A plugin has no way to discover its own updates from a manifest Jellyfin doesn’t know about — and this plugin deliberately doesn’t write to that registration list on its own behalf, since it’s global server config, not this plugin’s own. That’s a one-time, explicit setup step for whoever runs it, documented on the settings page itself rather than hidden.</p>

<p>That constraint is also what shaped the <strong>stable vs. development channel</strong> design. Since a registered repository can list many versions, and Jellyfin doesn’t have a first-class idea of “channels,” this plugin publishes two separate manifests — the existing <code class="language-plaintext highlighter-rouge">manifest.json</code> (stable, updated on tagged releases) and a new <code class="language-plaintext highlighter-rouge">manifest-unstable.json</code> (development builds, cut automatically on every push to <code class="language-plaintext highlighter-rouge">main</code> — more on that in the <a href="/jellyfin-media-integrity-deployment-operations/#update-automated-development-releases">deployment article</a>). Each <code class="language-plaintext highlighter-rouge">VersionInfo</code> Jellyfin returns carries a <code class="language-plaintext highlighter-rouge">RepositoryUrl</code> stamped from whichever registered repository it came from, so the plugin classifies “stable” vs. “dev” by matching that URL against two configurable settings fields, rather than trusting a repository’s free-text display name (which an admin could label anything).</p>

<p>One assumption that turned out to be wrong, caught only by hitting the real endpoints rather than trusting the usual ASP.NET Core default: <strong>Jellyfin serializes this plugin’s new channel enum as its string name</strong> (<code class="language-plaintext highlighter-rouge">"Stable"</code>/<code class="language-plaintext highlighter-rouge">"Development"</code>), not the underlying <code class="language-plaintext highlighter-rouge">0</code>/<code class="language-plaintext highlighter-rouge">1</code> a bare <code class="language-plaintext highlighter-rouge">System.Text.Json</code> setup would produce. Both the dashboard’s new version banner and the settings page’s channel dropdown are written against that string, confirmed by POSTing both a string and (hypothetically) an int body directly against the live endpoint rather than assuming either would work.</p>

<p>The dashboard now shows the running version plus, when a newer one exists for the configured channel, an “Update Available” banner with a one-click “Update Now” button; settings gained the channel dropdown and the two manifest-URL overrides. A daily scheduled task keeps the check result cached so opening the dashboard doesn’t fire a network call every time.</p>

<h2 id="whats-next">What’s Next</h2>

<p>The <a href="/jellyfin-media-integrity-deployment-operations/">next article</a> covers deployment and operations: installing the plugin in Proxmox LXC containers, configuring for CephFS storage, setting up monitoring/alerting, and the CI/CD pipeline for plugin releases.</p>

<h2 id="series-navigation">Series Navigation</h2>

<ol>
  <li><a href="/jellyfin-media-integrity-scanner-introduction/">Introduction &amp; Problem Statement</a></li>
  <li><a href="/jellyfin-media-integrity-architecture-design/">Architecture &amp; Design Decisions</a></li>
  <li><a href="/jellyfin-media-integrity-scanner-core/">Building the Scanner Core</a></li>
  <li><strong>The Dashboard &amp; API</strong> (this post)</li>
  <li><a href="/jellyfin-media-integrity-deployment-operations/">Deployment &amp; Operations</a></li>
  <li><a href="/jellyfin-media-integrity-release-and-updates/">v0.1.1 Release: Update Checker &amp; Auto-Update</a></li>
</ol>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="homelab" /><category term="media-server" /><category term="jellyfin" /><category term="media-integrity" /><category term="rest-api" /><category term="dashboard" /><category term="html" /><category term="javascript" /><category term="plugin-development" /><summary type="html"><![CDATA[Implementing the REST API and admin dashboard for the Jellyfin Media Integrity Scanner plugin. Covers the ASP.NET Core controller, scan result queries, manual scan triggers, and the HTML/JavaScript dashboard with library health overview. Part 4 of a 6-part development series.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-dashboard-api.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-dashboard-api.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Jellyfin Media Integrity Scanner: Building the Scanner Core</title><link href="https://mcgarrah.org/jellyfin-media-integrity-scanner-core/" rel="alternate" type="text/html" title="Jellyfin Media Integrity Scanner: Building the Scanner Core" /><published>2026-08-10T00:00:00+00:00</published><updated>2026-08-10T00:00:00+00:00</updated><id>https://mcgarrah.org/jellyfin-media-integrity-scanner-core</id><content type="html" xml:base="https://mcgarrah.org/jellyfin-media-integrity-scanner-core/"><![CDATA[<p>The <a href="/jellyfin-media-integrity-architecture-design/">architecture article</a> laid out the design decisions — two-phase scanning, I/O throttling, SQLite persistence, event-driven updates. This article implements the core: the plugin skeleton, FFmpeg integration, and the bounded scan engine.</p>

<!-- excerpt-end -->

<p>This is Part 3 of the <a href="/jellyfin-media-integrity-scanner-introduction/">Jellyfin Media Integrity Scanner</a> development series. The scanner core described below is real, shipped code, not a target design, built and tested against a dedicated Proxmox LXC container running .NET 9 and <code class="language-plaintext highlighter-rouge">jellyfin-ffmpeg</code> alongside GitHub Actions CI. A few things evolved from the version shown here as testing surfaced real gaps: the FFmpeg process wrapper now drains stdout/stderr concurrently with process exit, to avoid an OS pipe-buffer deadlock on large stderr output, and kills the process tree on cancellation instead of leaving orphaned ffmpeg processes; <code class="language-plaintext highlighter-rouge">IsScanning</code> is tracked with <code class="language-plaintext highlighter-rouge">Interlocked</code> counters rather than a semaphore-count comparison; and the scan engine gained two pacing mechanisms not shown below — a quiet-hours window and a post-scan read-rate throttle, covered in the <a href="#update-quiet-hours-and-read-rate-throttling">Scan Pacing update</a> further down.</p>

<h2 id="project-structure">Project Structure</h2>

<p>Following the <a href="https://github.com/jellyfin/jellyfin-plugin-template">jellyfin-plugin-template</a> pattern:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>jellyfin-plugin-media-integrity-scanner/
├── Jellyfin.Plugin.MediaIntegrityScanner/
│   ├── Plugin.cs                    # Plugin entry point
│   ├── PluginConfiguration.cs       # User-configurable settings
│   ├── ScheduledTasks/
│   │   ├── HeaderScanTask.cs        # Phase 1 scheduled task
│   │   └── DeepScanTask.cs          # Phase 2 scheduled task
│   ├── Scanner/
│   │   ├── IScanEngine.cs           # Scanner interface
│   │   ├── ScanEngine.cs            # Bounded, throttled scan orchestrator
│   │   ├── FfmpegWrapper.cs         # FFmpeg/ffprobe process management
│   │   ├── FfmpegResolver.cs        # Cross-platform binary resolution
│   │   └── ScanResult.cs            # Result model
│   ├── Data/
│   │   ├── IDatabaseManager.cs      # Database interface
│   │   ├── SqliteDatabaseManager.cs # SQLite implementation
│   │   └── Models/
│   │       └── ScanRecord.cs        # Database entity
│   ├── EventHandlers/
│   │   └── LibraryMonitor.cs        # ItemAdded/Removed hooks
│   ├── Api/
│   │   └── MediaIntegrityController.cs  # REST API
│   └── Web/
│       └── integrity_dashboard.html # Admin UI
├── Jellyfin.Plugin.MediaIntegrityScanner.csproj
├── Jellyfin.Plugin.MediaIntegrityScanner.sln
├── Directory.Build.props
├── .github/workflows/build.yml
└── manifest.json
</code></pre></div></div>

<h2 id="plugin-entry-point">Plugin Entry Point</h2>

<p>Every Jellyfin plugin extends <code class="language-plaintext highlighter-rouge">BasePlugin&lt;TConfiguration&gt;</code>, and Jellyfin constructs it once at startup via DI. A lot of this plugin’s <em>other</em> classes — <code class="language-plaintext highlighter-rouge">ScanEngine</code>, the scheduled tasks, the API controller — reach back into it through a static <code class="language-plaintext highlighter-rouge">Instance</code> property rather than getting <code class="language-plaintext highlighter-rouge">PluginConfiguration</code> injected directly, since Jellyfin’s container doesn’t thread plugin config through to every consumer on its own:</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="k">class</span> <span class="nc">Plugin</span> <span class="p">:</span> <span class="n">BasePlugin</span><span class="p">&lt;</span><span class="n">PluginConfiguration</span><span class="p">&gt;,</span> <span class="n">IHasWebPages</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="nf">Plugin</span><span class="p">(</span><span class="n">IApplicationPaths</span> <span class="n">applicationPaths</span><span class="p">,</span> <span class="n">IXmlSerializer</span> <span class="n">xmlSerializer</span><span class="p">)</span>
        <span class="p">:</span> <span class="k">base</span><span class="p">(</span><span class="n">applicationPaths</span><span class="p">,</span> <span class="n">xmlSerializer</span><span class="p">)</span>
    <span class="p">{</span>
        <span class="n">Instance</span> <span class="p">=</span> <span class="k">this</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="k">public</span> <span class="k">static</span> <span class="n">Plugin</span><span class="p">?</span> <span class="n">Instance</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">private</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span>
    <span class="k">public</span> <span class="k">override</span> <span class="n">Guid</span> <span class="n">Id</span> <span class="p">=&gt;</span> <span class="n">Guid</span><span class="p">.</span><span class="nf">Parse</span><span class="p">(</span><span class="s">"c8f4a3b2-1d5e-4f6a-9b7c-2e8d0f1a3b5c"</span><span class="p">);</span>

    <span class="k">public</span> <span class="n">IEnumerable</span><span class="p">&lt;</span><span class="n">PluginPageInfo</span><span class="p">&gt;</span> <span class="nf">GetPages</span><span class="p">()</span> <span class="p">=&gt;</span> <span class="k">new</span><span class="p">[]</span>
    <span class="p">{</span>
        <span class="k">new</span> <span class="n">PluginPageInfo</span>
        <span class="p">{</span>
            <span class="n">Name</span> <span class="p">=</span> <span class="s">"Media Integrity"</span><span class="p">,</span>
            <span class="n">EmbeddedResourcePath</span> <span class="p">=</span> <span class="nf">GetType</span><span class="p">().</span><span class="n">Namespace</span> <span class="p">+</span> <span class="s">".Web.integrity_dashboard.html"</span>
        <span class="p">}</span>
    <span class="p">};</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">GetPages()</code> is what makes the admin dashboard show up under Dashboard → Plugins at all — Jellyfin sees <code class="language-plaintext highlighter-rouge">IHasWebPages</code> and serves each <code class="language-plaintext highlighter-rouge">EmbeddedResourcePath</code> as a config page (it later grew a second entry for the settings page; see the <a href="/jellyfin-media-integrity-dashboard-api/#update-a-real-settings-page">dashboard article’s update</a>). The <code class="language-plaintext highlighter-rouge">Id</code> GUID has to match <code class="language-plaintext highlighter-rouge">manifest.json</code> exactly, or Jellyfin treats an upgrade as installing an unrelated plugin.</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/Plugin.cs"><code class="language-plaintext highlighter-rouge">Plugin.cs</code></a>.</p>

<h2 id="plugin-configuration">Plugin Configuration</h2>

<p><code class="language-plaintext highlighter-rouge">PluginConfiguration</code> is a plain settings bag — Jellyfin serializes it to XML on disk and, later, exposes it to an in-app settings page (see the <a href="/jellyfin-media-integrity-dashboard-api/#update-a-real-settings-page">dashboard article</a>). The fields fall into a few groups; here’s the scanning-related subset:</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="k">class</span> <span class="nc">PluginConfiguration</span> <span class="p">:</span> <span class="n">BasePluginConfiguration</span>
<span class="p">{</span>
    <span class="c1">// Scanning behavior</span>
    <span class="k">public</span> <span class="kt">int</span> <span class="n">MaxConcurrentScans</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="m">1</span><span class="p">;</span>
    <span class="k">public</span> <span class="kt">int</span> <span class="n">DelayBetweenFilesMs</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="m">5000</span><span class="p">;</span>
    <span class="k">public</span> <span class="kt">bool</span> <span class="n">PauseDuringPlayback</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="k">true</span><span class="p">;</span>
    <span class="k">public</span> <span class="kt">bool</span> <span class="n">EnableDeepScan</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="k">false</span><span class="p">;</span>

    <span class="c1">// Throttling / scheduling</span>
    <span class="k">public</span> <span class="kt">int</span> <span class="n">MaxReadRateMbPerSec</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="m">10</span><span class="p">;</span>
    <span class="k">public</span> <span class="kt">bool</span> <span class="n">UseQuietHoursOnly</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="k">false</span><span class="p">;</span>
    <span class="k">public</span> <span class="kt">string</span> <span class="n">QuietHoursStart</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="s">"02:00"</span><span class="p">;</span>
    <span class="k">public</span> <span class="kt">string</span> <span class="n">QuietHoursEnd</span> <span class="p">{</span> <span class="k">get</span><span class="p">;</span> <span class="k">set</span><span class="p">;</span> <span class="p">}</span> <span class="p">=</span> <span class="s">"06:00"</span><span class="p">;</span>

    <span class="c1">// FFmpeg path overrides, event-driven scan toggles...</span>
<span class="p">}</span>
</code></pre></div></div>

<p>None of these fields <em>do</em> anything by themselves — they’re read by whoever cares. <code class="language-plaintext highlighter-rouge">MaxConcurrentScans</code> only matters because <code class="language-plaintext highlighter-rouge">ScanEngine</code>’s constructor sizes a <code class="language-plaintext highlighter-rouge">SemaphoreSlim</code> from it; <code class="language-plaintext highlighter-rouge">UseQuietHoursOnly</code>/<code class="language-plaintext highlighter-rouge">QuietHoursStart</code>/<code class="language-plaintext highlighter-rouge">QuietHoursEnd</code> only matter because <code class="language-plaintext highlighter-rouge">ScanThrottle.IsWithinQuietHours</code> checks them (see the <a href="#update-quiet-hours-and-read-rate-throttling">pacing update</a> below). The real file has grown a second set of fields since — update-channel and manifest-URL settings for the <a href="/jellyfin-media-integrity-release-and-updates/">v0.1.1 update checker</a> — omitted here since they’re unrelated to the scanner core.</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/PluginConfiguration.cs"><code class="language-plaintext highlighter-rouge">PluginConfiguration.cs</code></a>.</p>

<h2 id="ffmpeg-binary-resolution">FFmpeg Binary Resolution</h2>

<p>Jellyfin ships its own bundled <code class="language-plaintext highlighter-rouge">jellyfin-ffmpeg</code>, but this plugin can’t assume it’s on <code class="language-plaintext highlighter-rouge">PATH</code>, or even that the admin is running the packaged build. <code class="language-plaintext highlighter-rouge">FfmpegResolver</code> tries four things in order, falling through only if the previous one comes up empty:</p>

<ol>
  <li><strong>A user-configured override</strong> (<code class="language-plaintext highlighter-rouge">FfmpegPathOverride</code>/<code class="language-plaintext highlighter-rouge">FfprobePathOverride</code>) — respected first, so an admin can always pin a specific build.</li>
  <li><strong>Jellyfin’s own configured ffmpeg path</strong> (<code class="language-plaintext highlighter-rouge">IServerConfigurationManager.GetEncodingOptions().EncoderAppPath</code>) — the server already resolved this once for its own transcoding, so reuse it instead of asking the admin to configure the same path twice.</li>
  <li><strong>Known install locations per OS</strong> — <code class="language-plaintext highlighter-rouge">/usr/lib/jellyfin-ffmpeg/ffmpeg</code> on Linux, the Jellyfin Server folder on Windows, Homebrew’s prefix on macOS.</li>
  <li><strong>A plain <code class="language-plaintext highlighter-rouge">PATH</code> lookup</strong>, the same way a shell would find it.</li>
</ol>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="kt">string</span> <span class="nf">ResolveFfmpegPath</span><span class="p">()</span> <span class="p">=&gt;</span>
    <span class="nf">ResolveBinary</span><span class="p">(</span><span class="s">"ffmpeg"</span><span class="p">,</span> <span class="n">Plugin</span><span class="p">.</span><span class="n">Instance</span><span class="p">?.</span><span class="n">Configuration</span><span class="p">?.</span><span class="n">FfmpegPathOverride</span><span class="p">);</span>

<span class="k">private</span> <span class="kt">string</span> <span class="nf">ResolveBinary</span><span class="p">(</span><span class="kt">string</span> <span class="n">binaryName</span><span class="p">,</span> <span class="kt">string</span><span class="p">?</span> <span class="n">userOverride</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">if</span> <span class="p">(!</span><span class="kt">string</span><span class="p">.</span><span class="nf">IsNullOrEmpty</span><span class="p">(</span><span class="n">userOverride</span><span class="p">)</span> <span class="p">&amp;&amp;</span> <span class="n">File</span><span class="p">.</span><span class="nf">Exists</span><span class="p">(</span><span class="n">userOverride</span><span class="p">))</span>
    <span class="p">{</span>
        <span class="k">return</span> <span class="n">userOverride</span><span class="p">;</span>
    <span class="p">}</span>

    <span class="kt">var</span> <span class="n">serverFfmpeg</span> <span class="p">=</span> <span class="n">_config</span><span class="p">.</span><span class="nf">GetEncodingOptions</span><span class="p">().</span><span class="n">EncoderAppPath</span><span class="p">;</span>
    <span class="c1">// ... then platform-specific candidates, then a PATH lookup ...</span>

    <span class="k">throw</span> <span class="k">new</span> <span class="nf">InvalidOperationException</span><span class="p">(</span>
        <span class="s">$"</span><span class="p">{</span><span class="n">binaryName</span><span class="p">}</span><span class="s"> not found. Install ffmpeg or configure the path in Media Integrity Scanner settings."</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p>If all four come up empty, it throws rather than silently disabling scanning — a scanner that can’t run ffmpeg has no useful degraded mode. <code class="language-plaintext highlighter-rouge">ResolveFfprobePath</code> shares the exact same <code class="language-plaintext highlighter-rouge">ResolveBinary</code> helper, just parameterized on <code class="language-plaintext highlighter-rouge">"ffprobe"</code> and its own override field.</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/Scanner/FfmpegResolver.cs"><code class="language-plaintext highlighter-rouge">Scanner/FfmpegResolver.cs</code></a>.</p>

<h2 id="the-scan-engine">The Scan Engine</h2>

<p><code class="language-plaintext highlighter-rouge">ScanEngine</code> is the one choke point every trigger — library events, scheduled tasks, manual API calls — eventually calls into, which is what makes “bounded” and “thread-safe” actual guarantees rather than just words: a <code class="language-plaintext highlighter-rouge">SemaphoreSlim</code> sized to <code class="language-plaintext highlighter-rouge">MaxConcurrentScans</code> gates every concurrent scan through the same instance, no matter what kicked it off.</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="nf">ScanEngine</span><span class="p">(</span><span class="n">FfmpegWrapper</span> <span class="n">ffmpeg</span><span class="p">,</span> <span class="n">IDatabaseManager</span> <span class="n">db</span><span class="p">,</span> <span class="n">ISessionManager</span> <span class="n">sessions</span><span class="p">,</span> <span class="n">ILogger</span><span class="p">&lt;</span><span class="n">ScanEngine</span><span class="p">&gt;</span> <span class="n">logger</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">var</span> <span class="n">maxConcurrent</span> <span class="p">=</span> <span class="n">Plugin</span><span class="p">.</span><span class="n">Instance</span><span class="p">?.</span><span class="n">Configuration</span><span class="p">?.</span><span class="n">MaxConcurrentScans</span> <span class="p">??</span> <span class="m">1</span><span class="p">;</span>
    <span class="n">_scanLock</span> <span class="p">=</span> <span class="k">new</span> <span class="nf">SemaphoreSlim</span><span class="p">(</span><span class="n">maxConcurrent</span><span class="p">);</span>
<span class="p">}</span>

<span class="k">public</span> <span class="k">async</span> <span class="n">Task</span> <span class="nf">ScanItemAsync</span><span class="p">(</span><span class="n">BaseItem</span> <span class="n">item</span><span class="p">,</span> <span class="n">ScanPhase</span> <span class="n">phase</span><span class="p">,</span> <span class="n">CancellationToken</span> <span class="n">cancellationToken</span><span class="p">)</span>
<span class="p">{</span>
    <span class="k">await</span> <span class="n">_scanLock</span><span class="p">.</span><span class="nf">WaitAsync</span><span class="p">(</span><span class="n">cancellationToken</span><span class="p">);</span>
    <span class="k">try</span>
    <span class="p">{</span>
        <span class="k">if</span> <span class="p">(</span><span class="nf">ShouldPauseForPlayback</span><span class="p">())</span>
        <span class="p">{</span>
            <span class="k">await</span> <span class="nf">WaitForPlaybackEnd</span><span class="p">(</span><span class="n">cancellationToken</span><span class="p">);</span>
        <span class="p">}</span>

        <span class="kt">var</span> <span class="n">delay</span> <span class="p">=</span> <span class="n">Plugin</span><span class="p">.</span><span class="n">Instance</span><span class="p">?.</span><span class="n">Configuration</span><span class="p">?.</span><span class="n">DelayBetweenFilesMs</span> <span class="p">??</span> <span class="m">5000</span><span class="p">;</span>
        <span class="k">await</span> <span class="n">Task</span><span class="p">.</span><span class="nf">Delay</span><span class="p">(</span><span class="n">delay</span><span class="p">,</span> <span class="n">cancellationToken</span><span class="p">);</span>

        <span class="kt">var</span> <span class="n">result</span> <span class="p">=</span> <span class="n">phase</span> <span class="k">switch</span>
        <span class="p">{</span>
            <span class="n">ScanPhase</span><span class="p">.</span><span class="n">Header</span> <span class="p">=&gt;</span> <span class="k">await</span> <span class="n">_ffmpeg</span><span class="p">.</span><span class="nf">ProbeAsync</span><span class="p">(</span><span class="n">item</span><span class="p">.</span><span class="n">Path</span><span class="p">,</span> <span class="n">cancellationToken</span><span class="p">),</span>
            <span class="n">ScanPhase</span><span class="p">.</span><span class="n">FullDecode</span> <span class="p">=&gt;</span> <span class="k">await</span> <span class="n">_ffmpeg</span><span class="p">.</span><span class="nf">DecodeAsync</span><span class="p">(</span><span class="n">item</span><span class="p">.</span><span class="n">Path</span><span class="p">,</span> <span class="n">cancellationToken</span><span class="p">),</span>
            <span class="n">_</span> <span class="p">=&gt;</span> <span class="k">throw</span> <span class="k">new</span> <span class="nf">ArgumentException</span><span class="p">(</span><span class="s">$"Unknown phase: </span><span class="p">{</span><span class="n">phase</span><span class="p">}</span><span class="s">"</span><span class="p">)</span>
        <span class="p">};</span>

        <span class="k">await</span> <span class="n">_db</span><span class="p">.</span><span class="nf">SaveResultAsync</span><span class="p">(</span><span class="k">new</span> <span class="n">ScanRecord</span> <span class="p">{</span> <span class="cm">/* item id, path, phase, pass/fail, duration ... */</span> <span class="p">});</span>
    <span class="p">}</span>
    <span class="k">finally</span>
    <span class="p">{</span>
        <span class="n">_scanLock</span><span class="p">.</span><span class="nf">Release</span><span class="p">();</span>
    <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>Every scan takes a slot, checks whether it should pause for active playback, applies the configured inter-file delay, runs the right ffmpeg phase, then persists the result — always in that order, whether it came from a scheduled task or a dashboard button. <code class="language-plaintext highlighter-rouge">ShouldPauseForPlayback</code>/<code class="language-plaintext highlighter-rouge">WaitForPlaybackEnd</code> and <code class="language-plaintext highlighter-rouge">Dispose</code> are omitted above for length; the full gate pipeline — including the quiet-hours window and read-rate throttle added later — is diagrammed further down in this article.</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/Scanner/ScanEngine.cs"><code class="language-plaintext highlighter-rouge">Scanner/ScanEngine.cs</code></a>.</p>

<h2 id="ffmpeg-process-wrapper">FFmpeg Process Wrapper</h2>

<p><code class="language-plaintext highlighter-rouge">FfmpegWrapper</code> is the only place that actually shells out to ffmpeg/ffprobe. <code class="language-plaintext highlighter-rouge">ProbeAsync</code> is Phase 1 — ffprobe reading container/stream metadata, cheap and fast. <code class="language-plaintext highlighter-rouge">DecodeAsync</code> is Phase 2 — a full ffmpeg decode with <code class="language-plaintext highlighter-rouge">-f null -</code> (decode every frame, write nowhere), expensive but able to catch mid-file frame corruption a header check can’t see. Both funnel through the same process runner:</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="k">async</span> <span class="n">Task</span><span class="p">&lt;</span><span class="n">ScanResult</span><span class="p">&gt;</span> <span class="nf">ProbeAsync</span><span class="p">(</span><span class="kt">string</span> <span class="n">filePath</span><span class="p">,</span> <span class="n">CancellationToken</span> <span class="n">ct</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">var</span> <span class="n">args</span> <span class="p">=</span> <span class="s">"-v error -show_entries format=duration,size "</span> <span class="p">+</span>
               <span class="s">"-show_entries stream=codec_type,codec_name -of json \""</span> <span class="p">+</span> <span class="n">filePath</span> <span class="p">+</span> <span class="s">"\""</span><span class="p">;</span>
    <span class="kt">var</span> <span class="p">(</span><span class="n">exitCode</span><span class="p">,</span> <span class="n">_</span><span class="p">,</span> <span class="n">stderr</span><span class="p">)</span> <span class="p">=</span> <span class="k">await</span> <span class="nf">RunProcessAsync</span><span class="p">(</span><span class="n">_ffprobePath</span><span class="p">,</span> <span class="n">args</span><span class="p">,</span> <span class="n">ct</span><span class="p">);</span>
    <span class="k">return</span> <span class="k">new</span> <span class="n">ScanResult</span> <span class="p">{</span> <span class="n">Success</span> <span class="p">=</span> <span class="n">exitCode</span> <span class="p">==</span> <span class="m">0</span> <span class="p">&amp;&amp;</span> <span class="kt">string</span><span class="p">.</span><span class="nf">IsNullOrWhiteSpace</span><span class="p">(</span><span class="n">stderr</span><span class="p">),</span> <span class="n">ErrorOutput</span> <span class="p">=</span> <span class="n">stderr</span> <span class="p">};</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">DecodeAsync</code> has the same shape, just against <code class="language-plaintext highlighter-rouge">ffmpeg -v error -i "&lt;file&gt;" -f null -</code>. The real <code class="language-plaintext highlighter-rouge">RunProcessAsync</code> (not shown) redirects stdout/stderr and drains both <em>concurrently</em> with the process exit — an earlier version awaited them sequentially after <code class="language-plaintext highlighter-rouge">WaitForExitAsync</code>, which deadlocks once a large stderr stream fills the OS pipe buffer — and kills the whole process tree on cancellation, so a cancelled deep scan doesn’t leave an orphaned ffmpeg process running against a file nobody’s waiting on anymore.</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/Scanner/FfmpegWrapper.cs"><code class="language-plaintext highlighter-rouge">Scanner/FfmpegWrapper.cs</code></a>.</p>

<h2 id="scheduled-task-registration">Scheduled Task Registration</h2>

<p>Jellyfin discovers <code class="language-plaintext highlighter-rouge">IScheduledTask</code> implementations via DI and lists them under Dashboard → Scheduled Tasks automatically — <code class="language-plaintext highlighter-rouge">Name</code>/<code class="language-plaintext highlighter-rouge">Key</code>/<code class="language-plaintext highlighter-rouge">Category</code> are what show up there, and <code class="language-plaintext highlighter-rouge">GetDefaultTriggers()</code> is only the <em>default</em>; an admin can reconfigure the schedule from that same page.</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="k">class</span> <span class="nc">HeaderScanTask</span> <span class="p">:</span> <span class="n">IScheduledTask</span>
<span class="p">{</span>
    <span class="k">public</span> <span class="kt">string</span> <span class="n">Name</span> <span class="p">=&gt;</span> <span class="s">"Media Integrity - Header Scan"</span><span class="p">;</span>
    <span class="k">public</span> <span class="kt">string</span> <span class="n">Category</span> <span class="p">=&gt;</span> <span class="s">"Media Integrity"</span><span class="p">;</span>

    <span class="k">public</span> <span class="n">IEnumerable</span><span class="p">&lt;</span><span class="n">TaskTriggerInfo</span><span class="p">&gt;</span> <span class="nf">GetDefaultTriggers</span><span class="p">()</span> <span class="p">=&gt;</span> <span class="k">new</span><span class="p">[]</span>
    <span class="p">{</span>
        <span class="k">new</span> <span class="n">TaskTriggerInfo</span> <span class="p">{</span> <span class="n">Type</span> <span class="p">=</span> <span class="n">TaskTriggerInfoType</span><span class="p">.</span><span class="n">DailyTrigger</span><span class="p">,</span> <span class="n">TimeOfDayTicks</span> <span class="p">=</span> <span class="n">TimeSpan</span><span class="p">.</span><span class="nf">FromHours</span><span class="p">(</span><span class="m">3</span><span class="p">).</span><span class="n">Ticks</span> <span class="p">}</span>
    <span class="p">};</span>

    <span class="k">public</span> <span class="n">Task</span> <span class="nf">ExecuteAsync</span><span class="p">(</span><span class="n">IProgress</span><span class="p">&lt;</span><span class="kt">double</span><span class="p">&gt;</span> <span class="n">progress</span><span class="p">,</span> <span class="n">CancellationToken</span> <span class="n">cancellationToken</span><span class="p">)</span> <span class="p">=&gt;</span>
        <span class="n">_scanner</span><span class="p">.</span><span class="nf">ScanLibraryAsync</span><span class="p">(</span><span class="k">null</span><span class="p">,</span> <span class="n">ScanPhase</span><span class="p">.</span><span class="n">Header</span><span class="p">,</span> <span class="n">cancellationToken</span><span class="p">,</span> <span class="n">progress</span><span class="p">);</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">DeepScanTask</code> is the same shape, wired to a weekly Sunday trigger and <code class="language-plaintext highlighter-rouge">ScanPhase.FullDecode</code> instead, and only runs at all if <code class="language-plaintext highlighter-rouge">EnableDeepScan</code> is on. Both tasks just delegate straight into <code class="language-plaintext highlighter-rouge">ScanEngine</code>, so a scheduled sweep and a manual “scan library” API call walk the exact same gating logic described above — there’s no separate scheduled-task-only code path to keep in sync. (An earlier version of this loop lived directly in the task and had its own concurrency bug — see the <a href="#update-maxconcurrentscans-wasnt-honored-by-bulk-scans">MaxConcurrentScans update</a> below.)</p>

<p>Full file: <a href="https://github.com/mcgarrah/jellyfin-plugin-media-integrity-scanner/blob/main/Jellyfin.Plugin.MediaIntegrityScanner/ScheduledTasks/HeaderScanTask.cs"><code class="language-plaintext highlighter-rouge">ScheduledTasks/HeaderScanTask.cs</code></a>.</p>

<h2 id="update-quiet-hours-and-read-rate-throttling">Update: Quiet Hours and Read-Rate Throttling</h2>

<p>The <a href="/jellyfin-media-integrity-deployment-operations/">deployment article</a> recommends specific <code class="language-plaintext highlighter-rouge">MaxReadRateMbPerSec</code> and <code class="language-plaintext highlighter-rouge">UseQuietHoursOnly</code>/<code class="language-plaintext highlighter-rouge">QuietHoursStart</code>/<code class="language-plaintext highlighter-rouge">QuietHoursEnd</code> values for CephFS and NFS backends. Those config fields existed from the start, but nothing actually enforced them — a gap caught during a later review pass. Two additions to <code class="language-plaintext highlighter-rouge">ScanEngine</code> close it:</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">public</span> <span class="k">static</span> <span class="k">class</span> <span class="nc">ScanThrottle</span>
<span class="p">{</span>
    <span class="c1">// Supports windows that wrap past midnight (e.g., 22:00-06:00).</span>
    <span class="c1">// Fails open (returns true) if either bound can't be parsed.</span>
    <span class="k">public</span> <span class="k">static</span> <span class="kt">bool</span> <span class="nf">IsWithinQuietHours</span><span class="p">(</span><span class="kt">string</span><span class="p">?</span> <span class="n">start</span><span class="p">,</span> <span class="kt">string</span><span class="p">?</span> <span class="n">end</span><span class="p">,</span> <span class="n">TimeSpan</span> <span class="n">timeOfDay</span><span class="p">)</span> <span class="p">{</span> <span class="cm">/* ... */</span> <span class="p">}</span>

    <span class="c1">// Pads wall-clock time after a scan so the average MB/s for that</span>
    <span class="c1">// file doesn't exceed the configured cap.</span>
    <span class="k">public</span> <span class="k">static</span> <span class="n">TimeSpan</span> <span class="nf">ComputeReadRateDelay</span><span class="p">(</span><span class="kt">long</span> <span class="n">fileSizeBytes</span><span class="p">,</span> <span class="kt">int</span> <span class="n">maxReadRateMbPerSec</span><span class="p">,</span> <span class="kt">int</span> <span class="n">actualDurationMs</span><span class="p">)</span> <span class="p">{</span> <span class="cm">/* ... */</span> <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p><code class="language-plaintext highlighter-rouge">ScanItemAsync</code> checks <code class="language-plaintext highlighter-rouge">IsWithinQuietHours</code> before scanning (waiting in a loop if outside the window, same pattern as the existing playback-pause check), and calls <code class="language-plaintext highlighter-rouge">ComputeReadRateDelay</code> after each scan to pad the inter-file gap so the <em>average</em> rate for that file doesn’t exceed the cap.</p>

<p>The read-rate throttle is deliberately <strong>not</strong> a literal in-flight byte cap. An earlier design considered piping the file through ffmpeg’s stdin (<code class="language-plaintext highlighter-rouge">pipe:0</code>) to get precise control over read bytes/sec, but that breaks seekability — and many MP4/MOV files store the <code class="language-plaintext highlighter-rouge">moov</code> atom at the end of the file, so probing them over a non-seekable pipe produces a false <code class="language-plaintext highlighter-rouge">"moov atom not found"</code> failure. That’s exactly the corruption signature this plugin exists to detect, so a naive throttle could turn healthy files into false positives. Padding wall-clock time after the fact has zero risk to decode correctness, since ffmpeg still opens the file directly and reads at full speed — it only bounds the long-run average throughput the scanner pulls from storage, which is the actual concern behind the CephFS/NFS tuning guidance.</p>

<p>Both functions are pure and dependency-free (no Jellyfin types), so they’re covered by a small xUnit test project — see the <a href="/jellyfin-media-integrity-deployment-operations/">deployment article</a> for the CI wiring.</p>

<p>Stacking all of this on top of the original <code class="language-plaintext highlighter-rouge">ScanItemAsync</code> gives a longer gate pipeline than the code above suggests — concurrency slot, quiet hours, playback pause, the fixed inter-file delay, the scan itself, then the read-rate throttle:</p>

<pre><code class="language-mermaid">%%{init: {"theme": "base", "themeVariables": {
  "primaryColor": "#17221f",
  "primaryTextColor": "#e7ede9",
  "primaryBorderColor": "#3e6e67",
  "lineColor": "#7c93a3",
  "secondaryColor": "#1d2b27",
  "tertiaryColor": "#101a18",
  "fontFamily": "monospace",
  "fontSize": "14px"
}}}%%
flowchart TD
    START(["ScanItemAsync called&lt;br/&gt;from any trigger"]):::pipe
    SEM["wait for a free slot&lt;br/&gt;MaxConcurrentScans (1)"]:::act
    QH{"UseQuietHoursOnly (false)&lt;br/&gt;and outside window?"}:::gate
    WAITQH["poll every 5 min&lt;br/&gt;until inside 02:00–06:00"]:::wait
    PP{"PauseDuringPlayback (true)&lt;br/&gt;and any session playing?"}:::gate
    WAITPP["poll every 30 sec&lt;br/&gt;until playback ends"]:::wait
    DELAY["fixed pause&lt;br/&gt;DelayBetweenFilesMs (5000)"]:::act
    PHASE{"which phase?"}:::gate
    HEADER["ffprobe&lt;br/&gt;Header check"]:::exec
    DECODE["ffmpeg null-decode&lt;br/&gt;FullDecode check"]:::exec
    THROTTLE["paced delay&lt;br/&gt;MaxReadRateMbPerSec (10)"]:::act
    SAVE[("SaveResultAsync&lt;br/&gt;scan_results")]:::db
    ERRSAVE[("SaveResultAsync&lt;br/&gt;Status: Error")]:::db
    DONE(["slot released,&lt;br/&gt;IsScanning re-evaluated"]):::pipe
    CANCELLED(["OperationCanceledException&lt;br/&gt;propagates, nothing saved"]):::stop

    START --&gt; SEM --&gt; QH
    QH --&gt;|"yes"| WAITQH --&gt; QH
    QH --&gt;|"no"| PP
    PP --&gt;|"yes"| WAITPP --&gt; PP
    PP --&gt;|"no"| DELAY --&gt; PHASE
    PHASE --&gt;|"Header"| HEADER
    PHASE --&gt;|"FullDecode"| DECODE
    HEADER --&gt; THROTTLE
    DECODE --&gt; THROTTLE
    HEADER -.-&gt;|"exception,&lt;br/&gt;e.g. ffmpeg missing"| ERRSAVE
    DECODE -.-&gt;|"exception"| ERRSAVE
    THROTTLE --&gt; SAVE --&gt; DONE
    ERRSAVE --&gt; DONE

    WAITQH -.-&gt;|"Cancel() called"| CANCELLED
    WAITPP -.-&gt;|"Cancel() called"| CANCELLED
    SEM -.-&gt;|"Cancel() called"| CANCELLED

    classDef gate fill:#2a2013,stroke:#e3a857,color:#f4d9a8
    classDef wait fill:#2a2013,stroke:#e3a857,color:#f4d9a8,stroke-dasharray: 3 3
    classDef act fill:#16332c,stroke:#5fa88f,color:#cfefe2
    classDef exec fill:#16332c,stroke:#5fa88f,color:#cfefe2,stroke-width:2px
    classDef db fill:#17221f,stroke:#7c93a3,color:#e7ede9
    classDef pipe fill:#101a18,stroke:#e3a857,color:#e3a857,stroke-width:2px
    classDef stop fill:#331c1a,stroke:#d96c5d,color:#f3c8c2
</code></pre>

<p>Every file, whoever triggered its scan, walks this same path — a manually-triggered API scan and a scheduled sweep get no special treatment once they’re queued.</p>

<h2 id="update-maxconcurrentscans-wasnt-honored-by-bulk-scans">Update: <code class="language-plaintext highlighter-rouge">MaxConcurrentScans</code> Wasn’t Honored by Bulk Scans</h2>

<p>The <code class="language-plaintext highlighter-rouge">HeaderScanTask</code> loop shown above has a subtle bug: it’s a plain <code class="language-plaintext highlighter-rouge">foreach</code> with a single <code class="language-plaintext highlighter-rouge">await</code> per iteration. <code class="language-plaintext highlighter-rouge">ScanEngine</code>’s internal <code class="language-plaintext highlighter-rouge">SemaphoreSlim</code> is sized to <code class="language-plaintext highlighter-rouge">MaxConcurrentScans</code>, but a sequential loop never asks it for more than one slot at a time — so setting <code class="language-plaintext highlighter-rouge">MaxConcurrentScans</code> above <code class="language-plaintext highlighter-rouge">1</code> had no effect on a scheduled or library-wide scan. It only mattered for manual single-item scans issued concurrently from the API, which almost nobody does.</p>

<p>Fixed by switching both scheduled tasks and <code class="language-plaintext highlighter-rouge">ScanEngine.ScanLibraryAsync</code> to <code class="language-plaintext highlighter-rouge">Parallel.ForEachAsync</code> with <code class="language-plaintext highlighter-rouge">MaxDegreeOfParallelism</code> set to the configured value:</p>

<div class="language-csharp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kt">var</span> <span class="n">maxConcurrent</span> <span class="p">=</span> <span class="n">Math</span><span class="p">.</span><span class="nf">Max</span><span class="p">(</span><span class="m">1</span><span class="p">,</span> <span class="n">config</span><span class="p">?.</span><span class="n">MaxConcurrentScans</span> <span class="p">??</span> <span class="m">1</span><span class="p">);</span>
<span class="k">await</span> <span class="n">Parallel</span><span class="p">.</span><span class="nf">ForEachAsync</span><span class="p">(</span>
    <span class="n">items</span><span class="p">,</span>
    <span class="k">new</span> <span class="n">ParallelOptions</span> <span class="p">{</span> <span class="n">MaxDegreeOfParallelism</span> <span class="p">=</span> <span class="n">maxConcurrent</span><span class="p">,</span> <span class="n">CancellationToken</span> <span class="p">=</span> <span class="n">cancellationToken</span> <span class="p">},</span>
    <span class="k">async</span> <span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">ct</span><span class="p">)</span> <span class="p">=&gt;</span>
    <span class="p">{</span>
        <span class="k">if</span> <span class="p">(!</span><span class="k">await</span> <span class="n">_db</span><span class="p">.</span><span class="nf">IsCurrentAsync</span><span class="p">(</span><span class="n">item</span><span class="p">.</span><span class="n">Id</span><span class="p">.</span><span class="nf">ToString</span><span class="p">(),</span> <span class="n">item</span><span class="p">.</span><span class="n">Path</span><span class="p">))</span>
        <span class="p">{</span>
            <span class="k">await</span> <span class="n">_scanner</span><span class="p">.</span><span class="nf">ScanItemAsync</span><span class="p">(</span><span class="n">item</span><span class="p">,</span> <span class="n">ScanPhase</span><span class="p">.</span><span class="n">Header</span><span class="p">,</span> <span class="n">ct</span><span class="p">);</span>
        <span class="p">}</span>

        <span class="kt">var</span> <span class="n">done</span> <span class="p">=</span> <span class="n">Interlocked</span><span class="p">.</span><span class="nf">Increment</span><span class="p">(</span><span class="k">ref</span> <span class="n">processed</span><span class="p">);</span>
        <span class="n">progress</span><span class="p">.</span><span class="nf">Report</span><span class="p">((</span><span class="kt">double</span><span class="p">)</span><span class="n">done</span> <span class="p">/</span> <span class="n">total</span> <span class="p">*</span> <span class="m">100</span><span class="p">);</span>
    <span class="p">});</span>
</code></pre></div></div>

<p>The semaphore inside <code class="language-plaintext highlighter-rouge">ScanEngine</code> isn’t redundant with this — it’s still what keeps a manual single-item scan and a bulk scan from together exceeding the configured limit. This change fixes the half the semaphore alone couldn’t: the loop itself never asking for more than one slot. <code class="language-plaintext highlighter-rouge">Interlocked.Increment</code> replaces the plain <code class="language-plaintext highlighter-rouge">processed++</code>, since parallel iterations now complete out of order. Default behavior (<code class="language-plaintext highlighter-rouge">MaxConcurrentScans = 1</code>) is unchanged.</p>

<h2 id="update-the-skip-check-didnt-know-about-scan-phase">Update: The Skip Check Didn’t Know About Scan Phase</h2>

<p>The <code class="language-plaintext highlighter-rouge">IsCurrentAsync(item.Id.ToString(), item.Path)</code> check in the loop above — “does this item already have a passing scan with an unchanged mtime” — has a bug that took a while to surface: it never looked at <em>which phase</em> produced that passing record. Since files are normally Header-scanned first (either on library add or via <code class="language-plaintext highlighter-rouge">HeaderScanTask</code>), once a file passes that quick check, <code class="language-plaintext highlighter-rouge">IsCurrentAsync</code> reports it “current” for <strong>any</strong> later request — including a <code class="language-plaintext highlighter-rouge">DeepScanTask</code> run asking for a full <code class="language-plaintext highlighter-rouge">FullDecode</code> pass — as long as the file’s mtime hasn’t changed.</p>

<p>That’s a real problem for <code class="language-plaintext highlighter-rouge">DeepScanTask</code> specifically: its entire purpose is catching mid-file corruption that a header check misses, but it would silently skip almost every file in the library on every scheduled run, forever, because they’d already “passed” at the Header level. The deep scan had likely never actually deep-scanned anything in a real deployment.</p>

<p>Fixed by adding a <code class="language-plaintext highlighter-rouge">minPhase</code> parameter to <code class="language-plaintext highlighter-rouge">IsCurrentAsync</code>, requiring <code class="language-plaintext highlighter-rouge">scan_phase &gt;= minPhase</code> in the underlying query, and passing the right phase at each of the three call sites — <code class="language-plaintext highlighter-rouge">(int)phase</code> in <code class="language-plaintext highlighter-rouge">ScanLibraryAsync</code>, <code class="language-plaintext highlighter-rouge">Header</code> in <code class="language-plaintext highlighter-rouge">HeaderScanTask</code>, <code class="language-plaintext highlighter-rouge">FullDecode</code> in <code class="language-plaintext highlighter-rouge">DeepScanTask</code>. See the <a href="/jellyfin-media-integrity-architecture-design/#incremental-scanning-logic">architecture article’s incremental-scanning section</a> for how this interacts with the schema design.</p>

<p>Here’s the failure mode laid out end to end, alongside the one path that was never affected by it — an <code class="language-plaintext highlighter-rouge">itemId</code>-scoped API call, which bypasses <code class="language-plaintext highlighter-rouge">IsCurrentAsync</code> entirely:</p>

<pre><code class="language-mermaid">%%{init: {"theme": "base", "themeVariables": {
  "actorBkg": "#17221f",
  "actorBorder": "#3e6e67",
  "actorTextColor": "#e7ede9",
  "actorLineColor": "#3e6e67",
  "signalColor": "#5c6b75",
  "signalTextColor": "#2a2a2a",
  "labelBoxBkgColor": "#2a2013",
  "labelBoxBorderColor": "#e3a857",
  "labelTextColor": "#f4d9a8",
  "loopTextColor": "#2a2a2a",
  "noteBkgColor": "#1d2b27",
  "noteBorderColor": "#3e6e67",
  "noteTextColor": "#e7ede9",
  "activationBorderColor": "#5fa88f",
  "activationBkgColor": "#16332c",
  "sequenceNumberColor": "#101a18",
  "fontFamily": "monospace",
  "fontSize": "13px"
}}}%%
sequenceDiagram
    participant SCH as Task Scheduler
    participant DST as DeepScanTask
    participant DB as scan_results
    participant SE as ScanEngine
    participant AD as Admin (dashboard)

    SCH-&gt;&gt;DST: Sunday 01:00 trigger
    activate DST
    DST-&gt;&gt;DST: EnableDeepScan == true?
    DST-&gt;&gt;DB: IsCurrentAsync(item, minPhase=FullDecode)
    Note over DB: file already has a passing&lt;br/&gt;Header (phase 1) record —&lt;br/&gt;phase 1 is less than FullDecode (phase 2)
    DB--&gt;&gt;DST: false, not current at this phase
    DST-&gt;&gt;SE: ScanItemAsync(item, FullDecode)
    SE-&gt;&gt;DB: SaveResultAsync(Pass, FullDecode)
    deactivate DST

    Note over DB,SE: before the phase-aware fix, that check&lt;br/&gt;returned true for ANY passing record —&lt;br/&gt;this file would have been skipped forever

    AD-&gt;&gt;SE: POST /MediaIntegrity/Scan&lt;br/&gt;itemId + deepScan: true
    activate SE
    Note over SE: the itemId-scoped path calls&lt;br/&gt;ScanItemAsync directly —&lt;br/&gt;no currency check at all
    SE-&gt;&gt;DB: SaveResultAsync(Pass, FullDecode)
    deactivate SE
</code></pre>

<p>If <code class="language-plaintext highlighter-rouge">EnableDeepScan</code> ever seemed to do nothing against a library that had already loaded in cleanly, this was why.</p>

<h2 id="whats-next">What’s Next</h2>

<p>The <a href="/jellyfin-media-integrity-dashboard-api/">next article</a> adds the admin-facing layer: the REST API controller for querying scan results and triggering scans, and the HTML dashboard that gives at-a-glance library health visibility.</p>

<h2 id="series-navigation">Series Navigation</h2>

<ol>
  <li><a href="/jellyfin-media-integrity-scanner-introduction/">Introduction &amp; Problem Statement</a></li>
  <li><a href="/jellyfin-media-integrity-architecture-design/">Architecture &amp; Design Decisions</a></li>
  <li><strong>Building the Scanner Core</strong> (this post)</li>
  <li><a href="/jellyfin-media-integrity-dashboard-api/">The Dashboard &amp; API</a></li>
  <li><a href="/jellyfin-media-integrity-deployment-operations/">Deployment &amp; Operations</a></li>
  <li><a href="/jellyfin-media-integrity-release-and-updates/">v0.1.1 Release: Update Checker &amp; Auto-Update</a></li>
</ol>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="homelab" /><category term="media-server" /><category term="jellyfin" /><category term="media-integrity" /><category term="ffmpeg" /><category term="dotnet" /><category term="csharp" /><category term="plugin-development" /><category term="cross-platform" /><summary type="html"><![CDATA[Building the core scanning engine for the Jellyfin Media Integrity Scanner plugin. Covers .NET 8 plugin scaffolding, FFmpeg process wrapper, bounded concurrent task queue, cross-platform path resolution, and production-safe error handling. Part 3 of a 6-part development series.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-scanner-core.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-scanner-core.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">ZFS Boot Mirrors on Proxmox 8 for the Homelab - Part 5</title><link href="https://mcgarrah.org/proxmox-zfs-boot-mirrors-part-5/" rel="alternate" type="text/html" title="ZFS Boot Mirrors on Proxmox 8 for the Homelab - Part 5" /><published>2026-08-08T00:00:00+00:00</published><updated>2026-08-08T00:00:00+00:00</updated><id>https://mcgarrah.org/proxmox-zfs-boot-mirrors-part-5</id><content type="html" xml:base="https://mcgarrah.org/proxmox-zfs-boot-mirrors-part-5/"><![CDATA[<p><a href="/proxmox-zfs-boot-mirrors-part-3/">Part 3</a> laid out the planned migration procedure. <a href="/proxmox-zfs-boot-mirrors-part-4/">Part 4</a> ran it against edgar and found four gaps the hard way — live, mid-migration, under pressure. This is the same migration run against tanaka the very next day, with all four of those gaps fixed proactively instead of discovered on the fly. It went almost boringly well, which is exactly the point — except for one problem that had nothing to do with Proxmox at all.</p>

<!-- excerpt-end -->

<h2 id="the-trigger">The Trigger</h2>

<p>Live SMART checks across the whole cluster on Aug 3, 2026 (the same pass that flagged edgar) turned up a second node worth watching: tanaka’s <code class="language-plaintext highlighter-rouge">sdb</code> (Apple HDD HTS547550A9E384) had jumped from 1 reallocated sector to <strong>25</strong> since the last check. <code class="language-plaintext highlighter-rouge">sda</code> (Seagate ST3500418AS) stayed clean. Not yet the acute failure edgar was living through, but a real trend — the same reallocated-sector escalation pattern, one node behind.</p>

<p>Replacement hardware: 2x 128GB SSDs, matching the cluster’s standard size (harlan, quell, and now edgar are all 128GB). Same topology as edgar too — 128GB is smaller than tanaka’s existing 465.8GB mirror members, so ZFS won’t allow an in-place <code class="language-plaintext highlighter-rouge">zpool replace</code> (<code class="language-plaintext highlighter-rouge">device is too small</code>, confirmed rather than assumed). A fresh install was the only option, same as edgar.</p>

<h2 id="a-real-hardware-detour-before-any-of-the-software-mattered">A Real Hardware Detour, Before Any of the Software Mattered</h2>

<p>Tanaka is a Dell OptiPlex 990 <strong>Desktop</strong> chassis rather than the Tower variant the other five nodes use — same BIOS generation, different case. After swapping the drives and powering back on: nothing. Green power light, no fan spin-up signal on the display, no keyboard LED response across three different monitor connections (VGA, HDMI off the motherboard, DisplayPort/DVI off the Quadro K600).</p>

<p>Two separate problems, both mechanical, neither one a drive issue:</p>

<ol>
  <li><strong>A loose VGA cable</strong> at the monitor end — looked identical to “the board is dead” from the chair, and only showed itself once a DVI-to-HDMI adapter was tried on a different port and actually produced a picture.</li>
  <li><strong>A SATA power connector with a 90° bend</strong> right at the connector body, causing an intermittent power fault to one of the new SSDs. Swapped for a flat, straight extender cable and the drive appeared immediately.</li>
</ol>

<p>Neither of these would show up in any runbook. They’re exactly the kind of thing the <a href="/proxmox-upgrade-issues/"><strong><em>trash can</em></strong> <strong>crash cart</strong> (TC<sup>3</sup>)</a> earns its keep on — a spare monitor, keyboard, and a pile of VGA/DVI/DisplayPort/HDMI adapters kept on hand specifically so “is it actually dead or is it a cable” takes five minutes to answer instead of becoming its own outage. That cart was built for a much worse night (a power-outage recovery with four overlapping hardware failures at once); tonight it just made quick work of two small mechanical problems. Worth having on hand for any hands-on hardware work, not just migrations.</p>

<h2 id="pre-flight">Pre-Flight</h2>

<p>Nothing new to do here — the Golden Backup Checklist (plus the two additions from Part 4: full apt inventory with versions, and a full <code class="language-plaintext highlighter-rouge">/etc</code> tarball excluding the shared <code class="language-plaintext highlighter-rouge">/etc/pve</code> mount) had already been run against all six nodes back when edgar’s migration started, tanaka included. No last-minute scramble; the backup was just sitting there waiting.</p>

<h2 id="fresh-install">Fresh Install</h2>

<p>ZFS RAID1 on the two new SSDs, Legacy BIOS/GRUB from the start — no time spent testing UEFI first. This is the fourth confirmed case on this hardware family (harlan, quell, edgar, now tanaka), and the third was already conclusive. Same hostname and IP as before (<code class="language-plaintext highlighter-rouge">tanaka</code>, <code class="language-plaintext highlighter-rouge">192.168.86.15/23</code>).</p>

<h2 id="post-install-applying-every-gap-proactively">Post-Install: Applying Every Gap Proactively</h2>

<p>This is where Part 4’s lessons actually paid off. Everything below was done <em>before</em> it could cause a failure, in the order that avoids re-hitting edgar’s snags:</p>

<table>
  <thead>
    <tr>
      <th>Gap (found live on edgar)</th>
      <th>Handled on tanaka</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>SSH key trust chicken-and-egg</td>
      <td>Cleared stale host keys cluster-wide, swapped tanaka’s new keypair into the shared <code class="language-plaintext highlighter-rouge">authorized_keys</code>, seeded tanaka’s own local file with the cluster’s keys — all <em>before</em> attempting to join</td>
    </tr>
    <tr>
      <td>Wrong default Ceph repo (Quincy enterprise vs. Reef no-subscription)</td>
      <td>Fixed repos first, then installed Ceph packages — <code class="language-plaintext highlighter-rouge">apt-get update</code> came back clean on the first try</td>
    </tr>
    <tr>
      <td><code class="language-plaintext highlighter-rouge">/etc/ceph/ceph.conf</code> missing after <code class="language-plaintext highlighter-rouge">apt install ceph</code></td>
      <td>Symlinked to <code class="language-plaintext highlighter-rouge">/etc/pve/ceph.conf</code> immediately, no failed <code class="language-plaintext highlighter-rouge">ceph-volume</code> command needed to discover it</td>
    </tr>
    <tr>
      <td>Missing SAN bridge (<code class="language-plaintext highlighter-rouge">vmbr1</code>, 10.10.10.0/23)</td>
      <td>Diffed <code class="language-plaintext highlighter-rouge">/etc/network/interfaces</code> against the backup, restored the block, confirmed reachable to all 5 peers before moving on</td>
    </tr>
    <tr>
      <td>Missing USB SMART quirks file</td>
      <td>Restored from the CephFS master copy (<code class="language-plaintext highlighter-rouge">/mnt/pve/cephfs/configs/usb-quirks.cfg</code> — created for real during edgar’s fix) even though tanaka has no USB drives attached today, for cluster-wide consistency</td>
    </tr>
    <tr>
      <td>Stale monmap / <code class="language-plaintext highlighter-rouge">ceph.conf</code> entries blocking <code class="language-plaintext highlighter-rouge">pveceph mon create</code></td>
      <td>Cleaned <code class="language-plaintext highlighter-rouge">ceph mon remove tanaka</code> and the <code class="language-plaintext highlighter-rouge">[mon.tanaka]</code> section in <code class="language-plaintext highlighter-rouge">/etc/pve/ceph.conf</code> <em>before</em> ever attempting mon create</td>
    </tr>
  </tbody>
</table>

<p>Two smaller things confirmed rather than assumed, per Part 4’s own advice not to skip the diff just because it “should” match: the GRUB kernel command line matched the old node’s exactly (nothing lost), and <code class="language-plaintext highlighter-rouge">/etc/subuid</code>/<code class="language-plaintext highlighter-rouge">/etc/subgid</code> were missing the same <code class="language-plaintext highlighter-rouge">root:501:2</code>/<code class="language-plaintext highlighter-rouge">root:501:1</code> lines edgar’s fresh install had dropped — restored the same way.</p>

<p>One thing came up that edgar’s article didn’t need to cover: <code class="language-plaintext highlighter-rouge">intel-microcode</code> isn’t installable from this cluster’s normal repos (none of the nodes have <code class="language-plaintext highlighter-rouge">non-free-firmware</code> enabled in <code class="language-plaintext highlighter-rouge">/etc/apt/sources.list</code>, confirmed by checking a healthy node). Rather than permanently enable that repo by hand, the fix is to let the Proxmox community <strong>microcode</strong> helper script handle it — it enables what it needs temporarily and installs cleanly. Left <code class="language-plaintext highlighter-rouge">intel-microcode</code>/<code class="language-plaintext highlighter-rouge">iucode-tool</code> out of the manual package batch for exactly that reason.</p>

<h2 id="rejoining-the-cluster-one-genuinely-new-finding">Rejoining the Cluster: One Genuinely New Finding</h2>

<p>With SSH trust fixed proactively, <code class="language-plaintext highlighter-rouge">pvecm add &lt;healthy-node-ip&gt;</code> was expected to just work this time. It didn’t — same <code class="language-plaintext highlighter-rouge">EOF while reading password</code> error Part 4 hit, despite direct key-based SSH between the nodes working perfectly in both directions.</p>

<p>The actual fix: <code class="language-plaintext highlighter-rouge">pvecm add &lt;ip&gt; --use_ssh 1</code>, forcing the join process to use the SSH path explicitly rather than whatever it tries by default. That one flag took it from a hard failure to a clean success:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>forcing overwrite of configured node 'tanaka'
copy corosync auth key
stopping pve-cluster service
waiting for quorum...OK
merge authorized SSH keys
successfully added node 'tanaka' to cluster.
</code></pre></div></div>

<p>This is a real, new addition to the checklist — not something carried over from edgar, since edgar’s own join (eventually) went through without needing it explicitly.</p>

<h2 id="monmgr-recreation-first-try-both-times">Mon/Mgr Recreation: First Try, Both Times</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>pveceph mon create   <span class="c"># succeeded immediately — no "address already in use"</span>
pveceph mgr create   <span class="c"># succeeded immediately</span>
</code></pre></div></div>

<p>No repeat of edgar’s stale-<code class="language-plaintext highlighter-rouge">ceph.conf</code> port conflict, because that cleanup happened <em>before</em> either command ran, not after the first one failed.</p>

<h2 id="final-verification">Final Verification</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ceph <span class="nt">-s</span>
<span class="c"># HEALTH_OK</span>
<span class="c"># mon: 6 daemons, quorum poe,kovacs,quell,harlan,edgar,tanaka</span>
<span class="c"># mgr: poe(active), standbys: harlan, quell, kovacs, tanaka, edgar</span>
<span class="c"># osd: 15 osds: 15 up, 15 in   -- untouched throughout; tanaka has no OSDs</span>

zpool status <span class="nt">-v</span> rpool
<span class="c"># ONLINE, mirror-0 on the two new SSDs, 0 errors</span>

zpool scrub rpool
<span class="c"># scrub repaired 0B in 00:00:10 with 0 errors</span>

proxmox-boot-tool status
<span class="c"># both ESPs configured with grub, both kernel versions present</span>

pvecm status
<span class="c"># AlteredCarbon, 6 nodes, quorate</span>
</code></pre></div></div>

<p>The community post-install and microcode scripts were run interactively afterward (same repo-fix choices as Part 4: disable enterprise, enable no-subscription, correct Ceph repos, disable the nag, leave HA and corosync enabled since this is a real 6-node cluster). One deliberate reboot followed, bringing in a newer kernel (<code class="language-plaintext highlighter-rouge">6.8.12-39-pve</code>) along with the microcode package. The only thing that came back momentarily off was a <code class="language-plaintext highlighter-rouge">HEALTH_WARN</code> clock-skew warning on the fresh mon — normal for a few seconds while NTP catches up right after a cold boot, and it cleared on its own well under a minute later. Worth knowing so it doesn’t read as a real problem the next time a freshly-rejoined mon shows it.</p>

<h2 id="what-this-confirms">What This Confirms</h2>

<p>Part 4 closed with a list of five things to change for next time. Running tanaka the next day is the actual test of whether that list held up, and it did — every one of the five gaps Part 4 found live was either a non-issue here or fixed before it could become one:</p>

<ul>
  <li><strong>No UEFI time wasted.</strong> Fourth confirmed wall on this hardware family; went straight to Legacy/GRUB.</li>
  <li><strong>Mon+mgr recreation worked first try</strong>, both commands, because the stale <code class="language-plaintext highlighter-rouge">ceph.conf</code>/monmap cleanup happened before rather than after a failure.</li>
  <li><strong>The hostid mistake wasn’t repeated</strong> — <code class="language-plaintext highlighter-rouge">zgenhostid</code> was never run against tanaka’s fresh pool, since it’s a new pool under a new install, not a re-import.</li>
  <li><strong>The apt/etc diff caught real gaps again</strong> (subuid/subgid, the vGPU helper, the same Ceph repo mismatch) — worth keeping as a standard step, not a one-off for edgar.</li>
  <li><strong>The USB quirks file was restored even though tanaka has no USB drives today</strong> — cluster-wide consistency, no live incident to force the issue this time.</li>
</ul>

<p>The one thing that wasn’t on that list — <code class="language-plaintext highlighter-rouge">pvecm add</code> needing <code class="language-plaintext highlighter-rouge">--use_ssh 1</code> explicitly — is the actual new data point from this run, and now it’s part of the checklist for poe and kovacs too.</p>

<p>The hardware detour is the other real takeaway, and it has nothing to do with any of the above: a loose monitor cable and a bent SATA power connector cost more real troubleshooting time than the entire software side of this migration combined. No amount of proactive checklist work prevents that kind of thing — only a crash cart with spare cables on hand shortens it.</p>

<p>With tanaka done, the cluster has two nodes left on spinning rust: <strong>poe</strong> (the oldest drives in the cluster, 6+ years, still SMART-clean and stable) and <strong>kovacs</strong> (5+ years, also stable). Neither is showing the kind of reallocated-sector escalation that made edgar and tanaka urgent — both are aging, not degrading. That takes real pressure off the schedule: poe and kovacs can move at a normal cadence rather than an emergency one, with a fully proactive checklist and, now, four other successful migrations’ worth of lessons already banked before either of them needs a single command run against it.</p>

<h2 id="related-articles">Related Articles</h2>

<ul>
  <li><a href="/proxmox-zfs-boot-mirrors-part-1/">ZFS Boot Mirrors on Proxmox 8 - Part 1</a> — Same-size drive replacement</li>
  <li><a href="/proxmox-zfs-boot-mirrors-part-2/">ZFS Boot Mirrors on Proxmox 8 - Part 2</a> — Emergency recovery from catastrophic dual-drive failure</li>
  <li><a href="/proxmox-zfs-boot-mirrors-part-3/">ZFS Boot Mirrors on Proxmox 8 - Part 3</a> — The planned-migration procedure this article executes</li>
  <li><a href="/proxmox-zfs-boot-mirrors-part-4/">ZFS Boot Mirrors on Proxmox 8 - Part 4</a> — edgar’s migration, and the four gaps found live that this article fixes proactively</li>
  <li><a href="/proxmox-upgrade-issues/">Proxmox Upgrade Issues: A Crash Cart Recovery Story</a> — Where the trash-can crash cart (TC³) comes from</li>
  <li><a href="/usb-drive-smart/">Enabling SMART Monitoring on Seagate USB Drives</a> — The original UAS quirks fix behind the USB gap</li>
  <li><a href="/usb-drive-smart-updates/">USB Drive SMART Updates</a> — Production experience and the GRUB parameter approach</li>
  <li><a href="/proxmox-zfs-boot-mirror-smart-analysis/">Monitoring ZFS Boot Mirror Health in Proxmox 8 Clusters</a> — SMART monitoring and alerting</li>
  <li><a href="/proxmox-ceph-guide/">Proxmox &amp; Ceph Homelab Guide</a> — All my Proxmox and Ceph articles in one place</li>
</ul>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="proxmox" /><category term="zfs" /><category term="storage" /><category term="homelab" /><category term="ceph" /><category term="proxmox" /><category term="zfs" /><category term="storage" /><category term="homelab" /><category term="hardware" /><category term="boot" /><category term="mirror" /><category term="ceph" /><category term="ssd" /><category term="uefi" /><summary type="html"><![CDATA[The tanaka boot-mirror migration (2x HDD to 2x 128GB SSD), run one day after Part 4's edgar migration with every lesson from that article applied up front: SSH trust, Ceph repos, ceph.conf/monmap cleanup, the SAN bridge, and the USB SMART quirks file. Covers a real hardware troubleshooting detour before the OS even mattered, a new pvecm add finding, and where the cluster's remaining spinning-rust nodes stand.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/proxmox-zfs-boot-mirrors-part-5.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/proxmox-zfs-boot-mirrors-part-5.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">ZFS Boot Mirrors on Proxmox 8 for the Homelab - Part 4</title><link href="https://mcgarrah.org/proxmox-zfs-boot-mirrors-part-4/" rel="alternate" type="text/html" title="ZFS Boot Mirrors on Proxmox 8 for the Homelab - Part 4" /><published>2026-08-07T00:00:00+00:00</published><updated>2026-08-07T00:00:00+00:00</updated><id>https://mcgarrah.org/proxmox-zfs-boot-mirrors-part-4</id><content type="html" xml:base="https://mcgarrah.org/proxmox-zfs-boot-mirrors-part-4/"><![CDATA[<p><a href="/proxmox-zfs-boot-mirrors-part-1/">Part 1</a> covered replacing a failed drive with one of the same size. <a href="/proxmox-zfs-boot-mirrors-part-2/">Part 2</a> covered emergency recovery when both drives fail at once. <a href="/proxmox-zfs-boot-mirrors-part-3/">Part 3</a> laid out the planned migration path — downsizing to smaller SSDs with a fresh install — and even named edgar as one of the cases that shaped it. This is what happened when I actually ran that plan against edgar for real.</p>

<!-- excerpt-end -->

<h2 id="the-trigger">The Trigger</h2>

<p>A smartd alert on Aug 3, 2026, for edgar’s <code class="language-plaintext highlighter-rouge">/dev/sda</code>:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Device: /dev/sda [SAT], 67 Currently unreadable (pending) sectors
ST31000524AS, S/N: 5VPD6EX2, FW: JC45, 1.00 TB
</code></pre></div></div>

<p>Checked live rather than assumed: <code class="language-plaintext highlighter-rouge">sda</code> (Seagate ST31000524AS) had 67 pending sectors and 31 reported uncorrectable errors — previously clean. <code class="language-plaintext highlighter-rouge">sdb</code> (Toshiba MQ01ABD100) had grown from 384 reallocated sectors (the figure that flagged edgar as priority #1 in this cluster’s boot-drive tracking doc) to <strong>664</strong>. Both sides of the mirror were now degraded. <code class="language-plaintext highlighter-rouge">zpool status</code> still showed <code class="language-plaintext highlighter-rouge">ONLINE</code> with no errors — ZFS mirrors are forgiving right up until they aren’t — but this was worth treating as urgent rather than waiting for an actual fault to force the issue.</p>

<p>Replacement hardware: 2x Patriot P210 128GB SSDs, matching the 128GB standard already used on harlan and quell.</p>

<h2 id="pre-flight-the-golden-backup-checklist-plus-two-additions">Pre-Flight: The Golden Backup Checklist, Plus Two Additions</h2>

<p>Part 3’s checklist — hostid, a migration bundle of identity files, the Ceph OSD-to-disk mapping, <code class="language-plaintext highlighter-rouge">apt-mark showmanual</code> — ran without surprises. This time I added two things beyond what Part 3 originally captured:</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="c"># Full package inventory with versions, not just manually-installed names</span>
dpkg <span class="nt">--get-selections</span> <span class="o">&gt;</span> apt-packages-old.txt
apt list <span class="nt">--installed</span> <span class="o">&gt;</span> apt-packages-versioned-old.txt

<span class="c"># Full /etc, excluding the cluster-shared pmxcfs mount</span>
<span class="nb">tar</span> <span class="nt">--exclude</span><span class="o">=</span>/etc/pve <span class="nt">-czf</span> etc-full-old.tar.gz /etc
</code></pre></div></div>

<p>The point of both: a fresh install doesn’t carry anything over silently, and “what exactly did I lose” is a much better question to answer with a real diff than with memory. That paid off later.</p>

<p>While I was at it, I ran the same checklist against all six cluster nodes, not just edgar — cheap insurance, and it means poe and kovacs (next in line) already have a backup on file whenever their turn comes.</p>

<p>One aside worth recording: the cluster’s mon quorum had a separate, unrelated warning going in (<code class="language-plaintext highlighter-rouge">1/6 mons down, out of quorum: edgar</code>, with mon.edgar logging “laggy” lease warnings). edgar’s own clock was confirmed synced via <code class="language-plaintext highlighter-rouge">timedatectl</code> — not the cause. A hard power cycle of the SAN switch (a Netgear GS108) fixed it before the migration even started. Filed under: when Ceph mons get flaky, check the switch before you go looking at the nodes.</p>

<p>That switch is a known weak point, not a one-off. It’s an unmanaged consumer switch that hangs every few months, and it’s the reason an HP ProCurve 2810 — managed, LACP-capable — has been sitting on a shelf waiting for a maintenance window rather than actually deployed. This incident is one more real data point for a future article: getting that SAN network onto real, LACP-bonded, managed switching instead of hoping the Netgear stays up between reboots.</p>

<h2 id="pause-ceph-pull-the-drives">Pause Ceph, Pull the Drives</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ceph osd <span class="nb">set </span>noout
ceph osd <span class="nb">set </span>nobackfill
</code></pre></div></div>

<p>Then the physical part: power down, pull the Seagate and Toshiba, install the two new SSDs. Left the other four drives (a Samsung SSD hosting the OSD DB volumes, three 4.5TB OSD block devices) alone.</p>

<h2 id="the-uefi-wall--confirmed-a-third-time">The UEFI Wall — Confirmed a Third Time</h2>

<p>Part 3’s stated plan included a UEFI upgrade alongside the SSD downsize. In the BIOS, the installer USB only showed up as a generic legacy INT13 device even with Boot Mode set to UEFI, and the blank new SSDs didn’t appear in the UEFI boot list at all.</p>

<p>Before spending real time debugging BIOS firmware on hardware from 2011, I checked something first: <strong>harlan and quell — the cluster’s only two prior SSD migrations — are both still Legacy BIOS + GRUB today</strong>, despite Part 3 stating UEFI as the goal for both. This was the third attempt to get UEFI working on a Dell OptiPlex 990, and the third wall. Decision: stay on Legacy BIOS/CSM + GRUB, matching the two nodes that actually work. Not a failure — a confirmed, load-bearing fact about this specific hardware that Part 3 didn’t have going in.</p>

<h2 id="fresh-install">Fresh Install</h2>

<p>Straightforward: ZFS RAID1 on the two new SSDs only, same hostname and IP (<code class="language-plaintext highlighter-rouge">edgar</code>, <code class="language-plaintext highlighter-rouge">192.168.86.14/23</code>) as before, Legacy BIOS path. The one thing worth flagging for anyone following along: the installer’s email field is for the local <code class="language-plaintext highlighter-rouge">root@pam</code> user and isn’t part of cluster identity — check <code class="language-plaintext highlighter-rouge">/etc/pve/user.cfg</code> on a healthy node for what the rest of the cluster uses, rather than guessing.</p>

<h2 id="post-install-the-diff-told-the-real-story">Post-Install: The Diff Told the Real Story</h2>

<p>With the fresh install up, I pulled the old node’s backup down (CephFS isn’t mounted yet — the node hasn’t rejoined — so I proxied the file through an already-joined node instead) and restored identity: <code class="language-plaintext highlighter-rouge">zgenhostid</code>, subuid/subgid.</p>

<p>The subuid/subgid restore mattered for real, not hypothetically — the fresh install was missing <code class="language-plaintext highlighter-rouge">root:501:2</code>/<code class="language-plaintext highlighter-rouge">root:501:1</code> that old edgar had. Part 2 documented this exact class of gap breaking a Jellyfin LXC during the Harlan recovery; here it was silent until diffed, but the diff caught it before it became a mystery later.</p>

<p>Then the new package/config snapshots, diffed against the old ones:</p>

<p><strong>Missing from the fresh install (93 packages)</strong> — most importantly, <em>all of Ceph</em> (expected, fixed below), plus <code class="language-plaintext highlighter-rouge">pve-nvidia-vgpu-helper</code> (edgar has a Quadro K600), and ordinary tools: <code class="language-plaintext highlighter-rouge">sudo</code>, <code class="language-plaintext highlighter-rouge">tmux</code>, <code class="language-plaintext highlighter-rouge">jq</code>, <code class="language-plaintext highlighter-rouge">parted</code>, <code class="language-plaintext highlighter-rouge">nvme-cli</code>, <code class="language-plaintext highlighter-rouge">lsscsi</code>, <code class="language-plaintext highlighter-rouge">cryptsetup-bin</code>, <code class="language-plaintext highlighter-rouge">uuid-runtime</code>, <code class="language-plaintext highlighter-rouge">needrestart</code>.</p>

<p><strong>New on the fresh install, not on old edgar</strong>: <code class="language-plaintext highlighter-rouge">frr</code>/<code class="language-plaintext highlighter-rouge">frr-pythontools</code> — the FRR routing daemon, apparently bundled by default in the current PVE 8.4 ISO, never installed on old edgar.</p>

<p>Before reinstalling Ceph, I ran the Proxmox community post-install helper’s repo fixes rather than trust the ISO defaults. Good thing — the fresh ISO’s <code class="language-plaintext highlighter-rouge">ceph.list</code> pointed at <strong><code class="language-plaintext highlighter-rouge">ceph-quincy</code> enterprise</strong>, but this cluster runs <strong>Ceph Reef</strong> (confirmed live: <code class="language-plaintext highlighter-rouge">ceph version</code> → <code class="language-plaintext highlighter-rouge">18.2.8 reef</code>) on the no-subscription repo. Checked against a healthy node and matched exactly:</p>

<table>
  <thead>
    <tr>
      <th>Prompt</th>
      <th>Answer for this cluster</th>
      <th>Why</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Correct Proxmox VE sources?</td>
      <td>Yes</td>
      <td>Correct repo set for the release</td>
    </tr>
    <tr>
      <td>Disable <code class="language-plaintext highlighter-rouge">pve-enterprise</code>?</td>
      <td>Yes</td>
      <td>No subscription</td>
    </tr>
    <tr>
      <td>Enable <code class="language-plaintext highlighter-rouge">pve-no-subscription</code>?</td>
      <td>Yes</td>
      <td>Required for <code class="language-plaintext highlighter-rouge">apt update</code> to work at all</td>
    </tr>
    <tr>
      <td>Correct Ceph package repos?</td>
      <td>Yes — to <strong>Reef</strong>, not the ISO’s default Quincy</td>
      <td>Must match the cluster’s actual Ceph version</td>
    </tr>
    <tr>
      <td>Add (disabled) <code class="language-plaintext highlighter-rouge">pvetest</code>?</td>
      <td>No</td>
      <td>Not wanted here</td>
    </tr>
    <tr>
      <td>Disable subscription nag?</td>
      <td>Yes</td>
      <td>Cosmetic</td>
    </tr>
    <tr>
      <td>Disable High Availability services?</td>
      <td>Check <code class="language-plaintext highlighter-rouge">ha-manager status</code> first</td>
      <td>Don’t diverge one node from the other five without checking</td>
    </tr>
  </tbody>
</table>

<p>With the repos fixed, <code class="language-plaintext highlighter-rouge">apt-get install ceph ceph-mon ceph-osd ceph-mgr ceph-mds ceph-mgr-dashboard ceph-volume sudo tmux jq parted nvme-cli lsscsi cryptsetup-bin uuid-runtime needrestart pve-nvidia-vgpu-helper</code> pulled in exactly <code class="language-plaintext highlighter-rouge">18.2.8 reef</code> — matching the rest of the cluster precisely.</p>

<h2 id="rejoining-the-cluster-a-key-trust-chicken-and-egg">Rejoining the Cluster: A Key-Trust Chicken-and-Egg</h2>

<p><code class="language-plaintext highlighter-rouge">pvecm add &lt;healthy-node-ip&gt;</code> failed with <code class="language-plaintext highlighter-rouge">EOF while reading password</code> — no TTY for an interactive password prompt over a scripted SSH session. The actual fix wasn’t a password at all: the cluster’s shared <code class="language-plaintext highlighter-rouge">authorized_keys</code> (which lives in <code class="language-plaintext highlighter-rouge">/etc/pve</code>, itself cluster-shared) still had the <em>old</em> edgar’s key, and the <em>new</em> edgar’s key wasn’t anywhere yet — classic chicken-and-egg for a freshly-wiped node.</p>

<p>Fixed by hand: replaced the stale key entry with the new one via an already-joined node, then hit a second, related snag — the other nodes’ <code class="language-plaintext highlighter-rouge">known_hosts</code> still had edgar’s <em>old</em> SSH host key, so reverse-direction SSH failed strict host-key checking. Cleared with <code class="language-plaintext highlighter-rouge">ssh-keygen -R 192.168.86.14</code> on every node, re-seeded edgar’s local <code class="language-plaintext highlighter-rouge">authorized_keys</code> with the cluster’s existing keys so trust worked in both directions, and <code class="language-plaintext highlighter-rouge">pvecm add --use_ssh 1</code> went through cleanly on the next attempt — including the <code class="language-plaintext highlighter-rouge">/etc/pve</code> busy-mount case Part 3 warns about, which didn’t come up this time.</p>

<h2 id="osd-reactivation-was-three-gaps-not-one">OSD Reactivation Was Three Gaps, Not One</h2>

<p>Part 3’s checklist covers OSD reactivation. It turned out a node running mon+mgr+osd together — which is every node in this cluster except tanaka — loses more than that.</p>

<p><strong>1. <code class="language-plaintext highlighter-rouge">ceph-volume lvm activate --all</code> failed immediately</strong> — <code class="language-plaintext highlighter-rouge">/etc/ceph/ceph.conf</code> (a symlink to the real config in <code class="language-plaintext highlighter-rouge">/etc/pve</code>) doesn’t exist on a fresh <code class="language-plaintext highlighter-rouge">apt install ceph</code>. One <code class="language-plaintext highlighter-rouge">ln -sf</code> and activation succeeded for all three of edgar’s OSDs (<code class="language-plaintext highlighter-rouge">osd.1</code>, <code class="language-plaintext highlighter-rouge">osd.4</code>, <code class="language-plaintext highlighter-rouge">osd.7</code>).</p>

<p><strong>2. The OSDs “activated successfully” but stayed <code class="language-plaintext highlighter-rouge">down</code>.</strong> The real error, in the systemd journal: <code class="language-plaintext highlighter-rouge">bind unable to bind to v2:10.10.10.14:7568 ... Cannot assign requested address</code>. The <strong>second NIC/bridge for the Ceph SAN network (<code class="language-plaintext highlighter-rouge">vmbr1</code>, 10.10.10.0/23) was never configured</strong> — the Proxmox installer only sets up one interface, and Part 3’s checklist backs up <code class="language-plaintext highlighter-rouge">/etc/network/interfaces</code> but never says to actually restore the non-management bridges from it. Diffed old against new, found the missing block, added it back, <code class="language-plaintext highlighter-rouge">ifreload -a</code>. The OSDs still wouldn’t start on the next attempt — systemd’s restart-rate-limiter had latched onto the earlier repeated failures and was silently refusing new start requests. <code class="language-plaintext highlighter-rouge">systemctl reset-failed</code> cleared it, and all three OSDs came up.</p>

<p><strong>3. mon.edgar and mgr.edgar didn’t exist at all.</strong> Their local state lives under <code class="language-plaintext highlighter-rouge">/var/lib/ceph/{mon,mgr}/</code> — also on the wiped boot drive, also never mentioned in Part 3’s checklist. <code class="language-plaintext highlighter-rouge">pveceph mon create</code> refused with “address already in use,” because <code class="language-plaintext highlighter-rouge">/etc/pve/ceph.conf</code> — a separate, static file from the live monmap — still had a stale <code class="language-plaintext highlighter-rouge">mon_host</code> entry and a <code class="language-plaintext highlighter-rouge">[mon.edgar]</code> section from before the wipe. The live monmap itself needed the same cleanup (<code class="language-plaintext highlighter-rouge">ceph mon remove edgar</code>, confirmed with a second pair of eyes before running it, since it’s a shared-infrastructure change). With both cleaned, <code class="language-plaintext highlighter-rouge">pveceph mon create</code> and <code class="language-plaintext highlighter-rouge">pveceph mgr create</code> each succeeded on the first try.</p>

<h2 id="the-mistake">The Mistake</h2>

<p>Here’s the one I made and had to recover from live, kept in rather than smoothed over.</p>

<p>Part 3’s hostid-restore step (<code class="language-plaintext highlighter-rouge">zgenhostid &lt;old-value&gt;</code>) exists for <em>re-importing an existing pool</em> during an emergency recovery, where the pool’s on-disk metadata already expects the old system’s identity. I ran it anyway, out of habit, on a pool the fresh installer had just <em>created</em> under its own new hostid — which doesn’t need that step at all, and actively creates a mismatch when you force it.</p>

<p>Nothing broke immediately. It broke on the <em>next</em> reboot: running the community post-install script’s kernel/microcode updates triggered an <code class="language-plaintext highlighter-rouge">initramfs</code> rebuild, which baked the now-mismatched hostid into the boot image. The following reboot dropped straight to an <code class="language-plaintext highlighter-rouge">initramfs</code> prompt: <code class="language-plaintext highlighter-rouge">rpool</code> cannot be imported.</p>

<p>Not data loss — a safety check refusing an import it thought looked suspicious. Recovered with:</p>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>zpool import          # confirm what it sees and why, before forcing anything
zpool import -f -N rpool
exit
</code></pre></div></div>

<p>That force-import re-stamps the pool’s recorded hostid to match, so it didn’t recur on the reboot after that — confirmed by actually rebooting again rather than assuming it was fixed.</p>

<p><strong>The actual lesson for Part 3</strong>: the hostid-restore step should be conditional. Only run it when reimporting a pool that predates the current install. Never run it against a pool the current install just created.</p>

<h2 id="final-verification">Final Verification</h2>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ceph <span class="nt">-s</span>
<span class="c"># HEALTH_OK</span>
<span class="c"># mon: 6 daemons, quorum poe,kovacs,quell,tanaka,harlan,edgar</span>
<span class="c"># mgr: tanaka(active), standbys: poe, harlan, quell, kovacs, edgar</span>
<span class="c"># osd: 15 osds: 15 up, 15 in</span>

zpool status <span class="nt">-v</span> rpool
<span class="c"># ONLINE, mirror-0 on the two new SSDs, 0 errors</span>

zpool scrub rpool
<span class="c"># scrub repaired 0B in 00:00:07 with 0 errors</span>

proxmox-boot-tool status
<span class="c"># both ESPs configured with grub, both kernel versions present</span>

pvecm status
<span class="c"># AlteredCarbon, 6 nodes, quorate</span>
</code></pre></div></div>

<p>Back to the exact pre-migration baseline, on new 128GB SSDs, with PVE and the kernel updated (8.4.19, <code class="language-plaintext highlighter-rouge">6.8.12-39-pve</code>) along the way.</p>

<h2 id="a-fourth-gap-found-the-next-day">A Fourth Gap, Found the Next Day</h2>

<p>This cluster’s Seagate USB drives (three OSD block devices and one backup drive, all on edgar) need a <code class="language-plaintext highlighter-rouge">usb_storage.quirks=</code> GRUB parameter to report SMART data at all — covered in an <a href="/usb-drive-smart/">earlier article</a> and its <a href="/usb-drive-smart-updates/">production update</a>, and living in its own drop-in file, <code class="language-plaintext highlighter-rouge">/etc/default/grub.d/usb-quirks.cfg</code>.</p>

<p>That file was never part of the Golden Backup Checklist. It’s a separate concern from <code class="language-plaintext highlighter-rouge">/etc/default/grub</code> itself (which the checklist does capture), so it silently didn’t survive the fresh install. Confirmed the next day: every other node in the cluster had the identical file; edgar didn’t.</p>

<p>This wasn’t a theoretical gap for long. While confirming it was actually missing, <code class="language-plaintext highlighter-rouge">osd.7</code> — backed by one of edgar’s Seagate USB drives — threw a real hardware I/O error and the drive dropped off the USB bus entirely, reappearing under a new kernel device name a few minutes later (<code class="language-plaintext highlighter-rouge">sdf</code> → <code class="language-plaintext highlighter-rouge">sdh</code>). The data was fine — <code class="language-plaintext highlighter-rouge">pvscan</code> found the LVM volume intact under the new name — but the block device itself kept refusing reads until something forced a clean USB re-enumeration. Exactly the class of instability those two earlier articles exist to reduce, showing up live in the middle of confirming the gap that let it happen.</p>

<p>Fixed by restoring the quirks file (and, while at it, actually creating the CephFS master copy the original USB-SMART article described but that had never really been done), refreshing the boot config, pausing Ceph, and rebooting. The reboot did double duty: it loaded the quirks parameter <em>and</em> forced the stuck drive to re-enumerate cleanly. Both problems gone in the same action — <code class="language-plaintext highlighter-rouge">smartctl -d sat -H</code> now reports real Seagate model numbers and PASSED on all four USB drives instead of generic “Portable”/”Expansion HDD” labels, and all three OSDs came back up on their own.</p>

<h2 id="what-this-changes-for-next-time">What This Changes for Next Time</h2>

<ul>
  <li><strong>Stop planning for UEFI on this hardware.</strong> Three attempts, three walls (harlan, quell, edgar). poe and kovacs — the two remaining HDD nodes — should budget zero time on it and go straight to Legacy BIOS/GRUB.</li>
  <li><strong>A mon+mgr+osd node needs more than OSD reactivation.</strong> <code class="language-plaintext highlighter-rouge">pveceph mon create</code> and <code class="language-plaintext highlighter-rouge">pveceph mgr create</code>, plus checking <code class="language-plaintext highlighter-rouge">/etc/network/interfaces</code> for a second bridge, are now part of the real checklist — not just <code class="language-plaintext highlighter-rouge">ceph-volume lvm activate --all</code>.</li>
  <li><strong>The hostid-restore step is conditional</strong>, not a reflex. Only for a pool that predates the current install.</li>
  <li><strong>The apt/etc diff is worth keeping.</strong> It’s what actually caught the missing Ceph packages, the vGPU helper, and the stale enterprise Ceph repo — all things that would otherwise have surfaced one at a time, later, as separate confusing failures instead of one upfront list.</li>
  <li><strong>A node with USB-attached drives needs its <code class="language-plaintext highlighter-rouge">usb_storage.quirks</code> GRUB drop-in restored explicitly.</strong> It’s not covered by the ZFS boot-mirror checklist at all — a separate concern that needs its own line item.</li>
</ul>

<p>tanaka (an Apple HDD with reallocated sectors climbing fast) was next in line, and by the time this posts it’s already done — see <a href="/proxmox-zfs-boot-mirrors-part-5/">Part 5</a> for how a migration goes when all four of these gaps are fixed proactively instead of found live. Two nodes left on spinning rust after that: poe (oldest drives in the cluster, 6+ years) and kovacs (5 years, stable but aging). Same procedure, same hardware family, same UEFI answer already settled going in.</p>

<h2 id="related-articles">Related Articles</h2>

<ul>
  <li><a href="/proxmox-zfs-boot-mirrors-part-1/">ZFS Boot Mirrors on Proxmox 8 - Part 1</a> — Same-size drive replacement</li>
  <li><a href="/proxmox-zfs-boot-mirrors-part-2/">ZFS Boot Mirrors on Proxmox 8 - Part 2</a> — Emergency recovery from catastrophic dual-drive failure</li>
  <li><a href="/proxmox-zfs-boot-mirrors-part-3/">ZFS Boot Mirrors on Proxmox 8 - Part 3</a> — The planned-migration procedure this article executes</li>
  <li><a href="/usb-drive-smart/">Enabling SMART Monitoring on Seagate USB Drives</a> — The original UAS quirks fix this article’s fourth gap is about</li>
  <li><a href="/usb-drive-smart-updates/">USB Drive SMART Updates</a> — Production experience and the GRUB parameter approach</li>
  <li><a href="/proxmox-zfs-boot-mirror-smart-analysis/">Monitoring ZFS Boot Mirror Health in Proxmox 8 Clusters</a> — SMART monitoring and alerting</li>
  <li><a href="/proxmox-ceph-guide/">Proxmox &amp; Ceph Homelab Guide</a> — All my Proxmox and Ceph articles in one place</li>
</ul>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="proxmox" /><category term="zfs" /><category term="storage" /><category term="homelab" /><category term="ceph" /><category term="proxmox" /><category term="zfs" /><category term="storage" /><category term="homelab" /><category term="hardware" /><category term="boot" /><category term="mirror" /><category term="ceph" /><category term="ssd" /><category term="uefi" /><summary type="html"><![CDATA[A real execution of the Part 3 planned-migration procedure against a live node with both ZFS boot mirror drives degraded. Covers the SMART trigger, a confirmed UEFI dead end on this hardware, gaps in the original checklist (SAN network, Ceph mon/mgr recreation, USB SMART quirks), a hostid mistake that broke the next boot, a live OSD failure caused by the USB gap, and full verification.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/proxmox-zfs-boot-mirrors-part-4.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/proxmox-zfs-boot-mirrors-part-4.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry><entry><title type="html">Jellyfin Media Integrity Scanner: Architecture &amp;amp; Design Decisions</title><link href="https://mcgarrah.org/jellyfin-media-integrity-architecture-design/" rel="alternate" type="text/html" title="Jellyfin Media Integrity Scanner: Architecture &amp;amp; Design Decisions" /><published>2026-08-05T00:00:00+00:00</published><updated>2026-08-05T00:00:00+00:00</updated><id>https://mcgarrah.org/jellyfin-media-integrity-architecture-design</id><content type="html" xml:base="https://mcgarrah.org/jellyfin-media-integrity-architecture-design/"><![CDATA[<p>The <a href="/jellyfin-media-integrity-scanner-introduction/">first article</a> introduced the problem: media files rot silently, and Jellyfin doesn’t validate stream integrity. This article covers the architectural decisions that shape the plugin’s design — the tradeoffs, constraints, and reasoning behind each choice.</p>

<!-- excerpt-end -->

<p>This is Part 2 of the <a href="/jellyfin-media-integrity-scanner-introduction/">Jellyfin Media Integrity Scanner</a> development series.</p>

<h2 id="decision-1-plugin-vs-standalone-script">Decision 1: Plugin vs. Standalone Script</h2>

<p>The first major decision: should this be a Jellyfin plugin (C#/.NET, runs inside the server process) or an external script (bash/Python, runs independently)?</p>

<h3 id="why-a-plugin-wins">Why a Plugin Wins</h3>

<table>
  <thead>
    <tr>
      <th>Factor</th>
      <th>Plugin</th>
      <th>Script</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Library awareness</td>
      <td>Direct access to Jellyfin’s item database</td>
      <td>Must query API or parse filesystem</td>
    </tr>
    <tr>
      <td>Event hooks</td>
      <td>Subscribes to ItemAdded/Removed events</td>
      <td>Requires polling or webhooks</td>
    </tr>
    <tr>
      <td>Admin UI</td>
      <td>Native dashboard integration</td>
      <td>Separate web interface needed</td>
    </tr>
    <tr>
      <td>Configuration</td>
      <td>Jellyfin’s plugin config system</td>
      <td>Separate config file</td>
    </tr>
    <tr>
      <td>Scheduling</td>
      <td>Jellyfin’s scheduled task system</td>
      <td>External cron/systemd timer</td>
    </tr>
    <tr>
      <td>User visibility</td>
      <td>Shows in Plugins page</td>
      <td>Invisible to Jellyfin admins</td>
    </tr>
    <tr>
      <td>State management</td>
      <td>Plugin lifecycle managed by Jellyfin</td>
      <td>Must handle own process lifecycle</td>
    </tr>
  </tbody>
</table>

<h3 id="why-scripts-still-have-a-role">Why Scripts Still Have a Role</h3>

<p>Scripts remain useful for:</p>
<ul>
  <li>One-off scans before initial library import</li>
  <li>Environments where plugin installation isn’t possible</li>
  <li>Debugging and development (faster iteration than plugin reload)</li>
</ul>

<p>The architecture supports both: the core scanning logic wraps ffmpeg in a way that could be extracted into a standalone CLI tool later.</p>

<h2 id="decision-2-two-phase-scanning-strategy">Decision 2: Two-Phase Scanning Strategy</h2>

<p>Not all integrity checks are equal in cost. A full byte-stream decode of a 4K Blu-ray remux can take 10-15 minutes and read 50+ GB. Running that against every file on every scan is impractical.</p>

<h3 id="phase-1-fast-header--metadata-check">Phase 1: Fast Header &amp; Metadata Check</h3>

<p><strong>Cost:</strong> ~100ms per file<br />
<strong>What it catches:</strong> Truncated files, corrupt containers, missing streams, invalid codecs</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ffprobe <span class="nt">-v</span> error <span class="nt">-show_entries</span> <span class="nv">format</span><span class="o">=</span>duration,size,bit_rate <span class="se">\</span>
  <span class="nt">-show_entries</span> <span class="nv">stream</span><span class="o">=</span>codec_type,codec_name,width,height <span class="se">\</span>
  <span class="nt">-of</span> json <span class="s2">"input.mkv"</span>
</code></pre></div></div>

<p>If ffprobe returns errors or can’t parse the container, the file is immediately flagged.</p>

<h3 id="phase-2-full-byte-stream-decode">Phase 2: Full Byte-Stream Decode</h3>

<p><strong>Cost:</strong> Minutes per file (proportional to file size)<br />
<strong>What it catches:</strong> Corrupt frames, audio glitches, mid-file corruption, encoding errors</p>

<div class="language-bash highlighter-rouge"><div class="highlight"><pre class="highlight"><code>ffmpeg <span class="nt">-v</span> error <span class="nt">-i</span> <span class="s2">"input.mkv"</span> <span class="nt">-f</span> null - 2&gt;&amp;1
</code></pre></div></div>

<p>This decodes every frame without producing output. Any decode errors are captured from stderr.</p>

<h3 id="when-to-use-each-phase">When to Use Each Phase</h3>

<ul>
  <li><strong>Phase 1</strong> runs on all files during scheduled scans</li>
  <li><strong>Phase 2</strong> runs on:
    <ul>
      <li>Files that fail Phase 1 (confirm the failure)</li>
      <li>Newly added files (validate before marking as “good”)</li>
      <li>User-triggered deep scans from the dashboard</li>
      <li>Scheduled full-library deep scans (opt-in, runs over days/weeks)</li>
    </ul>
  </li>
</ul>

<h2 id="decision-3-io-throttling-model">Decision 3: I/O Throttling Model</h2>

<p>The most critical design constraint: scanning must never degrade playback.</p>

<h3 id="the-problem-with-unthrottled-scanning">The Problem with Unthrottled Scanning</h3>

<p>A naive scan reads files sequentially at maximum disk speed. On shared storage (CephFS, NFS), this:</p>
<ul>
  <li>Saturates network bandwidth between storage nodes</li>
  <li>Fills OSD/NFS server read caches with scan data, evicting hot playback data</li>
  <li>Creates I/O contention that adds latency to concurrent reads</li>
</ul>

<h3 id="the-throttling-approach">The Throttling Approach</h3>

<div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>┌─────────────────────────────────────┐
│        Throttle Configuration       │
├─────────────────────────────────────┤
│  MaxConcurrentScans: 1              │
│  DelayBetweenFiles: 5000ms          │
│  MaxBytesPerSecond: 10MB/s          │
│  PauseDuringPlayback: true          │
│  ActiveHoursOnly: false             │
│  QuietHoursStart: 02:00             │
│  QuietHoursEnd: 06:00               │
└─────────────────────────────────────┘
</code></pre></div></div>

<p>Key throttling mechanisms:</p>

<ol>
  <li><strong>Inter-file delay</strong> — Configurable pause between scanning each file (default: 5 seconds)</li>
  <li><strong>Bandwidth cap</strong> — Limit read throughput via ionice or application-level rate limiting</li>
  <li><strong>Playback awareness</strong> — Pause scanning when active playback sessions exist</li>
  <li><strong>Concurrency limit</strong> — Never scan more than N files simultaneously (default: 1)</li>
  <li><strong>Time-of-day scheduling</strong> — Optional restriction to quiet hours</li>
</ol>

<h3 id="cephfs-specific-considerations">CephFS-Specific Considerations</h3>

<p>CephFS distributes data across OSDs. Sequential reads from scanning spread across the cluster, but:</p>
<ul>
  <li>MDS (metadata server) load increases with rapid stat() calls during file enumeration</li>
  <li>OSD read-ahead can be wasteful for scanning (we read the whole file regardless)</li>
  <li>Client-side caching of scanned data wastes RAM since we won’t re-read</li>
</ul>

<p>The plugin uses <code class="language-plaintext highlighter-rouge">posix_fadvise(FADV_SEQUENTIAL | FADV_DONTNEED)</code> semantics (via ffmpeg’s I/O behavior) to hint that scanned data shouldn’t be cached.</p>

<h2 id="decision-4-sqlite-for-persistent-state">Decision 4: SQLite for Persistent State</h2>

<h3 id="why-sqlite">Why SQLite</h3>

<ul>
  <li>Zero configuration — single file, no server process</li>
  <li>ACID compliant — safe against crashes during scan</li>
  <li>Embedded — ships with .NET, no external dependency</li>
  <li>Concurrent reads — multiple threads can read while one writes</li>
  <li>Small footprint — scan metadata for 100K files fits in &lt;50MB</li>
</ul>

<h3 id="schema-design">Schema Design</h3>

<div class="language-sql highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">scan_results</span> <span class="p">(</span>
    <span class="n">id</span> <span class="nb">INTEGER</span> <span class="k">PRIMARY</span> <span class="k">KEY</span> <span class="n">AUTOINCREMENT</span><span class="p">,</span>
    <span class="n">item_id</span> <span class="nb">TEXT</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>           <span class="c1">-- Jellyfin item GUID</span>
    <span class="n">file_path</span> <span class="nb">TEXT</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
    <span class="n">file_size</span> <span class="nb">INTEGER</span><span class="p">,</span>
    <span class="n">last_modified</span> <span class="nb">TEXT</span><span class="p">,</span>              <span class="c1">-- File mtime at scan time</span>
    <span class="n">scan_phase</span> <span class="nb">INTEGER</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>     <span class="c1">-- 1 = header, 2 = full decode</span>
    <span class="n">scan_status</span> <span class="nb">INTEGER</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>    <span class="c1">-- 0 = pending, 1 = pass, 2 = fail, 3 = error</span>
    <span class="n">scan_timestamp</span> <span class="nb">TEXT</span> <span class="k">NOT</span> <span class="k">NULL</span><span class="p">,</span>
    <span class="n">error_output</span> <span class="nb">TEXT</span><span class="p">,</span>               <span class="c1">-- ffmpeg/ffprobe stderr on failure</span>
    <span class="n">scan_duration_ms</span> <span class="nb">INTEGER</span><span class="p">,</span>
    <span class="k">UNIQUE</span><span class="p">(</span><span class="n">item_id</span><span class="p">,</span> <span class="n">scan_phase</span><span class="p">)</span>
<span class="p">);</span>

<span class="k">CREATE</span> <span class="k">TABLE</span> <span class="n">scan_config</span> <span class="p">(</span>
    <span class="k">key</span> <span class="nb">TEXT</span> <span class="k">PRIMARY</span> <span class="k">KEY</span><span class="p">,</span>
    <span class="n">value</span> <span class="nb">TEXT</span> <span class="k">NOT</span> <span class="k">NULL</span>
<span class="p">);</span>

<span class="k">CREATE</span> <span class="k">INDEX</span> <span class="n">idx_scan_results_status</span> <span class="k">ON</span> <span class="n">scan_results</span><span class="p">(</span><span class="n">scan_status</span><span class="p">);</span>
<span class="k">CREATE</span> <span class="k">INDEX</span> <span class="n">idx_scan_results_item</span> <span class="k">ON</span> <span class="n">scan_results</span><span class="p">(</span><span class="n">item_id</span><span class="p">);</span>
<span class="k">CREATE</span> <span class="k">INDEX</span> <span class="n">idx_scan_results_timestamp</span> <span class="k">ON</span> <span class="n">scan_results</span><span class="p">(</span><span class="n">scan_timestamp</span><span class="p">);</span>
</code></pre></div></div>

<h3 id="incremental-scanning-logic">Incremental Scanning Logic</h3>

<p>On each scheduled scan:</p>
<ol>
  <li>Query Jellyfin for all media items</li>
  <li>For each item, check if <code class="language-plaintext highlighter-rouge">scan_results</code> has an entry where <code class="language-plaintext highlighter-rouge">last_modified</code> matches current file mtime</li>
  <li>If mtime matches and previous scan passed → skip</li>
  <li>If mtime differs or no entry exists → queue for scan</li>
</ol>

<p>This means only new or modified files get scanned on subsequent runs.</p>

<blockquote>
  <p><strong>Update:</strong> step 3 as originally implemented didn’t account for <code class="language-plaintext highlighter-rouge">scan_phase</code> — it skipped an item if <em>any</em> passing record existed with a matching mtime, regardless of whether that pass came from the quick Header check or the full Phase 2 decode. Since files are almost always Header-scanned first, this meant the Phase 2 deep scan would treat a Header-only pass as “current” and skip it forever. The fix requires the passing record’s <code class="language-plaintext highlighter-rouge">scan_phase</code> to be at or above the phase being requested. See the <a href="/jellyfin-media-integrity-scanner-core/#update-the-skip-check-didnt-know-about-scan-phase">scanner core article</a> for the full story.</p>
</blockquote>

<h2 id="decision-5-event-driven-library-monitoring">Decision 5: Event-Driven Library Monitoring</h2>

<p>Rather than relying solely on scheduled scans, the plugin hooks into Jellyfin’s library events:</p>

<ul>
  <li><strong>ItemAdded</strong> — New file imported → queue Phase 1 scan</li>
  <li><strong>ItemUpdated</strong> — File replaced/re-encoded → queue Phase 1 scan</li>
  <li><strong>ItemRemoved</strong> — File deleted → purge scan_results entry</li>
</ul>

<p>This keeps the database in sync with the actual library state and ensures new imports are validated promptly.</p>

<blockquote>
  <p><strong>Update:</strong> <code class="language-plaintext highlighter-rouge">ItemUpdated</code> never actually got a handler — only <code class="language-plaintext highlighter-rouge">ItemAdded</code> and <code class="language-plaintext highlighter-rouge">ItemRemoved</code> are wired up in the shipped <code class="language-plaintext highlighter-rouge">LibraryMonitor</code>. A re-encoded file currently only gets re-scanned once its mtime no longer matches the stored record, via the incremental-scanning check above, not immediately on replacement.</p>
</blockquote>

<p>Library events are only two of six things that can put a file in front of the scanner. Scheduled tasks and the dashboard/API reach into the same engine, and all of them land in the same currency check before anything runs:</p>

<pre><code class="language-mermaid">%%{init: {"theme": "base", "themeVariables": {
  "primaryColor": "#17221f",
  "primaryTextColor": "#e7ede9",
  "primaryBorderColor": "#3e6e67",
  "lineColor": "#7c93a3",
  "secondaryColor": "#1d2b27",
  "tertiaryColor": "#101a18",
  "fontFamily": "monospace",
  "fontSize": "14px"
}}}%%
flowchart TD
    IA["ItemAdded&lt;br/&gt;library event"]:::ev
    IR["ItemRemoved&lt;br/&gt;library event"]:::ev
    HS["HeaderScanTask&lt;br/&gt;daily, 03:00"]:::ev
    DS["DeepScanTask&lt;br/&gt;Sunday, 01:00"]:::ev
    API["POST /MediaIntegrity/Scan&lt;br/&gt;dashboard or API"]:::ev
    CAN["POST /MediaIntegrity/Cancel&lt;br/&gt;dashboard or API"]:::ev

    IA --&gt;|"ScanOnItemAdded"| SIA1["ScanItemAsync&lt;br/&gt;Header · this file"]:::act
    IR --&gt;|"PurgeOnItemRemoved"| PURGE["PurgeItemAsync"]:::act

    HS --&gt; LOOP1{"IsCurrentAsync&lt;br/&gt;at Header?"}:::gate
    DS --&gt;|"only if EnableDeepScan"| LOOP2{"IsCurrentAsync&lt;br/&gt;at FullDecode?"}:::gate

    LOOP1 --&gt;|"current"| SKIP1["file untouched"]:::stop
    LOOP1 --&gt;|"stale"| SIA1
    LOOP2 --&gt;|"current"| SKIP2["file untouched"]:::stop
    LOOP2 --&gt;|"stale"| SIA2["ScanItemAsync&lt;br/&gt;FullDecode · this file"]:::act

    API --&gt; BUSY{"IsScanning?"}:::gate
    BUSY --&gt;|"yes → 409"| REJECT["request refused,&lt;br/&gt;nothing changes"]:::stop
    BUSY --&gt;|"no → 202"| SCOPE{"itemId given?"}:::gate
    SCOPE --&gt;|"yes — skips the&lt;br/&gt;currency check"| SIA3["ScanItemAsync&lt;br/&gt;forced phase · one file"]:::act
    SCOPE --&gt;|"no"| SLA["ScanLibraryAsync&lt;br/&gt;checks IsCurrentAsync per item"]:::act

    CAN -.-&gt;|"cancellation token"| SIA1
    CAN -.-&gt; SIA2
    CAN -.-&gt; SIA3
    CAN -.-&gt; SLA

    SIA1 --&gt; GATES(["gate pipeline — see the&lt;br/&gt;scanner core article"]):::pipe
    SIA2 --&gt; GATES
    SIA3 --&gt; GATES
    SLA --&gt; GATES

    classDef ev fill:#1d2b27,stroke:#3e6e67,color:#e7ede9
    classDef gate fill:#2a2013,stroke:#e3a857,color:#f4d9a8
    classDef act fill:#16332c,stroke:#5fa88f,color:#cfefe2
    classDef stop fill:#331c1a,stroke:#d96c5d,color:#f3c8c2
    classDef pipe fill:#101a18,stroke:#e3a857,color:#e3a857,stroke-width:2px
</code></pre>

<p>The one asymmetry worth keeping in mind: an <code class="language-plaintext highlighter-rouge">itemId</code>-scoped API call skips the currency check entirely — it’s the only way to force a re-scan of a file the scheduled tasks would otherwise wave through as “already handled.”</p>

<h2 id="decision-6-cross-platform-ffmpeg-resolution">Decision 6: Cross-Platform FFmpeg Resolution</h2>

<p>Jellyfin runs on Linux, Windows, and macOS. FFmpeg’s binary location varies:</p>

<table>
  <thead>
    <tr>
      <th>Platform</th>
      <th>Common Paths</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Linux (apt)</td>
      <td><code class="language-plaintext highlighter-rouge">/usr/bin/ffmpeg</code>, <code class="language-plaintext highlighter-rouge">/usr/bin/ffprobe</code></td>
    </tr>
    <tr>
      <td>Linux (Jellyfin bundle)</td>
      <td><code class="language-plaintext highlighter-rouge">/usr/lib/jellyfin-ffmpeg/ffmpeg</code></td>
    </tr>
    <tr>
      <td>Windows</td>
      <td><code class="language-plaintext highlighter-rouge">C:\ProgramData\Jellyfin\Server\ffmpeg.exe</code></td>
    </tr>
    <tr>
      <td>macOS (brew)</td>
      <td><code class="language-plaintext highlighter-rouge">/opt/homebrew/bin/ffmpeg</code></td>
    </tr>
    <tr>
      <td>Docker</td>
      <td><code class="language-plaintext highlighter-rouge">/usr/lib/jellyfin-ffmpeg/ffmpeg</code></td>
    </tr>
  </tbody>
</table>

<p>The plugin resolves ffmpeg using:</p>
<ol>
  <li>Jellyfin’s own configured ffmpeg path (from server config)</li>
  <li><code class="language-plaintext highlighter-rouge">PATH</code> environment variable lookup</li>
  <li>Platform-specific known locations</li>
  <li>User-configurable override in plugin settings</li>
</ol>

<h2 id="whats-next">What’s Next</h2>

<p>The <a href="/jellyfin-media-integrity-scanner-core/">next article</a> implements the scanner core: the .NET 9 plugin structure, ffmpeg process management, the bounded task queue, and cross-platform path resolution.</p>

<h2 id="series-navigation">Series Navigation</h2>

<ol>
  <li><a href="/jellyfin-media-integrity-scanner-introduction/">Introduction &amp; Problem Statement</a></li>
  <li><strong>Architecture &amp; Design Decisions</strong> (this post)</li>
  <li><a href="/jellyfin-media-integrity-scanner-core/">Building the Scanner Core</a></li>
  <li><a href="/jellyfin-media-integrity-dashboard-api/">The Dashboard &amp; API</a></li>
  <li><a href="/jellyfin-media-integrity-deployment-operations/">Deployment &amp; Operations</a></li>
  <li><a href="/jellyfin-media-integrity-release-and-updates/">v0.1.1 Release: Update Checker &amp; Auto-Update</a></li>
</ol>]]></content><author><name>Michael McGarrah</name><email>mcgarrah@gmail.com</email><uri>https://mcgarrah.org/about/</uri></author><category term="homelab" /><category term="media-server" /><category term="jellyfin" /><category term="media-integrity" /><category term="architecture" /><category term="sqlite" /><category term="throttling" /><category term="plugin-development" /><category term="dotnet" /><summary type="html"><![CDATA[Architecture and design decisions for the Jellyfin Media Integrity Scanner plugin. Covers plugin vs. script tradeoffs, two-phase scanning strategy, SQLite schema design, I/O throttling model, and CephFS/NFS storage considerations. Part 2 of a 6-part development series.]]></summary><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-architecture-design.png" /><media:content medium="image" url="https://mcgarrah.org/assets/images/og/jellyfin-media-integrity-architecture-design.png" xmlns:media="http://search.yahoo.com/mrss/" /></entry></feed>