Skip to content

.NET: [Bug]: Serialized workflow-agent session grows ~cubically with turns (every checkpoint kept, nested managers copied) #9371

Description

@tzdevelopteam

Description

The serialized session of a workflow hosted as an agent (workflow.AsAIAgent(), then agent.SerializeSessionAsync(session)) grows roughly with the cube of the number of turns. With an outer workflow that contains a handoff workflow bound via BindAsExecutor, we measured:

Turns Serialized session
1 1.3 MB
4 47 MB

That makes an in-memory or distributed session store impractical after a few turns.

The growth comes from two things:

  1. InMemoryCheckpointManager keeps every superstep checkpoint of every turn.
  2. The sub-workflow keeps its own checkpoint manager inside the parent's checkpoint state. Each parent checkpoint therefore carries a full copy of the child's whole history.

Resuming a session only reads the session's lastCheckpoint, and inside it only the last entry of the sub-workflow manager's index. Every other checkpoint is kept only for time travel, which a chat agent never uses.

Expected behavior

A hosted workflow agent's session keeps only what a resume needs. Possible shapes:

  • SerializeSessionAsync writes only the checkpoint chain needed to resume.
  • A retention option on the in-memory checkpoint manager, such as "keep the last N checkpoints". Nested sub-workflow managers would honor it too.

Workaround we use

We post-process the serialized JSON. In each checkpoint manager we keep only the checkpoint that lastCheckpoint points to (for nested managers, the last index entry) and drop the rest. Four turns become about 430 KB, and multi-turn resume keeps working.

This depends on the internal serialization shape (store / checkpointIndex / cache, plus the type name Microsoft.Agents.AI.Workflows.Checkpointing.InMemoryCheckpointManager in stateData). Any framework update can break it silently.

Repro

  1. Build a handoff workflow (AgentWorkflowBuilder.CreateHandoffBuilderWith(...)) with two or more agents.
  2. Bind it with BindAsExecutor inside an outer WorkflowBuilder workflow.
  3. Host the outer workflow with AsAIAgent().
  4. Run four turns on one session, calling SerializeSessionAsync after each, and compare the payload sizes.

Versions

  • Microsoft.Agents.AI.Workflows 1.24.0
  • Microsoft.Agents.AI.Hosting 1.24.0-preview.261006.1
  • .NET 10

Activity

  1. added
    .NETUsage: [Issues, PRs], Target: .Net
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Oct 14, 2026
  2. kartikmadan11 commented on Oct 27, 2026

    @kartikmadan11
    Contributor

    Reproduced this on main with a nested handoff, the session hits about 21 MB after 6 turns.

    I have a fix locally and wanted to check the approach first. The sub-workflow keeps only its latest checkpoint, and the session's own manager drops older ones after a resumed run saves a new one. Custom managers/stores are left alone. Same 6 turns end up around 260 KB.

    Downside is you can't recover to an earlier turn anymore, only the current one. Would an opt-in "keep last N" setting be worth adding for that?

  3. added a commit that references this issue on Oct 29, 2026
    e797c34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    .NETUsage: [Issues, PRs], Target: .NettriageUsage: [Issues], Target: All issues that still need to be triaged

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions