#!/usr/bin/env bash # debug-execution: Show details for a failed task execution from the production DB. # Usage: ./scripts/debug-execution # Example: ./scripts/debug-execution c74c877f set -euo pipefail DB="/site/doot.terst.org/data/claudomator.db" PREFIX="${1:?Usage: $0 }" if [[ ! -f "$DB" ]]; then echo "ERROR: DB not found at $DB" >&2 exit 1 fi # Look up execution ROW=$(sqlite3 "$DB" " SELECT id, task_id, exit_code, status, stdout_path, stderr_path, error_msg FROM executions WHERE id LIKE '${PREFIX}%' ORDER BY start_time DESC LIMIT 1; ") if [[ -z "$ROW" ]]; then echo "ERROR: No execution found matching '${PREFIX}'" >&2 exit 1 fi IFS='|' read -r EXEC_ID TASK_ID EXIT_CODE STATUS STDOUT_PATH STDERR_PATH ERROR_MSG <<< "$ROW" echo "=== Execution ===" echo " ID: $EXEC_ID" echo " Status: $STATUS" echo " Exit code: $EXIT_CODE" echo " Error: ${ERROR_MSG:-(none)}" # Look up task TASK_ROW=$(sqlite3 "$DB" " SELECT name, json_extract(config_json, '$.working_dir'), json_extract(config_json, '$.model') FROM tasks WHERE id = '${TASK_ID}'; ") if [[ -n "$TASK_ROW" ]]; then IFS='|' read -r TASK_NAME WORKING_DIR MODEL <<< "$TASK_ROW" echo "" echo "=== Task ===" echo " ID: $TASK_ID" echo " Name: $TASK_NAME" echo " Model: ${MODEL:-(not set)}" echo " Working dir: ${WORKING_DIR:-(not set)}" fi # Logs print_log() { local label="$1" path="$2" echo "" echo "=== $label ===" if [[ -z "$path" ]]; then echo " (path not recorded)" elif [[ ! -f "$path" ]]; then echo " (file not found: $path)" elif [[ ! -s "$path" ]]; then echo " (empty)" else tail -n 50 "$path" fi } print_log "stdout (last 50 lines)" "$STDOUT_PATH" print_log "stderr (last 50 lines)" "$STDERR_PATH"