fix(desktop): retain cold-start budget after runtime installation

This commit is contained in:
2026-09-05 13:50:35 +03:00
parent b9bb62ea82
commit 9b6020f761
2 changed files with 30 additions and 2 deletions
+19
View File
@@ -3,6 +3,25 @@ import { describe, expect, it, vi } from 'vitest'
import { withBootstrapAwareTimeout, withTimeout } from './with-timeout' import { withBootstrapAwareTimeout, withTimeout } from './with-timeout'
describe('withTimeout', () => { describe('withTimeout', () => {
it('allows a full cold start when installation finishes near a deadline', async () => {
vi.useFakeTimers()
try {
let active = true
let finish!: (value: string) => void
const connection = new Promise<string>(resolve => {
finish = resolve
})
const result = withBootstrapAwareTimeout(connection, 45_000, 'timeout', async () => ({ active }))
await vi.advanceTimersByTimeAsync(75_000)
active = false
await vi.advanceTimersByTimeAsync(25_000)
finish('connected')
await expect(result).resolves.toBe('connected')
} finally {
vi.useRealTimers()
}
})
it.each([{ active: true }, { setupChoice: { active: true } }])( it.each([{ active: true }, { setupChoice: { active: true } }])(
'waits beyond cold boot during setup: %j', 'waits beyond cold boot during setup: %j',
async state => { async state => {
+11 -2
View File
@@ -39,6 +39,7 @@ export async function withBootstrapAwareTimeout<T>(
cancelled: () => boolean = () => false cancelled: () => boolean = () => false
): Promise<T> { ): Promise<T> {
let settled = false let settled = false
let setupObserved = false
const request = promise.then( const request = promise.then(
value => { value => {
settled = true settled = true
@@ -58,9 +59,17 @@ export async function withBootstrapAwareTimeout<T>(
throw error throw error
} }
const state = await withTimeout(bootstrapState(), Math.min(ms, 5_000), message) const state = await withTimeout(bootstrapState(), Math.min(ms, 5_000), message)
if (!state?.active && !state?.setupChoice) { if (state?.active || state?.setupChoice) {
throw error setupObserved = true
continue
} }
// Setup may have finished just before this probe. The new backend must
// still receive one complete cold-start budget after the installer.
if (setupObserved) {
setupObserved = false
continue
}
throw error
} }
} }
} }