Skip to content

Fix: Deep Research Functionality - Parameter Fixes, Rate Limiting & Timeout Handling #16

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

deciduus
Copy link

@deciduus deciduus commented Apr 15, 2025

Fix: Deep Research Functionality - Parameter Fixes, Rate Limiting & Timeout Handling

Chronological Changes

1. Resolved Parameter and Async Issues (85a51c2)

  • Fixed parameter name mismatch in run_deep_search function
    • Changed max_search_iterations to max_search_iteration_input
    • Changed max_query_per_iteration to max_query_per_iter_input
  • Added missing await keyword when calling async run_deep_search function
  • Resolved errors:
    • Parameter name mismatch errors
    • Undefined variable errors
    • "Cannot unpack non-iterable coroutine object" error

2. Added Timeout Mechanism and Enhanced Rate Limiting (9db40cf)

  • Implemented timeout mechanism for research function
    • Added 4-minute (240s) default timeout to stay under MCP's 5-minute limit
    • Added checks before/after each search iteration
    • Ensures graceful termination with partial results when time is running out
  • Enhanced rate limiting implementation
    • Used RateLimiter singleton class respecting REQUESTS_PER_MINUTE variable
    • Applied rate limiting at key points in execution flow
    • Implemented queue system to handle request throttling
  • Updated configuration options
    • Added MCP_MAX_DURATION_SECONDS environment variable (default: 240)
    • Documented environment variables in server.py comments
  • Improved error handling
    • Added special report formatting for timeout/error cases
    • Ensured proper browser resource cleanup

End Result

Deep research now functions correctly with appropriate rate limiting and timeout behavior, preventing MCP timeouts while maximizing research quality within time constraints.

- Fix parameter name mismatch in run_deep_search function
- Add missing await keyword when calling async run_deep_search function
- Resolves three errors: parameter name mismatch, undefined variable, and "Cannot unpack non-iterable coroutine object"
- Implement 4-minute default timeout (configurable via MCP_MAX_DURATION_SECONDS)
- Add timeout checks before/after each search iteration
- Gracefully terminate with partial results when approaching timeout
- Properly integrate with existing rate limiter (REQUESTS_PER_MINUTE)
- Document environment variables in server.py
- Ensure browser resources are properly closed on early termination
@deciduus deciduus changed the title Fix: Resolve Deep Research functionality issues in server.py Fix: Deep Research Functionality - Parameter Fixes, Rate Limiting & Timeout Handling Apr 15, 2025
@Saik0s
Copy link
Owner

Saik0s commented May 10, 2025

Sorry for my late reply, and thank you for this contribution. I have updated some code, and deep research is working now, though I haven't tested the MCP timeouts yet. Given that this is such a lengthy process, I think it would be nice to implement state restoration to allow users to resume interrupted research sessions. Could you update the PR to reflect the latest changes?

@deciduus
Copy link
Author

deciduus commented May 10, 2025 via email

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.

3 participants