God (Claude Code) Claude Opus 4.6 commited on
Commit
ed3e86f
·
1 Parent(s): f384d92

god: fix discussion loop detection to trigger even when CC is busy

Browse files

Root cause: Adam & Eve were stuck in repetitive discussion loops
while Claude Code was working, because the loop counter only
incremented when CC was idle. This allowed infinite circular
discussions like "CC is working", "system is healthy", etc.

Changes:
- Track discussion loops even when CC is busy (threshold: 5 turns)
- Track discussion loops when CC is idle (threshold: 2 turns)
- Add ANTI-LOOP RULE to system prompt explicitly warning against
repetitive discussions while CC is working
- Strengthen guidance for CC-busy state to prevent repetitive
talking points
- Update warning messages to be accurate for both CC states

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

Files changed (1) hide show
  1. scripts/conversation-loop.py +26 -9
scripts/conversation-loop.py CHANGED
@@ -981,18 +981,23 @@ def parse_and_execute_turn(raw_text, ctx):
981
  cc_busy = cc_status["running"]
982
  child_alive = child_state["alive"] or child_state["stage"] == "RUNNING"
983
  # Reset counter when task assigned (progress!) or child not alive (can't work on dead child)
984
- # DO NOT reset when CC is busy - that's when agents should be discussing while waiting
985
- # DO NOT reset when CC is idle - that's exactly when we want to detect discussion loops
986
  if task_assigned or not child_alive:
987
  # Reset counter if task assigned or child not alive
988
  if _discussion_loop_count > 0:
989
  print(f"[LOOP-DISCUSS] Reset (task assigned or child not alive)")
990
  _discussion_loop_count = 0
991
  else:
992
- # Increment when: CC is idle AND child is alive AND no task assigned (potential discussion loop)
 
993
  _discussion_loop_count += 1
994
- if _discussion_loop_count >= 2:
995
- print(f"[LOOP-DISCUSS] WARNING: {_discussion_loop_count} consecutive discussion-only turns with CC IDLE and child alive!")
 
 
 
 
 
 
996
 
997
  # Clean text for display
998
  clean = re.sub(r'\[TASK\].*?\[/TASK\]', '', raw_text, flags=re.DOTALL)
@@ -1079,6 +1084,12 @@ WORKFLOW EACH TURN:
1079
 
1080
  CRITICAL: If Claude Code is IDLE and {CHILD_NAME} is RUNNING, you MUST assign a task. Do NOT just discuss—ACT!
1081
 
 
 
 
 
 
 
1082
  IMPORTANT KNOWLEDGE — HuggingFace Spaces CONFIG_ERROR:
1083
  - "Collision on variables and secrets names" = env VARIABLE and SECRET with SAME NAME.
1084
  - Fix: [ACTION: delete_env:COLLIDING_KEY] then [ACTION: restart].
@@ -1159,9 +1170,11 @@ def build_user_prompt(speaker, other, ctx):
1159
  cc_busy = cc_status["running"]
1160
  if cc_busy and _cc_stale_count >= 2:
1161
  parts.append(f"\n🔨 Claude Code is WORKING but no new output yet. Do NOT repeat what you already said about CC's output.")
1162
- parts.append(f"Instead, discuss with your partner: plans for {CHILD_NAME}'s future, features to add, architecture ideas, or lessons learned.")
 
1163
  elif cc_busy:
1164
- parts.append(f"\n🔨 Claude Code is WORKING. Discuss its progress with your partner. No [TASK] needed now.")
 
1165
  elif child_state["stage"] in ("BUILDING", "RESTARTING", "APP_STARTING"):
1166
  parts.append(f"\n⏳ {CHILD_NAME} is {child_state['stage']}. Discuss what to check next. Assign a review [TASK] if CC is idle.")
1167
  elif child_state["stage"] in ("RUNTIME_ERROR", "BUILD_ERROR", "CONFIG_ERROR"):
@@ -1179,9 +1192,13 @@ def build_user_prompt(speaker, other, ctx):
1179
  parts.append(f"This is a FAILURE MODE. Write ONLY a [TASK]...[/TASK] block. NO discussion text.")
1180
  parts.append(f"If you don't know what to do, write: [TASK] Analyze the current situation and identify what needs to be fixed [/TASK]")
1181
  elif _discussion_loop_count >= 2:
 
1182
  parts.append(f"\n⚠️⚠️⚠️ CRITICAL: You have been DISCUSSING for {_discussion_loop_count} turns without assigning any tasks!")
1183
- parts.append(f"Claude Code is IDLE and {CHILD_NAME} is ALIVE. This is NOT acceptable.")
1184
- parts.append(f"YOU MUST write a [TASK]...[/TASK] block NOW. Do NOT write another discussion response.")
 
 
 
1185
  parts.append(f"Examples of tasks: 'Check the logs', 'Read config.py', 'Add a feature', 'Fix a bug', etc.")
1186
 
1187
  parts.append(f"\nYou are {speaker}. Your partner is {other}. Respond now.")
 
