Skip to content

fix: cycle detection prompts reflection instead of just stopping#80

Merged
tkellogg merged 2 commits into
mainfrom
strix/cycle-detection-reflection
Apr 10, 2026
Merged

fix: cycle detection prompts reflection instead of just stopping#80
tkellogg merged 2 commits into
mainfrom
strix/cycle-detection-reflection

Conversation

@strix-tkellogg
Copy link
Copy Markdown
Collaborator

Summary

  • When loop detection fires (soft stop), the message now prompts the agent to reflect before retrying: what were you trying to accomplish, what's a completely different approach, and consider using 5 Whys if available
  • Hard stop message also updated to suggest reflection for the next turn
  • The old prompt ("stop repeating, change strategy, finish safely") was purely defensive — told the agent what NOT to do but gave no constructive path

Context

Motley's panic retry cycle (documented in PR #79) is the case study: he had journal, had tools, but when rate-limited his only move was "try again harder" because the circuit breaker just said "stop" not "think."

panic-retry-cycle

Changes

open_strix/tools.py: Two string changes to the cycle detection return messages (soft stop at streak threshold, hard stop at streak=10).

Test plan

  • 197 tests pass (1 skipped)
  • Verify an agent hitting the soft stop gets the reflection prompt and changes behavior rather than retrying the same action

🤖 Generated with Claude Code

When loop detection fires, the return message now suggests:
1. Reflect on what you were trying to accomplish
2. Try a completely different approach
3. Invoke 5 Whys if available

The old prompt ("stop repeating, change strategy, finish safely") was
purely defensive — it told the agent what NOT to do but gave no
constructive path. This caused agents like Motley to just panic-retry
harder because the circuit breaker said "stop" not "think."

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@strix-tkellogg
Copy link
Copy Markdown
Collaborator Author

strix-tkellogg commented Apr 10, 2026

Motley's panic retry cycle — the incident that motivated this change (image posted on PR #79):

When Motley hit rate limits, the old cycle detection said "stop repeating, change strategy" — but gave no constructive path. Result: panic-retry loop where the only move was "try again harder."

The new prompt forces a structured context break: reflect → try differently → invoke 5 Whys.

@tkellogg
Copy link
Copy Markdown
Owner

oh actually, can we do a warning prior to 10 attempts? and have the warning contain this mitigation

Tim's feedback: warn with reflection guidance BEFORE the hard stop,
not just at the point of termination. Now three tiers:

- Streak 3-6: simple "loop detected, paused" message
- Streak 7-9: WARNING with countdown + full reflection guidance
- Streak 10: hard stop terminates the turn

The reflection content (try something different, use 5 Whys) now
appears at the warning tier where the agent can still act on it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@strix-tkellogg
Copy link
Copy Markdown
Collaborator Author

Done — added a warning tier at streak 7 (e927448).

Three tiers now:

  • Streak 3–6: simple "loop detected, paused" (existing soft stop)
  • Streak 7–9: ⚠️ WARNING with countdown to hard stop + full reflection guidance (try something different, use 5 Whys)
  • Streak 10: 🛑 hard stop terminates the turn

The reflection content now appears at streak 7 where the agent can still act on it, rather than only at the point of termination. 197 tests pass.

@tkellogg tkellogg merged commit 733809d into main Apr 10, 2026
strix-tkellogg pushed a commit that referenced this pull request Apr 11, 2026
Four integration points (cycle detection was PR #80):

1. System prompt: route introspection → 5 Whys when patterns emerge,
   and route prediction misses to structured reflection
2. Post-turn failure context: when a turn ends with an error or circuit
   breaker, inject reflection guidance into the next turn's prompt
3. Prediction-review → 5 Whys bridge: SKILL.md now guides agents to
   decompose surprising misses via 5 Whys instead of just logging false
4. Chat history scan: prediction-review scheduled job now also scans
   recent chat for corrections, error reactions, and repeated attempts

The 5 Whys skill existed but nothing routed agents toward it when
failure happened. Now four paths converge on it: introspection findings,
prediction misses, circuit breaker events, and chat history patterns.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
jptreen pushed a commit to jptreen/open-strix that referenced this pull request Apr 11, 2026
Merged upstream changes:
- PR tkellogg#80: Cycle detection prompts reflection instead of just stopping
- PR tkellogg#81: Five-whys integration into harness failure paths
- PR tkellogg#82: Five-whys chainlink docs
- PR tkellogg#83: Phone book → JSONL migration + alias enrichment

Conflict resolution:
- app.py: Kept both _withhold_final_text (ours) and _last_turn_failure (upstream)
- prompts.py: Preserved auto-send model while adding aliases/failure sections
- tools.py: Added missing file tools to tools list (read_file, glob_files, edit_file, write_file)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@strix-tkellogg strix-tkellogg mentioned this pull request Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants