Skip to content

[Bug]: 2.0.5 compaction rejects valid text summaries containing ThinkingBlock #4210

Open

Description

@ju123123

Describe the bug

In the published AgentScope Java 2.0.5 artifact, ConversationCompactor.SummaryCollection rejects a valid text summary when the same response stream also contains a normal ThinkingBlock.

The maintenance-line implementation marks every non-TextBlock as invalid. This includes reasoning blocks even when the final text is nonempty, ends with stop, and the replacement would reduce context.

Because a rejected candidate leaves the original history in place, a caller checking that same above-threshold history on later rounds can attempt compaction repeatedly.

To Reproduce (no provider/API key required)

Using io.agentscope:agentscope-harness:2.0.5, run the following with the normal AgentScope message/model imports and Reactor Flux:

for (boolean thinking : List.of(false, true)) {
    Model model = new Model() {
        @Override
        public String getModelName() {
            return "synthetic-summary";
        }

        @Override
        public Flux<ChatResponse> stream(
                List<Msg> messages, List<ToolSchema> tools, GenerateOptions options) {
            var text = TextBlock.builder().text("FACT=retained").build();
            var reason = ThinkingBlock.builder().thinking("summarizing").build();
            return Flux.just(ChatResponse.builder()
                    .content(thinking ? List.of(reason, text) : List.of(text))
                    .finishReason("stop")
                    .build());
        }
    };

    var history = List.of(
            Msg.builder().role(MsgRole.USER)
                    .textContent("old context ".repeat(1_000)).build(),
            Msg.builder().role(MsgRole.USER).textContent("continue").build());
    var config = CompactionConfig.builder()
            .triggerTokens(1).triggerMessages(0)
            .keepTokens(0).keepMessages(1)
            .prune(null).truncateArgs(null)
            .flushBeforeCompact(false).offloadBeforeCompact(false).build();

    var result = new ConversationCompactor(model, new MemoryFlushManager(null, null))
            .compactIfNeeded(
                    RuntimeContext.builder().build(), history, config, "agent", "session")
            .block(Duration.ofSeconds(10));

    System.out.println(
            "thinking=" + thinking + ", summaryAccepted=" + result.isPresent());
}

Executed locally on Java 21 with the published 2.0.5 artifacts:

thinking=false, summaryAccepted=true
thinking=true, summaryAccepted=false

A separate stream chunk containing only reasoning before the text response has the same issue.

Error messages

Rejected summary: model returned non-text content or tool calls

Environment

  • AgentScope Java: published 2.0.5 artifacts
  • Java: 21
  • OS: macOS
  • Reproduction uses a synthetic Model, with no external service.

Additional context: source of the regression

The original PR #3855, merged as 616ab47, only marks ToolUseBlock as invalid; reasoning blocks are ignored.

Its 2.0.x backport, 98f7736, broadens this to every non-text block. The published v2.0.5 implementation contains that broader check.

Expected behavior / suggested fix

Ignore only ThinkingBlock while collecting summary text. Keep all other validation, including rejection of tool calls, images/other unsupported blocks, empty or reasoning-only output, provider output-limit termination, and non-reducing candidates.

For example, retain sawNonText but narrow the branch:

if (block instanceof TextBlock tb) {
    text.append(tb.getText());
} else if (!(block instanceof ThinkingBlock)) {
    sawNonText = true;
}

Continue preserving finish reason/metadata, cancellation, errors, lightweight reductions, and history-commit checks.

Validation scope

The reproduction above was compiled and executed locally on Java 21 against the published 2.0.5 artifacts, with a synthetic Model and no provider or API credentials. The two cases differ only in the presence of ThinkingBlock.

Please add coverage for reasoning and text in the same chunk and in separate chunks. Ignoring a reasoning block must not turn reasoning-only output into an accepted summary or weaken the other existing rejection checks.

AI assistance was used for investigation; the SDK-only reproduction was executed locally.

Activity

  1. added
    bug
    on Nov 16, 2026
  2. lishibin commented on Nov 17, 2026

    @lishibin

    Hi, I’d like to work on this issue.

    I can reproduce it locally on macOS with Java 21.
    I plan to add regression tests for ThinkingBlock and TextBlock
    in the same and separate stream chunks, then narrow the summary
    validation so ThinkingBlock is ignored while unsupported blocks
    remain rejected.

  3. littlebird69 commented on Nov 17, 2026

    @littlebird69
    Contributor

    Confirming this against a real provider — it is not synthetic-only.

    Reproduced in production wiring with DeepSeek deepseek-v4-flash (a thinking model): every compaction attempt logs

    INFO  ConversationCompactor : Compaction triggered: total=7 msgs / 649 tokens, cutoff=5, keeping=2 msgs
    WARN  ConversationCompactor : Rejected summary: model returned non-text content or tool calls
    

    and the history is never replaced, on every reasoning round above the threshold — the wasted-summary-call loop the report describes.

    Two additions from our side:

    1. The overflow-recovery path breaks the same way. CompactionMiddleware.reasonWithRecovery → emergencyCompact (and any caller-side forceCompact built on ConversationCompactor.compactIfNeeded) goes through the same summarizePrefix; with a thinking summary model the candidate is rejected, compaction returns empty, and context-overflow recovery degrades back to the original error. So on 2.0.5 a thinking model loses both regular compaction and the overflow safety net.

    2. What the rejection seems intended for. Per the javadoc the rule guards against the model returning tool calls / no usable text. ThinkingBlock is neither: it is the normal streaming shape of every reasoning model, and 2.0.4's accumulator simply skipped non-text blocks (if (block instanceof TextBlock tb ...)) while keeping the text. Rejecting on it turns "strict about malformed summaries" into "never compacts with reasoning models".

    Our interim workaround (restores the 2.0.4 semantics without touching the framework): wrap the summary model at the wiring seam with a delegating Model whose stream filters non-TextBlock content blocks (id / finishReason / usage / metadata preserved). Happy to PR a framework-side fix instead if maintainers prefer — e.g. have SummaryCollection only set sawNonText for blocks that actually indicate a unusable summary (tool calls), or drop ThinkingBlock before validation.

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions