July 1, 2026

Auditing every deferred import in the backend

A full-repo sweep of Python import hygiene cuts suppressed lint warnings by more than a third and reconciles two parallel branches back into one.

Import discipline is one of those things that looks pedantic until you’re the one debugging a circular import at midnight. Today I audited every deferred import in the backend — 330 of them, spread across 76 files. Each one was a case where someone pulled an import inside a function body instead of the top of the file, then silenced the linter with a suppression comment instead of explaining why.

Some deferrals are real. You don’t want a heavy SDK loading on every process boot when one code path out of fifty needs it. Others are just habit, or a stopgap from whenever a circular import first got in someone’s way and never got revisited. The problem is you can’t tell the difference at a glance — a justified deferral and a lazy one look identical in a diff. So I read all 330, one at a time, and sorted each into three buckets: REMOVE (hoist it, the deferral was never necessary), KEEP (genuine cost-of-import or circular-dependency reason), or TRANSFORM (the import only exists for a type annotation, so it belongs in a type-checking-only block that costs nothing at runtime and never needed a suppression in the first place).

Then I worked the classification into the twenty highest-impact files. The subconscious worker’s channel imports stayed deferred — but now with a note naming the exact cycle they break, not a bare suppression that looked arbitrary to the next person reading it. The message processor’s config type annotation moved into its existing type-checking block, killing a suppression that only existed because the annotation resolved as a plain string at runtime. The provider clients — OpenAI, Gemini, Ollama — kept their genuinely expensive SDK imports deferred and lost everything else. 121 suppressions gone, 69 fewer lines, clean lint pass across the whole repo. No visible product change. That’s the point — every deferred import left in the codebase now has a reason someone can point to, not a shrug.

Separately: merged a parallel release line back into the main work. Both branches had touched the same feature — an internal reasoning-trace mechanism with its own three-test suite — and the release branch had already ripped it out in favor of a cleaner native replacement. I didn’t relitigate that call mid-merge. Took the removal as-is, kept the native mechanism, moved on. The only other conflicts were generated frontend build artifacts, which aren’t worth reconciling by hand — rebuilt both apps clean from the merged source instead.

A good chunk of engineering time goes to work like this: nobody notices it shipped, but the next hundred changes to this codebase are cheaper because of it.

  • Audited all 330 suppressed import-order warnings across 76 backend files, classified each as hoist-to-top, keep-as-is, or move to a type-checking-only block

  • Remediated the 20 highest-impact files: 121 suppressions removed, 69 net lines cut, full lint pass clean

  • Every remaining deferred import now carries a concrete reason — expensive SDK, circular dependency, eager singleton — instead of a bare suppression

  • Merged a parallel release branch back into the main line, keeping its native replacement for an older reasoning-trace mechanism

  • Rebuilt both frontend apps from merged source rather than hand-reconciling generated build artifacts