mastra-ai/mastra · error

GitHub ${resource} id must be a positive integer.

Error message

GitHub ${resource} id must be a positive integer.

What it means

Thrown by requirePositiveId when a resource id string (e.g. pull request, issue, review comment id) does not parse as a positive integer. The helper is used across GitHub capabilities to coerce string ids into numeric GitHub REST identifiers before building request paths; the thrown message names the specific resource.

Source

Thrown at mastracode/factory/src/integrations/platform/github/integration.ts:1594

  const match =
    externalId.match(/^(.+\/.+):(\d+)$/) ??
    externalId.match(/^github:(\d+):(?:issue|pull-request):(\d+)$/) ??
    externalId.match(/^(\d+):(\d+)$/);
  if (!match?.[1] || !match[2] || parsePositiveInteger(match[2]) === null) return null;
  return { repository: match[1], issueId: match[2] };
}

function optionalPositiveIntegerEnv(name: 'MASTRA_PLATFORM_GITHUB_POLLING_INTERVAL_MS'): number | undefined {
  const value = process.env[name]?.trim();
  if (!value) return undefined;
  const parsed = parsePositiveInteger(value);
  if (parsed === null) throw new Error(`${name} must be a positive integer.`);
  return parsed;
}

function requirePositiveId(value: string, resource: string): number {
  const parsed = parsePositiveInteger(value);
  if (parsed === null) throw new Error(`GitHub ${resource} id must be a positive integer.`);
  return parsed;
}

function reviewEvent(event: 'approve' | 'request-changes' | 'comment') {
  if (event === 'approve') return 'APPROVE' as const;
  if (event === 'request-changes') return 'REQUEST_CHANGES' as const;
  return 'COMMENT' as const;
}

function isNotFound(error: unknown): boolean {
  return error instanceof PlatformApiError && error.status === 404;
}

// Platform answers 404 when the installation row is gone, 409 when it is suspended or soft-deleted.
// A 502 also covers a dead installation but is indistinguishable from a transient GitHub outage.
function isDeadInstallation(error: unknown): boolean {
  return error instanceof PlatformApiError && (error.status === 404 || error.status === 409);
}

View on GitHub (pinned to 75dd419e61)

Solutions

  1. Pass the raw numeric GitHub object id as a digit-only string (e.g. '1234567890')
  2. Map the platform record to its stored GitHub external numeric id before calling
  3. Strip display prefixes like '#' or 'PR-' before invocation
  4. Validate the id with /^\d+$/ in the calling layer to fail earlier with clearer context

Example fix

// before
await github.mergePullRequest({ installationId, sourceId, pullRequestId: 'PR-42' });
// after
await github.mergePullRequest({ installationId, sourceId, pullRequestId: '1234567890' });
Defensive patterns

Strategy: validation

Validate before calling

function requireNumericId(value: string, what: string): number {
  if (!/^\d+$/.test(value) || Number(value) <= 0) throw new Error(`${what} must be a numeric GitHub id, got: ${value}`);
  return Number(value);
}

Try / catch

try {
  await github.mergePullRequest({ installationId, sourceId, pullRequestId });
} catch (err) {
  if (err instanceof Error && err.message.includes('id must be a positive integer')) {
    pullRequestId = await mapPlatformIdToGithubId(pullRequestId);
    // retry once with the corrected id
  } else throw err;
}

Prevention

When it happens

Trigger: Calling a capability with an id argument like 'abc', '', '0', 'PR-123', or a global platform id (e.g. a UUID) where a numeric GitHub object id is expected — via requirePositiveId(value, resource).

Common situations: Passing a platform/database surrogate key instead of the GitHub numeric id; string interpolation lost digits or added prefixes; UI state held a display label ('#42') instead of the raw id; ids from another provider (GitLab issue number vs GitHub id).

Related errors


AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30). Data as JSON: /api/errors/a99f1d721fa5f8d6. Report an issue: GitHub.