Skip to content

fix(agents): the heartbeat loop guard trips on a looping agent - #630

Open
Maneek21 wants to merge 2 commits into
masterfrom
fix/158-loop-detector
Open

Maneek21 wants to merge 2 commits into
masterfrom
fix/158-loop-detector

Conversation

@Maneek21

Copy link
Copy Markdown
Owner

The agent loop guard never tripped (RC13B on 157, medium). The guard is meant to mark an agent employee unhealthy when its last five task creations or chat posts repeat. It looked at the employee's five newest agent_actions rows. The heartbeat had just queued its own heartbeat_tick row, which isn't a write, so the guard said "no loop" every time. Rows from MCP send_message weren't counted either.

Now the guard reads only the employee's writes: create_task, task_create, post_message, message_post and send_message. Queued work (heartbeat_tick, chat_mention, trigger_dispatch, task_assigned) can't hide a loop any more. The guard also runs before the tick is queued. A looping employee is marked unhealthy, its turn is logged as skipped_unhealthy, and it gets no new tick until an owner or admin clears the flag.

Tests: heartbeat-loop-detector-db covers:

  • five repeated messages behind a heartbeat tick: trips, no new tick;
  • five repeated send_message behind a chat_mention: trips;
  • five repeated task titles: trips;
  • five different writes: no trip, tick queued;
  • fewer than five: no trip.

The three trip cases fail on master. phase8-heartbeat-routing and protected-agent-writers still pass; the writer count for the handler stays at 7. CHANGELOG and the CLAUDE.md circuit-breaker sentence are updated. No local typecheck (laptop rule).

Created with Claude Opus 5.5 in Claude Code.

🤖 Generated with Claude Code

Maneek21 and others added 2 commits November 28, 2026 00:01
RC13B on 157: detectActionLoop read the employee's five newest
agent_actions rows. The heartbeat queued its own heartbeat_tick row
first, and the detector returned "no loop" on any row that isn't a
task or message write, so the circuit breaker never tripped. The MCP
send_message tool's rows were not counted either.

The detector now reads only the employee's writes (create_task,
task_create, post_message, message_post, send_message), so queued work
rows (heartbeat_tick, chat_mention, trigger_dispatch, task_assigned)
can't hide a loop. It runs before the tick is queued: a looping
employee is marked unhealthy, the turn is logged as skipped_unhealthy,
and no tick is queued.

Test: heartbeat-loop-detector-db (repeated messages after a tick,
send_message, task titles, varied writes, fewer than five).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review finding (gpt-6.1-sol): after an owner or admin cleared the
breaker (mark_healthy), the next heartbeat read the same five writes
and tripped it again, so the employee could never recover. The
detector now reads only writes after the employee's latest
skipped_unhealthy turn. Test: trip, clear, heartbeat stays healthy and
queues its tick; five new identical writes trip it again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant