Skip to content

Bug: agents enter infinite post-work cleanup loop after completing primary task #1067

Closed

Description

@pdebruin

Description

A spawned agent completed its primary work (~15 minutes, domain doc written and committed) but then entered an infinite loop of post-work hygiene operations — retrying history updates, decision file writes, and git commits for over 45 additional minutes (195 tool calls total) before being manually stopped.

The agent's actual deliverable was done and committed early on. The loop was entirely in the "AFTER work" phase (history.md updates, decision inbox writes, skill extraction attempts, git operations).

Observed behavior

  • Agent spawned with standard template (including AFTER work and RESPONSE ORDER blocks)
  • Primary task completed in ~15 minutes (domain doc written, committed)
  • Agent continued running for ~45 more minutes doing post-work hygiene
  • 195 tool calls total before manual stop via stop_agent
  • No new meaningful work was produced after the first ~30 tool calls

Expected behavior

Agent should complete post-work hygiene quickly (5-10 tool calls) and terminate.

Suggested mitigations

  1. Tool call hard cap in spawn prompts — e.g. ⚠️ HARD LIMIT: 80 tool calls. After 60, finish current task and stop. This gives the agent a budget it can self-enforce.

  2. Strict separation of agent work from Scribe hygiene — The spawn template already delegates logging/decisions/commits to Scribe, but agents still have AFTER work instructions that overlap with Scribe's responsibilities. Making this exclusive (agent does ZERO post-work file ops, Scribe does ALL of it) would eliminate the loop trigger.

  3. Platform-level timeout — A max_tool_calls or timeout parameter on the task tool would be the cleanest fix, but requires platform support.

Environment

  • Platform: GitHub Copilot CLI
  • Agent type: general-purpose (background mode)
  • Model: claude-sonnet-4.5
  • Squad version: 0.9.1

Related issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions