Architecture Audit Finding — P2
Problem
106 setTimeout/setInterval calls across the codebase, with no centralized tracking or cleanup mechanism. Examples:
src/server.ts — config reload debounce timer, approval action cleanup
src/pipeline.ts — cleanup timers tracked per-pipeline (good pattern)
src/session.ts — idle timeout polling, hook cleanup TTL
src/budgets/evaluator.ts — evaluation timer
src/sse-limiter.ts — periodic pruning
Most are not tracked for cleanup on shutdown. If the server is stopped or a module is torn down, orphaned timers can fire against disposed resources.
Blast Radius
P2 — Timer leaks cause intermittent issues on restart/reload. Not critical in practice because the server process exits, but makes graceful shutdown unreliable and tests potentially flaky.
Suggested Remediation
- Create a
TimerRegistry utility that tracks all timers and provides clearAll()
- Register all timers through the registry
- Call
timerRegistry.clearAll() during graceful shutdown
- The
pipeline.ts pattern of tracking timers per-pipeline is a good model
Suggested Branch
chore/timer-registry
Required Tests
- Verify all timers are cleared on shutdown
- Test that no timer fires after module teardown
Architecture Audit Finding — P2
Problem
106
setTimeout/setIntervalcalls across the codebase, with no centralized tracking or cleanup mechanism. Examples:src/server.ts— config reload debounce timer, approval action cleanupsrc/pipeline.ts— cleanup timers tracked per-pipeline (good pattern)src/session.ts— idle timeout polling, hook cleanup TTLsrc/budgets/evaluator.ts— evaluation timersrc/sse-limiter.ts— periodic pruningMost are not tracked for cleanup on shutdown. If the server is stopped or a module is torn down, orphaned timers can fire against disposed resources.
Blast Radius
P2 — Timer leaks cause intermittent issues on restart/reload. Not critical in practice because the server process exits, but makes graceful shutdown unreliable and tests potentially flaky.
Suggested Remediation
TimerRegistryutility that tracks all timers and providesclearAll()timerRegistry.clearAll()during graceful shutdownpipeline.tspattern of tracking timers per-pipeline is a good modelSuggested Branch
chore/timer-registryRequired Tests