feat: rhythm engine stage 1 — observe-only day-phase inference#6
Merged
Conversation
…vidence log, atomic state
…escape, anchor day-class Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <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
Stage 1 of the Rhythm Engine: the daemon infers the occupant's day phase (
dawn → morning → daylight → evening → wind_down → night → sleep), detects sleep onset and wake, learns wake/bed anchors — and drives nothing. Observe-only: zero bridge writes (enforced by a test client that asserts on any write), zero behavior change whenrhythm:is absent from config.rhythm:config block — bed target, weekend drift cap, presence tunables, signal-file paths, rolloutstage(only"observe"starts;mornings/fullrefuse with a ConfigError until those stages ship).presence.py— per-room activity judging with pet discounting (light change = human; room-to-room progression = human; motion near a light change = human; solo single-room motion = pet). Every judgment carries its rule name.rhythm_control.py— learned-anchor store (bounded to 14 samples per weekday/weekend class, corrupt-file-safe JSON) + the phase engine (anchored, negotiated transitions; sleep-onset confidence vote; sustained-wake confirmation; night wakings explicitly rejected from the wake anchor; restart-safe seeding verified by a 24-hour sweep test)..next-alarm/.phone-chargingsignal files (same control-file channel as TV bias), phase changes logged at INFO with the full evidence dict, atomic state persistence (tmp + rename), rhythm failures isolated from the drive loop, all rhythm state lock-guarded on both threads.hueman rhythm— status command: phase, target vs learned anchors, weekly phase error in minutes, last decision's evidence. Degrades cleanly on malformed state files; needs no bridge access.Process & verification
Built task-by-task with a fresh reviewer gating each task, then a whole-branch final review, which caught and drove fixes for two restart-path Criticals (morning restart stranding the engine in
night; cold-start recording a fabricated sleep onset) and a design hole where nightly bathroom trips would poison the learned wake anchor. All fixes verified by direct simulation against the shipped head.mypy --strict: cleanAfter merge (ops side)
Deploy with
stage: "observe"andlog_level: debug(night-waking rejections trace at DEBUG), let it run ≥5 days, comparehueman rhythm+ therhythm:log lines against reality before designing stage 2 (dawn ramp) on the observed data.🤖 Generated with Claude Code