Skip to content

Conversation

@connor-tyndall
Copy link
Contributor

@connor-tyndall connor-tyndall commented Jan 11, 2026

Summary

Fixes #13 - Agent continues indefinitely with regression tests after all features complete

  • Adds is_project_complete() function to detect when all features are passing
  • Adds completion check in agent main loop that exits gracefully when project is done
  • Updates coding prompt template with instructions for graceful shutdown

Problem

When all features are complete (passing = total and pending = 0), the agent:

  1. Calls feature_get_next and receives "All features are passing!"
  2. Ignores this signal and continues anyway
  3. Runs endless regression tests via feature_get_for_regression
  4. Loop repeats indefinitely, wasting ~10,000 tokens per unnecessary session

Solution

After each session with status == "continue", the loop now checks is_project_complete():

  • If all features pass (and none are in-progress), the agent stops cleanly
  • Displays a clear "ALL FEATURES COMPLETE!" message
  • The prompt also teaches the agent what to do when it sees the completion signal

Test plan

  • Run agent on a project with all features already complete - verify it stops after 1 session
  • Run agent on a project with pending features - verify it continues normally
  • Verify is_project_complete() returns correct values for various states

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added automatic project completion detection that recognizes when all tasks are finished and no work remains in progress.
    • Agent now terminates gracefully with a final summary when project completion is detected.

✏️ Tip: You can customize this high-level summary in your review settings.

Fixes issue where the agent continues indefinitely with regression tests
after all features are implemented, wasting tokens on unnecessary sessions.

Changes:
- Add is_project_complete() function to progress.py that checks if all
  features are passing and none are in-progress
- Add completion check in agent.py main loop that breaks out when project
  is complete, displaying a clear success message
- Update coding_prompt.template.md with instructions for graceful shutdown
  when feature_get_next returns the completion signal

This prevents the endless regression loop that was consuming ~10,000 tokens
per unnecessary session after project completion.

Closes leonvanzyl#13

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Jan 11, 2026

📝 Walkthrough

Walkthrough

This PR implements automatic project completion detection to prevent the agent from running indefinitely after all features are passing. A new completion check function is added to evaluate project state, integrated into the agent loop with an early exit condition, and supplemented with prompt guidance explaining the completion workflow.

Changes

Cohort / File(s) Summary
Completion Detection Function
progress.py
Added is_project_complete() function that returns True when total features exist, all features are passing, and no features are in progress. Uses existing count_passing_tests() result.
Agent Loop Completion Check
agent.py
Imported is_project_complete and added conditional check after "continue" status to break the loop and exit when project is complete, preventing indefinite regression testing cycles.
Prompt Template Completion Guidance
.claude/templates/coding_prompt.template.md
Added explicit "PROJECT COMPLETION" guidance block documenting steps to follow when completion signal is received: write final summary, perform optional verification, commit final state, and end session.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 Hop, hop, hurray! The agent now sees
When all features pass and there's work done with ease—
No more endless loops of regression so deep,
The project's complete, it's time now to sleep! 🌙✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: Stop agent when all features are complete' directly and clearly summarizes the main change: adding logic to stop the agent loop when project completion is detected.
Linked Issues check ✅ Passed The pull request fully implements all coding requirements from issue #13: adds is_project_complete() function, implements completion check in agent loop, and updates the coding prompt template with completion instructions.
Out of Scope Changes check ✅ Passed All changes are directly aligned with the objectives of issue #13; no unrelated or out-of-scope modifications are present in the three modified files.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b1473cd and 75cb593.

📒 Files selected for processing (3)
  • .claude/templates/coding_prompt.template.md
  • agent.py
  • progress.py
🧰 Additional context used
📓 Path-based instructions (4)
.claude/templates/**/*.template.md

📄 CodeRabbit inference engine (CLAUDE.md)

Prompt templates should follow a fallback chain: project-specific in {project_dir}/prompts/{name}.md, then base template in .claude/templates/{name}.template.md

