Skip to content

[Feature]: /retry command to resume failed execution from last completed step #252

Description

@JeremyDev87

Problem Statement

When execution fails, the rescue mechanism creates a draft PR with partial progress. However,
retrying requires /approve which restarts from scratch — wasting turns on already-completed
steps and risking conflicts with existing commits.

Proposed Solution

Add a /retry command that:

  1. Checks out the existing branch from the failed execution
  2. Parses completed steps from git commit history (step N: pattern)
  3. Resumes execution from the next incomplete step

Technical Approach

New files:

  • src/prompts/retry.ts — Retry prompt builder

Files to modify:

  • src/types.ts — Add "retry" to LeonidasMode
  • src/main.ts — Add handleRetryMode(), extend isValidLeonidasMode()
  • src/github.ts — Add getCompletedSteps(branchName, baseBranch) using octokit.rest.repos.compareCommits()
  • src/i18n.ts — Add keys: retry_starting, retry_no_branch, retry_no_steps
  • src/comment_builder.ts — Handle retry mode in buildFailureComment()
  • src/post_process_cli.ts — Extend mode validation in runPostFailure()

Dynamic turn budget:

const MIN_RETRY_TURNS = 15;
const proportionalTurns = Math.ceil((remainingSteps / totalSteps) * maxTurns);
const retryMaxTurns = Math.min(
  Math.max(proportionalTurns, MIN_RETRY_TURNS),
  maxTurns,
);

Retry prompt structure:

  • Include original plan comment (wrapped with wrapUserContent())
  • List already-completed step commits
  • Instruct: git fetch origin {branch} && git checkout {branch}
  • Continue from next step, following standard execute mode flow

/retry + /revise interaction:

/retry always reads the current (latest) plan comment. If user runs /revise after failure
then /retry, the revised plan is used — this is intentional.

Error handling:

Scenario Action
Branch not on remote Comment: "Cannot retry — no branch from previous execution" + core.setFailed()
No step commits found Comment: "No completed steps found. Use /approve instead." + core.setFailed()
No plan comment Comment: "No plan found. Add leonidas label first." + core.setFailed()
Conflict with base Warning comment, proceed (Claude attempts resolution)

Cross-cutting changes (shared with A1):

  • action.yml: retry uses same composite steps as execute (post-completion, rescue, post-process-pr, trigger-ci)
  • Workflow YAML: Already extended in A1 to match /retry

Depends on: #250 (A1: /revise — shares workflow trigger changes)
Benefits from: #251 (A2: Progress Tracking — helps identify failure point)

Acceptance Criteria

  • /retry resumes execution from the last completed step
  • Completed steps are correctly parsed from branch commit history
  • Turn budget is dynamically calculated based on remaining steps
  • Error comments posted for: no branch, no steps, no plan
  • Authorization check applied
  • All user content sanitized with wrapUserContent()
  • Tests cover handleRetryMode(), getCompletedSteps(), retry prompt builder, all error scenarios

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestleonidasTrigger Leonidas automation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions