Skip to content

Commit b3cf6d9

Browse files
committed
Add timeout for running agent
1 parent 4d95f80 commit b3cf6d9

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

evals/buffbench/agent-runner.ts

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { execSync } from 'child_process'
22
import path from 'path'
33

4+
import { withTimeout } from '@codebuff/common/util/promise'
45
import { loadLocalAgents } from '@codebuff/npm-app/agents/load-agents'
56
import { CodebuffClient } from '../../sdk/src/client'
67
import { withTestRepo } from '../subagents/test-repo-utils'
@@ -71,31 +72,36 @@ export async function runAgentOnCommit({
7172
}
7273
}
7374

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') {
8296
flushStep()
97+
} else if (event.type === 'error') {
98+
console.error(`[${agentId}] Error event:`, event.message)
8399
}
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+
)
99105

100106
flushStep()
101107
cost = result.sessionState.mainAgentState.creditsUsed / 100

0 commit comments

Comments
 (0)