feat(phase5): wire adaptive sleep analytics + skip gating into run()#138
Merged
Conversation
PR-A landed the sleep_phase_analytics table and the recordPhaseAnalytics / shouldSkipPhase helpers as analytics-only infrastructure. This commit wires them into SleepCycleEngine.run() so the table actually fills and the skip heuristic takes effect. Every top-level phase invocation in run() is now wrapped in timing plus a recordPhaseAnalytics write — one row per phase per cycle. The cleanup / reflection tail (graph-maintenance, entity-dedup, reflection, schema- detection, temporal-validation, procedure-evolution, embedding-migration, deprecated-decay) additionally consults shouldSkipPhase() and short- circuits when the last three runs had zero changes, saving I/O on quiet agents. Core hot-path phases (weight adaptation, scoring, triage, capacity eviction, conflict resolution, Phase 3 revision, Phase 6 audit archive) always run. Skipped phases intentionally do not record a fresh analytics row — writing one would just re-anchor the zero history under a new timestamp, so the silent skip is what lets the heuristic remain self-stable. Integration tests verify both that a single cycle records one row per phase that ran, and that a pre-seeded zero-change history causes the skippable phases to short-circuit on the next cycle while the core phases still record. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
PR-A (#136) landed the
sleep_phase_analyticstable plus therecordPhaseAnalytics/shouldSkipPhasehelpers as analytics-onlyinfrastructure — the helpers were not yet called from
SleepCycleEngine.run(), so the table stayed empty. This PR wires them in.run()is wrapped with timing +recordPhaseAnalytics()— one row per phase per cycle. Phaseidentifiers:
weight-adaptation,scoring,triage,capacity-eviction,conflict-resolution,revision,graph-maintenance,entity-dedup,reflection,cold-purge,schema-detection,temporal-validation,procedure-evolution,embedding-migration,deprecated-decay,epistemic-promotion,drift-snapshot,audit-archive.shouldSkipPhase()gating applied only to the cleanup / reflectiontail —
graph-maintenance,entity-dedup,reflection,schema-detection,temporal-validation,procedure-evolution,embedding-migration,deprecated-decay. When the last three recordedruns of that phase had
changes_made = 0, the phase short-circuitswithout I/O and without writing a fresh row (a write would re-anchor
the zero history; the silent skip keeps the heuristic self-stable).
triage, capacity eviction, conflict resolution, the Phase 3 revision
loop, and Phase 6 audit archive are never skipped.
description of the wiring and phase-identifier list.
Test plan
npm run type-check— cleannpm run build— cleannpm run lint— cleannpm run test:adaptive-sleep— 20/20 pass, including two newintegration tests:
-
records one analytics row per phase that ran in a single cycle-
skips skippable phases on subsequent cycles when prior runs were idlenpm audit --omit=dev— 0 vulnerabilities