1e86ed8a44
- chat-history.jsonl rotates at 10MB or 7d -> logs/archive/*.jsonl.gz + .sha256 - job-log.jsonl rotates at 2MB or 14d -> same archive layout - followups.json archives resolved>7d / escalated>30d -> followups.archive.jsonl (append-only) - verify wrapper: sha256 -c, gzip -t, clean listing, spot-extract JSON + ts bounds - driver + hourly systemd user timer (retention-rotations.timer) - archive-only: nothing is ever deleted; thread backfill excluded (needs human-reviewed preview) First run 2026-10-05 16:35Z: chat-history 29.7MB + job-log 4.7MB rotated and verified; followups 0 eligible of 163.
46 lines
1.6 KiB
Bash
Executable File
46 lines
1.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# retention-rotate-chat-history.sh — retention piece 1 (board bug b67084660385).
|
|
# Rotates logs/chat-history.jsonl when it exceeds 10MB or is older than 7 days.
|
|
#
|
|
# Live-writer safety: the harvester (bin/response-harvester.py) opens the file
|
|
# in append mode per write and closes it immediately, so an atomic `mv` of the
|
|
# live file is safe — the next write recreates a fresh file. We also `touch`
|
|
# the new live file for tidiness and to keep ownership/visibility stable.
|
|
#
|
|
# Archives land in logs/archive/chat-history-YYYYMMDD-HHMMSS.jsonl.gz with a
|
|
# sha256 sidecar. Nothing is ever deleted by this script.
|
|
set -euo pipefail
|
|
|
|
ROOT="${NETVM_ROOT:-/home/super/Projects/NetVM}"
|
|
LIVE="$ROOT/logs/chat-history.jsonl"
|
|
ARCHIVE_DIR="$ROOT/logs/archive"
|
|
SIZE_LIMIT=$((10 * 1024 * 1024)) # 10MB
|
|
AGE_LIMIT_DAYS=7
|
|
TS="$(date -u +%Y%m%d-%H%M%S)"
|
|
|
|
mkdir -p "$ARCHIVE_DIR"
|
|
|
|
if [ ! -f "$LIVE" ]; then
|
|
echo "SKIP chat-history: no live file at $LIVE"
|
|
exit 0
|
|
fi
|
|
|
|
size="$(stat -c %s "$LIVE")"
|
|
age_days=$(( ( $(date +%s) - $(stat -c %Y "$LIVE") ) / 86400 ))
|
|
|
|
if [ "$size" -lt "$SIZE_LIMIT" ] && [ "$age_days" -lt "$AGE_LIMIT_DAYS" ]; then
|
|
echo "SKIP chat-history: ${size}B, ${age_days}d old (limits ${SIZE_LIMIT}B / ${AGE_LIMIT_DAYS}d)"
|
|
exit 0
|
|
fi
|
|
|
|
lines="$(wc -l < "$LIVE")"
|
|
base="chat-history-$TS"
|
|
echo "ROTATE chat-history: ${size}B / ${lines} lines (${age_days}d old) -> $ARCHIVE_DIR/$base.jsonl.gz"
|
|
|
|
mv "$LIVE" "$ARCHIVE_DIR/$base.jsonl"
|
|
gzip -9 "$ARCHIVE_DIR/$base.jsonl"
|
|
( cd "$ARCHIVE_DIR" && sha256sum "$base.jsonl.gz" > "$base.jsonl.gz.sha256" )
|
|
touch "$LIVE"
|
|
|
|
echo "OK chat-history: archived $base.jsonl.gz, live file recreated empty"
|