api.py: wire up dream_mode setting (Track 1 Finding 9)

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).
This commit is contained in:
2026-05-02 23:38:29 +00:00
parent 3f7fba7e0e
commit 7bebd8ae50
+13 -4
View File
@@ -50,7 +50,7 @@ DEFAULT_SETTINGS = {
"show_sources": True, "show_sources": True,
"dream_hour_utc": 8, "dream_hour_utc": 8,
"dream_minute_utc": 0, "dream_minute_utc": 0,
"dream_mode": "nrem", "dream_mode": "pipeline",
"ingest_hour_utc": 2, "ingest_hour_utc": 2,
"ingest_minute_utc": 30, "ingest_minute_utc": 30,
"share_time": True, "share_time": True,
@@ -1105,16 +1105,25 @@ async def corpus_reconcile(request: Request, background_tasks: BackgroundTasks,
scheduler = BackgroundScheduler() scheduler = BackgroundScheduler()
def run_dream_job(): 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: try:
import subprocess 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") dream_script = str(Path.home() / "aaronai" / "scripts" / "dream.py")
cmd = [PYTHON, dream_script]
if mode != "pipeline":
cmd += ["--mode", mode]
result = subprocess.run( result = subprocess.run(
[PYTHON, dream_script], cmd,
cwd=str(Path.home() / "aaronai"), cwd=str(Path.home() / "aaronai"),
capture_output=True, text=True, timeout=600 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: if result.returncode != 0:
print(f"Dreamer error: {result.stderr[-200:] if result.stderr else 'unknown'}") print(f"Dreamer error: {result.stderr[-200:] if result.stderr else 'unknown'}")
except Exception as e: except Exception as e: