for about a month my bot logged TypeError: fetch failed around 450 times a day. i ignored it. it told me nothing.
what was happening
Akiko's AI features call a worker container on the same box. it's slow. summarizing a plain 20 message conversation took 55 seconds, and real ones queue behind other requests and take longer.
i'd given the summarize call a one hour timeout with an AbortController. it didn't matter. Node's fetch (undici) has its own headersTimeout and bodyTimeout of 300 seconds that have nothing to do with your abort signal. anything over five minutes got killed, and the one hour timeout was a story i'd told myself.
why it took a month
the error showed up as a bare fetch failed. i was logging errors with String(err), which drops err.cause. the cause is the only thing that tells ECONNREFUSED apart from UND_ERR_HEADERS_TIMEOUT. about 7,400 errors, all identical, none of them actionable.
there's a helper now that keeps the cause. trust the cause, not the message.
the fix
- a module level undici
AgentwithheadersTimeout: 0andbodyTimeout: 0, passed as thedispatcheron the long calls. any new long running endpoint needs it too, or the default quietly caps it at 300 seconds. - the summarizer model has a 4096 token window and i was feeding it up to 20 raw conversation rows. one request was 5,899 tokens. it now clamps input to about 2,400 tokens, newest first.
a day after the fix, 545 summarize calls, all 200.
one more thing. the worker's /health answers in about a millisecond even when inference is badly backed up. a green healthcheck told me nothing about whether requests were working :3
Akiko's free to add: https://upload.motzumoto.com/devto













