Skip to content

[Bug]:MemoryConsolidator blocks agent call via concatWith + .block() #2225

Open

Description

@WingsLong

Observed behavior

Agent calls are delayed by 20-30s after the main response completes due to MemoryConsolidator running synchronously on the tail of the Flux.

Log timeline:

2026-07-15 16:22:54 INFO  [/TimingMiddleware] - 【agent_call】 crowd-rule: 3417ms
2026-07-15 16:23:23 INFO  [/MemoryConsolidator] - MEMORY.md consolidated (2770 chars), watermark advanced to ...

Root cause

1. MemoryMaintenanceMiddleware uses concatWith

// MemoryMaintenanceMiddleware.java:142
return next.apply(input)
    .concatWith(
        Mono.<AgentEvent>fromRunnable(() -> maybeRunMaintenance(rc))
            .subscribeOn(Schedulers.boundedElastic())
            ...
    );

concatWith waits for the inner Mono to complete before the Flux terminates. If the caller uses blockLast(), the consolidation delay is added to total latency.

2. consolidateMemory() calls .block() inside the elastic thread

// MemoryMaintenanceMiddleware.java:270
consolidator.consolidate(rc).block();

This blocks a boundedElastic thread for the full LLM call duration.

3. MemoryConsolidator.consolidate() performs an LLM call

// MemoryConsolidator.java:169
return model.stream(messages, null, null)
    .reduce(...)
    .flatMap(...);

Impact

  • Agent call latency inflated by consolidation time (~29s in the reported case)
  • boundedElastic threads can be exhausted under concurrent load
  • Documentation describes "background / fire-and-forget" behavior, but the implementation is synchronous

Environment

  • AgentScope version: (2.0.0)
  • Java: 21
  • Framework: Spring Boot + WebFlux

Activity

  1. added
    bug
    on Jul 15, 2026
  2. moved this from Backlog to In progress in AgentScope Javaon Jul 16, 2026
  3. added 8 commits that reference this issue on Aug 8, 2026
    d03f60e
    e93bf29
    e2aa070
    5006d08
    828f416
    3de23dd
    f4aa01b
    991632d
  4. added 2 commits that reference this issue on Aug 29, 2026
    af09aee
    9f04c09
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

    area/core/memorybug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions