Skip to content

Duplicate iteration loop logic between processIssue and processIssueInDir #23

@casperpanduro

Description

@casperpanduro

Problem

src/core/loop.ts contains two nearly identical iteration loops: processIssue (lines 39–111) and processIssueInDir (lines 182–237). Both implement the same core pattern:

  • Load contexts, instructions, workflow
  • Resolve template
  • Spawn agent
  • Accumulate token usage
  • Check timeouts and exit codes
  • Run checks and collect failures
  • Sleep between iterations

The only meaningful differences are (1) processIssue uses log.step while processIssueInDir uses log.issue, and (2) processIssue sets up the branch before the loop. Any bug fix or behavioral change must be applied in two places, and they have already drifted (e.g. processIssueInDir is missing the explicit check-failure log line).

Suggested fix

Extract a shared runIterationLoop function that takes the issue, config, cwd, and a logger variant. Both processIssue and processIssueInDir call this shared function after their own setup steps:

async function runIterationLoop(
  issue: GitHubIssue,
  config: StormConfig,
  cwd: string,
): Promise<{ totalUsage: AgentUsage }> {
  // single implementation of the loop
}

This eliminates the duplication and ensures both paths stay in sync.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions