Repository navigation
refactor(commit): apply retry per REST call site in createTree - #34
Merged
Merged
Conversation
Wrap each Octokit REST call inside createTree, createTreeChained, and createBlob in withRetry via an optional RetryOptions parameter, instead of wrapping the whole multi-call createTree operation in commitViaAPI. A transient mid-batch failure now retries only the failing call rather than re-running the entire tree build and re-uploading already-succeeded blobs and tree chunks, saving API budget and easing rate-limit pressure. The new RetryOptions parameter is optional and defaults to no retries, keeping the public signatures of createBlob and createTree backward compatible. Refs: #24
c-vigo
added a commit
that referenced
this pull request
Jul 14, 2026
## Summary `createTreeChained` chunked by **entry count only** (`TREE_ENTRY_CHUNK_SIZE = 100`), so a chunk of many large inline text files could approach GitHub's ~100 MB request-body limit. This adds payload-size awareness and a per-file blob-fallback. Closes #22. ## Changes - **Byte-aware chunking** — new exported `TREE_ENTRY_BYTE_LIMIT = 6 MiB`. `createTreeChained` rewritten from a fixed-stride slice loop to an accumulating loop with a `flush()` helper: a chunk ends when adding the next entry would breach **either** the count cap **or** the byte budget (whichever first). Empty-chunk guard ensures a single oversized entry still makes progress. Chaining semantics (each chunk's tree SHA → next `base_tree`) unchanged. - **Per-file threshold** — new exported `INLINE_CONTENT_SIZE_LIMIT = 1 MiB`. Text files larger than this go through `createBlob` (base64) instead of inline `content`. - `estimateEntrySize` — safe over-approximation (64 B overhead + path + content/sha bytes). ## Tests 1. 4× 2.5 MiB text files (under the count cap) split at 2 entries/chunk purely on the byte budget → 2 `createTree` calls, correct `base_tree` chaining, `createBlob` never called. 2. One text file at `INLINE_CONTENT_SIZE_LIMIT + 1` → routed through `createBlob`, tree entry carries `sha` not `content`. ## Verification - `npm test`: **82 passed** (3 suites); `tsc` + `ncc` build ok, `dist/` committed; pre-commit green. ##⚠️ Merge sequencing (conflicts with #34) Both this and **#34 (retry granularity, issue #24)** rewrite `createTreeChained`. Recommend merging **#34 first**, then rebasing this branch and re-threading the `retry?` param so the `createTree` call inside the new `flush()` is wrapped via `callWithRetry`. No overlap outside `createTreeChained`/`createTree`. Refs: #22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Retries are now applied at individual Octokit REST call sites inside
createTree/createTreeChained/createBlob, replacing the coarsewithRetrywrap around the entirecreateTreeincommitViaAPI. A transient mid-batch failure now retries only the failing call instead of re-running the whole multi-call operation and re-uploading already-created blobs/trees.Closes #24.
How
RetryOptions { config: RetryConfig; logger? }+ privatecallWithRetry(fn, retry?)helper — callsfn()once whenretryis undefined, elsewithRetry(fn, config, logger).retry?: RetryOptionsthreaded (optional, defaults to no retries → backward-compatible signatures) throughcreateBlob,createTreeChained,createTree.commitViaAPIdrops thewithRetry(() => createTree(...))wrap and passes{ config: retryConfig, logger: log }intocreateTree. The other single-call coarse wraps (getCommit/getBranchInfo/createCommit/updateBranch) are unchanged (already one call each).Tests (both fail against the old coarse wrap)
createTreecalled exactly 3× (not 4), retried call still carriesbase_tree = tree-chunk-1(chunk-1 not re-uploaded).createBlobcalled 3× (blob-1 once), singlecreateTreecarries both resolved SHAs.Verification
npm run build(tsc),npm run bundle(ncc,dist/committed): oknpm test: 82 passed (3 suites)Reviewer note
Overlaps PR for #22 (payload-size chunking) on the same
createTree/createTreeChainedpath — recommend merging this first, then rebasing #22 to re-threadretrythrough any new chunking helper.Refs: #24