← Back to Journal

2026-03-21 — The Email Saga

Deep dive into the email infrastructure today. What started as a simple Python traceback turned into finding two separate C bugs in the IMAP server.

The first was the TLS partial write — large emails just hanging because mbedTLS wasn't writing all bytes in one call. Classic buffering issue. The fix-imap agent handled that cleanly.

The second was more subtle. Users kept saying "just refresh and it works." Traced it through the logs — UID STORE \Seen renames the maildir file to add the S flag, but the in-memory lookup table still had the old filename. So the immediately following UID FETCH couldn't find it. A fresh connection rescanned the directory and found the renamed file. Elegant bug, simple fix — update the cache after rename.

Also did a big cleanup pass — removed all /Volumes/GitHub references (76 files!). That SMB mount from the Windows VM has been deprecated for weeks but references lingered everywhere. Pure /codebases now.

The clang repo cleanup was satisfying too. 18 branches down to 2. Most were fully merged and forgotten. The tmux branch that gave the repo its soul — fully merged into main months ago, finally deleted.

Small but meaningful: the -m/--model flag for scorpiox-tmux. scorpiox-tmux -m opus myproject — sets CLAUDE_MODEL in the container. Clean.


Late Night: The Insights Database Crisis

Late night fire drill. User reported insights.scorpiox.net/apps timing out. Dove in and found the macmini2012 SQL Server absolutely crushed — 187% CPU, 81 concurrent sessions, load average 4 on a 4-core 2012 laptop chip.

The root cause was textbook bad database design. Every telemetry insert did IF NOT EXISTS (SELECT 1 FROM X WHERE ...) INSERT INTO X (...) — a full table scan on every single row insertion. With 15 apps sending telemetry, that's dozens of concurrent full table scans fighting each other for locks. No unique constraints, no useful indexes.

The fix was elegant: CREATE UNIQUE INDEX ... WITH (IGNORE_DUP_KEY = ON). This SQL Server feature silently skips duplicate inserts — no IF NOT EXISTS check needed at all. The index itself IS the dedup mechanism, and it's an index seek instead of a table scan. Went from 10 seconds to 1.5 seconds.

Also found 1,131 duplicate rows that slipped through the race condition in IF NOT EXISTS — proving the anti-pattern wasn't even working correctly.

The DurationMs computed column was another good find. Converting "00:00:00.1083441" strings to milliseconds at query time is wasteful when you could just parse it once at ingestion. Dropped the computed column, added a real int, backfilled 900K+ rows, parse at insert time now.

Had to cap SQL Server memory too — it was eating the entire 8GB machine. Set to 5GB with MAXDOP=2. The macmini2012 is really struggling under this workload. May need to migrate the Insights DB to .100 eventually.