refactor(exec): route async /task through TaskExecutionService (#95)#320
Merged
Conversation
Delete _execute_task_background (~220 lines of duplicated lifecycle) from routers/chat.py. Async /task now delegates to TaskExecutionService.execute_task via a thin _run_async_task_with_persistence wrapper, matching the pattern already used by public.py and internal.py async paths. Preserves observable behavior: - 429-upfront at capacity: router pre-acquires slot, passes slot_already_held=True - CHAT_START activity retains parallel_mode flag (extra_activity_details) so src/frontend/src/stores/network.js:255 still includes async executions - CHAT_START parented to collaboration activity via parent_activity_id - save_to_session + chat_response_ready broadcast moved to shared _persist_chat_session helper, guarded on SUCCESS to avoid empty assistant messages on FAILED/CANCELLED executions - subscription_id now snapshotted on pre-created execution (E3 fix) Adds to TaskExecutionService.execute_task(): - parent_activity_id, extra_activity_details, slot_already_held params Tests: 2 new parity tests (429-upfront, parallel_mode flag). Existing async tests pass; pre-existing failure on test_async_mode_execution_completes is unrelated and reproduces on main. Closes #95. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
AndriiPasternak31
added a commit
to AndriiPasternak31/trinity
that referenced
this pull request
Apr 19, 2026
Adds three test classes covering behaviors not exercised by the upstream TestAsyncModeUnifiedExecutor (landed via Abilityai#320): - TestAsyncSessionPersistence (3 tests) — save_to_session creates user+assistant messages, explicit session_id is respected, WebSocket chat_response_ready fires. - TestAsyncCollaborationActivity (1 test) — agent-to-agent async task completes the collaboration activity end-to-end. - TestAsyncSafetyNet (1 test) — execution record is created before the background task is spawned (no silent launch failure). Closes Abilityai#95 test coverage gaps. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
4 tasks
AndriiPasternak31
added a commit
to AndriiPasternak31/trinity
that referenced
this pull request
Apr 25, 2026
Adds three test classes covering behaviors not exercised by the upstream TestAsyncModeUnifiedExecutor (landed via Abilityai#320): - TestAsyncSessionPersistence (3 tests) — save_to_session creates user+assistant messages, explicit session_id is respected, WebSocket chat_response_ready fires. - TestAsyncCollaborationActivity (1 test) — agent-to-agent async task completes the collaboration activity end-to-end. - TestAsyncSafetyNet (1 test) — execution record is created before the background task is spawned (no silent launch failure). Closes Abilityai#95 test coverage gaps. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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
_execute_task_background(~220 lines of duplicated lifecycle) fromsrc/backend/routers/chat.py. Async/tasknow delegates toTaskExecutionService.execute_taskvia a thin_run_async_task_with_persistencewrapper, matching the pattern already used bypublic.pyandinternal.pyasync paths.TaskExecutionService.execute_task():parent_activity_id,extra_activity_details,slot_already_held. These preserve async-specific behaviors (collaboration parent linkage,parallel_modeflag for the Network-view filter, router-side pre-acquire for the 429-upfront contract)._persist_chat_sessionhelper used by both sync and async branches ofexecute_parallel_task. Guarded onstatus == SUCCESSto avoid empty assistant messages on FAILED/CANCELLED. Fixes a subscription_id snapshot gap (E3) by passingsubscription_idintodb.create_task_executionon the async path.Preserved behavior
slot_already_held=Trueso the service skips its own acquire but still releases infinally.parallel_mode: Trueon CHAT_START activity — required bysrc/frontend/src/stores/network.js:255, preserved viaextra_activity_details.parent_activity_idparam.chat_response_readyWebSocket broadcast — moved into the shared helper, still fires on the async path.Test Plan
tests/test_parallel_task.py::TestAsyncModeUnifiedExecutor:test_async_mode_at_capacity_returns_429_upfront— confirms 429 contract preserved.test_async_mode_activity_has_parallel_mode_flag— confirms Network-view filter still matches.TestAsyncMode*classes still pass (no regression).execute_parallel_taskasync branch serves 202 +execution_idwithin 1s.grep -r "_execute_task_background"returns zero hits insrc/.chat_response_readyWebSocket event fires whensave_to_session=True.Context
First Tier 0 item from
docs/planning/ORCHESTRATION_RELIABILITY_2026-04.md. Unblocks the remaining Sprint A fixes (#285, #61, #226, #286, #132, #56) and the Sprint C orchestration work (#260, #294) that layer on the unified executor.Closes #95.
🤖 Generated with Claude Code