Automatic compaction was keyed only on stats.last_in, the prompt size the provider reports with usage. A resumed session starts at 0, and a provider that reports no usage leaves it at 0 - the session outgrows every endpoint's window, the first request is refused, no usage arrives, and every later resume fails the same way. Measured on 2026-11-22: a 9,095,724-byte session, ctx=2,286,261 at junction, 503 no_endpoint_available on every retry. The conversation bytes are there before anything is sent; the same four bytes per token the target already uses are the second trigger. tests/test_compact_resume.sh: a ~300 kB session, one turn after --resume; the first request must be compacted. Counter-proof with the old agent.c: 302 messages, 321,087 bytes.
127 lines
3.8 KiB
Bash
Executable File
127 lines
3.8 KiB
Bash
Executable File
#!/bin/sh
|
|
#
|
|
# splinter -- a resumed session that is already over the window compacts
|
|
# before its first request.
|
|
#
|
|
# What it guards: compaction used to be judged only by stats.last_in, the
|
|
# prompt size a provider reports with its usage chunk. A session starts at 0
|
|
# after --resume, so a transcript that grew past every endpoint's window was
|
|
# sent whole on the first turn; the endpoint refused it, no usage ever came
|
|
# back, and the session stayed unusable for every later resume as well.
|
|
# Measured 2026-11-22: 9,095,724 bytes, ctx=2,286,261 at junction, 503
|
|
# no_endpoint_available on every retry.
|
|
#
|
|
# The fix also judges the local conversation bytes (compact_threshold * 4),
|
|
# which are there before anything is sent. One turn in ONE process: without
|
|
# the fix that request carries the whole session; with it, the compactor has
|
|
# run and the request is down at the target.
|
|
set -u
|
|
cd "$(dirname "$0")/.." || exit 1
|
|
. "$(dirname "$0")/sh/port.sh"
|
|
D=$(mktemp -d "${TMPDIR:-/var/tmp}/splinter-compact-resume-XXXXXX") || exit 1
|
|
P=$(free_port)
|
|
F=
|
|
S=
|
|
fails=0
|
|
cleanup() {
|
|
[ -n "$F" ] && kill "$F" 2>/dev/null
|
|
[ -n "$S" ] && kill "$S" 2>/dev/null
|
|
rm -rf "$D"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
fail() { echo "FAIL $*"; fails=$((fails + 1)); }
|
|
|
|
mkdir -p "$D/home" "$D/sess"
|
|
|
|
# 150 turns of 2000 bytes plus answers: ~300 kB, well past threshold * 4
|
|
# (50000 tokens * 4 bytes). Written in the old chat shape on purpose - the
|
|
# resumed-session loader has to read what older binaries wrote.
|
|
python3 -I - "$D/sess/sess-big.jsonl" <<'PY'
|
|
import json, sys
|
|
out = []
|
|
for i in range(1, 151):
|
|
out.append({"role": "user", "text": "frage %d %s" % (i, "y" * 2000)})
|
|
out.append({"role": "assistant", "text": "antwort %d" % i})
|
|
open(sys.argv[1], "w").write("".join(json.dumps(l) + "\n" for l in out))
|
|
PY
|
|
|
|
cat > "$D/conf" <<EOF
|
|
core {
|
|
locale = en
|
|
session_dir = $D/sess
|
|
embed = off
|
|
compact_threshold = 50000
|
|
compact_target = 2000
|
|
}
|
|
EOF
|
|
|
|
python3 -I tests/fake_strict_usage.py "$P" "$D/requests.log" \
|
|
> "$D/fake.log" 2>&1 &
|
|
F=$!
|
|
if ! wait_listen "$P" "$F"; then
|
|
echo "FAIL the fake endpoint did not start"
|
|
cat "$D/fake.log"
|
|
exit 1
|
|
fi
|
|
|
|
HOME="$D/home" ./splinter --config "$D/conf" \
|
|
--serve --socket "$D/s.sock" \
|
|
--endpoint "http://127.0.0.1:$P/v1" --model m \
|
|
--session-id sess-big --resume \
|
|
> "$D/serve.log" 2>&1 &
|
|
S=$!
|
|
i=0
|
|
while [ "$i" -lt 60 ]; do
|
|
[ -S "$D/s.sock" ] && break
|
|
i=$((i + 1))
|
|
sleep 0.2
|
|
done
|
|
if [ ! -S "$D/s.sock" ]; then
|
|
echo "FAIL the server did not start"
|
|
cat "$D/serve.log"
|
|
exit 1
|
|
fi
|
|
|
|
./splinterctl --socket "$D/s.sock" --say "turn eins" > /dev/null 2>&1
|
|
|
|
if [ ! -s "$D/requests.log" ]; then
|
|
echo "FAIL no request reached the endpoint"
|
|
cat "$D/serve.log"
|
|
exit 1
|
|
fi
|
|
|
|
n=$(wc -l < "$D/requests.log")
|
|
msgs=$(tail -1 "$D/requests.log" |
|
|
sed -n 's/.*msgs=\([0-9]*\).*/\1/p')
|
|
bytes=$(tail -1 "$D/requests.log" |
|
|
sed -n 's/.*bytes=\([0-9]*\).*/\1/p')
|
|
if [ "$n" -ne 1 ]; then
|
|
fail "expected one request, got $n"
|
|
fi
|
|
if [ -z "$msgs" ] || [ -z "$bytes" ]; then
|
|
fail "cannot read the request"
|
|
cat "$D/requests.log"
|
|
elif [ "$msgs" -ge 60 ]; then
|
|
fail "the first request after resume still carried $msgs messages" \
|
|
"(compaction did not fire; request was $bytes bytes)"
|
|
elif [ "$bytes" -ge 100000 ]; then
|
|
fail "the first request after resume was still $bytes bytes"
|
|
else
|
|
echo "ok first turn after resume: $bytes bytes, $msgs messages (compacted)"
|
|
fi
|
|
|
|
# The compactor must have run before the request, and the turn must have
|
|
# finished: the endpoint reports usage, so a later resume has a size again.
|
|
if ! grep -q "compacted" "$D/serve.log"; then
|
|
echo "note: no compaction line in the server log (the request is the proof)"
|
|
fi
|
|
|
|
if [ "$fails" -ne 0 ]; then
|
|
cat "$D/requests.log"
|
|
cat "$D/serve.log"
|
|
exit 1
|
|
fi
|
|
echo "test_compact_resume: ok"
|
|
exit 0
|