Artifact d37416dbf201a2d7029d0208eff2d73a628b435c430cf5144fb5bf9556983121:
- File
test/pic/migrate.sh
— part of check-in
[5453014491]
at
2026-11-19 02:30:01
on branch compaction
— Compact long conversations with Pi's algorithm, for any model
Before each reply pic estimates the context as Pi does (the last reply's usage plus chars/4 for what followed) and past the model's window minus 16384 tokens it summarizes the history beyond the newest 20000 tokens, cutting only where a call is not separated from its result and handling a split turn as Pi does. The summary requests use Pi's prompts and serialization, are journaled as generations of their own and retried like replies; the summary, read and modified files, the first kept entry and the tokens before commit together. Requests then send the summary, the kept entries (rebuilt without thinking when older than the compaction) and what followed. Instruction updates that were summarized go out again. A context overflow compacts once and retries; pic compact asks for one before the next request; --context-window overrides the window. Schema 6. (user: dmestas, size: 2136) [annotate] [blame] [check-ins using] [more...]
#!/bin/sh # Journals written by earlier pic versions open with the current one: the # schema-3 fixture is migrated in place, passes pic check, keeps its history, # and takes new work. Needs the sqlite3 command to build the fixture. set -eu PIC=${PIC:?set PIC to the pic binary} command -v sqlite3 > /dev/null || { echo "migrate: skipped, no sqlite3 command"; exit 0; } T=$(mktemp -d "${TMPDIR:-/tmp}/pic-migrate.XXXXXX") trap 'rm -rf -- "$T"' EXIT HUP INT TERM fail() { printf 'FAIL: %s\n' "$*" >&2; exit 1; } DB="$T/journal.sqlite" mkdir "$T/ws" sqlite3 "$DB" < "$(dirname "$0")/journal-v3.sql" pic() { "$PIC" --db "$DB" --workspace "$T/ws" "$@"; } pic check > /dev/null || fail "migrated journal fails pic check" out=$(pic dump) printf '%s\n' "$out" | grep -qF 'entry 2 1 assistant | [{"type":"thinking","thinking":"Write it.","signature":"SIG-OLD"},{"type":"toolCall","id":"toolu_old","name":"write","arguments":{"path":"notes.txt","content":"hi"}}]' || fail "reply not converted to the neutral form" printf '%s\n' "$out" | grep -q '^entry 4 1 answer | \[{"type":"text","text":"done"}\]$' || fail "answer" printf '%s\n' "$out" | grep -q '^generation 1 1.0.1 done stop=toolUse' || fail "stop reasons not renamed" [ "$(sqlite3 "$DB" "SELECT value FROM pic_meta WHERE key='schema_version'")" = 6 ] || fail "version not 6" [ "$(sqlite3 "$DB" "SELECT count(*) FROM pic_session")" = 1 ] || fail "submission not given a session" [ "$(sqlite3 "$DB" "SELECT group_concat(coalesce(parent_seq, 0), ' ') FROM (SELECT parent_seq FROM pic_entry WHERE submission_id = 1 ORDER BY seq)")" = "0 1 2 3" ] || fail "entries not chained" [ "$(sqlite3 "$DB" "SELECT provider || '/' || model || ' ' || (native LIKE '%tool_use%') FROM pic_entry WHERE seq=2")" = \ "anthropic/unknown 1" ] || fail "origin or native form" printf 'tool write new.txt again\ntext done again\n' > "$T/script" pic submit job-2 'more' > /dev/null pic run --script "$T/script" pic check > /dev/null || fail "journal broken after new work" [ "$(cat "$T/ws/new.txt")" = again ] || fail "new work did not run" printf 'PASS: a schema-3 journal migrates and keeps working\n'