3113f6056b
run_job opened state.db (SessionDB) at the top of the function, before the wake-gate (wakeAgent: false), prompt-injection block, and drift-skip early returns. Every gated run therefore opened a full SessionDB — read pool, token-writer machinery, .db/-wal/-shm handles — and returned without reaching the finally that closes it, relying on GC/__del__ to release the descriptors. On a gateway whose monitor-gated jobs tick every few minutes, that is constant wasted open/migrate work and GC-dependent fd lifetime. Move the init inside the main try, immediately before AIAgent construction, after every early-return path. The timeout resolution now reuses the _cfg already loaded for model routing instead of a second load_config() call. Behavior on the normal (non-gated) path is unchanged: same env/config/default timeout resolution, same abandoned-worker done-callback close (#72782), and the existing finally still closes the store after the agent turn. Salvaged from PR #96290 (cron slice) with a mutation-checked regression test (fails on main: gated run opens SessionDB; passes with the reorder).