The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 23:30 UTC
fix(cli): installers retry transient GitHub errors (#32913)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 10, 2026 at 19:16 UTC
fae2d204a24490c7ee57749a033a103aa6819ae4
5 files changed
+83
-18
scripts/build-npm-launcher.test.ts
+10
-1
@@ -74,9 +74,13 @@ exit 7
74
const archive = yield* fs.readFile(path.join(root, "release", archiveName));
75
let checksum = NodeCrypto.createHash("sha256").update(archive).digest("hex");
76
const requests: Array<string> = [];
77
+ const failures: Array<number> = [];
78
const server = NodeHttp.createServer((request, response) => {
79
requests.push(request.url ?? "");
79
- if (request.url === `/v${VERSION}/SHA256SUMS`) {
80
+ const failure = failures.shift();
81
+ if (failure !== undefined) {
82
+ response.writeHead(failure).end("upstream timed out");
83
+ } else if (request.url === `/v${VERSION}/SHA256SUMS`) {
84
response.end(`${checksum} ${archiveName}\n`);
85
} else if (request.url === `/v${VERSION}/${archiveName}`) {
86
response.writeHead(200, { "Content-Length": archive.length }).end(archive);
@@ -101,6 +105,9 @@ exit 7
105
corruptChecksum: () => {
106
checksum = "0".repeat(64);
107
},
108
+ failNextRequests: (...statuses: Array<number>) => {
109
+ failures.push(...statuses);
110
+ },
111
};
112
});
113
@@ -137,6 +144,8 @@ it.layer(NodeServices.layer)("build-npm-launcher", (it) => {
144
const packageDir = path.join(installed, "package");
145
146
const release = yield* serveFakeRelease(root);
147
+ // regression: #32897
148
+ release.failNextRequests(504, 524);
149
const home = path.join(root, "home");
150
const env = {
151
PATH: (yield* HostProcess.Environment).PATH,
scripts/install.ps1
+22
-4
@@ -64,17 +64,35 @@ function Draw-Download([long] $bytes, [long] $total) {
64
[Console]::Error.Write("`r$esc[2K" + $line.Substring(0, [Math]::Min($line.Length, $columns - 1)))
65
}
66
}
67
+# Waits 1, 2, then 4 s before retrying a 408, 429, 5xx, or network error (status 0).
68
+# Retry-After is ignored so a throttled GitHub cannot stall the install for minutes.
69
+function Wait-Retry([int] $status, [int] $attempt) {
70
+ if ($attempt -ge 4 -or ($status -ge 400 -and $status -lt 500 -and $status -ne 408 -and $status -ne 429)) { return $false }
71
+ Start-Sleep -Seconds ([Math]::Pow(2, $attempt - 1))
72
+ return $true
73
+}
74
+function Invoke-Retrying([scriptblock] $request) {
75
+ for ($attempt = 1; ; $attempt++) {
76
+ try { return & $request }
77
+ catch { if (-not (Wait-Retry ([int]$_.Exception.Response.StatusCode) $attempt)) { throw } }
78
+ }
79
+}
80
function Fetch([string] $uri, [string] $destination, [switch] $progress) {
81
if (-not $progress -or -not $interactive) {
82
$ProgressPreference = if ($progress -and $terminal) { "Continue" } else { "SilentlyContinue" }
70
- Invoke-WebRequest -Uri $uri -OutFile $destination -UseBasicParsing
83
+ Invoke-Retrying { Invoke-WebRequest -Uri $uri -OutFile $destination -UseBasicParsing }
84
return
85
}
86
Add-Type -AssemblyName System.Net.Http
87
$client = New-Object System.Net.Http.HttpClient
88
$response = $source = $file = $null
89
try {
77
- $response = $client.GetAsync($uri, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).GetAwaiter().GetResult()
90
+ for ($attempt = 1; ; $attempt++) {
91
+ try { $response = $client.GetAsync($uri, [System.Net.Http.HttpCompletionOption]::ResponseHeadersRead).GetAwaiter().GetResult() }
92
+ catch { if (Wait-Retry 0 $attempt) { continue } throw }
93
+ if ($response.IsSuccessStatusCode -or -not (Wait-Retry ([int]$response.StatusCode) $attempt)) { break }
94
+ $response.Dispose()
95
+ }
96
$response.EnsureSuccessStatusCode() | Out-Null
97
$source = $response.Content.ReadAsStreamAsync().GetAwaiter().GetResult()
98
$file = [IO.File]::Create($destination)
@@ -138,12 +156,12 @@ if (-not $version) {
156
if ($channel -eq "stable") {
157
# release.yml marks only plain stable releases latest. This is a github.com
158
# page, so it is not cut off by a page of newer nightlies or the API quota.
141
- $release = Invoke-RestMethod -Uri "https://github.com/$repo/releases/latest" -Headers @{ "User-Agent" = "t3-install"; "Accept" = "application/json" }
159
+ $release = Invoke-Retrying { Invoke-RestMethod -Uri "https://github.com/$repo/releases/latest" -Headers @{ "User-Agent" = "t3-install"; "Accept" = "application/json" } }
160
$tag = ($release | Where-Object { $_.tag_name -match $tagPattern }).tag_name
161
} else {
162
$tag = $null
163
for ($page = 1; -not $tag -and $page -le 10; $page++) {
146
- $releases = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases?per_page=100&page=$page" -Headers @{ "User-Agent" = "t3-install" }
164
+ $releases = Invoke-Retrying { Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases?per_page=100&page=$page" -Headers @{ "User-Agent" = "t3-install" } }
165
$tag = ($releases | Where-Object { -not $_.draft -and $_.tag_name -match $tagPattern } | Select-Object -First 1).tag_name
166
if (-not $releases) { break }
167
}
scripts/install.sh
+33
-9
@@ -63,10 +63,24 @@ if "$interactive"; then
63
fi
64
step "Finding your release..."
65
66
+# Sleeps 1, 2, then 4 s before retrying a 408, 429, 5xx, or network error. Not curl
67
+# --retry: older curl waits out any Retry-After, however long.
68
+backoff() {
69
+ case "$1" in 408 | 429) ;; 4??) return 1 ;; esac
70
+ [ "$2" -lt 4 ] && sleep "$((1 << ($2 - 1)))"
71
+}
72
+
73
# Exit 44 on a 404 so callers can tell "no such asset" from a network failure.
74
fetch() {
75
if command -v curl >/dev/null 2>&1; then
69
- status="$(curl -sSL -H "Accept: ${3:-*/*}" -w '%{http_code}' "$1" -o "$2")" || return 1
76
+ attempt=1
77
+ while :; do
78
+ code=0; status="$(curl -sSL -H "Accept: ${3:-*/*}" -w '%{http_code}' "$1" -o "$2")" || code=$?
79
+ case "$code:$status" in 0:2??) break ;; esac
80
+ backoff "$status" "$attempt" || break
81
+ attempt=$((attempt + 1))
82
+ done
83
+ [ "$code" -eq 0 ] || return 1
84
case "$status" in
85
2??) return 0 ;;
86
404) return 44 ;;
@@ -85,18 +99,30 @@ mb() {
99
tenths=$((($1 * 10 + 524288) / 1048576))
100
printf '%s.%s' "$((tenths / 10))" "$((tenths % 10))"
101
}
88
-# Poll the file written by the downloader; no progress-output parsing or extra request.
89
-download() {
90
- if ! "$interactive"; then fetch "$1" "$2"; return; fi
102
+download_start() {
103
if command -v curl >/dev/null 2>&1; then
92
- curl -fsSL -D "$2.headers" "$1" -o "$2" 2>"$2.errors" &
104
+ curl -fsSL -w '%{http_code}' -D "$2.headers" "$1" -o "$2" >"$2.status" 2>"$2.errors" &
105
else
106
wget -q --server-response "$1" -O "$2" 2>"$2.headers" &
107
fi
108
download_pid=$!
109
+}
110
+# Reaps the finished download, then restarts it if curl hit a transient error.
111
+download_retry() {
112
+ result=0; wait "$download_pid" || result=$?
113
+ download_pid=
114
+ [ "$result" -ne 0 ] && [ -f "$2.status" ] && backoff "$(cat "$2.status")" "$attempt" || return 1
115
+ attempt=$((attempt + 1))
116
+ download_start "$1" "$2"
117
+}
118
+# Poll the file written by the downloader; no progress-output parsing or extra request.
119
+download() {
120
+ if ! "$interactive"; then fetch "$1" "$2"; return; fi
121
+ attempt=1
122
+ download_start "$1" "$2"
123
previous=-1
124
cr="$(printf '\r')"
99
- while kill -0 "$download_pid" 2>/dev/null; do
125
+ while kill -0 "$download_pid" 2>/dev/null || download_retry "$1" "$2"; do
126
bytes=0; total=0
127
if [ -f "$2" ]; then bytes="$(wc -c < "$2")"; fi
128
if [ -f "$2.headers" ]; then
@@ -124,8 +150,6 @@ download() {
150
fi
151
sleep 0.1
152
done
127
- result=0; wait "$download_pid" || result=$?
128
- download_pid=
153
if [ "$result" -ne 0 ]; then
154
printf '\n' >&2
155
if [ -f "$2.errors" ]; then cat "$2.errors" >&2; else cat "$2.headers" >&2; fi
@@ -133,7 +157,7 @@ download() {
157
fi
158
size="$(mb "$(wc -c < "$2")")"
159
printf '\r\033[2K %s■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■%s 100%% %s%s / %s MB%s\n' "$accent" "$reset" "$muted" "$size" "$size" "$reset" >&2
136
- rm -f "$2.headers" "$2.errors"
160
+ rm -f "$2.headers" "$2.errors" "$2.status"
161
}
162
163
case "$(uname -s)" in
scripts/install.test.ts
+5
-3
@@ -63,12 +63,14 @@ describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer home
63
// regression: #22490
64
describe.skipIf(HostProcess.Platform.defaultValue() !== "linux")("installer channel lookup", () => {
65
it.each([
66
- ["stable", "1.2.3"],
67
- ["preview", "1.2.4-preview.20261019.50"],
68
- ])("finds the newest %s release behind a full page of nightlies", async (channel, version) => {
66
+ // regression: #32897
67
+ ["stable", "1.2.3", 1],
68
+ ["preview", "1.2.4-preview.20261019.50", 0],
69
+ ])("finds %s %s behind nightlies and %i HTTP 504s", async (channel, version, failures) => {
70
const root = await NodeFSP.mkdtemp(NodePath.join(NodeOS.tmpdir(), "t3-install-index-"));
71
const target = NodePath.join(root, "home/runtime/versions", version);
72
const server = NodeHttp.createServer((request, response) => {
73
+ if (failures-- > 0) return response.writeHead(504).end();
74
const url = new URL(request.url ?? "/", "http://fixture");
75
const body =
76
url.pathname === "/pingdotgg/t3code/releases/latest" &&
scripts/npm-launcher/t3.mjs
+13
-1
@@ -20,8 +20,20 @@ function t3Home() {
20
return path.resolve(raw);
21
}
22
23
+const isTransient = (status) => status === 408 || status === 429 || status >= 500;
24
+
25
async function get(url) {
24
- const response = await fetch(url);
26
+ let response;
27
+ for (let attempt = 1; ; attempt++) {
28
+ try {
29
+ response = await fetch(url);
30
+ if (attempt === 4 || !isTransient(response.status)) break;
31
+ await response.body?.cancel();
32
+ } catch (error) {
33
+ if (attempt === 4) throw error;
34
+ }
35
+ await new Promise((resolve) => setTimeout(resolve, 500 * 2 ** (attempt - 1)));
36
+ }
37
if (response.status === 404) {
38
throw new Error(
39
`${url} does not exist yet. If ${version} was just released, try again in a few minutes.`,