Skip to content

Fix: add watchdog timer to unblock Gemini when OpenClaw tool call stalls#51

Open
kbaker827 wants to merge 1 commit intoIntent-Lab:mainfrom
kbaker827:fix/tool-call-timeout
Open

Fix: add watchdog timer to unblock Gemini when OpenClaw tool call stalls#51
kbaker827 wants to merge 1 commit intoIntent-Lab:mainfrom
kbaker827:fix/tool-call-timeout

Conversation

@kbaker827
Copy link
Copy Markdown

Problem

When Gemini delegates a task that involves a slow OpenClaw skill (web search, sending a message to an external service, etc.), the conversation freezes. The UI shows Running: execute... and Gemini never speaks again. The underlying cause is that there is no per-call deadline — the conversation just waits for the 120s URLSession hard timeout, which is far too long for a voice interaction.

Fixes #12

Solution

Race the delegateTask call against a 60-second watchdog inside withTaskGroup. The first child to finish wins, the other is cancelled immediately:

let result = await withTaskGroup(of: ToolResult.self) { group in
    group.addTask { await bridge.delegateTask(...) }
    group.addTask {
        try? await Task.sleep(nanoseconds: 60 * 1_000_000_000)
        return .failure("The gateway did not respond within 60 seconds. ...")
    }
    let first = await group.next()!
    group.cancelAll()
    return first
}

If the gateway responds in time, the watchdog task is cancelled and no behaviour changes. If the gateway stalls, Gemini receives a clear failure message after 60 seconds and can speak an apology, keeping the conversation alive.

Test plan

  • Configure OpenClaw and ask Gemini to search the web while OpenClaw is intentionally slow/unreachable
  • Confirm the UI transitions from "Running: execute..." to "Failed: execute" within ~60 seconds
  • Confirm Gemini speaks a timeout apology rather than hanging
  • Confirm fast tool calls (< 60s) are unaffected

🤖 Generated with Claude Code

Tool calls involving web search or slow external services could leave
Gemini stuck in the "execute" state indefinitely. The URLSession has a
120s hard timeout, but that's long enough to make the conversation feel
completely frozen.

Race the delegate call against a 60s watchdog using withTaskGroup. The
first result wins and cancels the other child task. If the watchdog fires,
Gemini receives a clear timeout failure and can speak an apology instead
of hanging silently.

Fixes Intent-Lab#12

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini stuck once it tries to search the web

1 participant