Repository navigation
Description
Summary
services/backlog_service.py:240 lazily imports _execute_task_background from routers.chat, but that function no longer exists in routers/chat.py. Every backlog drain attempt fails with an ImportError, marks the queued execution as failed, and leaves the persistent task backlog (BACKLOG-001) silently non-functional. Observed on a live instance with a fan-out workload — 23 backlog drain failures in 24 hours, all with the same import error.
Component
Backend / Backlog Service (BACKLOG-001)
Priority
P1
Error
Backlog drain spawn failed: cannot import name '_execute_task_background' from 'routers.chat' (/app/routers/chat.py)
Location
- File:
services/backlog_service.py - Line: 240
- Function:
BacklogService._spawn_drain
Root Cause
_spawn_drain does:
from routers.chat import _execute_task_backgroundgrep -rn 'def _execute_task_background\|def execute_task_background' /app/ finds zero matches in routers/chat.py. The function appears to have been renamed or moved (likely during the work tracked in #95 "Route async task mode through TaskExecutionService") without updating this lazy import. The exception is caught at backlog_service.py:222-228, so the only surface signal is the per-execution Backlog drain spawn failed: ... error in schedule_executions.error.
The drain is invoked from BacklogService.on_slot_released (called by SlotService on slot free) and from periodic maintenance, so every queued task that should drain hits this error.
Net behavior: BACKLOG-001 is dead — any execution that gets queued to the backlog stays queued until it gets pulled and immediately fails on drain. Sync-mode chat_with_agent callers don't see this because they bypass the backlog (see related issue), but any async-mode caller relies on this path.
Reproduction Steps
- Have an agent at full slot capacity (e.g.,
max_parallel_tasks=3and 3 active executions) - Submit an async-mode parallel chat request to that agent (
async_mode=true, parallel=true) - The chat router enqueues the request to the backlog — verify with
SELECT * FROM schedule_executions WHERE status='queued' - Wait for a slot to free (or trigger a periodic drain)
- Check
schedule_executions.errorfor the dropped execution — observeBacklog drain spawn failed: cannot import name '_execute_task_background' from 'routers.chat'
Suggested Fix
Locate the renamed/moved function and update the lazy import. Search hits for the old name in the deployed image:
services/backlog_service.py:19: Drain imports `_execute_task_background` lazily to avoid a circular import
services/backlog_service.py:141: Spawn `_execute_task_background` on the reconstituted request.
services/backlog_service.py:240: from routers.chat import _execute_task_background
services/backlog_service.py:258: _execute_task_background(...)
routers/internal.py:267: asyncio.create_task(_execute_task_internal_background(...))
routers/internal.py:306: async def _execute_task_internal_background(task_service, request: ...)
Likely candidate: route through TaskExecutionService directly (per #95), reconstructing the same call shape used by the chat router's async path. The signature _spawn_drain builds includes release_slot=True, user_id, user_email, subscription_id, task_activity_id, collaboration_activity_id, x_source_agent — whichever replacement is wired up needs to accept those (or an equivalent context object).
A regression test that exercises the slot-release → drain path would prevent recurrence; the current exception-swallowing makes this kind of break silent.
Environment
- Trinity version:
c3f3f1c - Python: 3.x (deployed image)
- Observed on a live instance with a fan-out caller dispatching 4-7 task batches every 1-5 min to 7 worker agents
Related
- feat: Persistent task backlog for async execution (BACKLOG-001) #260 (BACKLOG-001 feature) — the feature this regression silently breaks
- Route async task mode through TaskExecutionService #95 (route async task mode through TaskExecutionService) — likely the rename point
- refactor: consolidate ExecutionQueue + SlotService + BacklogService into CapacityManager #428 (refactor: consolidate ExecutionQueue + SlotService + BacklogService) — touches the same area
Activity
fix(backlog): repair drain spawn — lazy-import target after #95 (#496) (
docs(feature-flows): sync index + parallel-capacity for Abilityai#496
test(catalog): register test_backlog_drain_unit.py (Abilityai#496)
merge: upstream/dev (PR Abilityai#500 superseded Abilityai#496 fix; r…
test: drop redundant test_backlog_drain_unit.py
docs(feature-flows): clean up #95 drift missed by #500 (#496) (#503)
Release: v0.5.0 (#608)
docs(planning): Abilityai#408 dissolution gated on Abilityai#428, not A…