Require a timeout on every agent tool
This commit is contained in:
@@ -153,6 +153,7 @@ final class Chrome: @unchecked Sendable {
|
||||
}
|
||||
|
||||
func send(_ method: String, _ params: [String: Any] = [:], session: String? = nil, timeout: Int = 30) async throws -> [String: Any] {
|
||||
try Task.checkCancellation()
|
||||
let id = lock.withLock {
|
||||
next += 1
|
||||
return next
|
||||
@@ -180,7 +181,7 @@ final class Chrome: @unchecked Sendable {
|
||||
}
|
||||
}
|
||||
Task {
|
||||
await pause(timeout * 1000)
|
||||
try? await pause(timeout * 1000)
|
||||
resolve(id, .failure(ToolError("\(method) got no answer from Chrome in \(timeout)s")))
|
||||
}
|
||||
}
|
||||
@@ -413,7 +414,7 @@ func openChrome() async throws -> (Chrome, String) {
|
||||
if let chrome = await chromeFromProfile() {
|
||||
return (chrome, "started Chrome with byre's profile\n")
|
||||
}
|
||||
await pause(200)
|
||||
try await pause(200)
|
||||
}
|
||||
throw ToolError("Chrome's debugger for byre's profile didn't answer within 15s; quit any already-running byre-profile Chrome once and retry")
|
||||
}
|
||||
@@ -528,7 +529,7 @@ func traceStop(_ c: Chrome, _ t: TabState, _ target: String) async throws -> Str
|
||||
if Date().timeIntervalSince(start) > 60 {
|
||||
throw ToolError("Chrome didn't finish the trace within 60s")
|
||||
}
|
||||
await pause(100)
|
||||
try await pause(100)
|
||||
stream = c.lock.withLock { t.traceStream }
|
||||
}
|
||||
var data = Data()
|
||||
@@ -686,14 +687,14 @@ func chromeTool(_ args: [String: Any]) async throws -> [Content] {
|
||||
if let err = r.string("errorText") {
|
||||
throw ToolError("navigating to \(url) failed: \(err)")
|
||||
}
|
||||
let timeout = Double(try args.ms("timeout_ms") ?? 15000) / 1000
|
||||
let timeout = Double(try args.ms("wait_timeout_ms") ?? 15000) / 1000
|
||||
let start = Date()
|
||||
await pause(300)
|
||||
try await pause(300)
|
||||
var loaded = false
|
||||
while !loaded, Date().timeIntervalSince(start) < timeout {
|
||||
loaded = (try? await evaluate(c, t, "document.readyState")) == "complete"
|
||||
if !loaded {
|
||||
await pause(200)
|
||||
try await pause(200)
|
||||
}
|
||||
}
|
||||
log.append(String(format: loaded ? "loaded after %.1fs" : "still loading after %.1fs", Date().timeIntervalSince(start)))
|
||||
|
||||
Reference in New Issue
Block a user