fix(serper): add request timeout and credential guard#3468
Open
Harsh23Kashyap wants to merge 2 commits into
Open
fix(serper): add request timeout and credential guard#3468Harsh23Kashyap wants to merge 2 commits into
Harsh23Kashyap wants to merge 2 commits into
Conversation
Mirrors the same three-bug reliability pattern from PR langgenius#3456 (tools/google) and PR langgenius#3466 (tools/searchapi): - requests.get had no timeout= argument; stalled hosts blocked until the framework-level 120s ceiling. Add timeout=10. - self.runtime.credentials["serperapi_api_key"] raised KeyError when the key was absent or empty. Replace with an early guard that yields a friendly error message and returns; use .get() for the value lookup. - Wrap the HTTP call in try/except requests.RequestException so a timeout, connection reset, DNS failure, or 5xx surfaces as a friendly message instead of a stack trace. serper has no user-supplied hl / gl (the values are hardcoded to "us" / "en"), so the invoke fall-through bug from PR langgenius#3456 does not apply. No public API change; successful 200-path responses are byte-identical. Adds tools/serper/tests/test_serper.py with 6 in-process test cases. Bumps manifest 0.0.7 -> 0.0.8. Refs langgenius#3465 Refs langgenius#3456
This was referenced Jul 20, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
Adds reliability safeguards to the Serper tool.
Changes:
- Adds credential validation and a 10-second request timeout.
- Converts request failures into user-facing messages.
- Adds regression tests and bumps the plugin version.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
tools/serper/tools/serper_search.py |
Adds credential and request-error handling. |
tools/serper/tests/test_serper.py |
Tests credentials, timeout, failures, and success. |
tools/serper/tests/__init__.py |
Initializes the tests package. |
tools/serper/manifest.yaml |
Bumps version to 0.0.8. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+38
to
+42
| except requests.exceptions.RequestException as exc: | ||
| yield self.create_text_message( | ||
| f"An error occurred while invoking the tool: {exc}." | ||
| ) | ||
| return |
| @@ -0,0 +1,212 @@ | |||
| """In-process tests for tools/serper (no pytest required). | |||
Comment on lines
+12
to
+14
| They use only Python stdlib (`unittest.mock`) and tiny in-test stubs for | ||
| `requests`, `dify_plugin`, and `pydantic` so they can run in environments | ||
| where the plugin dependencies are not pre-installed. |
Drop the misleading no-pytest-required wording and remove pydantic from the stub dependency list. The test file uses bare test_* functions with assert and is intended to run under pytest. Refs langgenius#3465
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mirrors the same two-bug reliability pattern that PR #3456 (already MERGED on 2026-07-20,
tools/google) and PR #3466 (tools/searchapi, opened today) just fixed, applied totools/serper.Refs #3465 (umbrella tracker — also includes
tools/{searchapi, tianditu}).Changes
requests.get(...)now passestimeout=10. 10 s is well above the upstream Serper.dev p99 and well below the framework-level 120 s ceiling.self.runtime.credentials["serperapi_api_key"]is replaced with an early guard that yields"Serper.dev API key is required."and returns; the value is read via.get(). No moreKeyErroron a missing or empty key.try/except requests.exceptions.RequestExceptionso a timeout, connection reset, DNS failure, or 5xx surfaces as a friendly message instead of a stack trace.tools/serper/tests/test_serper.pywith 6 in-process test cases (nopytestordify_pluginruntime needed — uses onlyunittest.mock+ minimal sys-modules stubs).manifest.yamlPATCH bump0.0.7 -> 0.0.8.serper_search.pydoes not take user-suppliedhl/gl(the values are hardcoded to"us"/"en"), so the third bug from PR #3456 (invoke fall-through on invalidhl/gl) does not apply.Change Type
LLM Plugin Checklist
Not applicable — this is a tool plugin.
Version
manifest.yamlis0.0.8.requests>=2.34.2is already declared and locked.Testing
python3 -m pytest tests/test_serper.py -v-> 6 passed.uv run --frozen ruff check .-> All checks passed.python3 -m py_compile tools/serper_search.py tests/test_serper.py-> OK.Risks
Out of scope (deliberate)
tools/*.References
tools/google.tools/searchapiPR from this same rollout.tools/{searchapi, serper, tianditu}.