8000 fix(wait): apply the configured timeout and honor cancellation by HankGrimm · Pull Request #4600 · googleapis/mcp-toolbox · GitHub
[go: up one dir, main page]

Skip to content

fix(wait): apply the configured timeout and honor cancellation - #4600

Open
HankGrimm wants to merge 2 commits into
googleapis:mainfrom
HankGrimm:fix/wait-tool-timeout
Open

HankGrimm wants to merge 2 commits into
googleapis:mainfrom
HankGrimm:fix/wait-tool-timeout

Conversation

@HankGrimm
Copy link
Copy Markdown

Description

The wait tool parsed only duration and called time.Sleep unconditionally,
so the required timeout cap was never applied and cancelling the MCP request
did not stop the sleep.

Invoke now rejects a duration longer than the configured timeout, and
selects on ctx.Done() so cancellation aborts the sleep.

PR Checklist

  • Make sure you reviewed CONTRIBUTING.md
  • Ensure you have manually reviewed the entire diff before requesting a review
  • Ensure the tests and linter pass
  • Code coverage does not decrease (added TestWaitInvokeRespectsTimeout)
  • Appropriate docs were updated (not necessary for this bug fix)

🛠️ Fixes #4581

Invoke parsed only duration and called time.Sleep unconditionally, so the
required timeout cap was never applied and cancelling the MCP request did
not stop the sleep.

Reject a duration longer than the configured timeout, and select on
ctx.Done() so cancellation aborts the sleep.

Fixes googleapis#4581
@HankGrimm
HankGrimm requested a review from a team as a code owner November 25, 2026 02:07
@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the wait tool's Invoke method to enforce a configured timeout limit and support early cancellation by replacing time.Sleep with a timer and select block. It also adds corresponding unit tests. The feedback suggests optimizing performance and error detection by parsing and validating the configured timeout during the tool's initialization phase rather than on every invocation. Additionally, it recommends validating that the requested duration is strictly positive to prevent logical errors.

Comment thread internal/tools/utility/wait/wait.go Outdated
Comment on lines +97 to +100
timeout, err := time.ParseDuration(t.Cfg.Timeout)
if err != nil {
return nil, util.NewAgentError("invalid timeout configuration", err)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Parsing and validating the tool's configured timeout (t.Cfg.Timeout) on every invocation is inefficient and delays configuration error detection to runtime. Instead, this validation should be performed during the tool's initialization phase in Initialize (where an invalid timeout string can be rejected immediately at startup), and the parsed time.Duration can be stored in the Tool struct.

Comment thread internal/tools/utility/wait/wait.go Outdated
Comment on lines +101 to +104
if totalDuration > timeout {
return nil, util.NewAgentError(
fmt.Sprintf("duration %v exceeds the configured timeout %v", totalDuration, timeout), nil)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The duration parameter is parsed as a time.Duration, which can be negative or zero (e.g., "-5s" or "0s"). Waiting for a non-positive duration is a logical error and should be rejected with an error. Adding a validation check ensures that only positive durations are accepted.

Suggested change
if totalDuration > timeout {
return nil, util.NewAgentError(
fmt.Sprintf("duration %v exceeds the configured timeout %v", totalDuration, timeout), nil)
}
if totalDuration <= 0 {
return nil, util.NewAgentError("duration must be greater than zero", nil)
}
if totalDuration > timeout {
return nil, util.NewAgentError(
fmt.Sprintf("duration %v exceeds the configured timeout %v", totalDuration, timeout), nil)
}

…tions

Address review feedback: parse cfg.Timeout once in Initialize (storing the
time.Duration) instead of on every Invoke, and reject a non-positive duration
parameter.

Fixes googleapis#4581

This branch has not been deployed

No deployments
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.

wait tool ignores its configured timeout

2 participants

0