Skip to content
pi-c Artifact [276d6a2dab]
Login

Artifact [276d6a2dab]

Artifact 276d6a2dab5d28eac2e2db16a34abf350b45619a4489b7c7b9230f810f639a75:


#!/bin/sh
# Remote control watchdog, slow jobs, busy responses, restarts, and child reaping.
# Usage: test/pic/remote_ops.sh [--no-faults]
set -eu
PIC=${PIC:?set PIC to the pic binary}
SERVER=${SERVER:?set SERVER to the fake_server binary}
RELAY=${RELAY:?set RELAY to the fake_relay binary}
PHONE=${PHONE:?set PHONE to the fake_phone binary}
SQLITE3=${SQLITE3:-sqlite3}
FAULTS=1
[ "${1:-}" = --no-faults ] && FAULTS=0
here=$(cd "$(dirname "$0")" && pwd)
S=$here/streams
T=$(mktemp -d "${TMPDIR:-/tmp}/pic-remote-ops.XXXXXX")
export HOME="$T/home"
. "$here/remote_lib.sh"

init_paired 1

serve "sse:$S/text.sse"
pic ask 'first question' > /dev/null 2> "$T/ask.err" || fail "ask: $(cat "$T/ask.err")"
SID=$(q "SELECT id FROM pic_session ORDER BY updated_ms DESC LIMIT 1")
SESS="$DB/$SID"
remote

# Records a confirmed session cannot open, three in a row, reset it, so the phone makes a new one
# instead of waiting; a stream that keeps its keepalive while records stop is opened again once a
# phone on screen has been quiet that long (PIC_TEST_RC_QUIET_MS); and each line of the log says
# when, and why it reconnected, dropped or reset. (The phone takes a reset 5 s after its handshake.)
if [ "$FAULTS" = 1 ]; then
    kill "$RP"
    gone "$RP"
    nr=$((nr + 1))
    RO="$T/remote$nr.out"
    PIC_TEST_RC_QUIET_MS=1500 PIC_TEST_RC_STALL_MS=1500 PIC_TEST_RC_STALL_FILE="$T/stall" PIC_TEST_RC_PAGE=2 \
        PIC_TEST_RC_SLOW_PHASE="answering Phone One's command get_wakes:2500" \
        "$PIC" remote > "$RO" 2> "$T/remote$nr.err" &
    RP=$!
    bg $RP
    await "$RO" 'pic remote: connected'
    script "$T/ph1" <<EOS
send {"type":"ping"}
expect {"type":"pong"}
sleep 5500
garble 3
expectreset
send {"type":"ping"}
expect {"type":"pong"}
EOS
    done_ok $PR garble
    [ "$(grep -c '^session$' "$T/ph1.run")" -ge 2 ] || fail "garble: no new session: $(cat "$T/ph1.run")"
    cat "$RO" "$T/remote$nr.err" > "$T/garble.log"
    grep -qF 'did not open (2 in a row)' "$T/garble.log" || fail "garble: no drop line: $(cat "$T/garble.log")"
    grep -qF '3 records in a row did not open' "$T/garble.log" || fail "garble: no reset line: $(cat "$T/garble.log")"
    printf 'PASS: records a session cannot open, three in a row, reset it, and the phone starts a new one\n'

    script "$T/ph1" <<EOS
send {"type":"presence","payload":{"visible":true}}
send {"type":"ping"}
expect {"type":"pong"}
mark go-deaf
waitfor at-deaf
send {"type":"ping"}
expect {"type":"pong"}
EOS
    i=0; until [ -e "$T/ph1/go-deaf" ]; do i=$((i + 1)); [ "$i" -lt $TRIES ] || fail "deaf: $(cat "$T/ph1.run")"; sleep 0.05; done
    ctl deaf
    touch "$T/ph1/at-deaf"
    done_ok $PR deaf
    cat "$RO" "$T/remote$nr.err" > "$T/deaf.log"
    grep -qF 'reconnecting' "$T/deaf.log" || fail "deaf: no reconnect line: $(cat "$T/deaf.log")"
    grep -qF 'the stream ended (asked to reconnect)' "$T/deaf.log" || fail "deaf: no reason: $(cat "$T/deaf.log")"
    stamp='^[0-9]\{4\}-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]Z pic remote: '
    [ "$(grep -vc "$stamp" "$T/deaf.log")" = 0 ] || fail "log: a line without its time: $(grep -v "$stamp" "$T/deaf.log")"
    printf 'PASS: a stream that brings keepalives but no records is opened again; each log line has its time\n'

    # Another pic holding the journal's write lock (a loop round, a running request) does not stop
    # pic remote: a command that must write is answered busy at once, and everything else goes on.
    rm -f "$T/hold.in"
    mkfifo "$T/hold.in"
    "$SQLITE3" "$DB" < "$T/hold.in" > "$T/hold.out" 2>&1 &
    HOLD=$!
    bg $HOLD
    exec 4> "$T/hold.in"
    printf 'BEGIN IMMEDIATE; UPDATE pic_session SET updated_ms = updated_ms;\nSELECT 1;\n' >&4
    await "$T/hold.out" 1
    t0=$(date +%s)
    script "$T/ph1" <<EOS
send {"type":"ping"}
expect {"type":"pong"}
send {"type":"command","session":"$SESS","key":"k-held-0000000001","payload":{"type":"follow_up","message":"held"}}
expect "code":"busy"
send {"type":"sync","session":"$SESS","seq":-1}
expect {"type":"sync","session":"$SESS"
send {"type":"ping"}
expect {"type":"pong"}
EOS
    done_ok $PR held
    t1=$(date +%s)
    printf 'COMMIT;\n' >&4
    exec 4>&-
    gone $HOLD
    grep -qF 'busy on the computer' "$T/ph1.run" || fail "held: $(cat "$T/ph1.run")"
    [ $((t1 - t0)) -lt 15 ] || fail "held: the phone waited $((t1 - t0)) s"
    # held for the whole script, a loop that waited on the lock would be stuck seconds on end; a
    # second's hiccup on a loaded machine (the stall seam is 1.5 s here) is not that
    if grep -Eq '(moving again after|stuck for) ([5-9]|[1-9][0-9]+) s' "$RO"; then fail "held: the loop stalled: $(grep -F stall "$RO")"; fi
    printf 'PASS: a journal another pic is writing: a command is answered busy and pic remote goes on\n'

    # A long history goes a page at a time (PIC_TEST_RC_PAGE=2 entries), each page with its mark,
    # and arrives whole: every entry once, in order.
    script "$T/ph1" <<EOS
send {"type":"sync","session":"$SESS","seq":0}
expect "type":"agent_end"
sleep 2000
EOS
    done_ok $PR pages
    last=$(q "SELECT max(e.seq) FROM pic_entry e JOIN pic_submission u ON u.id = e.submission_id WHERE u.session_id = '$SID'")
    marks=$(grep -c '^<- {"type":"sync","session":"'"$SESS"'"' "$T/ph1.run")
    [ "$marks" -ge 2 ] || fail "pages: $marks marks: $(cat "$T/ph1.run")"
    grep -qF '"type":"sync","session":"'"$SESS"'","seq":'"$last"',' "$T/ph1.run" || fail "pages: no mark at $last: $(grep '"type":"sync"' "$T/ph1.run")"
    seqs=$(grep -o '"payload":{"type":"message_end","seq":[0-9]*' "$T/ph1.run" | grep -o '[0-9]*$')
    [ "$(printf '%s\n' "$seqs" | sort -n | uniq -d)" = "" ] || fail "pages: an entry twice"
    [ "$(printf '%s\n' "$seqs" | sort -n)" = "$seqs" ] || fail "pages: out of order"
    [ "$(printf '%s\n' "$seqs" | wc -l | tr -d ' ')" = "$(q "SELECT count(*) FROM pic_entry e JOIN pic_submission u ON u.id = e.submission_id WHERE u.session_id = '$SID' AND e.kind IN ('user', 'assistant', 'answer')")" ] ||
        fail "pages: messages: $seqs"
    printf 'PASS: a long history goes in pages, each with its mark, every message once and in order\n'

    # A loop that does not come back is logged by the watchdog, and pic remote status says stalled;
    # once it moves again, both say so.
    touch "$T/stall"
    await "$RO" 'stalled: the loop has been stuck'
    i=0
    until PIC_TEST_RC_STALL_MS=1500 "$PIC" remote status > "$T/stalled.out" 2>&1 && grep -qF 'stalled for' "$T/stalled.out"; do
        i=$((i + 1))
        [ "$i" -lt "$TRIES" ] || fail "stall: status: $(cat "$T/stalled.out")"
        sleep 0.05
    done
    rm -f "$T/stall"
    await "$RO" 'the loop is moving again'
    i=0
    until PIC_TEST_RC_STALL_MS=1500 "$PIC" remote status > "$T/stalled.out" 2>&1 && grep -qF ': connected' "$T/stalled.out"; do
        i=$((i + 1))
        [ "$i" -lt "$TRIES" ] || fail "stall: status after: $(cat "$T/stalled.out")"
        sleep 0.05
    done
    printf 'PASS: a stuck loop is logged with what it was doing, and status says stalled until it moves\n'

    # A command that reads the journal is a job on a worker: one held 2.5 s inside it
    # (PIC_TEST_RC_SLOW_PHASE sleeps there) is logged as slow with the phone and the command, while
    # the loop answers a ping at once and does not stall; the command's answer comes after.
    before=$(wc -l < "$RO")
    script "$T/ph1" <<EOS
cmd k-wakes-000000001 {"type":"command","session":"$SESS","key":"k-wakes-000000001","payload":{"type":"get_wakes"}}
ping 2000
expect "command":"get_wakes"
EOS
    done_ok $PR "slow job"
    grep -q '^pong [0-9]* ms$' "$T/ph1.run" || fail "slow job: no pong while the job ran: $(cat "$T/ph1.run")"
    [ "$(grep -n 'pong\|"command":"get_wakes"' "$T/ph1.run" | head -1 | grep -c pong)" = 1 ] || fail "slow job: the answer came before the pong: $(cat "$T/ph1.run")"
    await "$RO" "slow: answering Phone One's command get_wakes has run"
    if tail -n +$((before + 1)) "$RO" | grep -q 'stalled: the loop has been stuck'; then fail "slow job: the loop stalled: $(tail -n +$((before + 1)) "$RO" | grep stalled)"; fi
    printf 'PASS: a slow command is logged as a slow job with the phone and the command, and the loop goes on\n'
    kill "$RP"
    gone "$RP"

    # Every job slow (a slow disk: PIC_TEST_RC_JOB_MS sleeps in each get_state, and in each tick of
    # the journal) and 200 phone messages queued at once: the loop answers pings within a second
    # throughout (a late one or two allowed on a loaded machine), every command gets one answer,
    # and the answers of one journal come in the order sent. A command whose job runs far past its
    # budget is answered busy by the loop while it runs.
    nr=$((nr + 1))
    RO="$T/remote$nr.out"
    PIC_TEST_RC_JOB_MS="command get_state:20" PIC_TEST_RC_STALL_MS=1500 "$PIC" remote > "$RO" 2> "$T/remote$nr.err" &
    RP=$!
    bg $RP
    await "$RO" 'pic remote: connected'
    {
        i=1
        while [ $i -le 200 ]; do
            printf 'send {"type":"command","session":"%s","key":"k-many-%010d","payload":{"type":"get_state"}}\n' "$SESS" $i
            i=$((i + 1))
        done
        i=0
        while [ $i -lt 10 ]; do printf 'ping 1000\nsleep 300\n'; i=$((i + 1)); done
        printf 'waitcount "key":"k-many- 200\n'
    } > "$T/many.script"
    script "$T/ph1" < "$T/many.script"
    done_ok $PR "many"
    late=$(grep -c '^late pong$' "$T/ph1.run" || :)
    [ "$late" -le 2 ] || fail "many: $late of 10 pings went unanswered for a second: $(grep pong "$T/ph1.run")"
    for k in $(grep -o '"key":"k-many-[0-9]*"' "$T/ph1.run" | sort | uniq -d); do fail "many: two answers for $k"; done
    got=$(grep '"type":"response"' "$T/ph1.run" | grep -o 'k-many-[0-9]*' | sed 's/k-many-0*//')
    [ "$(printf '%s\n' "$got" | sort -n)" = "$got" ] || fail "many: answers out of order: $(printf '%s ' $got)"
    [ "$(printf '%s\n' "$got" | wc -l | tr -d ' ')" -ge 100 ] || fail "many: only $(printf '%s\n' "$got" | wc -l) answered, the rest busy"
    if grep -q 'stalled: the loop has been stuck' "$RO"; then fail "many: the loop stalled: $(grep stalled "$RO")"; fi
    printf 'PASS: 200 messages queued behind slow jobs: pings answered within a second, every command once, in order\n'
    kill "$RP"
    gone "$RP"

    nr=$((nr + 1))
    RO="$T/remote$nr.out"
    PIC_TEST_RC_JOB_MS="command get_session_stats:6000" PIC_TEST_RC_STALL_MS=1500 "$PIC" remote > "$RO" 2> "$T/remote$nr.err" &
    RP=$!
    bg $RP
    await "$RO" 'pic remote: connected'
    script "$T/ph1" <<EOS
send {"type":"command","session":"$SESS","key":"k-overrun-00000001","payload":{"type":"get_session_stats"}}
expect "code":"busy"
ping 1000
sleep 4000
EOS
    done_ok $PR "overrun"
    grep -q '^pong [0-9]* ms$' "$T/ph1.run" || fail "overrun: no pong: $(cat "$T/ph1.run")"
    [ "$(grep -c 'k-overrun-00000001' "$T/ph1.run")" = 1 ] || fail "overrun: answered twice: $(grep k-overrun "$T/ph1.run")"
    printf 'PASS: a command whose job runs past its budget is answered busy by the loop, once\n'
    kill "$RP"
    gone "$RP"

    # A busy answer is never a lie. A command whose job has committed when it runs past its budget
    # (PIC_TEST_RC_JOB_AFTER_MS holds the worker after the work) gets its own answer, not busy; one
    # held before its work is answered busy and commits nothing. An abort while nothing runs: its
    # row is written refused at once, so it changes nothing else.
    nr=$((nr + 1))
    RO="$T/remote$nr.out"
    PIC_TEST_RC_JOB_AFTER_MS="command abort:3500" "$PIC" remote > "$RO" 2> "$T/remote$nr.err" &
    RP=$!
    bg $RP
    await "$RO" 'pic remote: connected'
    script "$T/ph1" <<EOS
send {"type":"command","session":"$SESS","key":"k-late-0000000001","payload":{"type":"abort"}}
expect "key":"k-late-0000000001"
EOS
    done_ok $PR "committed, then late"
    grep -F 'k-late-0000000001' "$T/ph1.run" | grep -qF 'nothing to abort' ||
        fail "committed, then late: not its own answer: $(grep -F k-late "$T/ph1.run")"
    [ "$(q "SELECT count(*) FROM pic_inbox WHERE msg_key LIKE 'rc:%:k-late-0000000001'")" = 1 ] || fail "committed, then late: no row"
    kill "$RP"
    gone "$RP"
    nr=$((nr + 1))
    RO="$T/remote$nr.out"
    PIC_TEST_RC_JOB_MS="command abort:6000" PIC_TEST_RC_STALL_MS=1500 "$PIC" remote > "$RO" 2> "$T/remote$nr.err" &
    RP=$!
    bg $RP
    await "$RO" 'pic remote: connected'
    script "$T/ph1" <<EOS
send {"type":"command","session":"$SESS","key":"k-early-000000001","payload":{"type":"abort"}}
expect "code":"busy"
EOS
    done_ok $PR "late, then committing"
    await "$RO" "command abort ended after"
    [ "$(q "SELECT count(*) FROM pic_inbox WHERE msg_key LIKE 'rc:%:k-early-000000001'")" = 0 ] ||
        fail "late, then committing: answered busy, yet its row was written"
    kill "$RP"
    gone "$RP"
    # a saved key goes to the user database, which the journal's hook does not see: told busy, it is not saved
    nr=$((nr + 1))
    RO="$T/remote$nr.out"
    PIC_TEST_RC_JOB_MS="command set_credential:6000" "$PIC" remote > "$RO" 2> "$T/remote$nr.err" &
    RP=$!
    bg $RP
    await "$RO" 'pic remote: connected'
    script "$T/ph1" <<EOS
send {"type":"command","session":"$SESS","key":"k-early-persist001","payload":{"type":"set_credential","provider":"fake","label":"env","persist":true}}
expect "code":"busy"
EOS
    done_ok $PR "a saved key, answered busy"
    sleep 7 # the held job (6 s) has run its work by now
    [ "$(uq "SELECT count(*) FROM picu_setting WHERE key = 'activeKey:fake'")" = 0 ] ||
        fail "a saved key, answered busy: it was saved"
    kill "$RP"
    gone "$RP"
    nr=$((nr + 1)) # the control: the same command, not held, saves the key
    RO="$T/remote$nr.out"
    "$PIC" remote > "$RO" 2> "$T/remote$nr.err" &
    RP=$!
    bg $RP
    await "$RO" 'pic remote: connected'
    script "$T/ph1" <<EOS
send {"type":"command","session":"$SESS","key":"k-late-persist0001","payload":{"type":"set_credential","provider":"fake","label":"env","persist":true}}
expect "command":"set_credential","success":true
EOS
    done_ok $PR "a saved key, in time"
    [ "$(uq "SELECT count(*) FROM picu_setting WHERE key = 'activeKey:fake'")" = 1 ] ||
        fail "a saved key, in time: it was not saved"
    uq "DELETE FROM picu_setting WHERE key = 'activeKey:fake'"
    printf 'PASS: a command that committed before its job ran late gets its answer; one answered busy commits nothing\n'
    kill "$RP"
    gone "$RP"
    remote
fi

# A newer pic installed over a running pic remote: status says it is older, pic remote restart
# starts the new one in its place (the same pid), and on its own it does so once the file has kept
# still and nothing is under way; a phone is served again after.
kill "$RP"
gone "$RP"
mkdir -p "$T/bin"
cp "$PIC" "$T/bin/pic"
install_new() { cp "$PIC" "$T/bin/pic.new" && mv -f "$T/bin/pic.new" "$T/bin/pic"; } # a new file, as an install makes
nr=$((nr + 1))
RO="$T/remote$nr.out"
PIC_TEST_RC_SETTLE_MS=600000 "$T/bin/pic" remote > "$RO" 2> "$T/remote$nr.err" &
RP=$!
bg $RP
await "$RO" 'pic remote: connected'
"$PIC" remote status --json > "$T/stale0.json"
grep -qF '"stale":false' "$T/stale0.json" || fail "stale: a fresh one: $(cat "$T/stale0.json")"
install_new
"$PIC" remote status --json > "$T/stale1.json"
grep -qF '"stale":true' "$T/stale1.json" || fail "stale: after the install: $(cat "$T/stale1.json")"
"$PIC" remote status > "$T/stale1.out"
grep -qF 'older pic than the one installed now: pic remote restart' "$T/stale1.out" || fail "stale: status: $(cat "$T/stale1.out")"
"$PIC" remote restart > "$T/restart.out" 2>&1 || fail "restart: $(cat "$T/restart.out")"
grep -qF 'pic remote: restarted' "$T/restart.out" || fail "restart: $(cat "$T/restart.out")"
grep -qF 'pic remote: asked to restart' "$RO" || fail "restart: what it said: $(cat "$RO")"
"$PIC" remote status --json > "$T/stale2.json"
grep -qF '"stale":false' "$T/stale2.json" && grep -qF "\"pid\":$RP," "$T/stale2.json" || fail "restart: status: $(cat "$T/stale2.json")"
kill "$RP"
gone "$RP"
nr=$((nr + 1))
RO="$T/remote$nr.out"
"$T/bin/pic" remote > "$RO" 2> "$T/remote$nr.err" &
RP=$!
bg $RP
await "$RO" 'pic remote: connected'
install_new
await "$RO" 'pic remote: a newer pic was installed; starting /'
i=0
until [ "$(grep -c 'pic remote: connected' "$RO")" -ge 2 ]; do
    i=$((i + 1))
    [ "$i" -lt $TRIES ] || fail "restart: the new one did not connect: $(cat "$RO" "$T/remote$nr.err")"
    sleep 0.05
done
"$PIC" remote status --json > "$T/stale3.json"
grep -qF "\"pid\":$RP," "$T/stale3.json" && grep -qF '"stale":false' "$T/stale3.json" || fail "restart: status: $(cat "$T/stale3.json")"
script "$T/ph1" <<EOS
send {"type":"sessions"}
expect "session":"$SESS"
EOS
done_ok $PR "after the restart"
kill "$RP"
gone "$RP"
remote
printf 'PASS: a newer pic installed over pic remote: status says it is older; it restarts itself when quiet, or on pic remote restart, and serves again\n'

# Twenty restarts in a row while other processes ask whether pic remote runs (pic remote status
# tries its lock for an instant, as /rc and every terminal's footer do all the time). A probe that
# holds the lock across the restart's exec stands in for the unlucky one, holding it 100 ms
# whenever it gets it: the new pic waits it out rather than exiting as a second one, and it is
# running after each restart, in the same process.
rm -f "$T/probe.stop"
perl -e 'use Fcntl qw(:flock); use Time::HiRes qw(sleep); until (-e $ARGV[1]) { open(my $f, ">>", $ARGV[0]) or die;
    if (flock($f, LOCK_EX | LOCK_NB)) { sleep 0.1; } close $f; sleep 0.005; }' "$HOME/.pic/remote.lock" "$T/probe.stop" &
PROBE=$!
bg $PROBE
for k in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20; do
    before=$(grep -c 'pic remote: connected' "$RO")
    "$PIC" remote restart > "$T/restart$k.out" 2>&1 || { touch "$T/probe.stop"; fail "restart $k: $(cat "$T/restart$k.out" "$T/remote$nr.err")"; }
    i=0
    until [ "$(grep -c 'pic remote: connected' "$RO")" -gt "$before" ]; do
        i=$((i + 1))
        kill -0 "$RP" 2> /dev/null || { touch "$T/probe.stop"; fail "restart $k: pic remote exited: $(tail -5 "$RO" "$T/remote$nr.err")"; }
        [ "$i" -lt $TRIES ] || { touch "$T/probe.stop"; fail "restart $k: not connected again: $(tail -5 "$RO")"; }
        sleep 0.05
    done
done
touch "$T/probe.stop"
gone "$PROBE"
grep -qF 'one is already running' "$RO" "$T/remote$nr.err" && fail "restarts: refused itself: $(grep -F 'already running' "$RO" "$T/remote$nr.err")"
kill -0 "$RP" 2> /dev/null || fail "restarts: pic remote is not running"
printf 'PASS: twenty restarts while status is asked all along: pic remote is running after each\n'

SAVE_DB=$DB SAVE_WS=$WS SAVE_LOG=$LOG SAVE_SPID=$spid SAVE_MODELS=$PIC_MODELS_FILE
kill "$spid" 2>/dev/null || :

