Keep only the latest handler timing instead of one per output #948
All Vouch review confidence checks passed
Residual risk 0.24 = Change Risk (0.45) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.45 · 301 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Shallow Review Depth
shallow_review_depth
0.344
Diff Size
diff_size
0.342
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #948"
general
weight: 0.35
andimarafioti
Summary
BaseHandlerkeeps the duration of every output it has ever emitted:The only reader is
last_time, which takes the last entry. The list is never trimmed, so every handler thread grows it by one float for each output for the life of the process.OpenAICompatibleSTTHandlerappends to it too.The TTS stage is where this adds up. It emits one output per 512-sample block at 16 kHz, about 31 per second of speech, and the LLM stage emits one per streamed chunk. Each entry costs about 32 bytes (a float object plus a list slot), so a server that speaks for an hour keeps about 3.6 MB in the TTS handler's list alone. That memory is never released, because the handler threads, and with them the pooled Realtime pipeline units, live as long as the server.
Change
A
deque(maxlen=1)keeps the same interface,.append()and[-1], solast_time, the timing log andOpenAICompatibleSTTHandler's ownappendare unchanged. The tests that build handlers withobject.__new__and sethandler._times = [...]keep working. No other code reads_times:git grep -n "_times\b" srcfinds only these sites.Tests
New
tests/test_base_handler_timings.py::test_handler_keeps_only_the_latest_timing_not_one_per_outputruns a minimalBaseHandlersubclass throughrun()with inputs that emit 5,000 outputs and then 3. It checks that every output is forwarded in order, that_timesholds at most one entry, and thatlast_timeis still readable.On unmodified
main(6644d4f):With the change it passes.
Local gate (darwin/arm64, Python 3.12.16,
uv sync --group dev, the steps inci.yml):ruff check src/ tests/,ruff format --check src/ tests/andmypy src/are clean.pytest tests/ -q: 4191 passed, 11 skipped, 0 failed (mainat6644d4f: 4190 passed, 11 skipped; the difference is the new test).🤖 Generated with Claude Code