gabriel / musehub public
feat patch intel task/intel-db-pacing #2 / 2
AI Agent gabriel · 3 days ago · Nov 14, 2026 · Diff

feat(intel): pace analysis database writes so a cold index cannot starve the web

On 2026-11-13 a cold index of a 1.7k-commit repository ran ~10 min on a db.t3.micro: page queries took 56 s, the web pool (4+2) timed out and users saw 5xx. Memory is fixed separately; this is the database load. musehub_intel_pacing.DbPacer, off unless configured: - duty cycle (MUSEHUB_INTEL_DB_DUTY): after a unit of DB work that took t, sleep t*(1/d-1), capped at 20 s; - back-off while the web is busy (MUSEHUB_INTEL_DB_BUSY_THRESHOLD): wait while >= N other queries are active, bounded per unit and per job so analysis is delayed, never stopped; - applied per batch to the ingest (commit slices now 25), symbol intel, vitals, hash occurrences and the providers' row replacement; waiting is between statements, inside savepoint-guarded looks, never fatal. Hosted environments get duty 0.35, threshold 2, wall 3300 s via secrets.sh. Measured locally on real data: same outcome and rows, 106 s -> 206 s wall. Tests: 8 in test_intel_pacing.py (fake clock; real pg_stat_activity look; paced == unpaced results); focused regression 969 passed.

sha256:238a7da4341ade2c8d41ea9834d8e75e250647aefec02327f1e25fac55acd036 sha
+53 ~9 symbols
sha256:6d44f9f565f0a8e599e0b0006e621e4f58df74a1e01289ccf850a48426714541 snapshot
+53
symbols added
~9
symbols modified
0
dead code introduced
Semantic Changes 62 symbols
+ BUSY_ENV variable variable BUSY_ENV L33–33
+ DUTY_ENV variable variable DUTY_ENV L32–32
+ DbPacer class class DbPacer L54–119
+ __init__ method method __init__ L57–69
+ _other_active method async_method _other_active L83–85
+ _wait_for_quiet method async_method _wait_for_quiet L87–99
+ enabled method method enabled L80–81
+ from_environ method method from_environ L72–77
+ summary method method summary L118–119
+ unit method async_method unit L102–116
+ MAX_DUTY_SLEEP_SECONDS variable variable MAX_DUTY_SLEEP_SECONDS L38–38
+ MAX_WAIT_ENV variable variable MAX_WAIT_ENV L35–35
+ POLL_ENV variable variable POLL_ENV L34–34
+ TOTAL_WAIT_ENV variable variable TOTAL_WAIT_ENV L36–36
+ _OTHER_ACTIVE_QUERIES variable variable _OTHER_ACTIVE_QUERIES L40–43
+ _float function function _float L46–51
+ AsyncIterator import import AsyncIterator L24–24
+ AsyncSession import import AsyncSession L28–28
+ Awaitable import import Awaitable L24–24
+ Callable import import Callable L24–24
+ Mapping import import Mapping L24–24
+ annotations import import annotations L18–18
+ asynccontextmanager import import asynccontextmanager L25–25
+ asyncio import import asyncio L20–20
+ logging import import logging L21–21
+ os import import os L22–22
+ text import import text L27–27
+ time import import time L23–23
+ logger variable variable logger L30–30
~ tests/test_intel_pacing.py .py 20 symbols added
+ Clock class class Clock L15–25
+ __call__ method method __call__ L20–21
+ __init__ method method __init__ L16–18
+ sleep method async_method sleep L23–25
+ FakeSession class class FakeSession L28–48
+ __init__ method method __init__ L31–32
+ begin_nested method method begin_nested L34–38
+ execute method async_method execute L40–48
+ DbPacer import import DbPacer L12–12
+ MAX_DUTY_SLEEP_SECONDS import import MAX_DUTY_SLEEP_SECONDS L12–12
+ annotations import import annotations L8–8
+ pytest import import pytest L10–10
+ test_p1_a_disabled_pacer_touches_nothing function async_function test_p1_a_disabled_pacer_touches_nothing L62–67
+ test_p1_off_by_default_and_from_empty_environment function function test_p1_off_by_default_and_from_empty_environment L51–58
+ test_p2_a_failed_unit_does_not_nap function async_function test_p2_a_failed_unit_does_not_nap L83–90
+ test_p2_duty_cycle_sleeps_the_complement_and_is_capped function async_function test_p2_duty_cycle_sleeps_the_complement_and_is_capped L71–79
+ test_p3_a_failed_look_never_fails_the_analysis function async_function test_p3_a_failed_look_never_fails_the_analysis L115–120
+ test_p3_a_permanently_busy_database_delays_but_never_stops_the_job function async_function test_p3_a_permanently_busy_database_delays_but_never_stops_the_job L104–111
+ test_p3_it_waits_while_other_queries_are_active_then_proceeds function async_function test_p3_it_waits_while_other_queries_are_active_then_proceeds L94–100
+ test_p4_the_build_is_paced_unit_by_unit_and_unpaced_is_unchanged function async_function test_p4_the_build_is_paced_unit_by_unit_and_unpaced_is_unchanged L128–159
~ deploy/secrets.sh .sh 3 symbols added, 1 symbol modified
+ INTEL_DB_BUSY_THRESHOLD variable variable INTEL_DB_BUSY_THRESHOLD L136–136
+ INTEL_DB_DUTY variable variable INTEL_DB_DUTY L136–136
+ INTEL_DB_TOTAL_WAIT_SECONDS variable variable INTEL_DB_TOTAL_WAIT_SECONDS L136–136

0 comments

No comments yet. Be the first to start the discussion.

To add a comment, use the Muse CLI: muse hub commit comment sha256:238a7da4341ade2c8d41ea9834d8e75e250647aefec02327f1e25fac55acd036 --body "your comment"