Skip to main content

Module background_task_feed

Module background_task_feed 

Source
Expand description

The Claude CLI’s own structured task feed → db_background_tasks.

The CLI reports every task it runs on the agent’s stdout as system lines:

  • task_started — task_id, tool_use_id, description, task_type (local_bash, local_agent, local_workflow), is_backgrounded, and owned_by_subagent when a subagent launched it.
  • task_updated — task_id plus a patch: {is_backgrounded: true} when a running command is moved to the background, {status, end_time} when it ends (completed, failed, killed).
  • task_notification — task_id, tool_use_id, final status (completed, failed, stopped) and a summary.

These arrive on the PARENT agent’s stream even for tasks a subagent owns. Before this module nothing read them: the registry learned about a background task only from the renderer spotting the “Command running in background with ID:” result text, and learned it had ended only from a <task-notification> user message in the same pane. A subagent’s task gets the first but never the second, so its row stayed running forever; a top-level task’s result now carries empty stdout plus a structured backgroundTaskId, so the text match missed it entirely. See docs/specs/SPEC_BACKGROUND_TASK_STRUCTURED_FEED_AND_SWARM_OWNERSHIP_2026_09_27.md.

Scope: backgrounded local_bash tasks only, which is what the registry has always held. Subagents (local_agent) are Swarm’s subagent watcher’s job. The renderer’s existing observe/complete pushes still run; every write here is the same idempotent background_task_observe/background_task_complete call, so whichever arrives first wins and the other is a no-op or a refresh.

Functions§

publish_background_task_updated
Notify subscribers that block_id’s db_background_tasks state changed (observed, pid recorded, or completed), so the frontend can re-query COMMAND_LIST_BACKGROUND_TASKS instead of polling. Live-only (persist: 0) — a late subscriber gets the current state via the mount-time list query, not event replay. Deliberately carries no task data itself (just an invalidation signal): the list query is the single source of truth for the actual rows. See docs/specs/SPEC_BACKGROUND_TASK_DASHBOARD_INTELLIGENCE_2026_08_20.md §3.2.