stablyai/orca · warning

GitHub returned an invalid stack response.

Error message

GitHub returned an invalid stack response.

What it means

Thrown after a successful `gh api -X POST .../stacks` call when the JSON body's `number` field is missing, not an integer, or <= 0. The GitHub Stacks API (a preview/early feature) returned a 2xx envelope whose shape does not match the expected `{ number }` contract, so the stack registration result cannot be trusted. The surrounding try/catch downgrades this to a non-fatal `{ ok: false }` with code 'unknown'.

Source

Thrown at src/main/github/stacked-pr-creation.ts:289

    const parentStack = parentStacks[0]
    const endpoint = parentStack
      ? `repos/${args.repository.owner}/${args.repository.repo}/stacks/${parentStack.number}/add`
      : `repos/${args.repository.owner}/${args.repository.repo}/stacks`
    const pullRequests = parentStack
      ? [args.currentReview.number]
      : [args.parentReview.number, args.currentReview.number]
    const command = ['api', '-X', 'POST', endpoint]
    for (const pullRequest of pullRequests) {
      command.push('-F', `pull_requests[]=${pullRequest}`)
    }
    const { stdout } = await ghExecFileAsync(command, {
      ...ghOptions(args.repoPath, args.repository, args.connectionId, options),
      idempotent: false
    })
    const stackNumber = Number((JSON.parse(stdout) as { number?: unknown }).number)
    if (!Number.isInteger(stackNumber) || stackNumber <= 0) {
      throw new Error('GitHub returned an invalid stack response.')
    }
    return {
      ok: true,
      ...args.currentReview,
      stackNumber,
      parentReview: args.parentReview
    }
  } catch (error) {
    console.warn('GitHub stack registration failed:', error)
    return {
      ok: false,
      code: isStacksUnavailableError(error) ? 'validation' : 'unknown',
      error: isStacksUnavailableError(error)
        ? 'The pull request was created, but GitHub stacks are not available for this repository.'
        : 'The pull request was created, but GitHub could not add it to the stack. Retry to finish stack registration.',
      createdReview: args.currentReview
    }
  } finally {

View on GitHub (pinned to 1136503c6a)

Solutions

  1. Confirm GitHub Stacks is enabled for the repository/organization (preview feature flag) via the GitHub UI or `gh api repos/:owner/:repo/stacks`.
  2. Upgrade the gh CLI to a version matching the Stacks preview contract, then retry — the catch block returns code 'unknown' prompting a retry.
  3. Inspect the raw `stdout` from the gh call (add temporary logging) to see the actual returned shape and adjust the parser if the field moved (e.g. `stack.number`).
  4. If stacks are unavailable, treat the result as terminal: the PR was still created (createdReview is returned), so no re-create is needed.

Example fix

// before
const stackNumber = Number((JSON.parse(stdout) as { number?: unknown }).number)
if (!Number.isInteger(stackNumber) || stackNumber <= 0) {
  throw new Error('GitHub returned an invalid stack response.')
}
// after — tolerate nested or alternate envelope shapes
const parsed = JSON.parse(stdout) as { number?: unknown; stack?: { number?: unknown } }
const stackNumber = Number(parsed.number ?? parsed.stack?.number)
if (!Number.isInteger(stackNumber) || stackNumber <= 0) {
  throw new Error(`GitHub returned an invalid stack response: ${stdout.slice(0, 200)}`)
}
Defensive patterns

Strategy: try-catch

Type guard

function isStackResponse(body: unknown): body is { number: number } {
  return typeof body === 'object' && body !== null
    && Number.isInteger((body as { number?: unknown }).number)
    && (body as { number: number }).number > 0
}

Try / catch

// The surrounding code already try/catches and returns { ok: false, code: 'unknown' }.
// Callers should branch on result.ok === false and retry on code 'unknown':
if (!result.ok && result.code === 'unknown') {
  await retryStackRegistration(args) // limited retries, then surface to user
}

Prevention

When it happens

Trigger: POSTing to `repos/:owner/:repo/stacks` or `.../stacks/:n/add` against a GitHub tier or version where the Stacks REST endpoint exists but returns a different schema (e.g. wraps the number under `stack.number`, returns `null`, or returns an empty object on a soft failure). Also seen when the endpoint is reachable through a GitHub Enterprise proxy that rewrites the body.

Common situations: GitHub Stacks is a preview feature not enabled on the repository/organization; GitHub changed the preview API schema between versions; gh CLI is authenticated to a different account that can read but not write stacks; the repository is on GitHub App auth lacking the stacks scope.

Related errors


AI-assisted analysis of stablyai/orca@1136503c6a (2026-08-12). Data as JSON: /api/errors/2de37436c756e263. Report an issue: GitHub.