Skip to content

The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.

fix(release): retry stapler when Apple's CloudKit drops the connection

purple20826299f246
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index 07410063..7082a4dd 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -1698,7 +1698,8 @@ jobs:
fi
# The ticket is stapled to the app, so the first start works offline.
- xcrun stapler validate "$app"
+ # Retried: stapler asks Apple's CloudKit, see stapler_retry.
+ bash scripts/macos-release-signing.sh stapler validate "$app"
# The same question put to the signature itself: the requirement
# `notarized` holds only for code Apple has a ticket for. Unlike
@@ -1755,7 +1756,7 @@ jobs:
# reach a customer's Mac as an update Gatekeeper then refuses.
- name: Verify the updater archive holds the same signed, stapled app
shell: bash
- timeout-minutes: 5
+ timeout-minutes: 10
run: |
set -euo pipefail
dir="src-tauri/target/release/bundle/macos"
@@ -1767,7 +1768,7 @@ jobs:
tar -xzf "$archive" -C "$out"
[ -d "$out/LU.app" ] || { echo "FAIL: the updater archive does not unpack to LU.app" >&2; ls -la "$out" >&2; exit 1; }
codesign --verify --deep --strict --verbose=2 "$out/LU.app"
- xcrun stapler validate "$out/LU.app"
+ bash scripts/macos-release-signing.sh stapler validate "$out/LU.app"
built="$(codesign -dvvv "$dir/LU.app" 2>&1 | awk -F= '/^CDHash=/{print $2}')"
packed="$(codesign -dvvv "$out/LU.app" 2>&1 | awk -F= '/^CDHash=/{print $2}')"
echo "CDHash built: $built, in the archive: $packed"
diff --git a/scripts/macos-release-signing.sh b/scripts/macos-release-signing.sh
index be4ab001..3e4f4d09 100755
--- a/scripts/macos-release-signing.sh
+++ b/scripts/macos-release-signing.sh
@@ -15,6 +15,9 @@
# issuer BEFORE the build, in seconds.
# notarize-dmg FILE Submits the disk image, waits, staples the ticket,
# validates it and asks Gatekeeper.
+# stapler ACTION PATH `xcrun stapler staple|validate PATH`, tried up to
+# STAPLER_TRIES times (default 5) with STAPLER_PAUSE
+# seconds (default 60) in between. See stapler_retry.
# cleanup Deletes the keychain and the key file. Never fails.
#
# intermediate FILE Only the download and hash check of the intermediate
@@ -265,6 +268,39 @@ notary_check() {
echo "OK: Apple's notary service accepts the API key."
}
+# ── stapler ────────────────────────────────────────────────────────────────
+#
+# stapler fetches the ticket from Apple's CloudKit (api.apple-cloudkit.com),
+# for validate as well as for staple. On 2026-11-05 the 3.0.10 Mac job lost
+# that connection five times in a row ("The network connection was lost.",
+# Error 68), each time at a different stapler call, while the notarization
+# itself had been accepted. A dropped connection is retried; an answer that
+# cannot change with another try is not: a file with no ticket stapled to it
+# stays without one however often it is validated.
+stapler_retry() {
+ local action="${1:?usage: stapler staple|validate <path>}" path="${2:?usage: stapler staple|validate <path>}"
+ local tries="${STAPLER_TRIES:-5}" pause="${STAPLER_PAUSE:-60}" n out
+ case "$action" in staple|validate) ;; *) die "stapler: unknown action $action" ;; esac
+ local args=("$action")
+ [ "$action" = staple ] && args+=(-v)
+ for ((n = 1; n <= tries; n++)); do
+ if out="$(xcrun stapler "${args[@]}" "$path" 2>&1)"; then
+ printf '%s\n' "$out"
+ echo "stapler $action: OK on try $n of $tries ($(basename "$path"))"
+ return 0
+ fi
+ printf '%s\n' "$out" >&2
+ if [[ "$out" == *'does not have a ticket stapled'* ]]; then
+ die "stapler $action: $(basename "$path") has no ticket stapled to it; another try cannot change that"
+ fi
+ if [ "$n" -lt "$tries" ]; then
+ echo "::warning::stapler $action failed on try $n of $tries ($(basename "$path")); trying again in ${pause}s"
+ sleep "$pause"
+ fi
+ done
+ die "stapler $action failed $tries times for $(basename "$path")"
+}
+
# ── notarize-dmg ───────────────────────────────────────────────────────────
#
# The bundler notarizes and staples the .app and only signs the .dmg. The
@@ -306,8 +342,8 @@ notarize_dmg() {
fi
echo "== staple and validate"
- xcrun stapler staple -v "$dmg"
- xcrun stapler validate "$dmg"
+ stapler_retry staple "$dmg"
+ stapler_retry validate "$dmg"
# Stapling rewrites the file; the signature has to have survived it.
codesign --verify --verbose=2 "$dmg"
@@ -346,6 +382,7 @@ case "${1:-}" in
notary-key) notary_key ;;
notary-check) notary_check ;;
notarize-dmg) shift; notarize_dmg "$@" ;;
+ stapler) shift; stapler_retry "$@" ;;
cleanup) cleanup ;;
intermediate) shift; intermediate "$@" ;;
pick-identity) shift; pick_identity "$@" ;;
diff --git a/src/lib/__tests__/mac-release-lane.test.ts b/src/lib/__tests__/mac-release-lane.test.ts
index fa08d18d..e3096268 100644
--- a/src/lib/__tests__/mac-release-lane.test.ts
+++ b/src/lib/__tests__/mac-release-lane.test.ts
@@ -377,8 +377,8 @@ describe('release.yml, nothing is attached before it was judged', () => {
const order = [
'xcrun notarytool submit "$dmg" "${auth[@]}" --wait',
'if [ "$status" != "Accepted" ]; then',
- 'xcrun stapler staple -v "$dmg"',
- 'xcrun stapler validate "$dmg"',
+ 'stapler_retry staple "$dmg"',
+ 'stapler_retry validate "$dmg"',
'spctl -a -t open --context context:primary-signature',
].map((needle) => fn.indexOf(needle))
for (const at of order) expect(at).toBeGreaterThanOrEqual(0)
@@ -429,7 +429,7 @@ describe('release.yml, nothing is attached before it was judged', () => {
it('asks the updater archive the same questions as the app', () => {
const step = laneSteps[archive]
expect(step).toContain('codesign --verify --deep --strict')
- expect(step).toContain('xcrun stapler validate')
+ expect(step).toContain('macos-release-signing.sh stapler validate')
expect(step).toContain('CDHash')
expect(step).not.toMatch(/\|\|\s*true/)
})
diff --git a/src/lib/__tests__/signing-lanes.test.ts b/src/lib/__tests__/signing-lanes.test.ts
index 84f842db..6d147c3f 100644
--- a/src/lib/__tests__/signing-lanes.test.ts
+++ b/src/lib/__tests__/signing-lanes.test.ts
@@ -40,7 +40,7 @@
import { describe, it, expect } from 'vitest'
import { execFileSync } from 'node:child_process'
import { generateKeyPairSync } from 'node:crypto'
-import { readFileSync, mkdtempSync, rmSync, existsSync, statSync } from 'node:fs'
+import { readFileSync, mkdtempSync, rmSync, existsSync, statSync, writeFileSync, chmodSync } from 'node:fs'
import { tmpdir } from 'node:os'
import { fileURLToPath } from 'node:url'
import { dirname, resolve, join } from 'node:path'
@@ -375,6 +375,64 @@ describe('the signing identity, judged by execution', () => {
})
})
+describe('stapler, retried by execution', () => {
+ // stapler fetches the ticket from Apple's CloudKit. The 3.0.10 Mac job lost
+ // that connection five times in a row; a stand-in xcrun plays it here.
+ const SCRIPT = resolve(root, 'scripts/macos-release-signing.sh')
+ function run(failures: number, message: string, tries = 3): { ok: boolean; out: string; calls: number } {
+ const dir = mkdtempSync(join(tmpdir(), 'lu-stapler-'))
+ try {
+ writeFileSync(
+ join(dir, 'xcrun'),
+ [
+ '#!/bin/bash',
+ 'n=$(cat "$(dirname "$0")/calls" 2>/dev/null || echo 0); n=$((n+1)); echo $n > "$(dirname "$0")/calls"',
+ `if [ $n -le ${failures} ]; then echo '${message}'; exit 68; fi`,
+ 'echo "The $2 action worked!"',
+ ].join('\n'),
+ )
+ chmodSync(join(dir, 'xcrun'), 0o755)
+ const env = { PATH: `${dir}:${process.env.PATH ?? ''}`, STAPLER_TRIES: String(tries), STAPLER_PAUSE: '0' }
+ const calls = () => Number(existsSync(join(dir, 'calls')) ? readFileSync(join(dir, 'calls'), 'utf8') : 0)
+ try {
+ const out = execFileSync(BASH, [SCRIPT, 'stapler', 'staple', join(dir, 'LU.dmg')], {
+ encoding: 'utf8',
+ stdio: ['ignore', 'pipe', 'pipe'],
+ env,
+ })
+ return { ok: true, out, calls: calls() }
+ } catch (error) {
+ const e = error as { stdout?: string; stderr?: string }
+ return { ok: false, out: `${e.stdout ?? ''}${e.stderr ?? ''}`, calls: calls() }
+ }
+ } finally {
+ rmSync(dir, { recursive: true, force: true })
+ }
+ }
+ const LOST = 'The network connection was lost. The staple and validate action failed! Error 68.'
+
+ it('a lost connection is tried again, and every try is in the log', () => {
+ const got = run(2, LOST)
+ expect(got.ok).toBe(true)
+ expect(got.calls).toBe(3)
+ expect(got.out).toContain('failed on try 1 of 3')
+ expect(got.out).toContain('OK on try 3 of 3')
+ })
+
+ it('gives up after the last try', () => {
+ const got = run(5, LOST)
+ expect(got.ok).toBe(false)
+ expect(got.calls).toBe(3)
+ expect(got.out).toContain('failed 3 times')
+ })
+
+ it('a file without a ticket is not tried again', () => {
+ const got = run(5, 'LU.dmg does not have a ticket stapled to it.')
+ expect(got.ok).toBe(false)
+ expect(got.calls).toBe(1)
+ })
+})
+
// ── 2. Structure ───────────────────────────────────────────────────────────
describe('release.yml signs only where signing-config.sh said yes', () => {