Skip to content

feat(lib): Add task updates to adk#299

Merged
declan-scale merged 1 commit intonextfrom
declan-scale/add-task-updates-to-adk
Mar 30, 2026
Merged

feat(lib): Add task updates to adk#299
declan-scale merged 1 commit intonextfrom
declan-scale/add-task-updates-to-adk

Conversation

@declan-scale
Copy link
Copy Markdown
Contributor

@declan-scale declan-scale commented Mar 30, 2026

Greptile Summary

Extends the ADK TasksModule with task lifecycle management: status transitions (cancel, complete, fail, terminate, timeout), metadata updates, and Temporal workflow querying. Changes span all three layers — module, service, and Temporal activities — following the established dual-path pattern (direct service call vs Temporal activity execution). Well-tested with comprehensive unit tests across all layers.

  • Adds 7 new operations to TasksModule: cancel, complete, fail, terminate, timeout, update, and query_workflow
  • Introduces 3 new param models: TaskStatusTransitionParams, UpdateTaskParams, QueryWorkflowParams
  • Registers all new activities in get_all_activities for Temporal worker discovery
  • Adds new test conftest to mock optional langchain/langgraph dependencies for isolated unit testing
  • The five status transition methods are nearly identical and could be consolidated into a generic helper per the project's refactoring guidance

Confidence Score: 4/5

This PR is safe to merge — it adds new functionality without modifying existing behavior, and follows established patterns consistently.

All new code follows the existing dual-path (Temporal vs direct) pattern. Good test coverage across all three layers. No logical errors found. Deducted one point for significant code repetition across the five status transition methods that could benefit from refactoring.

src/agentex/lib/adk/_modules/tasks.py and src/agentex/lib/core/services/adk/tasks.py have significant repetition in the status transition methods.

Important Files Changed

Filename Overview
src/agentex/lib/adk/_modules/tasks.py Adds 7 new public methods (cancel, complete, fail, terminate, timeout, update, query_workflow) following the established dual-path pattern. Significant code repetition across status transition methods.
src/agentex/lib/core/services/adk/tasks.py Adds 7 new service methods with tracing and heartbeat support. Includes proper validation in update_task for task_id/task_name. query_workflow correctly skips model_dump() since result is already a dict.
src/agentex/lib/core/temporal/activities/adk/tasks_activities.py Adds 7 new Temporal activity definitions and 3 new param models. Clean, straightforward wiring to service layer.
src/agentex/lib/core/temporal/activities/init.py Registers the 7 new task activities in get_all_activities for Temporal worker discovery.
tests/lib/adk/conftest.py New conftest mocking langchain_core and langgraph dependencies for isolated unit testing.
tests/lib/adk/test_tasks_activities.py Comprehensive activity-layer tests covering all new operations including edge cases.
tests/lib/adk/test_tasks_module.py Tests for the module layer covering both direct service calls and Temporal workflow paths.
tests/lib/adk/test_tasks_service.py Service-layer tests with proper mocking of tracing spans and client calls.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[TasksModule] -->|in_temporal_workflow?| B{Temporal Workflow?}
    B -->|Yes| C[ActivityHelpers.execute_activity]
    B -->|No| D[TasksService]
    C --> E[TasksActivities]
    E --> D
    D --> F[AsyncAgentex Client]

    subgraph "New Operations"
        G[cancel / complete / fail / terminate / timeout]
        H[update by id or name]
        I[query_workflow]
    end

    A --> G
    A --> H
    A --> I
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agentex/lib/adk/_modules/tasks.py
Line: 135-343

Comment:
**Highly repetitive status transition methods**

The five status transition methods (`cancel`, `complete`, `fail`, `terminate`, `timeout`) are structurally identical — they differ only in the activity name and service method called. Consider extracting a private helper like:

```python
async def _transition_status(
    self,
    *,
    activity_name: TasksActivityName,
    service_method: str,
    task_id: str,
    reason: str | None = None,
    trace_id: str | None = None,
    parent_span_id: str | None = None,
    start_to_close_timeout: timedelta = timedelta(seconds=5),
    heartbeat_timeout: timedelta = timedelta(seconds=5),
    retry_policy: RetryPolicy = DEFAULT_RETRY_POLICY,
) -> Task:
    params = TaskStatusTransitionParams(
        task_id=task_id, reason=reason,
        trace_id=trace_id, parent_span_id=parent_span_id,
    )
    if in_temporal_workflow():
        return await ActivityHelpers.execute_activity(
            activity_name=activity_name, request=params,
            response_type=Task,
            start_to_close_timeout=start_to_close_timeout,
            retry_policy=retry_policy,
            heartbeat_timeout=heartbeat_timeout,
        )
    else:
        method = getattr(self._tasks_service, service_method)
        return await method(
            task_id=task_id, reason=reason,
            trace_id=trace_id, parent_span_id=parent_span_id,
        )
```

Then each public method becomes a one-liner. The same pattern applies to the service and activities layers.

**Rule Used:** When multiple functions have similar patterns for ... ([source](https://app.greptile.com/review/custom-context?memory=a7a6387f-a439-4ae5-a929-6658605ca15b))

**Learnt From**
[scaleapi/scaleapi#127166](https://github.com/scaleapi/scaleapi/pull/127166)

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "Add task updates to adk" | Re-trigger Greptile

Context used:

  • Rule used - When multiple functions have similar patterns for ... (source)

Learnt From
scaleapi/scaleapi#127166

@declan-scale declan-scale force-pushed the declan-scale/add-task-updates-to-adk branch from f74c758 to fae61cb Compare March 30, 2026 21:48
@declan-scale declan-scale force-pushed the declan-scale/add-task-updates-to-adk branch from fae61cb to a4e2a8d Compare March 30, 2026 22:18
@declan-scale declan-scale merged commit ff12ae1 into next Mar 30, 2026
9 checks passed
@declan-scale declan-scale deleted the declan-scale/add-task-updates-to-adk branch March 30, 2026 22:31
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