Skip to content

refactor(commit): apply retry per REST call site in createTree - #34

Merged
c-vigo merged 1 commit into
mainfrom
feature/24-createtree-retry-granularity
Jul 14, 2026
Merged

c-vigo merged 1 commit into
mainfrom
feature/24-createtree-retry-granularity

Conversation

@c-vigo

@c-vigo c-vigo commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Summary

Retries are now applied at individual Octokit REST call sites inside createTree / createTreeChained / createBlob, replacing the coarse withRetry wrap around the entire createTree in commitViaAPI. 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

  • New exported RetryOptions { config: RetryConfig; logger? } + private callWithRetry(fn, retry?) helper — calls fn() once when retry is undefined, else withRetry(fn, config, logger).
  • retry?: RetryOptions threaded (optional, defaults to no retries → backward-compatible signatures) through createBlob, createTreeChained, createTree.
  • commitViaAPI drops the withRetry(() => createTree(...)) wrap and passes { config: retryConfig, logger: log } into createTree. The other single-call coarse wraps (getCommit/getBranchInfo/createCommit/updateBranch) are unchanged (already one call each).

Tests (both fail against the old coarse wrap)

  1. Chunked tree retry: 101 files → 2 chunks; chunk-2 fails 503 once then succeeds → createTree called exactly 3× (not 4), retried call still carries base_tree = tree-chunk-1 (chunk-1 not re-uploaded).
  2. Blob retry: blob-2 fails 503 once → createBlob called 3× (blob-1 once), single createTree carries both resolved SHAs.

Verification

  • npm run build (tsc), npm run bundle (ncc, dist/ committed): ok
  • npm test: 82 passed (3 suites)
  • Pre-commit suite green (devkit dev-shell)

Reviewer note

Overlaps PR for #22 (payload-size chunking) on the same createTree/createTreeChained path — recommend merging this first, then rebasing #22 to re-thread retry through any new chunking helper.

Refs: #24

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
c-vigo merged commit fc49272 into main Jul 14, 2026
9 checks passed
@c-vigo
c-vigo deleted the feature/24-createtree-retry-granularity branch July 14, 2026 08:21
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: apply retry at individual API call sites inside createTree

1 participant