Show & Tell: Inside Phase5MetricsCollector — sliding windows, Blackboard namespacing, and circuit-breaker integration #217
web3guru888
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Overview
Phase 5 brings ASI:BUILD's first real-time self-modification loop: STDP weight updates during live CognitiveCycle ticks, federated hot-reload across mesh agents, and KG transactional writes during SLEEP_PHASE. But self-modification is only safe if you can measure whether it's helping.
Issue #215 defines the Phase 5 evaluation framework — this post walks through the key design decisions in
Phase5MetricsCollector.Architecture in one diagram
Design decision 1: Deque-based sliding windows
Every rate and percentile metric uses
collections.deque(maxlen=1000):At 100Hz,
maxlen=1000gives a 10-second rolling view. Why 10 seconds?For latency histograms, we use
deque(maxlen=10_000)— a longer window because latency outliers matter more than rates.Design decision 2: Blackboard key namespace
All Phase 5 metrics go under
metrics.phase5.<subsystem>.<name>with a 5-tick TTL:The 5-tick TTL means a stale metric disappears rather than staying at its last-seen value. A consumer that reads
Noneknows to treat it as "no data", not "last known good."Design decision 3: P95 without hot-path numpy
Calling
numpy.percentileevery tick on 1000 elements is ~0.05ms. At 100Hz that's 5ms/second of pure metric overhead — unacceptable for a real-time loop. Instead:This amortizes the sort cost over 100 ticks, giving a "snapshot P95" updated at 1Hz rather than 100Hz. For alerting purposes 1Hz is more than sufficient.
Design decision 4: Prometheus push in background asyncio.Task
Pushing every 10 seconds decouples the metric push from tick rate. If the cognitive cycle slows to 50Hz during a heavy coordination round, Prometheus still gets data on a wall-clock schedule.
Design decision 5: Circuit breaker reuse
Rather than inventing Phase 5-specific circuit breakers, we reuse the
CircuitStateenum and Blackboard key convention from Phase 4 (#137):STDPOnlineLearner.compute_update()already readscircuit.<module_id>.stateas part of the standard module health check. Addingcircuit.online_learning.stateto that check requires zero new infrastructure.Open questions
Metric cold start: On system boot, deques are empty. Should
Phase5MetricsCollectorsuppress alerts for the first 1000 ticks (10 seconds), or emit aNO_DATAstate to downstream consumers?Multi-agent aggregation: In a 4-agent mesh, each agent runs its own
Phase5MetricsCollector. Should per-agent metrics be aggregated inMeshCoordinatorbefore alerting, or should each agent alert independently (risking alert storms)?SLEEP_PHASE sampling:
episodic_consolidation_rateis only meaningful during SLEEP_PHASE ticks. Should the collector skip non-SLEEP_PHASE ticks for that metric, or track the phase flag via Blackboard read?Related: #215 | #216 | #210 | #213
All reactions