Skip to content

Commit 9382b63

Browse files
committed
debugging opencode failures on gpt-5-codex
1 parent 034d049 commit 9382b63

File tree

1 file changed

+33
-18
lines changed

1 file changed

+33
-18
lines changed

agents/opencode.ts

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,34 +22,49 @@ const DEFAULT_PERMISSION_CONFIG: NonNullable<OpencodeConfig["permission"]> = {
2222
webfetch: "allow",
2323
};
2424

25-
// Custom fetch with focused error logging
25+
// Custom fetch with focused error logging and extended timeout
2626
const customFetch = async (request: Request): Promise<Response> => {
2727
const startTime = Date.now();
2828

2929
try {
30-
const response = await fetch(request);
31-
const duration = Date.now() - startTime;
30+
// Create AbortController with 25-minute timeout
31+
const controller = new AbortController();
32+
const timeoutId = setTimeout(() => controller.abort(), 1_500_000);
3233

33-
// Only log non-OK responses or slow requests
34-
if (!response.ok || duration > 60000) {
35-
console.error(`[opencode] Request to ${request.url} - Status: ${response.status}, Duration: ${duration}ms`);
36-
37-
if (!response.ok) {
38-
try {
39-
const clonedResponse = response.clone();
40-
const responseText = await clonedResponse.text();
41-
console.error(`[opencode] Full error response body:`, responseText);
42-
} catch (e) {
43-
console.error(`[opencode] Could not read error response body`);
34+
try {
35+
const response = await fetch(request, { signal: controller.signal });
36+
clearTimeout(timeoutId);
37+
const duration = Date.now() - startTime;
38+
39+
// Only log non-OK responses or slow requests
40+
if (!response.ok || duration > 60000) {
41+
console.error(`[opencode] Request to ${request.url} - Status: ${response.status}, Duration: ${duration}ms`);
42+
43+
if (!response.ok) {
44+
try {
45+
const clonedResponse = response.clone();
46+
const responseText = await clonedResponse.text();
47+
console.error(`[opencode] Full error response body:`, responseText);
48+
} catch (e) {
49+
console.error(`[opencode] Could not read error response body`);
50+
}
4451
}
4552
}
46-
}
4753

48-
return response;
54+
return response;
55+
} catch (fetchError) {
56+
clearTimeout(timeoutId);
57+
throw fetchError;
58+
}
4959
} catch (error) {
5060
const duration = Date.now() - startTime;
5161
console.error(`[opencode] FETCH FAILED - URL: ${request.url}, Duration: ${duration}ms`);
52-
console.error(`[opencode] Error: ${error instanceof Error ? error.message : String(error)}`);
62+
63+
if (error instanceof Error && error.name === 'AbortError') {
64+
console.error(`[opencode] Error: Request timed out after 25 minutes`);
65+
} else {
66+
console.error(`[opencode] Error: ${error instanceof Error ? error.message : String(error)}`);
67+
}
5368

5469
if (error instanceof Error && error.stack) {
5570
console.error(`[opencode] Stack:`, error.stack);
@@ -63,7 +78,7 @@ const opencodePort = await detectPort(4096);
6378

6479
const opencode = await createOpencode({
6580
port: opencodePort,
66-
timeout: 600_000, // 10 minutes timeout for long-running LLM requests
81+
timeout: 1_500_000, // 25 minutes timeout for long-running LLM requests
6782
config: {
6883
permission: DEFAULT_PERMISSION_CONFIG,
6984
},

0 commit comments

Comments
 (0)