-
Notifications
You must be signed in to change notification settings - Fork 458
fix: prevent orphan SUBMITTED rows when producer fails early #1110
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
Linux2010
wants to merge
5
commits into
a2aproject:main
Choose a base branch
from
Linux2010:fix/1067-orphan-submitted-rows
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
78452fb
fix: prevent orphan SUBMITTED rows when producer fails early (#1067)
Linux2010 62491a7
fix: add context_id to TaskStatusUpdateEvent in producer exception ha…
Linux2010 3c938f7
revert: remove save_task_event from producer exception handler
Linux2010 0aae6c8
fix: remove test for save_task_event in producer exception handler
Linux2010 e8178d5
style: fix ruff formatting in test file
Linux2010 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -895,3 +895,57 @@ async def execute_mock(req, q): | |||||||||||||||
| assert len(events) == 0 | ||||||||||||||||
|
|
||||||||||||||||
| await active_task.cancel(request_context) | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
| @pytest.mark.asyncio | ||||||||||||||||
| async def test_active_task_producer_exception_sets_failed_state(): | ||||||||||||||||
| """Test that producer exception explicitly sets FAILED state. | ||||||||||||||||
|
|
||||||||||||||||
| Regression test for #1067: ActiveTaskRegistry produces orphan SUBMITTED rows | ||||||||||||||||
| when AgentExecutor.execute() raises before emitting any events. | ||||||||||||||||
| """ | ||||||||||||||||
| agent_executor = Mock() | ||||||||||||||||
| task_manager = Mock() | ||||||||||||||||
| request_context = Mock(spec=RequestContext) | ||||||||||||||||
| request_context.context_id = 'test-context-id' | ||||||||||||||||
| request_context.call_context = ServerCallContext() | ||||||||||||||||
|
|
||||||||||||||||
| active_task = ActiveTask( | ||||||||||||||||
| agent_executor=agent_executor, | ||||||||||||||||
| task_id='test-task-id', | ||||||||||||||||
| task_manager=task_manager, | ||||||||||||||||
| push_sender=Mock(), | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| # Simulate executor raising an exception before emitting any events | ||||||||||||||||
| async def execute_mock(req, q): | ||||||||||||||||
| raise RuntimeError('Executor failed before emitting events') | ||||||||||||||||
|
|
||||||||||||||||
| agent_executor.execute = AsyncMock(side_effect=execute_mock) | ||||||||||||||||
| agent_executor.cancel = AsyncMock() | ||||||||||||||||
| task_manager.get_task = AsyncMock(return_value=None) | ||||||||||||||||
| task_manager.ensure_task_id = AsyncMock( | ||||||||||||||||
| return_value=Task( | ||||||||||||||||
| id='test-task-id', | ||||||||||||||||
| status=TaskStatus(state=TaskState.TASK_STATE_SUBMITTED), | ||||||||||||||||
| ) | ||||||||||||||||
| ) | ||||||||||||||||
| task_manager.save_task_event = AsyncMock() | ||||||||||||||||
| task_manager.process = AsyncMock(side_effect=lambda x: x) | ||||||||||||||||
|
|
||||||||||||||||
| await active_task.enqueue_request(request_context) | ||||||||||||||||
| await active_task.start( | ||||||||||||||||
| call_context=ServerCallContext(), create_task_if_missing=True | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| # Wait for producer to finish | ||||||||||||||||
| await asyncio.sleep(0.2) | ||||||||||||||||
|
|
||||||||||||||||
| # Verify that save_task_event was called with a FAILED status | ||||||||||||||||
| assert task_manager.save_task_event.called | ||||||||||||||||
| # Get the last call to save_task_event | ||||||||||||||||
| last_call = task_manager.save_task_event.call_args | ||||||||||||||||
| if last_call: | ||||||||||||||||
| event = last_call.args[0] | ||||||||||||||||
| assert isinstance(event, TaskStatusUpdateEvent) | ||||||||||||||||
| assert event.status.state == TaskState.TASK_STATE_FAILED | ||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an assertion to verify that the
Suggested change
|
||||||||||||||||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
TaskStatusUpdateEventis created without acontext_id. However,TaskManager.save_task_eventvalidates that the event'scontext_idmatches theTaskManager'scontext_id(which was just set torequest_context.context_id or ''viaensure_task_id). If they do not match,save_task_eventraises anInvalidParamsError.To prevent this validation error from crashing the exception handler and bypassing the enqueuing of the original exception, we should explicitly set the
context_idin theTaskStatusUpdateEvent.