#!/bin/bash
set -u
OUT=/tmp/f804/05_final.out
exec > "$OUT" 2>&1

echo "=== stability check: NRestarts should still be 0, state active ==="
echo "gemini:"
systemctl --user show gemini-pr-reviewer.service -p ActiveState,SubState,MainPID,NRestarts
echo "codex:"
systemctl --user show codex-pr-reviewer.service -p ActiveState,SubState,MainPID,NRestarts

echo ""
echo "=== confirm running process loads the FIXED ask-ai.js (sandboxDir present) ==="
grep -c "sandboxDir" /home/claude/repos/pr-review-shared/lib/ask-ai.js
grep -c "600_000" /home/claude/repos/pr-review-shared/lib/ask-ai.js

echo ""
echo "=== any errors in last 40 lines since restart? ==="
journalctl --user -u gemini-pr-reviewer.service --since "5 min ago" --no-pager 2>&1 | grep -iE "error|crash|throw|unhandled|cannot|fail" || echo "GEM_NO_ERRORS"
journalctl --user -u codex-pr-reviewer.service --since "5 min ago" --no-pager 2>&1 | grep -iE "error|crash|throw|unhandled|cannot|fail" || echo "CODEX_NO_ERRORS"

echo ""
echo "=== live PR #804 reviews (latest verdicts per bot) ==="
gh api repos/gbharg/agents/pulls/804/reviews --jq 'sort_by(.submitted_at) | reverse | .[0:6] | .[] | {user: .user.login, state: .state, at: .submitted_at}' 2>&1

echo "=== DONE_05 ==="
