Chapter 6: Troubleshooting
Solve common issues from real-world experience
Common issues and solutions from my experience:
Issue 1: pmset Schedule Doesn't Wake System
Symptoms: System doesn't wake at scheduled time. pmset -g sched shows schedule, but nothing happens.
Solutions:
- Check power source:
pmstat -g battSystem must be plugged in (AC Power). Battery-only wakes are unreliable.
- Check sleep settings:
pmset -gEnsure "standby" and "hibernation" aren't interfering:
sudo pmset -a standby 0
sudo pmset -a hibernatemode 0- Verify schedule format:
# Wrong (won't work):
sudo pmset schedule wake "18:00"
# Correct:
sudo pmset schedule wake "10/03/2025 18:00:00"- Check for conflicting schedules:
pmset -g sched
# Cancel all and recreate:
sudo pmset schedule cancelall
./setup-automation.shIssue 2: LaunchAgent Doesn't Run
Symptoms: launchctl list | grep claude-automation shows nothing. Handler script never executes.
Solutions:
- Check plist syntax:
plutil -lint ~/Library/LaunchAgents/com.user.claude-automation.plistShould output: "OK"
- Check file permissions:
ls -la ~/Library/LaunchAgents/com.user.claude-automation.plistShould be owned by you, readable: -rw-r--r--
- Reload LaunchAgent:
launchctl unload ~/Library/LaunchAgents/com.user.claude-automation.plist
launchctl load ~/Library/LaunchAgents/com.user.claude-automation.plist
launchctl list | grep claude-automation- Check logs:
cat /tmp/claude-automation.err
cat /tmp/claude-automation.outIssue 3: Caffeinate Exits Prematurely
Symptoms: System sleeps before caffeinate duration ends. Logs show caffeinate started but tasks incomplete.
Solutions:
- Run caffeinate with stronger assertions:
# Instead of: caffeinate -t 1800
# Use:
caffeinate -dims -t 1800
# -d: prevent display sleep
# -i: prevent idle sleep
# -m: prevent disk sleep
# -s: prevent system sleep- Check for competing sleep triggers:
pmset -g assertionsLook for "PreventUserIdleSystemSleep" - should show your caffeinate process.
- Ensure caffeinate has proper path:
which caffeinate # Should be /usr/bin/caffeinate
# If not found, add to PATH in handler script:
export PATH="/usr/bin:$PATH"Issue 4: Handler Runs But Tasks Fail
Symptoms: Logs show handler executed, but automation tasks error out or don't run.
Solutions:
- Check script permissions:
chmod +x ~/automation-projects/claude-pipeline/scripts/*.sh- Verify PATH in LaunchAgent context:
LaunchAgents run with minimal PATH. Add to your handler:
export PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
export HOME="/Users/yourusername" # Use your actual home- Use absolute paths for all commands:
# Instead of: python3 process.py
# Use:
/usr/local/bin/python3 /Users/you/scripts/process.py- Check environment variables:
Add debug output to handler:
log_message "PATH: $PATH"
log_message "HOME: $HOME"
log_message "USER: $USER"
log_message "PWD: $(pwd)"Issue 5: Multiple Caffeinate Processes Accumulate
Symptoms: ps aux | grep caffeinate shows many processes. System never sleeps.
Solutions:
- Kill orphaned processes:
source ~/automation-projects/claude-pipeline/scripts/wake-utils.sh
stop_all_caffeinate- Add cleanup to handler:
# At start of automation-handler.sh main():
# Kill any existing caffeinate from previous runs
pkill -9 -f "caffeinate.*claude-automation"
# Then start your caffeinate:
caffeinate -t 1800 &- Use PID files to track processes:
CAFFEINATE_PID_FILE="/tmp/claude-automation-caffeinate.pid"
# Before running caffeinate:
if [ -f "$CAFFEINATE_PID_FILE" ]; then
old_pid=$(cat "$CAFFEINATE_PID_FILE")
kill "$old_pid" 2>/dev/null
fi
# Start caffeinate and save PID:
caffeinate -t 1800 &
echo $! > "$CAFFEINATE_PID_FILE"Issue 6: Logs Not Written
Symptoms: Log file empty or missing entries. Can't debug what happened.
Solutions:
- Check log file permissions:
ls -la ~/automation-projects/claude-pipeline/logs/automation.log
# If doesn't exist:
touch ~/automation-projects/claude-pipeline/logs/automation.log
chmod 644 ~/automation-projects/claude-pipeline/logs/automation.log- Ensure log directory exists:
mkdir -p ~/automation-projects/claude-pipeline/logs- Use tee for critical logs:
log_message() {
local msg="[$(date '+%Y-%m-%d %H:%M:%S')] $1"
echo "$msg" | tee -a "$LOG_FILE"
# Also log to system log:
logger -t claude-automation "$1"
}
# View system logs:
log show --predicate 'eventMessage contains "claude-automation"' --last 1hIssue 7: Permissions Errors
Symptoms: "Operation not permitted" errors. Handler can't access files or run commands.
Solutions:
- Grant Full Disk Access to Terminal:
System Preferences → Security & Privacy → Privacy → Select "Full Disk Access" → Add Terminal.app (or iTerm2)
- Grant automation permissions:
# Check TCC database:
sqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db "SELECT * FROM access WHERE service='kTCCServiceSystemPolicyAllFiles'"- Run with explicit user context:
In LaunchAgent plist, add:
<key>UserName</key>
<string>yourusername</string>
<key>GroupName</key>
<string>staff</string>