fix(mail): stop Gmail refusing the search, and stop calling that "hittade inget" (#1521)
Pressing Leta produced mails=25, documents=0 on a real two-mailbox run. Nothing was found because nothing was searched: every request came back 429 "Too many concurrent requests for user". Two bugs, and the second is the one that matters. The search fanned out with Promise.all over every message id at once, one Gmail request per message, per connection. Gmail enforces a per-user concurrency ceiling as well as a daily quota, and this sailed past it long before any volume worth worrying about. It now runs through a pool of five per connection, which is comfortably under and still finishes a page of results in a couple of round trips. The catch turned each refusal into an empty array, with a comment saying one mailbox's failure must not become the company's. Right instinct, wrong consequence: an empty array is also what an empty mailbox returns, and the manual hunt loop stops on fetched === 0 because that is its signal for "the mailboxes hold nothing more for what is open". So a rate-limited search told the user their receipts do not exist, and stopped looking. searchFailureCount() now separates "could not look" from "nothing there". The run route reports it, and the loop treats a pass with failures as failed rather than finished, so pressing again is the obvious next move instead of a pointless one. This is the failure this feature exists to catch, happening inside the feature: silence that reads as an answer. Restoring the unbounded fan-out fails one test; removing the failure counter fails three. Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Jakob Wennberg
Claude Opus 5
parent
709c0c817a
commit
f2d9e98af3
@@ -27,6 +27,8 @@ export interface HuntResult {
|
||||
proposed: number
|
||||
remaining: number
|
||||
failed?: boolean
|
||||
/** Connections that refused the search. See the stop condition below. */
|
||||
searchFailures?: number
|
||||
}
|
||||
|
||||
export interface HuntProgress {
|
||||
@@ -79,6 +81,15 @@ export function useReceiptHunt(onPass?: () => void) {
|
||||
onPass?.()
|
||||
|
||||
// Nothing new this pass: the mailboxes have no more for what is open.
|
||||
//
|
||||
// Unless a mailbox refused to be read, in which case zero fetched says
|
||||
// nothing about what is in there. Stopping on it, and reporting it as
|
||||
// "hittade inget", would tell the user their receipts do not exist
|
||||
// because Gmail was busy. Treat it as a failure and let them retry.
|
||||
if ((body.data.searchFailures ?? 0) > 0) {
|
||||
setResult({ ...body.data, fetched, proposed, failed: true })
|
||||
return
|
||||
}
|
||||
if (body.data.fetched === 0) {
|
||||
setResult({ ...body.data, fetched, proposed })
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user