tinyhumansai/openhuman · error · Error

gh api failed (${list.status}): ${list.stderr?.trim() || "un

Error message

gh api failed (${list.status}): ${list.stderr?.trim() || "unknown error"}

What it means

postOrUpdateTrackingComment() in scripts/agent-batch/status.mjs calls `gh api repos/<repo>/issues/<tracking_issue>/comments --paginate --jq '<filter>'` to find the existing batch tracking comment (matched by the <!-- batch:<id> --> marker) and throws on non-zero exit with gh's stderr. This is the read half of the --post flow; failure here means the script can neither find nor update the tracking comment.

Source

Thrown at scripts/agent-batch/status.mjs:136

function postOrUpdateTrackingComment(spec, body) {
  const issue = spec.tracking_issue;
  const list = spawnSync(
    "gh",
    [
      "api",
      `repos/${spec.base_repo}/issues/${issue}/comments`,
      "--paginate",
      "--jq",
      // Emit one object per line. `gh api --paginate` runs the jq filter
      // per-page; wrapping in `[...]` would produce concatenated array
      // fragments that aren't valid JSON. NDJSON sidesteps that.
      `.[] | select(.body | contains("${COMMENT_MARKER(spec.batch_id)}")) | {id, html_url}`,
    ],
    { encoding: "utf8" },
  );
  if (list.status !== 0) {
    throw new Error(
      `gh api failed (${list.status}): ${list.stderr?.trim() || "unknown error"}`,
    );
  }
  const existing = (list.stdout || "")
    .split("\n")
    .map((line) => line.trim())
    .filter((line) => line.length > 0)
    .map((line) => JSON.parse(line));
  if (existing.length === 0) {
    const r = spawnSync(
      "gh",
      [
        "issue",
        "comment",
        String(issue),
        "--repo",
        spec.base_repo,
        "--body-file",

View on GitHub (pinned to a221052e0d)

Solutions

  1. Run the same call manually to see the real error: `gh api repos/tinyhumansai/openhuman/issues/<N>/comments --limit 1`
  2. Check `gh auth status` and the token's scopes — issues read access on the target repo is required
  3. Verify spec.tracking_issue exists in tinyhumansai/openhuman and is an issue (not a discussion/PR-only number)
  4. Upgrade gh to a current version (needs --paginate and --jq), then re-run

Example fix

# before
$ node scripts/agent-batch/status.mjs batch.json --post
Error: gh api failed (1): HTTP 404: Not Found

# after (fix tracking_issue in batch.json to a real issue, then)
$ node scripts/agent-batch/status.mjs batch.json --post
[agent-batch] posted new tracking comment on #1234
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight: the exact REST call the script makes, minus pagination
import { spawnSync } from "node:child_process";
const r = spawnSync("gh", ["api", `repos/tinyhumansai/openhuman/issues/${issueNumber}/comments`, "--limit", "1"], { encoding: "utf8" });
if (r.status !== 0) throw new Error(`cannot list comments on #${issueNumber}: ${r.stderr}`);

Try / catch

try {
  postOrUpdateTrackingComment(spec, body);
} catch (e) {
  if (/gh api failed \((\d+)\)/.test(e.message) && /rate limit|5\d\d|ECONN/i.test(e.message)) {
    await sleep(30_000);
    postOrUpdateTrackingComment(spec, body); // one retry; a fresh listing re-resolves the comment id
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: Running status.mjs with --post when: no credentials for the REST API (401), the token lacks repo scope for a private repo (403/404), the tracking_issue number in the spec does not exist (404), secondary-rate-limit or network errors, or the gh api invocation itself fails (old gh version without --paginate/--jq support). The jq filter interpolates the batch_id, but validateSpec() constrains batch_id to a kebab-case slug, so filter injection is not a realistic cause.

Common situations: Fine-grained PATs granted only PR-read but not issues-read; spec's tracking_issue pointing at an issue in a different repo or deleted between runs; gh upgraded/downgraded around the --jq per-page behavior; intermittent GitHub API 5xx during batch monitoring loops.

Related errors


AI-assisted analysis of tinyhumansai/openhuman@a221052e0d (2026-08-16). Data as JSON: /api/errors/7547aa68c57bd636. Report an issue: GitHub.