# Every child pic remote starts is reaped: after phone-started requests and a compaction, none is
# left defunct.
spid=
serve "sse:$S/text.sse" "sse:$S/text.sse" "sse:$S/text.sse" "sse:$S/text.sse" "sse:$S/text.sse" "sse:$S/text.sse"
pic ask 'reap first' > /dev/null 2> "$T/askr.err" || fail "ask: $(cat "$T/askr.err")"
SESSR="$DB/$(q "SELECT id FROM pic_session")"
kill "$RP"
gone "$RP"
remote
children() { ps -A -o ppid= -o stat= | awk -v p="$RP" '$1 == p { print $2 }'; }
{
    printf 'send {"type":"sync","session":"%s","seq":-1}\nexpect {"type":"sync","session":"%s"\n' "$SESSR" "$SESSR"
    for k in 1 2 3 4; do
        printf 'cmd k-reap-prompt-00%s {"type":"command","session":"%s","key":"k-reap-prompt-00%s","payload":{"type":"prompt","message":"reap %s"}}\n' "$k" "$SESSR" "$k" "$k"
        printf 'seen :k-reap-prompt-00%s","status":"answered"\n' "$k"
    done
} > "$T/reap.script"
script "$T/ph1" < "$T/reap.script"
done_ok $PR "reap: prompts"
[ "$(q "SELECT count(*) FROM pic_submission WHERE request_key LIKE 'rc:%:k-reap-prompt-%' AND status = 'answered'")" = 4 ] ||
    fail "reap: $(q 'SELECT request_key, status FROM pic_submission')"
i=0
until [ -z "$(children | grep -v '^Z')" ] && [ -z "$(children | grep '^Z')" ]; do
    i=$((i + 1))
    [ "$i" -lt 100 ] || break
    sleep 0.05
done
[ -z "$(children | grep '^Z')" ] || fail "reap: $(children | grep -c '^Z') defunct children of pic remote"
printf 'PASS: every child pic remote starts is reaped: none defunct after phone-started requests\n'
kill "$spid" 2> /dev/null