diff --git a/docs/superpowers/evidence/fix-midnight-shutdown-heredoc-2026-06-22.json b/docs/superpowers/evidence/fix-midnight-shutdown-heredoc-2026-06-22.json new file mode 100644 index 0000000..0981a5f --- /dev/null +++ b/docs/superpowers/evidence/fix-midnight-shutdown-heredoc-2026-06-22.json @@ -0,0 +1,47 @@ +{ + "intent": "Fix the day-specific midnight shutdown timer silently failing on every fire (confirmed at 23:00/23:01 on 2026-06-21 and 07:01 on 2026-06-22), which caused the PC to stay on overnight and require a manual shutdown.", + "scope": [ + "linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh", + "Deployed artifacts regenerated by this script: /usr/local/bin/day-specific-shutdown-check.sh, /etc/systemd/system/day-specific-shutdown.timer", + "Non-goal: did not change the shutdown schedule (kept at original 21:00 Mon-Wed / 22:00 Thu-Sun / 05:00 morning end) or the schedule-lenience protection check" + ], + "changes": [ + "create_shutdown_check_script(): removed spurious backslash-escaping of $ in the hibernate/poweroff case block (tomorrow_dow, wake_epoch). The heredoc uses the quoted delimiter <<'EOF', so $ was never expanded at generation time; the escaped \\$ was written literally into the deployed script, producing a bash syntax error ('syntax error near unexpected token (') on every single invocation since commit 0d54c5d introduced the hibernate-on-alarm-night feature.", + "create_shutdown_timer(): fixed off-by-one in `seq \"$earliest_hour\" 24` -> `23`, which was emitting invalid OnCalendar=*-*-* 24:00:00/24:30:00 entries that systemd logged as parse failures on every daemon-reload." + ], + "verification": [ + { + "command": "bash -n linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh", + "result": "pass", + "evidence": "No syntax errors in the setup script itself." + }, + { + "command": "sudo ./setup_midnight_shutdown.sh enable (redeployed) && bash -n /usr/local/bin/day-specific-shutdown-check.sh", + "result": "pass", + "evidence": "Deployed check script now parses cleanly; previously failed with 'line 92: syntax error near unexpected token `(`'." + }, + { + "command": "sudo /usr/local/bin/day-specific-shutdown-check.sh", + "result": "pass", + "evidence": "Logged: '2026-06-22 07:08:33: Skipping shutdown - not within shutdown window for Monday (current: 07:08)' — correct decision, no crash." + }, + { + "command": "sudo systemctl start day-specific-shutdown.service && systemctl status day-specific-shutdown.service", + "result": "pass", + "evidence": "Process exited code=exited, status=0/SUCCESS (previously status=2/INVALIDARGUMENT)." + }, + { + "command": "cat /etc/shutdown-schedule.conf", + "result": "pass", + "evidence": "MON_WED_HOUR=21, THU_SUN_HOUR=22, MORNING_END_HOUR=5 — confirmed unchanged from original, lenience-block check confirmed intact in source diff." + } + ], + "risks": [ + "Redeploying re-runs the full setup script (chattr -i/+i, systemd daemon-reload, service restarts) on a live system; verified no other unrelated drift was introduced by diffing against the pre-change file.", + "Did not test the actual hibernate/rtcwake branch end-to-end (would require simulating an alarm-day shutdown), only confirmed syntax validity and that the script reaches/exits the case statement without crashing." + ], + "rollback": [ + "git revert this commit, then re-run `sudo chattr -i setup_midnight_shutdown.sh && sudo ./setup_midnight_shutdown.sh enable` to redeploy the prior (broken) version.", + "After rollback, confirm via `journalctl -t day-specific-shutdown` that the syntax error reappears, then re-apply this fix." + ] +} diff --git a/linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh b/linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh index 73858cc..6e31f2a 100755 --- a/linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh +++ b/linux_configuration/scripts/periodic_background/digital_wellbeing/setup_midnight_shutdown.sh @@ -720,7 +720,7 @@ Requires=day-specific-shutdown.service [Timer] EOF # Evening hours: from earliest shutdown hour to 23:30 - for hour in $(seq "$earliest_hour" 24); do + for hour in $(seq "$earliest_hour" 23); do printf 'OnCalendar=*-*-* %02d:00:00\n' "$hour" printf 'OnCalendar=*-*-* %02d:30:00\n' "$hour" done @@ -940,12 +940,12 @@ if [[ $should_shutdown == true ]]; then # inhibitor — a game, Steam, a video player, or our own controller idle-off # watcher — silently denies the hibernate ("Operation denied due to active # block inhibitor") and the PC stays up all night. -i overrides all locks. - tomorrow_dow=\$(date -d "tomorrow" +%u) - case "\$tomorrow_dow" in + tomorrow_dow=$(date -d "tomorrow" +%u) + case "$tomorrow_dow" in 1|5|6|7) - wake_epoch=\$(( \$(printf '%(%s)T' -1) + 8 * 3600 )) - logger -t day-specific-shutdown "Tomorrow is alarm day (dow=\$tomorrow_dow) — hibernating, RTC wake at epoch \$wake_epoch" - /usr/bin/sudo /usr/sbin/rtcwake -m no -t "\$wake_epoch" + wake_epoch=$(( $(printf '%(%s)T' -1) + 8 * 3600 )) + logger -t day-specific-shutdown "Tomorrow is alarm day (dow=$tomorrow_dow) — hibernating, RTC wake at epoch $wake_epoch" + /usr/bin/sudo /usr/sbin/rtcwake -m no -t "$wake_epoch" /usr/bin/systemctl hibernate -i ;; *)