Skip to content

refactor(exec): route async /task through TaskExecutionService (#95)#320

Merged
vybe merged 1 commit into
mainfrom
feature/95-unified-async-executor
Apr 13, 2026
Merged

refactor(exec): route async /task through TaskExecutionService (#95)#320
vybe merged 1 commit into
mainfrom
feature/95-unified-async-executor

Conversation

@vybe

@vybe vybe commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Delete _execute_task_background (~220 lines of duplicated lifecycle) from src/backend/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.
  • Add three parameters to TaskExecutionService.execute_task(): parent_activity_id, extra_activity_details, slot_already_held. These preserve async-specific behaviors (collaboration parent linkage, parallel_mode flag for the Network-view filter, router-side pre-acquire for the 429-upfront contract).
  • Extract a shared _persist_chat_session helper used by both sync and async branches of execute_parallel_task. Guarded on status == SUCCESS to avoid empty assistant messages on FAILED/CANCELLED. Fixes a subscription_id snapshot gap (E3) by passing subscription_id into db.create_task_execution on the async path.

Preserved behavior

  • 429-at-capacity returned synchronously — the router pre-acquires the slot and passes slot_already_held=True so the service skips its own acquire but still releases in finally.
  • parallel_mode: True on CHAT_START activity — required by src/frontend/src/stores/network.js:255, preserved via extra_activity_details.
  • Collaboration activity parenting — CHAT_START now linked to the collaboration activity via the new parent_activity_id param.
  • save_to_session + chat_response_ready WebSocket broadcast — moved into the shared helper, still fires on the async path.

Test Plan

  • New parity tests in 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.
  • Existing TestAsyncMode* classes still pass (no regression).
  • Backend restarts clean; execute_parallel_task async branch serves 202 + execution_id within 1s.
  • grep -r "_execute_task_background" returns zero hits in src/.
  • Reviewer manual verify: async task from the UI's Tasks tab completes, appears in Network timeline, chat_response_ready WebSocket event fires when save_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

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>
@vybe vybe linked an issue Apr 13, 2026 that may be closed by this pull request
@vybe
vybe merged commit ffd898d into main Apr 13, 2026
vybe added a commit that referenced this pull request Apr 14, 2026
Shipped:
- #95 (PR #320) - unified TaskExecutionService
- #285 (PR #322) - auth failure fast-fail
- #226 (PR #323) - per-agent slot TTL
- #286 (PR #324) - preserve error context

Remaining: #61, #132, #56

Co-Authored-By: Claude Opus 4.5 <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>
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>
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.

Route async task mode through TaskExecutionService

1 participant