#!/bin/sh # Client disconnects mid-request, against a running server. # # A disconnect runs the scheduler's reap at an arbitrary point in the step loop, so anything holding # a raw Request* across that point (a step plan entry, a drafter snapshot) is a use-after-free. # Other harnesses wait for their requests and never exercise this. # # Staying up is not enough: a freed slot feeding a live sequence shows as a changed answer. A # reference answer is taken first and the same question is asked after each drop; the hashes must # match. Every observation counts toward the verdict, since a transient divergence right after a # burst is the interesting case and a final re-check would hide it. # # Drop points are fractions of a timed full request; a drop past the end of the request exercises # nothing. `--max-time` is the disconnect (curl closes the socket); `running` returning to zero # well before the request would have finished confirms it. # # One divergence is not a finding: concurrency changes batch composition, and greedy decoding can # flip at a tie even on an unchanged binary. Rerun several times before believing a diverged row. # The reference question is stable against an idle server; only the contended path can tie-flip. # # P=8100 scripts/fndrop.sh P="${P:-8100}" H="${H:-127.0.0.1}" ROOT="${ROOT:-$(dirname "$0")/..}" URL="http://$H:$P" C=/dev/shm/fndrop-corpus.txt BPT=3 LONG="${LONG:-20000}" # tokens of prompt, so prefill is a measurable slice GEN="${GEN:-3000}" # tokens of generation, so decode is a long one too want=$((LONG * BPT + 8192)) touch "$C" [ "$(wc -c < "$C")" -ge "$want" ] || { : > "$C" while [ "$(wc -c < "$C")" -lt "$want" ]; do cat "$ROOT"/spec.md "$ROOT"/docs/*.md >> "$C" 2>/dev/null || exit 1; done; } alive() { pgrep -f "bin/radianc[e]" >/dev/null && echo ALIVE || echo DEAD; } healthy() { curl -s -m 5 "$URL/health" >/dev/null 2>&1 && echo ok || echo unreachable; } running() { curl -s -m 5 "$URL/stats" | jq -r '.running // "?"'; } ref() { curl -s -m 300 -X POST "$URL/v1/completions" -H 'Content-Type: application/json' \ -d '{"prompt":"List the first five prime numbers, comma separated.","max_tokens":48, "temperature":0}' | jq -r '.choices[0].text // "ERR"' | sha256sum | cut -c1-16 } body() { { printf 'drop %s\n\n' "$(date +%s%N)"; head -c $((LONG * BPT)) "$C"; } > /dev/shm/fndrop-p.txt jq -Rs --argjson g "$GEN" '{prompt: ., max_tokens: $g, ignore_eos: true, temperature: 0}' \ < /dev/shm/fndrop-p.txt > /dev/shm/fndrop-b.json } send() { body; curl -s -m "$1" -o /dev/null -X POST "$URL/v1/completions" \ -H 'Content-Type: application/json' --data-binary @/dev/shm/fndrop-b.json 2>/dev/null; return 0; } echo "server $URL, prompt ~$LONG tokens + $GEN generated" base=$(ref) t0=$(date +%s.%N); send 900; t1=$(date +%s.%N) FULL=$(awk -v a="$t0" -v b="$t1" 'BEGIN{printf "%.0f", b-a}') [ "$FULL" -lt 6 ] && { echo "a full request is only ${FULL}s -- raise LONG or GEN so the phases are separable"; exit 1; } printf ' a full request takes %ss; dropping inside it\n' "$FULL" printf ' %-40s %-7s %-10s %-9s %s\n' step alive health 'running+2s' answer printf ' %-40s %-7s %-10s %-9s %s <- reference\n' "before any drop" "$(alive)" "$(healthy)" "-" "$base" BAD=0; SEEN=0 observe() { # $1 = label; records the answer against the reference rather than only printing it a=$(ref); SEEN=$((SEEN + 1)); [ "$a" = "$base" ] || BAD=$((BAD + 1)) printf " %-40s %-7s %-10s %-9s %s%s\n" "$1" "$(alive)" "$(healthy)" "$(running)" "$a" \ "$( [ "$a" = "$base" ] || echo " <- DIVERGED" )" } drop() { # $1 = seconds, $2 = label send "$1"; sleep 2; observe "$2" } drop $((FULL / 8 + 1)) "dropped at 1/8 of it (early prefill)" drop $((FULL / 3 + 1)) "dropped at 1/3 of it" drop $((FULL / 2 + 1)) "dropped at 1/2 of it" drop $((FULL * 3 / 4)) "dropped at 3/4 of it (deep in decode)" for s in $((FULL / 4 + 1)) $((FULL / 3 + 1)) $((FULL / 4 + 1)) $((FULL / 2 + 1)); do send "$s" & done send 900 & wait sleep 2 observe "four concurrent drops + one survivor" echo if [ "$BAD" -eq 0 ]; then printf ' all %d answers matched the reference\n' "$SEEN" else printf ' %d of %d answers DIVERGED from the reference -- run it again before believing it\n' \ "$BAD" "$SEEN" fi