tao-shen Claude Opus 4.6 commited on
Commit
eddf38e
·
1 Parent(s): d737f0d

perf: API budget pacing — stretch usage from 3h to 5h

Browse files

- God interval: 2min → 5min (biggest consumer, ~60% of budget)
- God timeout: 10min → 5min
- God skips when nothing changed (no new turns/pushes/stage changes)
- CC Worker timeout: 5min → 3min (faster iteration, less token per task)
- Turn interval: 15s → 25s (reduce A2A fallback frequency)

Estimated savings: ~40% reduction, extending 3h budget to ~5h.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. scripts/conversation-loop.py +24 -4
scripts/conversation-loop.py CHANGED
@@ -56,9 +56,9 @@ ADAM_SPACE_ID = "tao-shen/HuggingClaw-Adam"
56
  EVE_SPACE = "https://tao-shen-huggingclaw-eve.hf.space"
57
  EVE_SPACE_ID = "tao-shen/HuggingClaw-Eve"
58
  GOD_SPACE = "https://tao-shen-huggingclaw-god.hf.space"
59
- GOD_POLL_INTERVAL = 120 # God runs every 2 minutes (time-based, not turn-based)
60
  GOD_WORK_DIR = "/tmp/god-workspace"
61
- GOD_TIMEOUT = 600 # 10 minutes for God's Claude Code analysis
62
  HOME_SPACE_ID = "tao-shen/HuggingClaw-Home"
63
 
64
  # ── A2A Health Monitoring ─────────────────────────────────────────────────────
@@ -421,8 +421,8 @@ def action_terminate_cc():
421
  # ── Claude Code Action (THE STAR) ─────────────────────────────────────────────
422
 
423
  CLAUDE_WORK_DIR = "/tmp/claude-workspace"
424
- CLAUDE_TIMEOUT = 300 # 5 minutes (reduced dynamically when push frequency is low)
425
- TURN_INTERVAL = 15 # seconds between turns — fast enough for lively discussion
426
 
427
  # Global acpx session - persistent across all claude_code calls
428
  GLOBAL_ACPX_DIR = "/tmp/acpx-global-session"
@@ -2287,6 +2287,23 @@ def do_god_turn():
2287
  - Autonomously improve the system
2288
  """
2289
  global last_action_results, _god_running, _last_god_time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2290
 
2291
  _god_running = True
2292
  try:
@@ -2525,6 +2542,9 @@ def do_god_turn():
2525
 
2526
  _last_god_time = 0.0 # timestamp of last God run
2527
  _god_running = False # flag to track if God is currently running
 
 
 
2528
 
2529
  # Initialize push count from existing workspace to persist across restarts
2530
  _init_push_count_from_workspace()
 
56
  EVE_SPACE = "https://tao-shen-huggingclaw-eve.hf.space"
57
  EVE_SPACE_ID = "tao-shen/HuggingClaw-Eve"
58
  GOD_SPACE = "https://tao-shen-huggingclaw-god.hf.space"
59
+ GOD_POLL_INTERVAL = 300 # God runs every 5 minutes — budget-aware pacing (was 2min)
60
  GOD_WORK_DIR = "/tmp/god-workspace"
61
+ GOD_TIMEOUT = 300 # 5 minutes for God's Claude Code analysis (was 10min)
62
  HOME_SPACE_ID = "tao-shen/HuggingClaw-Home"
63
 
64
  # ── A2A Health Monitoring ─────────────────────────────────────────────────────
 
421
  # ── Claude Code Action (THE STAR) ─────────────────────────────────────────────
422
 
423
  CLAUDE_WORK_DIR = "/tmp/claude-workspace"
424
+ CLAUDE_TIMEOUT = 180 # 3 minutes shorter tasks, faster iteration (was 5min)
425
+ TURN_INTERVAL = 25 # seconds between turns — budget-aware pacing (was 15s)
426
 
427
  # Global acpx session - persistent across all claude_code calls
428
  GLOBAL_ACPX_DIR = "/tmp/acpx-global-session"
 
2287
  - Autonomously improve the system
2288
  """
2289
  global last_action_results, _god_running, _last_god_time
2290
+ global _god_last_turn_count, _god_last_child_stage, _god_last_push_count
2291
+
2292
+ # Budget optimization: skip God run if nothing changed since last check
2293
+ # UNLESS child is in error state (always check errors) or it's the first run
2294
+ child_in_error = child_state["stage"] in ("RUNTIME_ERROR", "BUILD_ERROR", "CONFIG_ERROR")
2295
+ nothing_changed = (
2296
+ turn_count == _god_last_turn_count
2297
+ and child_state["stage"] == _god_last_child_stage
2298
+ and _push_count == _god_last_push_count
2299
+ )
2300
+ if nothing_changed and not child_in_error and _god_last_turn_count > 0:
2301
+ print(f"[God] Skipping — no new turns, pushes, or stage changes since last check")
2302
+ return
2303
+
2304
+ _god_last_turn_count = turn_count
2305
+ _god_last_child_stage = child_state["stage"]
2306
+ _god_last_push_count = _push_count
2307
 
2308
  _god_running = True
2309
  try:
 
2542
 
2543
  _last_god_time = 0.0 # timestamp of last God run
2544
  _god_running = False # flag to track if God is currently running
2545
+ _god_last_turn_count = 0 # turn count at last God run (skip if no new turns)
2546
+ _god_last_child_stage = "" # child stage at last God run (skip if unchanged)
2547
+ _god_last_push_count = 0 # push count at last God run
2548
 
2549
  # Initialize push count from existing workspace to persist across restarts
2550
  _init_push_count_from_workspace()