refactor: Route async task mode through TaskExecutionService (#95)#162
refactor: Route async task mode through TaskExecutionService (#95)#162AndriiPasternak31 wants to merge 4 commits intoAbilityai:mainfrom
Conversation
…ai#95) The async mode path in chat.py duplicated slot management, activity tracking, credential sanitization, and error handling instead of delegating to TaskExecutionService. Any fix to the service didn't apply to async mode, creating two maintenance surfaces. - Replace _execute_task_background() with thin wrapper delegating to TaskExecutionService (matches internal.py pattern) - Simplify async branch: remove inline slot/activity/status management - Extract _save_to_chat_session() helper to eliminate DRY violation between async and sync session persistence paths - Add 5 new tests for session persistence, collaboration activity, and safety net error handling - Net reduction of ~124 lines in chat.py Closes Abilityai#95 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Fix stringly-typed status comparison: "failed" → TaskExecutionStatus.FAILED - Remove unused `source` variable (ExecutionSource computed but never used) - Add try/except to sync path collaboration activity completion (matches async path) - Extract poll_execution_until_done() test helper, eliminating 5 duplicate polling loops Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Both branches added entries at the top of changelog.md. Kept both entries in chronological order (newest first): our Abilityai#95 refactor entry above upstream's Abilityai#74 and Abilityai#100 entries. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
vybe
left a comment
There was a problem hiding this comment.
Thanks for the clean refactor! The delegation pattern is solid and the 5 new tests are a great addition. A few items before merge:
Required
-
execution_time_msregression in_save_to_chat_session()— The old_execute_task_background()passedexecution_time_mstodb.add_chat_message(). The new helper omits it becauseTaskExecutionResulthas no such field. Async chat sessions will now always storeNULLfor execution time. Either addexecution_time_ms: Optional[int]toTaskExecutionResultand populate it in the service, or explicitly accept this loss and document it. -
context_usedguard dropped — Old:context_used if context_used > 0 else None. New: storesresult.context_useddirectly (could persist0instead ofNULL). Small behavior change worth preserving for consistency. -
Please rebase onto
mainbefore merge — the branch has a merge commit (merge: resolve changelog conflict with upstream/main) that should be cleaned up.
Minor
- Issue #95 is missing the
type-refactorlabel. - Confirm
public.py's_execute_public_chat_background()(line 775) is considered resolved — it appears to already delegate toTaskExecutionService, but the issue's "Files to Change" section lists it. Either close the loop in the PR description or follow up in a separate issue. - Add
## Security Considerationssection totask-execution-service.md(even a brief "N/A — service layer, no direct auth or user input" is sufficient to satisfy the flow format spec).
Please address the required items and request re-review.
Summary
_execute_task_background()with delegation toTaskExecutionService, matching the pattern used byinternal.pyandpublic.py_save_to_chat_session()helper to eliminate DRY violation between async and sync session persistence pathschat.pyChanges
src/backend/routers/chat.py— Rewrote_execute_task_background()as thin wrapper, simplified async branch, extracted shared helpertests/test_parallel_task.py— Added 5 new tests (session persistence, collaboration activity, safety net)docs/memory/changelog.md— Added changelog entrydocs/memory/feature-flows/task-execution-service.md— Updated flow documentationTest Plan
pytest tests/test_parallel_task.py -vTestAsyncSessionPersistence,TestAsyncCollaborationActivity,TestAsyncSafetyNetsave_to_sessionstill persists to chat sessionCloses #95
Generated with Claude Code