#!/usr/bin/env bash
# usage: sessions.sh <phase>  -> provider session rows (read-only, synthetic DBs) + claude child processes per server
set -u
out=/tmp/ev-23636/out/sessions.txt
{
echo "===== [$1] $(date -u +%FT%TZ)"
for b in after before; do
  case $b in after) pid=1453090;; before) pid=1453089;; esac
  echo "-- $b provider sessions (thread_id|status|updated_at)"
  sqlite3 -readonly /tmp/ev-23636/home-$b/userdata/statev2.sqlite "select thread_id, status, updated_at from orchestration_v2_projection_provider_sessions order by updated_at;"
  echo "-- $b claude child processes of server pid $pid: $(ps -o pid= --ppid $pid | wc -l)"
  ps -o pid=,etime= --ppid $pid
done
} >> $out
