Skip to content

Optimize createTree to reduce GitHub REST API usage #19

Closed

Description

@c-vigo

Description

When committing many files (e.g. 187 files in a smoke-test deploy), the action makes one createBlob API call per file sequentially before calling createTree. This results in ~190 REST API calls for a single commit, which triggers GitHub's secondary rate limit on the GitHub App installation.

This was observed in vig-os/devcontainer-smoke-test run #28, attempt 2 where the action failed with:

You have exceeded a secondary rate limit. Please wait a few minutes before you try again.

This is distinct from the transient Not Found refs error tracked in vig-os/devcontainer#354 (which hit attempt 1 of the same run), but both affect the same step and share the same root weakness: no retry/backoff, and an unnecessarily high number of API calls.

Steps to Reproduce

  1. Use the action to commit ~187 files (e.g. a full workspace deploy)
  2. Trigger the workflow in close proximity to other workflows using the same GitHub App installation
  3. Observe step failure with secondary rate limit error

Expected Behavior

The action should minimize API calls and complete successfully even when committing a large number of files, without triggering GitHub's secondary rate limits.

Actual Behavior

The action makes 187 individual createBlob calls plus 1 createTree call, 1 createCommit call, and 1 updateRef call (~190 total). The rapid-fire blob creation triggers GitHub's secondary rate limit, causing the step to fail.

Environment

  • Runner: GitHub-hosted ubuntu-22.04
  • Action version: c0024cbad0e501764127cccab732c6cd465b4646
  • Files committed: 187 (text-only: YAML, Markdown, shell scripts, Python, TOML, JSON)

Additional Context

Current implementation in src/commit.ts (createTree function):

for (const filePath of filePaths) {
  const { sha, mode } = await createBlob(octokit, owner, repo, filePath);
  treeEntries.push({ path: filePath, mode, type: "blob", sha });
}

Each iteration is a separate POST /repos/{owner}/{repo}/git/blobs call. For 187 files, this alone accounts for ~98% of all API calls.

Possible Solution

Use inline content in the createTree API instead of pre-creating blobs. The GitHub Create a tree endpoint accepts a content field on each tree entry — GitHub creates the blob server-side, eliminating all individual createBlob calls.

This would reduce the commit flow from ~192 API calls to 5:

  1. getRef (1 call)
  2. getCommit (1 call)
  3. createTree with inline content (1 call)
  4. createCommit (1 call)
  5. updateRef (1 call)

Caveats:

  • Binary files: The inline content field is a UTF-8 string. Binary files cannot use this path and would still require individual createBlob calls with encoding: "base64". The implementation should detect binary files (e.g. by attempting UTF-8 decode or checking file extension/MIME type) and fall back to createBlob for those.
  • Large payloads: All file contents are sent in a single createTree request body. For very large files or a very large number of files, this could hit GitHub's request payload size limits. A chunking strategy or a hybrid approach (inline small files, blob-create large ones) may be needed.
  • Complementary to retry: This optimization eliminates the secondary rate limit trigger but does not address the transient Not Found refs error from vig-os/devcontainer#354. Both fixes are independent and complementary.

Activity

  1. added
    bug
    and removed
    bug
    on Mar 24, 2026
  2. changed the title [-][BUG] Excessive API calls in createTree cause secondary rate limit failures[/-] [+]Optimize createTree to reduce GitHub REST API usage[/+] on Mar 24, 2026
  3. added
    enhancement
    on Mar 24, 2026
  4. added 2 commits that reference this issue on Mar 24, 2026
    687cf3e
    ae3d583
  5. added a commit that references this issue on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions