CommandCodeAI / CommandCodeAI/command-code

Bug Report: Agent Thrashing / Infinite Loop on Simple Debugging Task

Open
#512 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

windows
Dominant language
No language data
Stars
4k
Forks
350
PR merge metrics
No merged PRs in 30d

Description

Summary

On a simple, well-scoped debugging task (fix a JavaScript fetch error on a toggle button), the agent entered an infinite loop repeatedly making contradictory edits, undoing its own changes, and running useless commands — without ever resolving the issue. The session ran for an extended period with zero net progress.

Environment:
OS: Windows (native) / WSL Ubuntu
Command Code version: v0.26.2
Model: DeepSeek V4 Pro
Project: Laravel (Blade + vanilla JS fetch)
Tool: Command Code TUI

Task Given

"I'm still getting error toggling address status, even though the toggle works"

This is a straightforward AJAX/JSON mismatch debug expected resolution time under 2 minutes. The fix requires reading the JS fetch block and the controller method, identifying the mismatch, and applying a single change.

Impact:
Developer time wasted on a task that should take under 2 minutes
Multiple unnecessary file edits creating noisy git history
No resolution — bug remained unfixed after the entire session
Loss of confidence in the tool for production codebase work

Expected Behavior

Expected Behavior:

Read all relevant files before making any edit; in this case the JS fetch block and the controller method should have been read together before the first fix attempt
Maintain state across tool calls; if an edit was just made and reverted, the agent should recognize it's in a loop and stop, not continue the same cycle
Use debug output before discarding it; console.log statements should be added, the developer prompted to check the browser console, and the output acted upon before those statements are removed
Circuit breaker on repeated failed attempts; after 3 attempts at the same fix with no resolution, the agent should stop, summarize what it has tried, and ask the developer for additional context (e.g. browser console output, network tab response) rather than continuing to thrash
Cache clear is a one-time action — running php artisan view:clear more than once per session on the same issue should be flagged as a no-op and skipped

Actual Behavior

Observed Behavior

Repeated useless commands

  • php artisan view:clear && php artisan cache:clear was executed at least 6 times across the session. This command clears compiled view cache — it has no effect on a JavaScript/controller JSON response mismatch. Running it repeatedly after the first time is pure cargo-cult debugging with zero diagnostic value.

  • Contradictory edits with no logical progression

  • The controller's JSON response was changed back and forth repeatedly with no reasoning:

Iteration 1: return response()->json(['success' => true, 'message' => 'Status updated']);
Iteration 2: return response()->json(['success' => true]);
Iteration 3: return response()->json(['success' => true], 200);
Iteration 4: return response()->json(['success' => true]);
Iteration 5: return response()->json(['success' => true, 'new_status' => ...]);
Iteration 6: return response()->json(['success' => true, 'is_active' => $address->is_active]);
Iteration 7: return response()->json(['success' => true]);

The agent cycled through variations and back again with no forward progress — the final state is identical to iteration 2.

Debug instrumentation added then immediately removed without reading output

Console.log statements were added to the JavaScript:

javascriptconsole.log('Toggling address:', addressId);
console.log('URL:', url);
console.log('CSRF Token:', token);

These were removed in the very next edit without any indication the output was read or acted upon. Adding debug logging and then discarding it without using the information is worse than not adding it at all, it wastes tokens and makes the session history harder to follow.

Agent undoing its own changes

The fetch body was changed from:

javascriptbody: JSON.stringify({ _token: token })

to:

javascriptbody: JSON.stringify({})

And then back to:

javascriptbody: JSON.stringify({ _token: token })

The agent literally reversed its own edit within the same session, indicating complete loss of state between tool calls.

Connection error mid-session

⚠ Error: Connection error.
Type "continue" to try again.
Trace ID: 0b6ba5836ae889bdadab439845195504

A connection drop mid-session with no graceful recovery or context resumption. The agent restarted from scratch rather than resuming with awareness of what had already been tried.

Root Cause of the Loop (the actual bug the agent failed to find)

The real issue was a straightforward JSON response/fetch mismatch — a 2-minute fix requiring:
Read the JS fetch block fully
Read the controller method fully
Identify the specific mismatch
Apply one targeted fix

The agent never achieved this because it was not reading both files together holistically before each edit attempt — it was making isolated, incremental changes without maintaining full context of the problem across tool calls.

Steps to reproduce the issue
  1. Open an existing Laravel project with a toggle button that makes a JavaScript fetch() POST request to a controller endpoint
  2. Start a new Command Code session with DeepSeek V4 Pro
  3. Report the error: "I'm getting a javascript alert error while toggling address status, even though the toggle works"
  4. Observe the agent begin editing the controller's JSON response without first reading the JavaScript fetch block and controller method together
  5. Continue the session — observe the agent run php artisan view:clear && php artisan cache:clear repeatedly (6+ times) with no diagnostic value
  6. Observe the agent add console.log debug statements to the JavaScript, then remove them in the very next edit without reading or acting on the output
  7. Observe the controller response toggled back and forth across 7+ iterations with no forward progress, ending in the same state it started
  8. Observe the fetch body changed from JSON.stringify({ _token: token }) → JSON.stringify({}) → back to JSON.stringify({ _token: token }) — the agent reversing its own edit within the same session.

Note that the bug remains unresolved after the entire session 🤦‍♂️🤦‍♂️

Command Code Version

Unknown

Operating System

Windows

Terminal/IDE

Unknown

Shell

bash

Additional context

No response

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Command Code TUI session and tool-call handling, reproducing the Laravel toggle task described in the issue. Inspect how state survives edits, repeated commands, debug output, and connection recovery; done means the agent avoids repeated no-op actions, preserves context, and stops with a useful request for more information after failed attempts.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, laravel
Domain
cli, developer-experience, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.