Skip to content

Add idempotency guard to completeTask — prevent double API calls #172

@xliry

Description

@xliry

Problem

From agent logs, lota-1 called POST /tasks/148/complete twice (consecutive calls). This wastes API calls and could cause race conditions (double close, double label swap).

What to do

In src/github.ts, completeTask() function:

  1. At the start of the function, check if the task already has status:completed label
  2. If already completed, return early with a success response (idempotent)
  3. Don't post a duplicate completion comment or try to re-close
async function completeTask(id: number, body: any) {
  // Idempotency check
  const issue = await gh(`/repos/${REPO}/issues/${id}`);
  const labels = issue.labels.map((l: any) => l.name);
  if (labels.includes('status:completed')) {
    return { ok: true, message: 'Already completed (idempotent)' };
  }
  // ... rest of completion logic
}

Acceptance

  • Double-calling /complete is harmless (idempotent)
  • No duplicate comments or label swaps
  • Build passes: npm run build

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions