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:

  1. Check power source:
pmstat -g batt

System must be plugged in (AC Power). Battery-only wakes are unreliable.

  1. Check sleep settings:
pmset -g

Ensure "standby" and "hibernation" aren't interfering:

sudo pmset -a standby 0
sudo pmset -a hibernatemode 0
  1. Verify schedule format:
# Wrong (won't work):
sudo pmset schedule wake "18:00"

# Correct:
sudo pmset schedule wake "10/03/2025 18:00:00"
  1. Check for conflicting schedules:
pmset -g sched
# Cancel all and recreate:
sudo pmset schedule cancelall
./setup-automation.sh

Issue 2: LaunchAgent Doesn't Run

Symptoms: launchctl list | grep claude-automation shows nothing. Handler script never executes.

Solutions:

  1. Check plist syntax:
plutil -lint ~/Library/LaunchAgents/com.user.claude-automation.plist

Should output: "OK"

  1. Check file permissions:
ls -la ~/Library/LaunchAgents/com.user.claude-automation.plist

Should be owned by you, readable: -rw-r--r--

  1. 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
  1. Check logs:
cat /tmp/claude-automation.err
cat /tmp/claude-automation.out

Issue 3: Caffeinate Exits Prematurely

Symptoms: System sleeps before caffeinate duration ends. Logs show caffeinate started but tasks incomplete.

Solutions:

  1. 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
  1. Check for competing sleep triggers:
pmset -g assertions

Look for "PreventUserIdleSystemSleep" - should show your caffeinate process.

  1. 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:

  1. Check script permissions:
chmod +x ~/automation-projects/claude-pipeline/scripts/*.sh
  1. 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
  1. Use absolute paths for all commands:
# Instead of: python3 process.py
# Use:
/usr/local/bin/python3 /Users/you/scripts/process.py
  1. 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:

  1. Kill orphaned processes:
source ~/automation-projects/claude-pipeline/scripts/wake-utils.sh
stop_all_caffeinate
  1. 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 &
  1. 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:

  1. 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
  1. Ensure log directory exists:
mkdir -p ~/automation-projects/claude-pipeline/logs
  1. 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 1h

Issue 7: Permissions Errors

Symptoms: "Operation not permitted" errors. Handler can't access files or run commands.

Solutions:

  1. Grant Full Disk Access to Terminal:

System Preferences → Security & Privacy → Privacy → Select "Full Disk Access" → Add Terminal.app (or iTerm2)

  1. Grant automation permissions:
# Check TCC database:
sqlite3 ~/Library/Application\ Support/com.apple.TCC/TCC.db "SELECT * FROM access WHERE service='kTCCServiceSystemPolicyAllFiles'"
  1. Run with explicit user context:

In LaunchAgent plist, add:

<key>UserName</key>
<string>yourusername</string>
<key>GroupName</key>
<string>staff</string>