fix(gateway): prevent batch deadlock on rejected requests

elsium-ai/elsium-ai·May 12, 2026·✅ Merged

Unexpected rejection in processItem() left batch runner hanging indefinitely — running never decremented, Promise never resolved.

The batch execution system had a critical edge case: if a non-standard error escaped the internal request handling flow inside processItem(), the rejection was not handled in the scheduling loop. This meant running-- never executed, completed++ never executed, and the outer Promise never resolved — causing batch execution to deadlock even though all requests had already finished or failed.

The fix adds a .catch() handler around processItem(idx) that records unexpected failures as { success: false, error: ... }, preserves semaphore correctness by always decrementing running, ensures completed reaches requests.length, and continues scheduling remaining requests after a rejection. A regression test covering an injected TypeError scenario was also added. This was a 63-line addition across 2 files that prevented a subtle production-deadlocking bug.

GitHub
LinkedIn
LeetCode