#7810: fix: add fetch timeouts to prevent memory indexing hangs (#4370)
stale
Cluster:
Timeouts and Memory Management Fixes
Add AbortController-based timeouts to all fetch() calls in the memory embedding system to prevent indefinite hangs that cause SIGKILL.
Changes:
- batch-openai.ts: Add fetchWithTimeout() helper with 30s default
- /files upload: 30s timeout
- /batches create: 30s timeout
- /batches/{id} status: 30s timeout
- /files/{id}/content: 60s timeout (larger payloads)
- embeddings-openai.ts: Add 30s timeout to sync embed() path
This fixes the issue where memory indexing would hang indefinitely when OpenAI API requests stall, eventually triggering gateway SIGKILL.
Fixes #4370
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
This PR adds AbortController-based timeouts around OpenAI `fetch()` calls in the memory embedding subsystem. In `src/memory/batch-openai.ts`, a small `fetchWithTimeout()` helper is introduced and used for file upload, batch creation, batch status polling, and output file download (with a longer timeout for content). In `src/memory/embeddings-openai.ts`, the synchronous `embed()` path now uses an AbortController + timer to prevent indefinite hangs.
Overall, these changes fit the existing memory embedding flow by ensuring outbound OpenAI API calls fail fast instead of stalling the entire indexing pipeline until the process is killed.
<h3>Confidence Score: 4/5</h3>
- This PR is safe to merge with low functional risk and improves failure behavior under stalled network calls.
- Changes are localized to adding AbortController timeouts around existing fetch calls; the core request/response logic is otherwise unchanged. Main remaining concern is maintainability/consistency since timeout logic is duplicated across files.
- src/memory/embeddings-openai.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
**Context used:**
- Context from `dashboard` - CLAUDE.md ([source](https://app.greptile.com/review/custom-context?memory=fd949e91-5c3a-4ab5-90a1-cbe184fd6ce8))
- Context from `dashboard` - AGENTS.md ([source](https://app.greptile.com/review/custom-context?memory=0d0c8278-ef8e-4d6c-ab21-f5527e322f13))
<!-- /greptile_comment -->
Most Similar PRs
#5808: fix(memory): truncate oversized chunks before embedding
by douvy · 2026-02-01
80.7%
#10636: fix: setTimeout integer overflow causing server crash
by devmangel · 2026-02-06
77.2%
#8675: fix: Gemini batch embeddings state path, enum values, and download URL
by seasalim · 2026-02-04
74.6%
#20149: fix(memory): expose index concurrency as config option
by togotago · 2026-02-18
74.4%
#8713: feat: gateway memory monitor, install linger, docs and failover
by quratus · 2026-02-04
74.3%
#7316: fix: /chat dashboard performance
by felipcsousa · 2026-02-02
74.3%
#4534: fix: packaging and OpenAI vision format conversion
by SalimBinYousuf1 · 2026-01-30
74.3%
#7247: fix(telegram): abort stale getUpdates connections after long-poll t...
by JanderV · 2026-02-02
73.8%
#20148: fix(memory): persist session dirty state and fix reindex gate
by togotago · 2026-02-18
73.8%
#9085: fix: improve stability for terminated responses and telegram retries
by vladdick88 · 2026-02-04
73.4%