Skip to content

feat(phase5): wire adaptive sleep analytics + skip gating into run()#138

Merged
salishforge merged 1 commit into
mainfrom
feat/phase5-adaptive-sleep-wiring
May 22, 2026
Merged

feat(phase5): wire adaptive sleep analytics + skip gating into run()#138
salishforge merged 1 commit into
mainfrom
feat/phase5-adaptive-sleep-wiring

Conversation

@salishforge
Copy link
Copy Markdown
Owner

Summary

PR-A (#136) landed the sleep_phase_analytics table plus the
recordPhaseAnalytics / shouldSkipPhase helpers as analytics-only
infrastructure — the helpers were not yet called from
SleepCycleEngine.run(), so the table stayed empty. This PR wires them in.

  • Every top-level phase invocation in run() is wrapped with timing +
    recordPhaseAnalytics()
    — one row per phase per cycle. Phase
    identifiers: 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 / reflection
    tail
    graph-maintenance, entity-dedup, reflection,
    schema-detection, temporal-validation, procedure-evolution,
    embedding-migration, deprecated-decay. When the last three recorded
    runs of that phase had changes_made = 0, the phase short-circuits
    without I/O and without writing a fresh row (a write would re-anchor
    the zero history; the silent skip keeps the heuristic self-stable).
  • Core hot-path phases always run — weight adaptation, scoring,
    triage, capacity eviction, conflict resolution, the Phase 3 revision
    loop, and Phase 6 audit archive are never skipped.
  • CHANGELOG.md — the "Wiring deferred" note is replaced with a
    description of the wiring and phase-identifier list.

Test plan

  • npm run type-check — clean
  • npm run build — clean
  • npm run lint — clean
  • npm run test:adaptive-sleep — 20/20 pass, including two new
    integration tests:
    - records one analytics row per phase that ran in a single cycle
    - skips skippable phases on subsequent cycles when prior runs were idle
  • npm audit --omit=dev — 0 vulnerabilities
  • CI green

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>
@salishforge salishforge merged commit 990a9e6 into main May 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant