testsAndMisc/docs/superpowers/evidence/fix-midnight-shutdown-heredoc-2026-06-22.json
Krzysztof kuhy Rudnicki 12fe41049f fix: shutdown timer crashing on every fire due to heredoc escaping bug
The hibernate-on-alarm-night case block in create_shutdown_check_script()
escaped $ as \$ for an unquoted heredoc, but the heredoc is opened with the
quoted delimiter <<'EOF', so the backslashes were written literally into
the deployed check script. Every timer fire since commit 0d54c5d hit a bash
syntax error and exited before evaluating the shutdown window, so the PC
never auto-shut-down (confirmed failing at 23:00/23:01 last night and 07:01
this morning). Also fixed an off-by-one (seq ... 24 -> 23) that was emitting
invalid OnCalendar=24:00:00 entries systemd had to ignore.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LGHLfbAPmak6HtGJby57eo
2026-06-22 07:09:55 +02:00

48 lines
3.4 KiB
JSON

{
"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."
]
}