|
1 | 1 | import { execSync } from 'child_process' |
2 | 2 | import path from 'path' |
3 | 3 |
|
| 4 | +import { withTimeout } from '@codebuff/common/util/promise' |
4 | 5 | import { loadLocalAgents } from '@codebuff/npm-app/agents/load-agents' |
5 | 6 | import { CodebuffClient } from '../../sdk/src/client' |
6 | 7 | import { withTestRepo } from '../subagents/test-repo-utils' |
@@ -71,31 +72,36 @@ export async function runAgentOnCommit({ |
71 | 72 | } |
72 | 73 | } |
73 | 74 |
|
74 | | - const result = await client.run({ |
75 | | - agent: agentId, |
76 | | - prompt: commit.prompt, |
77 | | - agentDefinitions: localAgentDefinitions, |
78 | | - cwd: repoDir, |
79 | | - handleEvent: (event) => { |
80 | | - if (event.type === 'text') { |
81 | | - if (toolResults.length > 0) { |
| 75 | + const timeoutMs = 10 * 60 * 1000 // 10 minutes |
| 76 | + const result = await withTimeout( |
| 77 | + client.run({ |
| 78 | + agent: agentId, |
| 79 | + prompt: commit.prompt, |
| 80 | + agentDefinitions: localAgentDefinitions, |
| 81 | + cwd: repoDir, |
| 82 | + handleEvent: (event) => { |
| 83 | + if (event.type === 'text') { |
| 84 | + if (toolResults.length > 0) { |
| 85 | + flushStep() |
| 86 | + } |
| 87 | + responseText += event.text |
| 88 | + } else if (event.type === 'tool_call') { |
| 89 | + if (event.toolName === 'set_messages') { |
| 90 | + return |
| 91 | + } |
| 92 | + toolCalls.push(event) |
| 93 | + } else if (event.type === 'tool_result') { |
| 94 | + toolResults.push(event) |
| 95 | + } else if (event.type === 'finish') { |
82 | 96 | flushStep() |
| 97 | + } else if (event.type === 'error') { |
| 98 | + console.error(`[${agentId}] Error event:`, event.message) |
83 | 99 | } |
84 | | - responseText += event.text |
85 | | - } else if (event.type === 'tool_call') { |
86 | | - if (event.toolName === 'set_messages') { |
87 | | - return |
88 | | - } |
89 | | - toolCalls.push(event) |
90 | | - } else if (event.type === 'tool_result') { |
91 | | - toolResults.push(event) |
92 | | - } else if (event.type === 'finish') { |
93 | | - flushStep() |
94 | | - } else if (event.type === 'error') { |
95 | | - console.error(`[${agentId}] Error event:`, event.message) |
96 | | - } |
97 | | - }, |
98 | | - }) |
| 100 | + }, |
| 101 | + }), |
| 102 | + timeoutMs, |
| 103 | + `Agent ${agentId} timed out after ${timeoutMs / 1000} seconds`, |
| 104 | + ) |
99 | 105 |
|
100 | 106 | flushStep() |
101 | 107 | cost = result.sessionState.mainAgentState.creditsUsed / 100 |
|
0 commit comments