Skip to content

Commit d80c69e

Browse files
CopilotYuri05
andauthored
Fix timeouts in discussion-assistant.yml OpenAI embedding requests (#2133)
* Initial plan * Fix timeouts in discussion-assistant.yml: reduce batch size, increase timeout, add retry logic - Reduce OpenAI embedding batch size from 100 to 50 - Increase fetch timeout from 30s to 60s - Add retry logic (3 attempts) with exponential backoff - Increase inter-batch delay from 500ms to 1000ms - Raise discussion fetch limit from 500 to 1000 Co-authored-by: Yuri05 <25061876+Yuri05@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Yuri05 <25061876+Yuri05@users.noreply.github.com>
1 parent 43e4266 commit d80c69e

1 file changed

Lines changed: 31 additions & 22 deletions

File tree

.github/workflows/discussion-assistant.yml

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ jobs:
9797
cursor = result.repository.discussions.pageInfo.endCursor;
9898
9999
// Limit to prevent excessive API calls (adjust as needed)
100-
if (allDiscussions.length >= 500) break;
100+
if (allDiscussions.length >= 1000) break;
101101
}
102102
103103
console.log(`Fetched ${allDiscussions.length} existing discussions (excluding ignored categories)`);
@@ -119,34 +119,43 @@ jobs:
119119
// Prepare texts for batch embedding with indices
120120
const existingTexts = existingDiscussions.map(d => `${d.title}\n${d.body || ''}`);
121121
122-
// Process in batches of 100
123-
const BATCH_SIZE = 100;
122+
// Process in batches of 50
123+
const BATCH_SIZE = 50;
124+
const MAX_RETRIES = 3;
124125
const discussionEmbeddings = []; // Array of {discussion, embedding} pairs
125126
126127
for (let i = 0; i < existingTexts.length; i += BATCH_SIZE) {
127128
const batchStart = i;
128129
const batchEnd = Math.min(i + BATCH_SIZE, existingTexts.length);
129130
const batch = existingTexts.slice(batchStart, batchEnd);
130131
131-
try {
132-
const batchEmbeddings = await getEmbedding(batch, apiKey);
133-
if (!Array.isArray(batchEmbeddings) || batchEmbeddings.length !== batch.length) {
134-
throw new Error(`Expected ${batch.length} embeddings, got ${batchEmbeddings?.length || 0}`);
135-
}
136-
// Map embeddings back to their discussions
137-
for (let j = 0; j < batchEmbeddings.length; j++) {
138-
discussionEmbeddings.push({
139-
discussion: existingDiscussions[batchStart + j],
140-
embedding: batchEmbeddings[j]
141-
});
142-
}
143-
// Small delay between batches to avoid rate limits
144-
if (i + BATCH_SIZE < existingTexts.length) {
145-
await new Promise(resolve => setTimeout(resolve, 500));
132+
let success = false;
133+
for (let attempt = 1; attempt <= MAX_RETRIES && !success; attempt++) {
134+
try {
135+
const batchEmbeddings = await getEmbedding(batch, apiKey);
136+
if (!Array.isArray(batchEmbeddings) || batchEmbeddings.length !== batch.length) {
137+
throw new Error(`Expected ${batch.length} embeddings, got ${batchEmbeddings?.length || 0}`);
138+
}
139+
// Map embeddings back to their discussions
140+
for (let j = 0; j < batchEmbeddings.length; j++) {
141+
discussionEmbeddings.push({
142+
discussion: existingDiscussions[batchStart + j],
143+
embedding: batchEmbeddings[j]
144+
});
145+
}
146+
success = true;
147+
} catch (batchError) {
148+
console.error(`Error processing batch ${Math.floor(i / BATCH_SIZE) + 1} (discussions ${batchStart}-${batchEnd - 1}), attempt ${attempt}/${MAX_RETRIES}:`, batchError);
149+
if (attempt < MAX_RETRIES) {
150+
const backoff = Math.pow(2, attempt) * 1000;
151+
console.log(`Retrying in ${backoff / 1000}s...`);
152+
await new Promise(resolve => setTimeout(resolve, backoff));
153+
}
146154
}
147-
} catch (batchError) {
148-
console.error(`Error processing batch ${Math.floor(i / BATCH_SIZE) + 1} (discussions ${batchStart}-${batchEnd - 1}):`, batchError);
149-
// Skip this batch and continue with next one
155+
}
156+
// Delay between batches to avoid rate limits
157+
if (i + BATCH_SIZE < existingTexts.length) {
158+
await new Promise(resolve => setTimeout(resolve, 1000));
150159
}
151160
}
152161
@@ -197,7 +206,7 @@ jobs:
197206
? text.map(t => t.substring(0, 8000))
198207
: text.substring(0, 8000)
199208
}),
200-
signal: AbortSignal.timeout(30000) // 30s timeout
209+
signal: AbortSignal.timeout(60000) // 60s timeout
201210
});
202211
203212
if (!response.ok) {

0 commit comments

Comments
 (0)