Skip to content

Commit 00a30e3

Browse files
committed
Optimize queue fetching to prevent choppy playback with large queues
- Add skipQueue parameter to getNowPlaying() function - Skip queue fetching during status polling (every 2s) to avoid choppy playback - Queue is only fetched when needed (e.g., admin UI showing next tracks) - Fixes issue with choppy playback when queue has 400+ tracks - Minor formatting/whitespace cleanup in other files
1 parent 7401351 commit 00a30e3

7 files changed

Lines changed: 52 additions & 42 deletions

File tree

.github/agent/agent.mjs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,48 +1229,48 @@ This is ONE FILE ONLY. Generate the complete diff now:`;
12291229
if (!filesToModify || allDiffs.length === 0) {
12301230
console.log(`[AGENT] Using single-pass generation method...`);
12311231
const apiStartTime = Date.now();
1232-
try {
1233-
output = await retryWithBackoff(async () => {
1234-
return await callAI(prompt);
1235-
}, 3, 1000);
1236-
const apiDuration = Date.now() - apiStartTime;
1237-
console.log(`[AGENT] API call completed in ${apiDuration}ms`);
1238-
} catch (error) {
1239-
const errorDetails = formatErrorDetails(error, {});
1240-
await handleError(error, `${provider.toUpperCase()} API Error`, { errorDetails });
1241-
// handleError calls process.exit(1), so we never reach here
1232+
try {
1233+
output = await retryWithBackoff(async () => {
1234+
return await callAI(prompt);
1235+
}, 3, 1000);
1236+
const apiDuration = Date.now() - apiStartTime;
1237+
console.log(`[AGENT] API call completed in ${apiDuration}ms`);
1238+
} catch (error) {
1239+
const errorDetails = formatErrorDetails(error, {});
1240+
await handleError(error, `${provider.toUpperCase()} API Error`, { errorDetails });
1241+
// handleError calls process.exit(1), so we never reach here
12421242
}
12431243
}
12441244

12451245
// Extract diff from potential markdown code blocks (only if using fallback method)
12461246
let diff = output.trim();
12471247
if (!filesToModify || allDiffs.length === 0) {
12481248
// Only do markdown extraction for fallback single-pass method
1249-
if (output.includes("```")) {
1250-
// Try to extract content between code fences
1251-
// Handle both single and multiple code blocks
1252-
const matches = output.matchAll(/```(?:diff)?\n([\s\S]*?)```/g);
1253-
const extractedDiffs = [];
1254-
for (const match of matches) {
1255-
extractedDiffs.push(match[1].trim());
1256-
}
1257-
// Use the longest extracted diff (likely the actual diff)
1258-
if (extractedDiffs.length > 0) {
1259-
diff = extractedDiffs.reduce((a, b) => a.length > b.length ? a : b);
1260-
}
1261-
1262-
// If no code blocks found but output contains diff markers, use the whole output
1263-
if (!diff.includes("--- a/") && output.includes("--- a/")) {
1264-
// Extract everything after the first "--- a/" line
1265-
const diffStart = output.indexOf("--- a/");
1266-
diff = output.substring(diffStart).trim();
1267-
// Remove any trailing markdown or explanations
1268-
const diffEnd = diff.indexOf("\n\n```") !== -1 ? diff.indexOf("\n\n```") :
1269-
diff.indexOf("\n\n##") !== -1 ? diff.indexOf("\n\n##") :
1270-
diff.indexOf("\n\n**") !== -1 ? diff.indexOf("\n\n**") :
1271-
diff.length;
1272-
diff = diff.substring(0, diffEnd).trim();
1273-
}
1249+
if (output.includes("```")) {
1250+
// Try to extract content between code fences
1251+
// Handle both single and multiple code blocks
1252+
const matches = output.matchAll(/```(?:diff)?\n([\s\S]*?)```/g);
1253+
const extractedDiffs = [];
1254+
for (const match of matches) {
1255+
extractedDiffs.push(match[1].trim());
1256+
}
1257+
// Use the longest extracted diff (likely the actual diff)
1258+
if (extractedDiffs.length > 0) {
1259+
diff = extractedDiffs.reduce((a, b) => a.length > b.length ? a : b);
1260+
}
1261+
1262+
// If no code blocks found but output contains diff markers, use the whole output
1263+
if (!diff.includes("--- a/") && output.includes("--- a/")) {
1264+
// Extract everything after the first "--- a/" line
1265+
const diffStart = output.indexOf("--- a/");
1266+
diff = output.substring(diffStart).trim();
1267+
// Remove any trailing markdown or explanations
1268+
const diffEnd = diff.indexOf("\n\n```") !== -1 ? diff.indexOf("\n\n```") :
1269+
diff.indexOf("\n\n##") !== -1 ? diff.indexOf("\n\n##") :
1270+
diff.indexOf("\n\n**") !== -1 ? diff.indexOf("\n\n**") :
1271+
diff.length;
1272+
diff = diff.substring(0, diffEnd).trim();
1273+
}
12741274
}
12751275
} else {
12761276
// For one-file-at-a-time, diff is already clean (output from combined diffs)
@@ -1372,9 +1372,9 @@ if (validationResult.errors.length > 0 || diff.match(/\+\+\+ b\/[^\n]*$/m)) {
13721372
}
13731373

13741374
const errorMsg = `${truncationReason}. The AI model may have generated an incomplete diff.\n\nErrors:\n${validationResult.errors.join('\n')}\n\nAPI Response Info:\n- Stop reason: ${stopReason}\n- Output tokens used: ${outputTokens}\n- Was truncated: ${wasTruncated}\n\nDiff preview (last 500 chars):\n\`\`\`\n${diff.substring(Math.max(0, diffLength - 500))}\n\`\`\`\n\nPossible causes:\n- Model hit output token limit (check max_tokens setting)\n- Input context too large, leaving insufficient room for output\n- Model stopped generating for other reasons\n\nSuggestions:\n- Reduce input context size (fewer files) - already reduced to 400KB\n- Break task into smaller parts\n- Verify max_tokens is sufficient (currently 180K)`;
1375-
const errorDetails = formatErrorDetails(new Error(errorMsg), { diff: diff.substring(Math.max(0, diffLength - 1000)), files: validationResult.stats.filesChanged });
1375+
const errorDetails = formatErrorDetails(new Error(errorMsg), { diff: diff.substring(Math.max(0, diffLength - 1000)), files: validationResult.stats.filesChanged });
13761376
await handleError(new Error(errorMsg), "Incomplete Diff (Truncated)", { diff: diff.substring(Math.max(0, diffLength - 1000)), errorDetails });
1377-
// handleError calls process.exit(1), so we never reach here
1377+
// handleError calls process.exit(1), so we never reach here
13781378
}
13791379
}
13801380
}

app.manifest.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@
5656

5757

5858

59+
60+

docs/DISCORD_DISCOVERY_CONTENT.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,5 @@ Join our Discord server for:
109109

110110

111111

112+
113+

index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,15 +2340,15 @@ async function getNowPlaying(options = {}) {
23402340
// Only fetch queue if explicitly needed (skip for status polling to avoid choppy playback)
23412341
if (!skipQueue) {
23422342
promises.push(
2343-
sonos.getQueue().catch(err => {
2344-
// Ignore queue errors for now-playing
2345-
return null;
2346-
})
2343+
sonos.getQueue().catch(err => {
2344+
// Ignore queue errors for now-playing
2345+
return null;
2346+
})
23472347
);
23482348
} else {
23492349
promises.push(Promise.resolve(null));
23502350
}
2351-
2351+
23522352
const [state, volume, queue] = await Promise.all(promises);
23532353

23542354
// Fetch queue (next tracks) - only if we have queue data

lib/slack-validator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,5 @@ module.exports = {
9999

100100

101101

102+
103+

lib/sonos-discovery.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,3 +147,5 @@ module.exports = {
147147

148148

149149

150+
151+

lib/spotify-validator.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,5 @@ module.exports = {
6363

6464

6565

66+
67+

0 commit comments

Comments
 (0)