Skip to content

Bug: implement_task workspace prep failure loops infinitely (no retry_count increment) #178

Description

@danchild

Summary

When prepare_workspace fails inside implement_task, the node returns last_error but does not increment retry_count. The routing function _route_implementation checks retry_count >= 3 to escalate, but since it's never incremented, the workflow loops forever.

Observed in production: AISOS-2208 hit this path and logged 5,600+ retries in under 5 minutes with no backoff, burning CPU on a tight loop of git fetch fork failures.

Root Cause

In src/forge/workflow/nodes/implementation.py, the prepare_workspace exception handler (lines 63-69) omits retry_count:

except Exception as exc:
    logger.error("Unable to prepare implementation workspace for %s: %s", ticket_key, exc)
    return {
        **state,
        "last_error": str(exc),
        "current_node": implementation_node,
        # ← missing: "retry_count": state.get("retry_count", 0) + 1,
    }

The other two error paths in the same function (lines 150-152 and 267-272) correctly increment retry_count.

The Loop

  1. implement_taskprepare_workspace() raises (e.g. missing fork_owner/fork_repo in state) → returns with last_error but retry_count stays 0
  2. _route_implementation sees last_error with retry_count=0 < 3 → routes back to implement_task
  3. Goto 1 — forever

Fix

Add "retry_count": state.get("retry_count", 0) + 1 to the return dict at line 65.

Log Evidence

2026-07-17 12:00:46,030 - forge.workflow.nodes.implementation - ERROR - Unable to prepare implementation workspace for AISOS-2208: Cannot recreate workspace for AISOS-2208: missing branch_name, current_repo, fork_owner, or fork_repo in state
2026-07-17 12:00:46,034 - forge.workspace.git_ops - INFO - Syncing with fork/forge/aisos-2208 before implementing changes
2026-07-17 12:00:46,075 - forge.workflow.nodes.workspace_setup - WARNING - Workspace sync failed for AISOS-2208; recreating workspace from fork: Git command failed: git fetch fork

This three-line pattern repeated ~5,600 times in under 5 minutes with no backoff.

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