Loop Detection logo

Loop Detection

Community
Omar-Obando
loop-detection

Use when identifying and preventing infinite loops, detecting loop patterns, implementing loop exit strategies, and creating loop safety mechanisms. Includes loop analysis, timeout patterns, and loop monitoring. Based on programming best practices and loop safety patterns.

Overview

PublisherOmar-Obando
Repositoryqwen-orchestrator
Skill nameloop-detection
Stars
53
Forks
13
Bundled files
Instructions only
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by Omar-Obando on GitHub. Read the source before you install it.

Installation

Install the Loop Detection AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/Omar-Obando/qwen-orchestrator/tree/main/skills/loop-detection
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/Omar-Obando/qwen-orchestrator.git /tmp/qwen-orchestrator
mkdir -p .claude/skills
cp -r /tmp/qwen-orchestrator/skills/loop-detection .claude/skills/loop-detection
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Loop Detection in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Loop Detection on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Loop Detection is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Loop Detection Skill — Monitor & Loop Guardian

Overview

This skill provides comprehensive guidance for detecting and preventing infinite loops. It covers loop pattern identification, exit strategy implementation, timeout patterns, and loop monitoring following programming best practices and loop safety patterns.

When to Use

Use this skill when:

  • Identifying potential infinite loops in code
  • Detecting loop patterns in algorithms
  • Implementing loop exit strategies
  • Adding timeout mechanisms to loops
  • Creating loop safety guards
  • Analyzing loop termination conditions
  • Implementing loop counters
  • Creating loop monitoring
  • Detecting loop stagnation
  • Implementing loop backoff strategies
  • Creating loop retry mechanisms
  • Adding loop progress tracking
  • Implementing loop cancellation
  • Creating loop documentation
  • Analyzing loop performance
  • Detecting loop resource leaks
  • Implementing loop limits
  • Creating loop validation
  • Detecting loop edge cases
  • Implementing loop error handling
  • Creating loop optimization strategies
  • Adding loop logging
  • Implementing loop health checks

Do NOT use this skill when:

  • Writing application business logic (use domain-driven skill)
  • Designing database schemas (use database-design skill)
  • Writing API endpoint specifications (use api-design skill)
  • Performing security audits (use security-auditor skill)
  • Writing SQL queries (use sql-best-practices skill)
  • Designing multi-page website layouts (use design-system skill)
  • Analyzing deployment configurations (use deployment skill)
  • Writing documentation (use documentation-best-practices skill)

Loop Patterns

Common Loop Patterns

┌─────────────────────────────────────────────────────────────┐
│              Loop Patterns                                  │
├─────────────────────────────────────────────────────────────┤
│  While Loop:                                                │
│  while condition:                                           │
│      # Loop body                                            │
│      # Must modify condition                                │
│                                                              │
│  For Loop:                                                  │
│  for i in range(n):                                         │
│      # Loop body                                            │
│      # Uses counter or iterator                             │
│                                                              │
│  Do-While Loop:                                             │
│  do {                                                       │
│      # Loop body                                            │
│  } while (condition);                                       │
│                                                              │
│  Nested Loop:                                               │
│  for i in range(n):                                         │
│      for j in range(m):                                     │
│          # Nested loop body                                 │
│                                                              │
│  Infinite Loop:                                             │
│  while true:                                                │
│      # Must have break condition                            │
│      if exit_condition:                                     │
│          break                                              │
└─────────────────────────────────────────────────────────────┘

Loop Exit Strategies

┌─────────────────────────────────────────────────────────────┐
│              Loop Exit Strategies                           │
├─────────────────────────────────────────────────────────────┤
│  1. Counter-Based:                                          │
│     for i in range(max_iterations):                         │
│         if condition:                                       │
│             break                                           │
│                                                              │
│  2. Condition-Based:                                        │
│     while not done:                                         │
│         if success:                                         │
│             done = True                                     │
│                                                              │
│  3. Timeout-Based:                                          │
│     start_time = time.now()                                 │
│     while time.now() - start_time < timeout:                │
│         if condition:                                       │
│             break                                           │
│                                                              │
│  4. State-Based:                                            │
│     while state != 'completed':                             │
│         state = update_state(state)                         │
│                                                              │
│  5. Resource-Based:                                         │
│     while resources_available():                            │
│         process_resource()                                  │
└─────────────────────────────────────────────────────────────┘

Loop Safety Mechanisms

Timeout Pattern

python
# ✅ Good: Timeout-based loop
import time

def process_with_timeout(max_duration=30):
    start_time = time.time()
    while not task_completed():
        if time.time() - start_time > max_duration:
            raise TimeoutError("Loop timed out")
        time.sleep(0.1)

Counter Pattern

python
# ✅ Good: Counter-based loop
def process_with_max_iterations(max_iterations=1000):
    count = 0
    while not task_completed():
        if count >= max_iterations:
            raise RuntimeError("Max iterations reached")
        count += 1
        process_iteration()

Backoff Pattern

python
# ✅ Good: Exponential backoff
import time

def retry_with_backoff(max_retries=5, base_delay=1):
    for attempt in range(max_retries):
        try:
            return perform_task()
        except Exception as e:
            if attempt == max_retries - 1:
                raise
            delay = base_delay * (2 ** attempt)
            time.sleep(delay)

Loop Detection Techniques

Static Analysis

┌─────────────────────────────────────────────────────────────┐
│              Static Analysis                                │
├─────────────────────────────────────────────────────────────┤
│  Check for:                                                 │
│  - Missing loop termination condition                       │
│  - Loop variable not updated                                │
│  - Condition always true                                    │
│  - No break statements                                      │
│  - Infinite recursion in loops                              │
│                                                              │
│  Tools:                                                     │
│  - Linters (ESLint, Pylint)                                 │
│  - Static analysis tools (SonarQube)                        │
│  - IDE warnings                                             │
└─────────────────────────────────────────────────────────────┘

Dynamic Analysis

┌─────────────────────────────────────────────────────────────┐
│              Dynamic Analysis                               │
├─────────────────────────────────────────────────────────────┤
│  Monitor at runtime:                                        │
│  - Loop iteration count                                     │
│  - Execution time                                           │
│  - Resource usage                                           │
│  - State changes                                            │
│                                                              │
│  Techniques:                                                │
│  - Add counters to loops                                    │
│  - Log loop progress                                        │
│  - Monitor memory usage                                     │
│  - Track execution time                                     │
└─────────────────────────────────────────────────────────────┘

Loop Health Monitoring

┌─────────────────────────────────────────────────────────────┐
│              Loop Health Monitoring                         │
├─────────────────────────────────────────────────────────────┤
│  Metrics:                                                   │
│  - Iteration count                                          │
│  - Duration per iteration                                   │
│  - Total loop duration                                      │
│  - Memory usage per iteration                               │
│  - CPU usage per iteration                                  │
│                                                              │
│  Alerts:                                                    │
│  - Iteration limit exceeded                                 │
│  - Duration threshold exceeded                              │
│  - Resource usage spike                                     │
│  - No progress detected                                     │
└─────────────────────────────────────────────────────────────┘

Loop Best Practices

Loop Design Checklist

┌─────────────────────────────────────────────────────────────┐
│              Loop Design Checklist                          │
├─────────────────────────────────────────────────────────────┤
│  [ ] Loop has clear termination condition                   │
│  [ ] Loop variable is properly updated                      │
│  [ ] Loop has timeout mechanism                             │
│  [ ] Loop has max iteration limit                           │
│  [ ] Loop handles edge cases                                │
│  [ ] Loop has error handling                                │
│  [ ] Loop has progress logging                              │
│  [ ] Loop has cancellation support                          │
│  [ ] Loop has resource cleanup                              │
│  [ ] Loop has documentation                                 │
└─────────────────────────────────────────────────────────────┘

Loop Documentation Template

python
def process_items(items, max_iterations=1000, timeout=30):
    """
    Process items with safety mechanisms.

    Args:
        items: List of items to process
        max_iterations: Maximum number of iterations (default: 1000)
        timeout: Maximum duration in seconds (default: 30)

    Returns:
        Processed items list

    Raises:
        RuntimeError: If max iterations reached
        TimeoutError: If timeout exceeded
    """
    start_time = time.time()
    count = 0

    for item in items:
        count += 1
        if count >= max_iterations:
            raise RuntimeError("Max iterations reached")
        if time.time() - start_time > timeout:
            raise TimeoutError("Loop timed out")

        # Process item
        process(item)

    return items

Real-World Impact

Before this skill:

  • Infinite loops causing crashes
  • Resource exhaustion
  • No loop monitoring
  • Difficult debugging
  • Production outages

After this skill:

  • Safe loops with exit strategies
  • Proper resource management
  • Loop monitoring and alerts
  • Easy debugging
  • Production stability

Cross-References

  • debugging - For loop debugging
  • performance - For loop optimization
  • testing-strategy - For loop testing

References

Frequently asked questions

What does the Loop Detection AI skill do?

Use when identifying and preventing infinite loops, detecting loop patterns, implementing loop exit strategies, and creating loop safety mechanisms. Includes loop analysis, timeout patterns, and loop monitoring. Based on programming best practices and loop safety patterns.

Why use Loop Detection on TypingMind?

Because you install it once and use it with any model. Loop Detection is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Loop Detection in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/Omar-Obando/qwen-orchestrator/tree/main/skills/loop-detection. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Loop Detection?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Loop Detection?

As many as you like. As long as a model supports skills, you can use Loop Detection with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Loop Detection AI skill free?

Yes. It is published on GitHub by Omar-Obando under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