Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Getting Started with AI for VLSI Engineers5
  • Just Enough AI: Models and Context15
  • Prompting13
  • Trust and Verification14
  • Using AI for Engineering Work17
  • Engineering Walkthroughs7
  • Practical Foundations for AI Workflows4
  • Engineering Data5
  • Retrieval-Augmented Generation6
  • Agents and Tool Use18
    • What an Agent Is
    • Tool Use and Structured Output
    • Planning, Memory and Stopping
      • Task Decomposition and Success Criteria
      • Memory Outside the Model and Summaries
      • Step and Cost Budgets
      • Loop Detection and Stopping
    • Multi-Agent Patterns and When Not to Use Agents
  • Agent Design8
  • MCP and Skills6
  • Multi-Agent Design6
  • Practical Capstone6
  • Tokens, Cost and Latency12
  • Agentic Workflows for Chip Teams18
  • Interview and Judgment10
  • AI Skills: Full Course Index
  • Working with AI Glossary
  • Working with AI Cheatsheet
Loading lesson

‹Planning, Memory and Stopping
  1. Topics
  2. AI Skills for VLSI Engineers
  3. Agents and Tool Use
  4. Planning, Memory and Stopping
  5. Loop Detection and Stopping

Tools, Workflows and Agents · Beginner to Intermediate

Loop Detection and Stopping

Detect repeats and stalls, then stop with a reason and a summary.

On this page

    How loops show up

    A loop repeats actions without new information. Common shapes are one action three times in a row and a two-action cycle such as ABAB.

    Logs are data for the detector, including file contents and tool output. Prompt injection through files and logs is handled by treating observations as data, never as new instructions.

    Pattern

    Schematic action tail

    Meaning

    Triple repeat

    test, test, test

    The same action stalls twice in a row.

    Two-action cycle

    read, edit, read, edit

    Two steps alternate with no new result.

    Progress

    read, edit, test, read, edit

    No triple or cycle in the tail; the run continues.

    A loop detector

    The program below scans synthetic action names with two rules. Triple repeat and an ABAB cycle each need two equality comparisons per scan.

    example.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    import sys
    
    def is_stalled(actions):
        n = len(actions)
        if n >= 3 and actions[n - 1] == actions[n - 2] and actions[n - 2] == actions[n - 3]:
            return True
        if n >= 4 and actions[n - 1] == actions[n - 3] and actions[n - 2] == actions[n - 4]:
            return True
        return False
    
    def check(cond, msg):
        if not cond:
            print("FAIL: " + msg)
            sys.exit(1)
    
    t1 = ["read", "edit", "test", "read", "edit"]
    t2 = ["read", "edit", "test", "test", "test"]
    t3 = ["read", "edit", "read", "edit"]
    t4 = ["read", "read", "edit", "test"]
    check(is_stalled(t1) is False, "trace 1 got unexpected stall verdict")
    check(is_stalled(t2) is True, "trace 2 got unexpected stall verdict")
    check(is_stalled(t3) is True, "trace 3 got unexpected stall verdict")
    check(is_stalled(t4) is False, "trace 4 got unexpected stall verdict")
    check(is_stalled([]) is False, "empty history got unexpected stall verdict")
    check(is_stalled(["read"]) is False, "single entry got unexpected stall verdict")
    print("PASS: loop detector flagged 2 of 4 traces and cleared short histories")

    Two of the four schematic traces stall: one triple and one cycle. Short histories under three entries never stall.

    plaintext
    1
    2
    3
    4
    5
    comparisons per scan = 2 triple checks + 2 cycle checks = 4 (stated example values)
    scans = 20
    total = 20 x 4 = 80 comparisons
    detection lag: triple repeat found at the 3rd identical action
    2-step cycle found at the 4th action of the ABAB pattern

    Stop rules and success reports

    A stop names its reason: done, step budget, token budget, or loop. The report lists completed steps, the stop reason, and pointers to external notes.

    Stopping thresholds vary by task: measure them. A threshold that always continues is not a control.

    Stop reason

    When it fires

    Report line

    Done

    All success criteria check out

    Criteria met with check outputs attached.

    Step budget

    Next step would exceed the count

    Stopped before the named step number.

    Token budget

    Next step would exceed the tokens

    Stopped with tokens used and step named.

    Loop

    Triple repeat or ABAB cycle found

    Stopped with the matching tail quoted.

    Common mistakes

    Common pitfall

    Resetting the loop counter on trivial text changes hides a real cycle. Compare normalised action names in order, not raw text length.

    Interview

    Likely probes: detection rules and stop discipline.

    • Triple repeat and ABAB cycle are the two rules; short histories never stall.

    • Twenty scans at 4 comparisons each total 80 comparisons.

    • Every stop names its reason and points at the external notes.

    Check yourself The action tail is read, edit, read, edit. Does the detector stall, and why?

    It stalls. Positions 1 and 3 match and positions 2 and 4 match, which is the ABAB cycle rule.

    Check yourself The tail is read, read, edit, test. Does the detector stall?

    It does not. The last three differ and the last four are not an ABAB cycle, so both rules stay quiet.

    Related topics

    • Budgets and enforcement

    • Multi-agent patterns and when not to use agents

    • Tool use and structured output

    Previous

    100 / 173

    Next: Multi-Agent Patterns and When Not to Use Agents

    Up next

    Up nextMulti-Agent Patterns and When Not to Use Agents

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Task Decomposition and Success Criteria
    • Memory Outside the Model and Summaries