mirror of
https://github.com/leonvanzyl/autocoder.git
synced 2026-01-30 06:12:06 +00:00
fix: add completion detection to prevent infinite loop when all features done
The agent was running in an infinite loop when all kanban features were completed. This happened because: 1. The main loop in agent.py had no completion detection 2. The coding prompt instructs Claude to run regression tests BEFORE checking for new features 3. feature_get_next() returns "All features passing!" but nothing acted on it This fix adds three completion checks: 1. Pre-loop check: Exits immediately if project is already 100% complete when the agent starts (avoids running unnecessary sessions) 2. Post-session check: After each session, checks if all features are now passing and exits gracefully with a success message 3. Single-feature mode: Exits after one session since the parallel orchestrator manages spawning new agents for other features Tested with a project that had 240/240 features passing - agent now exits immediately with "ALL FEATURES ALREADY COMPLETE!" message. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
29
agent.py
29
agent.py
@@ -23,7 +23,7 @@ if sys.platform == "win32":
|
||||
sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding="utf-8", errors="replace", line_buffering=True)
|
||||
|
||||
from client import create_client
|
||||
from progress import has_features, print_progress_summary, print_session_header
|
||||
from progress import count_passing_tests, has_features, print_progress_summary, print_session_header
|
||||
from prompts import (
|
||||
copy_spec_to_project,
|
||||
get_coding_prompt,
|
||||
@@ -173,6 +173,17 @@ async def run_autonomous_agent(
|
||||
while True:
|
||||
iteration += 1
|
||||
|
||||
# Check if all features are already complete (before starting a new session)
|
||||
# Skip this check on first iteration if it's a fresh start (initializer needs to run)
|
||||
if not is_first_run and iteration == 1:
|
||||
passing, in_progress, total = count_passing_tests(project_dir)
|
||||
if total > 0 and passing == total:
|
||||
print("\n" + "=" * 70)
|
||||
print(" ALL FEATURES ALREADY COMPLETE!")
|
||||
print("=" * 70)
|
||||
print(f"\nAll {total} features are passing. Nothing left to do.")
|
||||
break
|
||||
|
||||
# Check max iterations
|
||||
if max_iterations and iteration > max_iterations:
|
||||
print(f"\nReached max iterations ({max_iterations})")
|
||||
@@ -269,6 +280,22 @@ async def run_autonomous_agent(
|
||||
|
||||
sys.stdout.flush() # this should allow the pause to be displayed before sleeping
|
||||
print_progress_summary(project_dir)
|
||||
|
||||
# Check if all features are complete - exit gracefully if done
|
||||
passing, in_progress, total = count_passing_tests(project_dir)
|
||||
if total > 0 and passing == total:
|
||||
print("\n" + "=" * 70)
|
||||
print(" ALL FEATURES COMPLETE!")
|
||||
print("=" * 70)
|
||||
print(f"\nCongratulations! All {total} features are passing.")
|
||||
print("The autonomous agent has finished its work.")
|
||||
break
|
||||
|
||||
# Single-feature mode: exit after one session (orchestrator manages agents)
|
||||
if feature_id is not None:
|
||||
print(f"\nSingle-feature mode: Feature #{feature_id} session complete.")
|
||||
break
|
||||
|
||||
await asyncio.sleep(delay_seconds)
|
||||
|
||||
elif status == "error":
|
||||
|
||||
Reference in New Issue
Block a user