-
Notifications
You must be signed in to change notification settings - Fork 1.1k
feat(ask): Add configurable max timeout for ask endpoint #1853
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat(ask): Add configurable max timeout for ask endpoint #1853
Conversation
WalkthroughA new configuration parameter for maximum ask query timeout was introduced and propagated through the service configuration, initialization, and request handling layers. The ask service now enforces per-request timeouts, with explicit error handling for queries exceeding the allowed duration. The changes add new configuration fields and refactor the ask logic to support timeout enforcement. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant API
participant AskService
participant _ask (internal)
Client->>API: Send AskRequest (with optional timeout)
API->>AskService: call ask(AskRequest)
AskService->>_ask: Run _ask within asyncio.wait_for (timeout = min(request.timeout, max_ask_timeout))
alt Query completes in time
_ask-->>AskService: Result
AskService-->>API: Return result
else Query times out
AskService-->>API: Return error ("Query timed out")
end
API-->>Client: Respond with result or timeout error
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~15 minutes Poem
Note ⚡️ Unit Test Generation is now available in beta!Learn more here, or try it out under "Finishing Touches" below. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
@SyedaAnshrahGillani great feature! thanks for contribution! I will review and test it asap |
This pull request enhances the timeout functionality for the /asks endpoint
by introducing a configurable maximum timeout. This provides an important
safety rail, preventing users from setting excessively long timeouts and
ensuring the stability of the service.
Use Case
While the initial timeout feature allows clients to specify a timeout, a user
could still potentially set a very large value (e.g., 1 hour), tying up
server resources for an unreasonable amount of time. This could happen by
mistake or with malicious intent.
By adding a server-side max_ask_timeout (e.g., 5 minutes), we can enforce a
reasonable upper bound. If a user requests a timeout longer than the allowed
maximum, the service will automatically cap it at the configured maximum,
preventing resource exhaustion and ensuring fair use.
Changes
config.py, allowing administrators to define a global maximum timeout for
all ask queries.
max_ask_timeout value.
setting to the AskService during instantiation.
This feature further improves the robustness and resilience of the Wren AI
service by providing administrators with more control over resource usage
and protecting against potential abuse.
If you find this feature meaningful and intend to add timeout functionality,
you may merge this pull request.
Summary by CodeRabbit