Files:

  • .claude/templates/coding_prompt.template.md
*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Python backend should use the ClaudeSDKClient configuration in client.py with security hooks and MCP servers

Files:

  • progress.py
  • agent.py
**/*.py

📄 CodeRabbit inference engine (CLAUDE.md)

Use SQLite with SQLAlchemy ORM for database access and feature management

Files:

  • progress.py
  • agent.py
agent.py

📄 CodeRabbit inference engine (CLAUDE.md)

Agent sessions should auto-continue with a 3-second delay between sessions

Files:

  • agent.py
🧠 Learnings (1)
📚 Learning: 2026-01-10T08:23:04.012Z
Learnt from: CR
Repo: leonvanzyl/autocoder PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-01-10T08:23:04.012Z
Learning: Applies to agent.py : Agent sessions should auto-continue with a 3-second delay between sessions

Applied to files:

  • agent.py
🧬 Code graph analysis (1)
agent.py (1)
progress.py (3)
  • is_project_complete (92-108)
  • print_progress_summary (230-242)
  • print_session_header (220-227)
🔇 Additional comments (4)
progress.py (1)

92-108: LGTM!

The completion detection logic is well-implemented with clear conditions:

  1. Features exist (total > 0)
  2. All features pass (passing == total)
  3. No work in progress (in_progress == 0)

The function correctly returns False when the database is empty or missing (via count_passing_tests returning (0, 0, 0)), preventing premature completion signals.

agent.py (2)

26-26: LGTM!

The import correctly adds is_project_complete to enable the completion detection feature.


200-209: LGTM!

The completion check is well-placed immediately after a successful session, before the auto-continue delay. This correctly:

  1. Detects completion at the earliest opportunity
  2. Avoids unnecessary delay before exiting
  3. Provides a clear user message explaining why the agent is stopping
  4. Falls through to the final summary block (lines 278-294)

Based on learnings, the 3-second delay is intended for auto-continuation between sessions, so skipping it on completion is appropriate.

.claude/templates/coding_prompt.template.md (1)

104-130: LGTM!

The completion guidance block is well-structured and provides clear instructions for the agent when all features are complete:

  1. Write final summary to progress file
  2. Optional final verification
  3. Commit final state
  4. End session gracefully

The explicit note that "The agent loop will automatically stop when it detects completion" correctly aligns with the is_project_complete check added in agent.py.


Comment @coderabbitai help to get the list of available commands and usage tips.

@leonvanzyl
Copy link
Owner

Analysis: This PR is now obsolete

After a detailed code review comparing this PR against current master, this functionality has already been implemented via different commits.

What's already on master:

  1. Pre-loop completion check (agent.py lines 188-197):

    • Checks if total > 0 and passing == total before starting each session
    • Prints "ALL FEATURES ALREADY COMPLETE!" and exits
  2. Response-based completion detection (agent.py lines 241-245):

    • Checks for "all features are passing" or "no more work to do" in response
    • Prints "PROJECT COMPLETE - ALL FEATURES PASSING!" and exits
  3. Post-session completion check (agent.py lines 308-315):

    • Checks if total > 0 and passing == total after each session
    • Prints "ALL FEATURES COMPLETE!" and exits

Relevant commits on master:

  • ffdd97a - "fix: add completion detection to prevent infinite loop when all features done"
  • 3d97cbf - "fix: exit agent loop when all features pass"

Conclusion:

The bug this PR aimed to fix (endless regression tests after completion) has been resolved through commits merged via PR #50 and #77. While this PR proposes a cleaner is_project_complete() helper function, the core functionality is identical to what's already implemented.

Recommendation: Close as obsolete. Thank you for the contribution - the issue was important and has been addressed!

@leonvanzyl leonvanzyl closed this Jan 22, 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.

Bug: Agent continues indefinitely with regression tests after all features complete

2 participants