The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(notarize): resume timed-out waits without resubmitting
ethernet15eb3be67684
diff --git a/.github/workflows/desktop-bundled-release.yml b/.github/workflows/desktop-bundled-release.ymlindex 1155eee7479..b62b989c0f5 100644--- a/.github/workflows/desktop-bundled-release.yml+++ b/.github/workflows/desktop-bundled-release.yml@@ -528,7 +528,7 @@ jobs:needs: validateruns-on: ${{ matrix.target.runner }}environment: release-signing- timeout-minutes: 180+ timeout-minutes: 360strategy:fail-fast: falsematrix:@@ -709,7 +709,7 @@ jobs:- name: Build and packageshell: bash- timeout-minutes: 160+ timeout-minutes: 330env:GITHUB_SHA: ${{ needs.validate.outputs.sha }}GITHUB_REF_NAME: ${{ inputs.tag }}diff --git a/apps/desktop/scripts/notarize.mjs b/apps/desktop/scripts/notarize.mjsindex a7b72f4c9cc..3ee97aa833c 100644--- a/apps/desktop/scripts/notarize.mjs+++ b/apps/desktop/scripts/notarize.mjs@@ -51,16 +51,38 @@ function resolveApiKeyPath(rawValue) {}}-async function submitAndStaple(zipPath, appPath, auth, { run, sleep, log }) {+async function submitAndStaple(zipPath, appPath, auth, { run, sleep, log, now }) {log(`[notarize] submitting ${zipPath}. Waiting for Apple's decision.`)+ const deadline = now() + 4 * 60 * 60 * 1000+ const waitDelays = [15000, 30000, 60000]+ let resumeIdlet resultlet submitError- try {- result = await run('xcrun', ['notarytool', 'submit', zipPath, ...auth, '--wait', '--output-format', 'json'])- } catch (error) {- // A rejected submission can still return a JSON result and a log ID.- result = error- submitError = error+ for (let attempt = 0; ; attempt++) {+ const remaining = Math.ceil(deadline - now())+ if (remaining <= 0) {+ throw new Error(`Notarization ${resumeId ?? zipPath} exceeded the wait budget`, { cause: submitError })+ }+ const action = resumeId ? ['wait', resumeId] : ['submit', zipPath, '--wait']+ try {+ result = await run('xcrun', [+ 'notarytool', ...action, ...auth, '--timeout', `${Math.ceil(remaining / 1000)}s`, '--output-format', 'json'+ ], { timeout: remaining + 60000 })+ submitError = undefined+ break+ } catch (error) {+ // A rejected submission can still return a JSON result and a log ID.+ result = error+ submitError = error+ const output = `${error.stdout ?? ''}\n${error.stderr ?? ''}\n${error.message}`+ if (!/NSURLErrorDomain\s+Code=-1001\b/.test(output)) break+ // The status-request URL identifies the uploaded app, unlike other UUIDs in the error.+ resumeId ??= output.match(/https:\/\/appstoreconnect\.apple\.com\/notary\/v2\/submissions\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})(?=[?\s,}]|$)/i)?.[1]+ const delay = waitDelays[attempt]+ if (!resumeId || delay === undefined || now() + delay >= deadline) break+ log(`[notarize] request timed out for ${resumeId}. Resuming wait in ${delay / 1000}s.`)+ await sleep(delay)+ }}let submissiontry {@@ -72,6 +94,9 @@ async function submitAndStaple(zipPath, appPath, auth, { run, sleep, log }) {if (typeof id !== 'string' || !id || typeof status !== 'string') {throw submitError ?? new Error(`Incomplete notarytool response: ${result.stdout}`)}+ if (resumeId && id !== resumeId) {+ throw new Error(`notarytool returned submission ${id} while waiting for ${resumeId}`)+ }log(`[notarize] submission ${id}: ${status}`)if (submitError || status !== 'Accepted') {let diagnostics@@ -103,7 +128,7 @@ async function submitAndStaple(zipPath, appPath, auth, { run, sleep, log }) {}export default async function notarize(context, {- run = runCommand, env = process.env, sleep = setTimeout, log = console.log+ run = runCommand, env = process.env, sleep = setTimeout, log = console.log, now = () => performance.now()} = {}) {const { electronPlatformName, appOutDir, packager } = contextif (electronPlatformName !== 'darwin') return@@ -137,7 +162,7 @@ export default async function notarize(context, {const zipPath = path.join(appOutDir, `${appName}.zip`)try {await run('ditto', ['-c', '-k', '--sequesterRsrc', '--keepParent', appPath, zipPath])- await submitAndStaple(zipPath, appPath, auth, { run, sleep, log })+ await submitAndStaple(zipPath, appPath, auth, { run, sleep, log, now })} finally {try {fs.rmSync(zipPath, { force: true })diff --git a/tests-js/notarize.test.mjs b/tests-js/notarize.test.mjsindex ca2df9b279c..e38304a69ba 100644--- a/tests-js/notarize.test.mjs+++ b/tests-js/notarize.test.mjs@@ -46,6 +46,7 @@ test('accepted submissions retry only ticket propagation, without resubmitting oexpect(calls.filter(c => c[0] === 'ditto')).toHaveLength(1)const submissions = calls.filter(c => c[1] === 'notarytool' && c[2] === 'submit')expect(submissions).toHaveLength(1)+ expect(calls.filter(c => c[1] === 'notarytool' && c[2] === 'wait')).toHaveLength(0)expect(submissions[0]).toEqual(expect.arrayContaining(['--wait', '--output-format', 'json']))expect(submissions[0]).toEqual(expect.arrayContaining(env.APPLE_NOTARY_PROFILE? ['--keychain-profile', env.APPLE_NOTARY_PROFILE]@@ -60,6 +61,118 @@ test('accepted submissions retry only ticket propagation, without resubmitting o}})+test('HTTP timeouts resume the same submission with notarytool wait and a shrinking budget', async () => {+ const f = fixture()+ // Replay the status-request failure from the macOS release log.+ const timeoutOutput = `Error: HTTPError(statusCode: nil, error: Error Domain=NSURLErrorDomain Code=-1001 "The request timed out." UserInfo={NSErrorFailingURLStringKey=https://appstoreconnect.apple.com/notary/v2/submissions/${submissionId}?, _kCFStreamErrorDomainKey=1})`+ try {+ for (const env of f.environments) {+ const calls = []+ let elapsed = 0+ let waits = 0+ const log = vi.fn()+ const run = async (command, args, options = {}) => {+ calls.push({ command, args, options })+ if (command === 'ditto') writeFileSync(args.at(-1), 'archive fixture')+ if (args[0] === 'notarytool' && args[1] === 'submit') {+ elapsed += 10 * 60 * 1000+ return runCommand(process.execPath, ['-e',+ 'process.stderr.write(process.argv[1]); process.exitCode = 1', timeoutOutput])+ }+ if (args[0] === 'notarytool' && args[1] === 'wait') {+ if (++waits === 1) {+ elapsed += 20 * 60 * 1000+ // The resumed command already owns the ID even if this error omits it.+ throw new Error('Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."')+ }+ return { stdout: JSON.stringify({ id: submissionId, status: 'Accepted' }) }+ }+ return { stdout: '', stderr: '' }+ }+ await notarize(f.context, {+ run, env, log, now: () => elapsed,+ sleep: async ms => { elapsed += ms },+ })+ expect(calls.filter(c => c.command === 'ditto')).toHaveLength(1)+ const notary = calls.filter(c => c.args[0] === 'notarytool')+ expect(notary.map(c => c.args[1])).toEqual(['submit', 'wait', 'wait'])+ expect(notary[0].args).toContain('--wait')+ const auth = env.APPLE_NOTARY_PROFILE+ ? ['--keychain-profile', env.APPLE_NOTARY_PROFILE]+ : ['--key', env.APPLE_API_KEY, '--key-id', env.APPLE_API_KEY_ID, '--issuer', env.APPLE_API_ISSUER]+ for (const call of notary) {+ expect(call.args).toEqual(expect.arrayContaining([...auth, '--output-format', 'json', '--timeout']))+ const waitTimeout = call.args[call.args.indexOf('--timeout') + 1]+ expect(waitTimeout).toMatch(/^[1-9][0-9]*s$/)+ expect(call.options.timeout).toBeGreaterThan(Number.parseInt(waitTimeout, 10) * 1000)+ }+ for (let i = 1; i < notary.length; i++) {+ expect(notary[i].args[2]).toBe(submissionId)+ const timeoutSeconds = call => Number.parseInt(call.args[call.args.indexOf('--timeout') + 1], 10)+ expect(timeoutSeconds(notary[i])).toBeLessThan(timeoutSeconds(notary[i - 1]))+ expect(notary[i].options.timeout).toBeLessThan(notary[i - 1].options.timeout)+ }+ expect(calls.filter(c => c.args[0] === 'stapler')).toHaveLength(1)+ expect(log).toHaveBeenCalledWith(expect.stringContaining(submissionId))+ expect(existsSync(path.join(f.root, 'Hermes.zip'))).toBe(false)+ }+ } finally { f.cleanup() }+})++test('wait recovery requires a known submission and stops at failures or its limits', async () => {+ const f = fixture()+ const timeout = 'Error Domain=NSURLErrorDomain Code=-1001 "The request timed out."'+ const submissionUrl = `https://appstoreconnect.apple.com/notary/v2/submissions/${submissionId}?`+ const scenarios = ['missing-id', 'malformed-id', 'auth', 'exhausted', 'budget', 'sleep-budget', 'invalid', 'wrong-id']+ try {+ for (const scenario of scenarios) {+ const calls = []+ let elapsed = 0+ const run = async (command, args, options = {}) => {+ calls.push([command, ...args])+ if (command === 'ditto') writeFileSync(args.at(-1), 'archive fixture')+ if (args[0] === 'notarytool' && args[1] === 'log') return { stdout: 'signature rejected' }+ if (args[0] === 'notarytool') {+ if (scenario === 'auth') throw new Error(`authentication failed for ${submissionUrl}`)+ if (scenario === 'missing-id') throw new Error(`${timeout} LocalDataTask <${submissionId}>`)+ if (scenario === 'malformed-id') throw new Error(`${timeout} ${submissionUrl.replace('?', 'garbage?')}`)+ if (scenario === 'budget') elapsed += options.timeout+ if (args[1] === 'wait' && scenario === 'invalid') {+ throw Object.assign(new Error('notarization rejected'), {+ stdout: JSON.stringify({ id: submissionId, status: 'Invalid' }),+ })+ }+ if (args[1] === 'wait' && scenario === 'wrong-id') {+ return { stdout: JSON.stringify({ id: '00000000-0000-4000-8000-000000000002', status: 'Accepted' }) }+ }+ throw new Error(`${timeout} ${submissionUrl}`)+ }+ return { stdout: '' }+ }+ const sleep = vi.fn(async ms => { elapsed += scenario === 'sleep-budget' ? 24 * 60 * 60 * 1000 : ms })+ const failure = await notarize(f.context, {+ run, env: f.environments[0], sleep, log: vi.fn(), now: () => elapsed,+ }).catch(error => error)+ expect(failure).toBeInstanceOf(Error)+ expect(calls.filter(c => c[2] === 'submit')).toHaveLength(1)+ expect(calls.filter(c => c[1] === 'stapler')).toHaveLength(0)+ const waits = calls.filter(c => c[2] === 'wait')+ if (scenario === 'exhausted') {+ expect(waits).toHaveLength(3)+ expect(sleep).toHaveBeenCalledTimes(waits.length)+ } else if (scenario === 'invalid' || scenario === 'wrong-id') {+ expect(waits).toHaveLength(1)+ expect(failure.message).toContain(scenario === 'invalid' ? 'signature rejected' : 'while waiting for')+ } else {+ expect(waits).toHaveLength(0)+ expect(sleep).toHaveBeenCalledTimes(scenario === 'sleep-budget' ? 1 : 0)+ }+ expect(calls.filter(c => c[2] === 'log')).toHaveLength(scenario === 'invalid' ? 1 : 0)+ expect(existsSync(path.join(f.root, 'Hermes.zip'))).toBe(false)+ }+ } finally { f.cleanup() }+})+test('rejections, unknown failures and exhausted propagation retries remain build failures', async () => {const f = fixture()try {