#25590·mastra

[BUG] Background workflow tools publish every nested-agent chunk to the shared background-tasks-result topic (60MB events, Redis OOM)

Author: BrandiATMuhkuhCreated Sep 30, 2026Updated Sep 30, 2026
Labelsstatus: needs triage

Describe the Bug

A background workflow tool publishes every chunk its nested agents write to the shared background-tasks-result topic, and there is no way to filter them. On Redis Streams pubsub, a single event reached 61.6MB. Six task runs put 379MB into the stream, which ran a 1GB Redis out of memory (allkeys-lru, 2,689 keys evicted).

In packages/core/src/background-tasks/workflow.ts, onProgress publishes each chunk as it comes:

typescript
await manager.publishLifecycleEvent('task.output', { ...task, chunk });

For a workflow tool whose steps call an agent, those chunks include the agent's step-start, step-finish and finish parts. Each of those carries the full model request, including base64 file parts. In our stream, step-finish plus finish made up 91% of the bytes. publishLifecycleEvent also copies task.args into every event, so a large input is repeated once per chunk.

What makes it worse:

  • One topic for everything. Every task on every pod goes to background-tasks-result, and every pod consumes all of it.
  • No filter hook. Nothing lets you drop or slim a chunk before it's published. progressThrottleMs only rate-limits, so it can drop the one progress event a UI needs and still let a 60MB snapshot through.

Steps To Reproduce

  1. Configure RedisStreamsPubSub as Mastra's pubsub, and enable backgroundTasks.
  2. Create a workflow with a .foreach whose step calls agent.generate() with a PDF file part of about 1MB. Expose it to an agent as a background workflow tool.
  3. Have the agent call the tool with about 6 items.
  4. Measure the stream with XRANGE background-tasks-result - + and sum the entry sizes. MEMORY USAGE samples, so it undercounts badly.

Each task.output entry holding a nested agent's step-finish/finish is roughly the size of the whole request, attachment included.

Link to Minimal Reproducible Example

Not yet. Steps 1–3 above are the whole repro, and I can turn them into a repo if that helps.

Expected Behavior

A background task's internal agent chunks don't reach the pubsub, or you can filter them. Any of these would fix it:

  1. Don't forward a nested agent's internal parts (step-*, finish, request snapshots) as task.output. Forward only the workflow's own events (workflow-step-progress, step start/finish), which is what a progress UI reads.
  2. Add a hook such as backgroundTasks.transformOutput(chunk, task) => chunk | null, so an app can slim or drop a chunk before it's published.
  3. Stop repeating args on every task.output event.
  4. Publish per task or per thread rather than to one global topic, and cap the event size or the stream length (MAXLEN) in @mastra/redis-streams.

Our workaround is to subclass RedisStreamsPubSub and drop, in publish(), every task.output event whose chunk.payload.output.type isn't workflow-step-progress.

Environment Information

  • @mastra/core 1.71.0 (still the same on main)
  • @mastra/redis-streams 0.5.1
  • Node 24, Redis with 1GB and allkeys-lru
  • Related: #15803 (progressThrottleMs)

Verification

  • I have searched the existing issues to make sure this is not a duplicate
  • I have included sufficient information for the team to reproduce and understand the issue