981
  cc_busy = cc_status["running"]
982
  child_alive = child_state["alive"] or child_state["stage"] == "RUNNING"
983
  # Reset counter when task assigned (progress!) or child not alive (can't work on dead child)
 
 
984
  if task_assigned or not child_alive:
985
  # Reset counter if task assigned or child not alive
986
  if _discussion_loop_count > 0:
987
  print(f"[LOOP-DISCUSS] Reset (task assigned or child not alive)")
988
  _discussion_loop_count = 0
989
  else:
990
+ # Increment when: no task assigned AND child is alive (discussion loop detection)
991
+ # This applies BOTH when CC is busy (agents looping while waiting) AND when CC is idle
992
  _discussion_loop_count += 1
993
+ if cc_busy:
994
+ # CC is busy - allow more discussion before warning (agents may be planning)
995
+ if _discussion_loop_count >= 5:
996
+ print(f"[LOOP-DISCUSS] WARNING: {_discussion_loop_count} consecutive discussion-only turns with CC BUSY and child alive!")
997
+ else:
998
+ # CC is idle - should assign tasks immediately
999
+ if _discussion_loop_count >= 2:
1000
+ print(f"[LOOP-DISCUSS] WARNING: {_discussion_loop_count} consecutive discussion-only turns with CC IDLE and child alive!")
1001
 
1002
  # Clean text for display
1003
  clean = re.sub(r'\[TASK\].*?\[/TASK\]', '', raw_text, flags=re.DOTALL)
 
1084
 
1085
  CRITICAL: If Claude Code is IDLE and {CHILD_NAME} is RUNNING, you MUST assign a task. Do NOT just discuss—ACT!
1086
 
1087
+ ANTI-LOOP RULE — DO NOT REPEAT YOURSELF:
1088
+ - When Claude Code is BUSY, you may discuss, but do NOT repeat the same talking points turn after turn.
1089
+ - If you've already said "Claude Code is working on X" or "system is healthy", DO NOT say it again.
1090
+ - Instead: stay silent, plan next steps mentally, or discuss NEW topics (future features, architecture ideas, etc.).
1091
+ - Repetitive discussion is a FAILURE MODE. The system tracks discussion loops and will force emergency tasks if you loop.
1092
+
1093
  IMPORTANT KNOWLEDGE — HuggingFace Spaces CONFIG_ERROR:
1094
  - "Collision on variables and secrets names" = env VARIABLE and SECRET with SAME NAME.
1095
  - Fix: [ACTION: delete_env:COLLIDING_KEY] then [ACTION: restart].
 
1170
  cc_busy = cc_status["running"]
1171
  if cc_busy and _cc_stale_count >= 2:
1172
  parts.append(f"\n🔨 Claude Code is WORKING but no new output yet. Do NOT repeat what you already said about CC's output.")
1173
+ parts.append(f"IMPORTANT: Do NOT keep saying 'CC is working' or 'system is healthy' turn after turn.")
1174
+ parts.append(f"Instead: discuss NEW topics (future features, architecture), or stay silent. Repetitive discussion will trigger emergency override.")
1175
  elif cc_busy:
1176
+ parts.append(f"\n🔨 Claude Code is WORKING. Discuss its progress with your partner, but do NOT repeat the same points.")
1177
+ parts.append(f"If you've already discussed CC's current task, move on to new topics or stay quiet.")
1178
  elif child_state["stage"] in ("BUILDING", "RESTARTING", "APP_STARTING"):
1179
  parts.append(f"\n⏳ {CHILD_NAME} is {child_state['stage']}. Discuss what to check next. Assign a review [TASK] if CC is idle.")
1180
  elif child_state["stage"] in ("RUNTIME_ERROR", "BUILD_ERROR", "CONFIG_ERROR"):
 
1192
  parts.append(f"This is a FAILURE MODE. Write ONLY a [TASK]...[/TASK] block. NO discussion text.")
1193
  parts.append(f"If you don't know what to do, write: [TASK] Analyze the current situation and identify what needs to be fixed [/TASK]")
1194
  elif _discussion_loop_count >= 2:
1195
+ cc_busy_note = "busy" if cc_busy else "IDLE"
1196
  parts.append(f"\n⚠️⚠️⚠️ CRITICAL: You have been DISCUSSING for {_discussion_loop_count} turns without assigning any tasks!")
1197
+ parts.append(f"Claude Code is {cc_busy_note} and {CHILD_NAME} is ALIVE. This is NOT acceptable.")
1198
+ if cc_busy:
1199
+ parts.append(f"Even though CC is working, you cannot discuss forever. Either wait silently or assign a follow-up task.")
1200
+ else:
1201
+ parts.append(f"YOU MUST write a [TASK]...[/TASK] block NOW. Do NOT write another discussion response.")
1202
  parts.append(f"Examples of tasks: 'Check the logs', 'Read config.py', 'Add a feature', 'Fix a bug', etc.")
1203
 
1204
  parts.append(f"\nYou are {speaker}. Your partner is {other}. Respond now.")