From 8e4f234d699ba0b0a04be85ee65c15a5ed396a12 Mon Sep 17 00:00:00 2001 From: Gagan Date: Mon, 6 Jul 2026 20:07:09 +0530 Subject: [PATCH] fix(apps): take bootstrap commit sha from the PUT response MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Re-reading refs/heads/main immediately after the bootstrap commit can 409 on a stale replica (GitHub eventual consistency) — the Contents API response already carries the commit sha, so use it directly. --- apps/x/packages/core/src/apps/publisher.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/apps/x/packages/core/src/apps/publisher.ts b/apps/x/packages/core/src/apps/publisher.ts index c346abaf..fdefae86 100644 --- a/apps/x/packages/core/src/apps/publisher.ts +++ b/apps/x/packages/core/src/apps/publisher.ts @@ -174,13 +174,14 @@ async function pushSource(token: string, login: string, repoName: string, folder const ref = await gh<{ object: { sha: string } }>(token, 'GET', `/repos/${login}/${repoName}/git/ref/heads/main`); parents = [ref.object.sha]; } catch { - await gh(token, 'PUT', `/repos/${login}/${repoName}/contents/README.md`, { + // Use the PUT response's own commit sha — re-reading the ref right + // after the first commit can 409 on a stale replica. + const put = await gh<{ commit: { sha: string } }>(token, 'PUT', `/repos/${login}/${repoName}/contents/README.md`, { message: 'bootstrap', content: Buffer.from(generatedReadme(manifest)).toString('base64'), branch: 'main', }); - const ref = await gh<{ object: { sha: string } }>(token, 'GET', `/repos/${login}/${repoName}/git/ref/heads/main`); - parents = [ref.object.sha]; + parents = [put.commit.sha]; } type TreeEntry = { path: string; mode: '100644'; type: 'blob'; sha: string };