GitHubPromptGenerator: splitRepository validation runs after the network search, hiding the clear error behind an API failure

Open Beginner friendly
#51 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
github, typescript
Domain
api, backend

Research direction

Start in src/prompt-generators/github.ts and trace GitHubPromptGenerator.generate, splitRepository, and github.searchIssues. Check the existing tests or test setup for generator validation and network calls. Done means malformed repository values produce splitRepository’s clear error before searchIssues makes any request.

Written by the indexing model from the issue text.

Description

bug S4

Observed behavior

In src/prompt-generators/github.ts, GitHubPromptGenerator.generate performs the GitHub search before validating the repository value:

async *generate(loopState: LoopState): AsyncIterable<Prompt> {
  const github = new GitHub(this.#task.github);
  const issues = await github.searchIssues(this.#task.search);   // <-- network call first
  const repository = this.#task.search.repository;
  const [owner, repo] = splitRepository(repository);             // <-- validation second
  ...
}

If repository is malformed (e.g. 'octocat', 'octocat/', 'owner/repo/extra', or an empty string), the helpful local error from splitRepository

GitHub repository must be in owner/repo form: octocat

never gets a chance to fire on its own. The library first builds a query like is:open repo:octocat is:issue, calls /search/issues, and either:

  1. Wastes the HTTP call (and a rate-limit unit) on a query GitHub returns zero results for, or
  2. Surfaces a confusing GitHub API error 422: Validation Failed if GitHub rejects the qualifier, with no hint that the root cause is the repository config field.

splitRepository then throws afterwards (or never throws if the search returned 422 first), so callers see either zero results or an opaque GitHub API error rather than the clear, actionable error the helper was designed to produce.

Expected behavior

A malformed repository should fail fast with splitRepository's message, before any network call is made, so the user is pointed straight at the bad config field.

Minimal reproduction

import { GitHubPromptGenerator } from 'loop-the-loop/prompt-generators/github';
import { LoopState } from 'loop-the-loop/util/loop-state';

const gen = await GitHubPromptGenerator.create({
  search: { repository: 'octocat', query: 'is:open' },
  promptTemplate: 'Review {{id}}',
});

const loopState = await LoopState.create('/tmp/state.json');
for await (const _ of (gen as any).generate(loopState)) {
  // never reached - but only after a wasted network call
}

Suggested fix

Validate repository before calling searchIssues. Either:

  1. Move the splitRepository call ahead of github.searchIssues(...) in generate, or
  2. Better: validate in the constructor (or in normalizeGitHubTaskConfig) so a misconfigured task is rejected before any generator iteration begins.

Option 2 also brings it into line with where other config invariants are enforced.

Dominant language
TypeScript
Stars
2
Forks
1
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from joewalker/loop-the-loop

All issues in joewalker/loop-the-loop

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.