From 7bebd8ae50d3d8de2ea8cdb712758f774ce7e497 Mon Sep 17 00:00:00 2001 From: Aaron Nelson Date: Sat, 2 May 2026 23:38:29 +0000 Subject: [PATCH] api.py: wire up dream_mode setting (Track 1 Finding 9) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The dream_mode setting was defined in DEFAULT_SETTINGS and watched by update_settings for reschedule, but run_dream_job never read it — silently-ignored configuration. Two changes: 1. DEFAULT_SETTINGS["dream_mode"] flipped from "nrem" to "pipeline". The default was a latent regression vector: wiring up the setting without changing the default would have silently switched all default-config users from full-pipeline (current production behavior) to NREM-only nightly runs. 2. run_dream_job reads dream_mode at fire-time, validates against {"pipeline", "nrem", "early-rem", "late-rem"}, falls back to pipeline with a warning on invalid values. Lucid intentionally excluded — it is on-demand only by design and remains available via CLI and /api/dreamer/run. Nightly dream production behavior is unchanged for current users (no settings.json key → default "pipeline" → no flag passed → same as before). Users can now meaningfully change the nightly mode by editing settings.json or via the SettingsPanel. Found by Track 1 inventory 2026-05-02 (Finding 9 / divergence #9). --- scripts/api.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/api.py b/scripts/api.py index b69e5a6..e0f1d6d 100644 --- a/scripts/api.py +++ b/scripts/api.py @@ -50,7 +50,7 @@ DEFAULT_SETTINGS = { "show_sources": True, "dream_hour_utc": 8, "dream_minute_utc": 0, - "dream_mode": "nrem", + "dream_mode": "pipeline", "ingest_hour_utc": 2, "ingest_minute_utc": 30, "share_time": True, @@ -1105,16 +1105,25 @@ async def corpus_reconcile(request: Request, background_tasks: BackgroundTasks, scheduler = BackgroundScheduler() def run_dream_job(): - """Runs nightly dreamer — full interdependent pipeline, no mode flag.""" + """Runs nightly dreamer at the mode set in settings.json (default: pipeline).""" try: import subprocess + settings = load_settings() + mode = settings.get("dream_mode", "pipeline") + valid_modes = {"pipeline", "nrem", "early-rem", "late-rem"} + if mode not in valid_modes: + print(f"Dreamer: invalid dream_mode={mode!r}; falling back to pipeline") + mode = "pipeline" dream_script = str(Path.home() / "aaronai" / "scripts" / "dream.py") + cmd = [PYTHON, dream_script] + if mode != "pipeline": + cmd += ["--mode", mode] result = subprocess.run( - [PYTHON, dream_script], + cmd, cwd=str(Path.home() / "aaronai"), capture_output=True, text=True, timeout=600 ) - print(f"Dreamer completed: {result.stdout[-200:] if result.stdout else 'no output'}") + print(f"Dreamer completed (mode={mode}): {result.stdout[-200:] if result.stdout else 'no output'}") if result.returncode != 0: print(f"Dreamer error: {result.stderr[-200:] if result.stderr else 'unknown'}") except Exception as e: