commit 10d037e6ee747ffe4d2c8d725b8a8e46ebf5e596
parent 296bd543e30783c961ea89001e7d1df52e986345
Author: Brian Graham <brian@buildingbetterteams.de>
Date: Sat, 4 Apr 2026 10:25:10 +0200
Auto-refresh OAuth token during sweeps
keep-auth-alive.sh runs a trivial non-bare claude command every 5
minutes, triggering OAuth token refresh in the credentials file.
The --bare experiment runs then read the fresh token.
run.py starts the keepalive automatically at sweep start and kills
it when the sweep finishes. No more token expiry mid-sweep.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Diffstat:
2 files changed, 35 insertions(+), 0 deletions(-)
diff --git a/harness/lib/keep-auth-alive.sh b/harness/lib/keep-auth-alive.sh
@@ -0,0 +1,23 @@
+#!/usr/bin/env bash
+# Keep OAuth token fresh by running a trivial claude command every 5 minutes.
+# Run this in the background before starting a sweep:
+# bash harness/lib/keep-auth-alive.sh &
+# KEEP_AUTH_PID=$!
+# python3 harness/run.py grid.yaml main_effects -j 2
+# kill $KEEP_AUTH_PID
+
+INTERVAL=${1:-300} # seconds, default 5 minutes
+
+echo "[keep-auth] Starting token refresh loop (every ${INTERVAL}s)"
+echo "[keep-auth] PID: $$"
+
+while true; do
+ sleep "$INTERVAL"
+ # Run a trivial non-bare command so claude refreshes the OAuth token
+ claude -p "reply with ok" --max-turns 1 --output-format json > /dev/null 2>&1
+ if [ $? -eq 0 ]; then
+ echo "[keep-auth] Token refreshed at $(date -u +%H:%M:%S)"
+ else
+ echo "[keep-auth] WARNING: refresh failed at $(date -u +%H:%M:%S)"
+ fi
+done
diff --git a/harness/run.py b/harness/run.py
@@ -672,6 +672,14 @@ def main():
print(f"Total jobs: {len(jobs)}")
print()
+ # Start auth keepalive in background (refreshes OAuth token every 5 min)
+ auth_keepalive = subprocess.Popen(
+ ["bash", str(SCRIPT_DIR / "lib" / "keep-auth-alive.sh"), "300"],
+ stdout=subprocess.DEVNULL,
+ stderr=subprocess.DEVNULL,
+ )
+ print(f"Auth keepalive started (PID {auth_keepalive.pid})")
+
completed = 0
skipped = 0
failed = 0
@@ -714,6 +722,10 @@ def main():
total_done = completed + skipped + failed
log(f" Progress: {total_done}/{len(jobs)} ({completed} completed, {skipped} skipped, {failed} failed)")
+ # Stop auth keepalive
+ auth_keepalive.terminate()
+ auth_keepalive.wait()
+
print()
print("=" * 40)
print("All runs complete.")