tenseleyflow/loader / a953bb4

Browse files

fix(critical): chatbot detection was checking filtered content

**The Bug:**
Chatbot detection was running AFTER safeguards filtered code blocks from content.
By the time _contains_unexecuted_code() ran, the code blocks were already gone,
so detection always failed!

**The Fix:**
Check response_content (original) instead of content (filtered).
Now detects numbered steps, code blocks, and tutorial patterns correctly.

**Why This Matters:**
Without this fix, even large models like Mixtral would slip into chatbot mode
and never get corrected because the detection was blind.

**Added:**
- Debug logging to trace detection decisions
- Check original content before filtering
- Visibility into what content is being evaluated
Authored by espadonne
SHA
a953bb4ab3b8d865dcf1df1376f1c8a986e92c1e
Parents
a97c3af
Tree
a22af7c

1 changed file

StatusFile+-
M src/loader/agent/loop.py 17 1
src/loader/agent/loop.pymodified
@@ -1286,8 +1286,24 @@ class Agent:
12861286
                 continue
12871287
 
12881288
             # No tool calls - check if model is describing instead of acting
1289
-            if self._contains_unexecuted_code(content) and iterations < self.config.max_iterations - 1:
1289
+            # IMPORTANT: Check ORIGINAL content before safeguards filtered it!
1290
+            # Debug log
1291
+            try:
1292
+                has_unexecuted = self._contains_unexecuted_code(response_content)
1293
+                with open("/tmp/loader_debug.log", "a") as f:
1294
+                    f.write(f"[chatbot-check] iterations={iterations}, has_unexecuted={has_unexecuted}\n")
1295
+                    f.write(f"[chatbot-check] response_content (first 200): {response_content[:200]}\n")
1296
+                    f.write(f"[chatbot-check] filtered content (first 200): {content[:200]}\n")
1297
+            except Exception:
1298
+                pass
1299
+
1300
+            if self._contains_unexecuted_code(response_content) and iterations < self.config.max_iterations - 1:
12901301
                 # Model outputted code blocks without using tools - nudge it
1302
+                try:
1303
+                    with open("/tmp/loader_debug.log", "a") as f:
1304
+                        f.write(f"[chatbot-check] TRIGGERING chatbot recovery\n")
1305
+                except Exception:
1306
+                    pass
12911307
                 await emit(AgentEvent(
12921308
                     type="error",
12931309
                     content="⚠ Chatbot mode detected - steering agent to use tools instead of giving instructions",