Agent-loop snapshots store the agent's entire system prompt in every step's span payload, about 5% of all persisted snapshot bytes
Describe the problem
Every agent-loop step result carries agentSpanData, the exported agent-run span the durable loop threads through its iteration state. Its attributes.instructions member is the agent's entire system prompt. It is stored on BOTH sides of a step result (payload and output), and the durable path re-persists the snapshot at every step boundary, so a full system prompt is re-serialized and rewritten dozens of times per turn.
Measured on a production durable-agent deployment over 300 real snapshots: agentSpanData.attributes.instructions accounted for 27.7 MB of 518.1 MB persisted, about 5% of everything written, spread over 2250 step-level copies. This is the largest remaining item after #21389 / #21390 removed the stepResult.request echo.
It matters more than 5% suggests, because of where the cost lands. Instrumenting a single 170 second turn on our deployment: 443 snapshot writes totalling 44.3s of write work, of which the finalization tail held only 2.6s. 94% of snapshot write cost happens between steps, where it stalls the visible stream rather than a background flush.
Why the copies are safe to drop
Nothing reads them back. There are exactly two rebuildSpan call sites that restore a run's agent span:
Both read initData.agentSpanData, which is context.input. pruneAgentLoopSnapshot deliberately leaves context.input whole, so one complete copy survives in every snapshot and a resumed run rebuilds its span from it. The live span was already exported with its attributes while the run was streaming, so the trace itself loses nothing either. The step-level copies are pure state carried forward.
This is the same reasoning that already justifies deleting the sibling metadata.request / metadata.response unconditionally, and the stepResult.request echo in #21390.
Expected behavior
pruneAgentLoopSnapshot drops agentSpanData.attributes.instructions from step payloads and outputs, terminal and non-terminal alike, while keeping the span itself, all its other attributes, and the complete context.input copy that resume reads.
Before, per snapshot: one full system prompt in context.input, plus one per step result side (two per step). After: one full system prompt in context.input, and nothing else.
Context
We have been running exactly this strip as a local dist patch in production since core 1.57, currently on 1.58.0, with the suspend/resume/HITL surface fully exercised, and traces still rebuild correctly on resume. Happy to send the PR.
Source: mastra-ai/mastra