Skip to content

[WIP]test: setup itk resubscribe tests#1031

Open
kdziedzic70 wants to merge 1 commit intomainfrom
dziedzick/setup-itk-resubscribe-tests
Open

[WIP]test: setup itk resubscribe tests#1031
kdziedzic70 wants to merge 1 commit intomainfrom
dziedzick/setup-itk-resubscribe-tests

Conversation

@kdziedzic70
Copy link
Copy Markdown
Contributor

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

Fixes #<issue_number_goes_here> 🦕

@kdziedzic70 kdziedzic70 requested a review from a team as a code owner April 30, 2026 09:41
Comment thread itk/main.py
TaskPushNotificationConfig,
)
from a2a.utils import TransportProtocol
from a2a.utils.errors import TaskNotCancelableError
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 introduces 'resubscribe' and 'hold task' behaviors to the ITK agent, adds helper functions for event and task management, and improves resource handling via an asynchronous context manager for the HTTP client. It also implements signal handling for graceful shutdowns, updates agent capabilities, and expands the test suite. Feedback was provided to correct Protobuf field presence checks and enum comparisons, remove a deprecated parameter, and restore configurable logging for the uvicorn server.

Comment thread itk/main.py
Comment on lines +160 to +163
if hasattr(event, 'task'):
task_obj = event.task
elif hasattr(event, 'HasField') and event.HasField('task'):
task_obj = event.task
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.

high

The logic to extract task_obj from the event is potentially incorrect. For a protobuf message like StreamResponse, hasattr(event, 'task') will always be True, but this doesn't mean the task field is actually set in the message. Accessing event.task when the field is not set will give you a default Task instance, which is likely not what you want. The correct way to check for presence is event.HasField('task').

The elif condition is currently unreachable because the if condition will always be met for a StreamResponse object. I suggest simplifying this block to correctly check for the task field.

Suggested change
if hasattr(event, 'task'):
task_obj = event.task
elif hasattr(event, 'HasField') and event.HasField('task'):
task_obj = event.task
if event.HasField('task'):
task_obj = event.task

Comment thread itk/main.py
if not results and task_obj and hasattr(task_obj, 'history'):
logger.info('Results empty after loop, reading from history.')
for msg in task_obj.history:
if msg.role == 'ROLE_AGENT' or msg.role == 'agent':
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.

high

Comparing the role enum field with strings like 'ROLE_AGENT' or 'agent' is not reliable and is likely incorrect. Protobuf enums in Python are integers, so this comparison will likely always evaluate to false. You should compare msg.role with the actual enum member.

To do this, you'll need to import Role from a2a.types.a2a_pb2 at the top of the file.

Suggested change
if msg.role == 'ROLE_AGENT' or msg.role == 'agent':
if msg.role == Role.ROLE_AGENT:

Comment thread itk/main.py
Comment on lines 471 to 475
push_sender = BasePushNotificationSender(
httpx_client=httpx.AsyncClient(),
httpx_client=httpx_client,
config_store=push_config_store,
context=ServerCallContext(),
)
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 context parameter of BasePushNotificationSender is deprecated and will be removed in a future version. The constructor logs a warning when it is used. You can safely remove it from this call.

    push_sender = BasePushNotificationSender(
        httpx_client=httpx_client,
        config_store=push_config_store,
    )

Comment thread itk/main.py

config = uvicorn.Config(
app, host='127.0.0.1', port=http_port, log_level=log_level_str.lower()
app, host='127.0.0.1', port=http_port, log_level='info'
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 log_level for uvicorn is now hardcoded to 'info'. This removes the ability to configure it using the ITK_LOG_LEVEL environment variable. It's better to restore the previous behavior to allow for flexible log level configuration during testing.

Suggested change
app, host='127.0.0.1', port=http_port, log_level='info'
app, host='127.0.0.1', port=http_port, log_level=log_level_str.lower()

@kdziedzic70 kdziedzic70 force-pushed the dziedzick/setup-itk-resubscribe-tests branch from 1464d89 to c7f3db7 Compare April 30, 2026 09:47
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.

1 participant