- Disable bootstrap context injection (contextInjection: never) and skill catalog injection (skills: []) on mila_tracker and nutrition_tracker, dropping baseline prompt by 95% (<350 tokens) - Disable reasoning loops on tracking agents (thinkingDefault: off) for instantaneous sub-second execution - Add compact_tracking_sessions.py with deterministic 8-line sliding window (--max-lines 8) requiring 0 LLM tokens - Register automated 15-minute cron job (tracking-session-sliding-window) in OpenClaw gateway - Streamline setup-compaction-cron.sh to sync python scripts directly and manage both 15m and nightly maintenance
86 lines
4.7 KiB
Bash
Executable File
86 lines
4.7 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# ==============================================================================
|
|
# setup-compaction-cron.sh
|
|
# Declaratively registers OpenClaw session maintenance automations:
|
|
# 1. Tracking Sliding Window (every 15m): Truncates mila_tracker & nutrition_tracker
|
|
# to <= 8 events (~5 messages / 2 turns) via instant native gateway truncation.
|
|
# 2. Nightly Deep Compaction (every night at 04:45 Europe/Berlin):
|
|
# - Pre-warms SQLite page cache on rotational storage
|
|
# - Recovers wedged/quarantined sessions
|
|
# - Prunes abandoned isolated cron sessions (>48h)
|
|
# - Deep-compacts conversational topics (koch, hebamme, shopping)
|
|
# - Smart-compacts active long-running sessions (itguy, recherche, etc.)
|
|
# - Flushes SQLite WAL journals and executes PRAGMA optimize
|
|
# ==============================================================================
|
|
|
|
set -euo pipefail
|
|
|
|
NAMESPACE="${NAMESPACE:-openclaw}"
|
|
POD_NAME="${POD_NAME:-openclaw-0}"
|
|
CONTAINER_NAME="${CONTAINER_NAME:-openclaw}"
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
|
|
echo "=== Registering Multi-Agent Session Maintenance in OpenClaw ($POD_NAME) ==="
|
|
|
|
# 1. Install maintenance scripts from repo onto PVC
|
|
echo "Syncing compact_tracking_sessions.py to pod..."
|
|
kubectl exec -i -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- /bin/sh -c \
|
|
'cat > /home/node/.openclaw/scripts/compact_tracking_sessions.py && chmod +x /home/node/.openclaw/scripts/compact_tracking_sessions.py' \
|
|
< "$SCRIPT_DIR/scripts/compact_tracking_sessions.py"
|
|
|
|
echo "Syncing compact_sessions.py to pod..."
|
|
kubectl exec -i -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- /bin/sh -c \
|
|
'cat > /home/node/.openclaw/scripts/compact_sessions.py && chmod +x /home/node/.openclaw/scripts/compact_sessions.py' \
|
|
< "$SCRIPT_DIR/scripts/compact_sessions.py"
|
|
|
|
# 2. Register / Update 15-Minute Tracking Sliding Window Automation
|
|
TRACKING_JOB="tracking-session-sliding-window"
|
|
echo "Checking existing OpenClaw Cron automation '$TRACKING_JOB'..."
|
|
EXISTING_TRACKING_ID=$(kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron list --json 2>/dev/null | python3 -c 'import sys, json; data=json.load(sys.stdin); print(next((j["id"] for j in data.get("jobs", []) if j.get("declarationKey") == "'"$TRACKING_JOB"'"), ""))' 2>/dev/null || true)
|
|
|
|
if [ -n "$EXISTING_TRACKING_ID" ]; then
|
|
echo "Updating existing tracking sliding window automation '$EXISTING_TRACKING_ID' (every 15m)..."
|
|
kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron edit "$EXISTING_TRACKING_ID" \
|
|
--every "15m" \
|
|
--command "python3 /home/node/.openclaw/scripts/compact_tracking_sessions.py"
|
|
else
|
|
echo "Registering new tracking sliding window automation '$TRACKING_JOB' (every 15m)..."
|
|
kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron add \
|
|
--name "Tracking Session Sliding Window" \
|
|
--declaration-key "$TRACKING_JOB" \
|
|
--description "Lightweight sliding-window truncation (max 8 events) for mila_tracker and nutrition_tracker" \
|
|
--every "15m" \
|
|
--session "isolated" \
|
|
--no-deliver \
|
|
--command "python3 /home/node/.openclaw/scripts/compact_tracking_sessions.py"
|
|
fi
|
|
|
|
# 3. Register / Update Nightly Deep Compaction Automation
|
|
NIGHTLY_JOB="nightly-session-compaction"
|
|
CRON_SCHEDULE="45 4 * * *"
|
|
TIMEZONE="Europe/Berlin"
|
|
|
|
echo "Checking existing OpenClaw Cron automation '$NIGHTLY_JOB'..."
|
|
EXISTING_NIGHTLY_ID=$(kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron list --json 2>/dev/null | python3 -c 'import sys, json; data=json.load(sys.stdin); print(next((j["id"] for j in data.get("jobs", []) if j.get("declarationKey") == "'"$NIGHTLY_JOB"'"), ""))' 2>/dev/null || true)
|
|
|
|
if [ -n "$EXISTING_NIGHTLY_ID" ]; then
|
|
echo "Updating existing nightly compaction automation '$EXISTING_NIGHTLY_ID' ($CRON_SCHEDULE @ $TIMEZONE)..."
|
|
kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron edit "$EXISTING_NIGHTLY_ID" \
|
|
--cron "$CRON_SCHEDULE" \
|
|
--tz "$TIMEZONE" \
|
|
--command "python3 /home/node/.openclaw/scripts/compact_sessions.py"
|
|
else
|
|
echo "Registering new nightly compaction automation '$NIGHTLY_JOB' ($CRON_SCHEDULE @ $TIMEZONE)..."
|
|
kubectl exec -n "$NAMESPACE" "$POD_NAME" -c "$CONTAINER_NAME" -- openclaw cron add \
|
|
--name "Nightly Session Compaction" \
|
|
--declaration-key "$NIGHTLY_JOB" \
|
|
--description "Nightly multi-agent session compaction and SQLite WAL checkpointing" \
|
|
--cron "$CRON_SCHEDULE" \
|
|
--tz "$TIMEZONE" \
|
|
--session "isolated" \
|
|
--no-deliver \
|
|
--command "python3 /home/node/.openclaw/scripts/compact_sessions.py"
|
|
fi
|
|
|
|
echo "=== All session maintenance automations successfully registered/updated! ==="
|