Skip to content

Commit 488e4d3

Browse files
committed
fix(i18n): forget a batch only when it is gone, not on an auth failure
1 parent 22c482d commit 488e4d3

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎lib/i18n/batch.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,8 +328,12 @@ describe('prefetchTranslations', () => {
328328
expect(posts).toBe(0)
329329
expect(polled).toEqual(['gone'])
330330
expect(pending.size).toBe(0)
331-
// The other model's batch is kept for when that model is used again.
332-
expect(Object.keys(JSON.parse(await readFile(ledgerPath, 'utf8')))).toEqual(['other'])
331+
// The other model's batch is kept for when that model is used again, and the
332+
// forbidden one for a run whose key can read it.
333+
expect(Object.keys(JSON.parse(await readFile(ledgerPath, 'utf8'))).sort()).toEqual([
334+
'gone',
335+
'other',
336+
])
333337
})
334338

335339
it('does not throw when a submit fails', async () => {

‎lib/i18n/batch.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,12 @@ export async function prefetchTranslations(
244244
let batch: BatchObject
245245
try {
246246
const res = await doFetch(`${BATCHES_URL}/${id}`, { headers, signal: timeout() })
247-
// Deleted, never ours, or no longer readable with this key (any 4xx but a
248-
// timeout or rate limit): nothing will ever arrive, so stop waiting on it.
247+
// Any 4xx but a timeout or rate limit will not change by asking again, so stop
248+
// waiting and let the requests run live. Only a 404 means the batch is gone;
249+
// an auth failure keeps it in the ledger for a run with a working key.
249250
if (res.status >= 400 && res.status < 500 && res.status !== 408 && res.status !== 429) {
250251
batches.delete(id)
251-
known.delete(id)
252+
if (res.status === 404) known.delete(id)
252253
opts.log(`batch ${id} unreadable (HTTP ${res.status}); its requests will run live`)
253254
continue
254255
}

0 commit comments

Comments
 (0)