stablyai/orca · error

missing head SHA

Error message

missing head SHA

What it means

Thrown by getRestPRByNumber after stack metadata passed validation but the PR's head SHA is not a valid git object ID (checked via isGitObjectId). Stack-aware code needs the head SHA to wire parent/child PR relationships to local refs, so a missing or malformed SHA makes the stack unusable even though the stack structure parsed.

Source

Thrown at src/main/github/client.ts:3011

    { ...ghOptions, ...githubHostExecOptions(ownerRepo) }
  )
  const parsed = JSON.parse(stdout) as unknown
  if (typeof parsed !== 'object' || parsed === null || Array.isArray(parsed)) {
    throw new Error('invalid response shape')
  }
  const restData = parsed as RestPullRequest
  const mapped = mapRestPullRequest(restData)
  if (
    options.requireUsableStackMetadata &&
    restData.stack !== undefined &&
    restData.stack !== null
  ) {
    // Why: GitHub omits stack for ordinary PRs; only unusable non-null metadata is unsafe.
    if (!isUsableRestStackMetadata(restData.stack) || !mapped.stack) {
      throw new Error('malformed stack')
    }
    if (!isGitObjectId(restData.head?.sha)) {
      throw new Error('missing head SHA')
    }
  }
  return mapped
}

function prunePRStackSummaryCache(now = Date.now()): void {
  for (const [key, cached] of prStackSummaryCache) {
    if (cached.expiresAt <= now) {
      prStackSummaryCache.delete(key)
    }
  }
  while (prStackSummaryCache.size > PR_STACK_SUMMARY_CACHE_MAX_ENTRIES) {
    const oldestKey = prStackSummaryCache.keys().next().value
    if (oldestKey === undefined) {
      return
    }
    prStackSummaryCache.delete(oldestKey)
  }

View on GitHub (pinned to 1136503c6a)

Solutions

  1. Check the PR on github.com — if the head branch/repo is gone, the lookup legitimately cannot provide a SHA.
  2. If the PR looks healthy, dump the raw response and verify `head.sha` is a full 40-char hex string.
  3. For a deleted-head PR, treat the stack view as unavailable rather than retrying.
Defensive patterns

Strategy: validation

Validate before calling

function isValidObjectId(sha: unknown): sha is string {
  return typeof sha === 'string' && /^[0-9a-f]{40}$/i.test(sha)
}

Type guard

function isValidObjectId(sha: unknown): sha is string {
  return typeof sha === 'string' && /^[0-9a-f]{40}$/i.test(sha)
}

Try / catch

try {
  const pr = await getRestPRByNumber(ownerRepo, number, ghOptions, { requireUsableStackMetadata: true })
} catch (err) {
  if ((err as Error).message === 'missing head SHA') {
    showStackUnavailableDueToDeletedHead(number)
    return null
  }
  throw err
}

Prevention

When it happens

Trigger: GitHub returned a PR whose head repo was deleted (head.sha null/empty); a draft PR from a deleted fork; an Enterprise Server bug returning an abbreviated or malformed SHA; the response was partially truncated.

Common situations: PR head branch deleted before the lookup; fork deleted by owner; SHA field present but not a 40-char hex object id.

Related errors


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