Skip to content

fix(hitl): respect poll_interval parameter in _poll_for_decision - #192

Open
RobinaMirbahar wants to merge 1 commit into
google:mainfrom
RobinaMirbahar:fix/191-hitl-poll-interval
Open

RobinaMirbahar wants to merge 1 commit into
google:mainfrom
RobinaMirbahar:fix/191-hitl-poll-interval

Conversation

@RobinaMirbahar

Copy link
Copy Markdown

Have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

Problem:
hitl_tool accepts a poll_interval: float = POLL_INTERVAL_S parameter and passes it as interval to _poll_for_decision(api_base, request_id, poll_interval, timeout) in src/google/adk_community/tools/hitl/gateway.py. However, inside _poll_for_decision, the sleep call hardcoded the module-level POLL_INTERVAL_S constant (await asyncio.sleep(POLL_INTERVAL_S + random.uniform(0, POLL_JITTER_S))) instead of using the interval parameter. Consequently, passing a custom poll_interval to @hitl_tool(agent_name="...", poll_interval=...) had no effect on polling delay.

Solution:

  • Updated _poll_for_decision in src/google/adk_community/tools/hitl/gateway.py to use interval + random.uniform(0, POLL_JITTER_S) when sleeping between pending poll cycles. Callers omitting poll_interval continue to default to POLL_INTERVAL_S (ADK_HITL_POLL_INTERVAL_S).
  • Added unit tests in tests/unittests/tools/test_hitl_gateway.py verifying that a custom poll_interval is passed to asyncio.sleep while polling a "pending" request and that TimeoutError is raised when polling exceeds timeout.

Testing Plan

1. Unit Tests (Command & Logs)

uv sync --extra test
pytest tests/unittests/tools/test_hitl_gateway.py -v
pytest tests/unittests

Verifiable Test Execution Log Output:

============================= test session starts =============================
platform win32 -- Python 3.12.15, pytest-9.1.1, pluggy-1.7.0
configfile: pyproject.toml
plugins: anyio-4.15.1, asyncio-1.4.1
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=function, asyncio_default_test_loop_scope=function
collected 8 items

tests/unittests/tools/test_hitl_gateway.py::test_serialise_args_positional PASSED [ 12%]
tests/unittests/tools/test_hitl_gateway.py::test_serialise_args_kwargs_only PASSED [ 25%]
tests/unittests/tools/test_hitl_gateway.py::test_serialise_args_non_serialisable_falls_back_to_str PASSED [ 37%]
tests/unittests/tools/test_hitl_gateway.py::test_approved_tool_runs PASSED [ 50%]
tests/unittests/tools/test_hitl_gateway.py::test_rejected_tool_raises PASSED [ 62%]
tests/unittests/tools/test_hitl_gateway.py::test_escalated_tool_raises PASSED [ 75%]
tests/unittests/tools/test_hitl_gateway.py::test_custom_poll_interval_used_while_pending PASSED [ 87%]
tests/unittests/tools/test_hitl_gateway.py::test_timeout_raises_timeout_error PASSED [100%]

============================== 8 passed in 4.03s ==============================

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • I have checked formatting matches styles.

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.

hitl_tool: _poll_for_decision ignores interval parameter and always sleeps for POLL_INTERVAL_S

1 participant