Skip to content

[Phase 2.5] Stall Detection: ReAct Agent and Runtime Integration #401

Description

@frankbria

Summary

Wire the stall detector into the ReAct agent's tool-use loop and the runtime's task execution flow.

Parent issue: #399

Scope

Changes to core/react_agent.py

  1. Initialize StallDetector at the start of ReactAgent.run()
  2. Call stall_detector.record_activity() after each successful tool execution
  3. Check stall_detector.is_stalled() at the top of each iteration loop
  4. On stall detection:
    • Log warning with elapsed time and last tool call context
    • Based on configured StallAction:
      • RETRY: raise StallDetectedError (runtime handles retry)
      • BLOCKER: create blocker with stall context, return BLOCKED
      • FAIL: return FAILED with stall reason

Changes to core/runtime.py

  1. Catch StallDetectedError in execute_agent()
  2. If retry configured: re-invoke agent (respecting max retry count)
  3. If blocker configured: create blocker with diagnostic context:
    • Time since last activity
    • Last tool call and result
    • Current iteration count
    • Token usage so far

Changes to CLI

  1. Add --stall-timeout flag to cf work start (default: 300s, 0 to disable)
  2. Pass through to runtime/agent

Acceptance Criteria

  • Stall detected during ReAct loop triggers configured recovery action
  • --stall-timeout 120 sets custom timeout via CLI
  • --stall-timeout 0 disables stall detection
  • Retry action re-invokes agent with context about the stall
  • Blocker action creates informative blocker
  • Stall detection works correctly during batch execution
  • Integration test: mock a stalled agent, verify recovery

Dependencies

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestphase-2.5Phase 2.5: Agent Execution Redesign (ReAct)symphony-inspiredInspired by OpenAI Symphony spec analysis

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions