Skip to content

Agents: skip redundant partial compaction summarization#61603

Merged
vincentkoc merged 2 commits into
openclaw:mainfrom
neeravmakwana:fix/compaction-redundant-partial-summarization
Apr 6, 2026
Merged

Agents: skip redundant partial compaction summarization#61603
vincentkoc merged 2 commits into
openclaw:mainfrom
neeravmakwana:fix/compaction-redundant-partial-summarization

Conversation

@neeravmakwana

Copy link
Copy Markdown
Contributor

Summary

  • Problem: When full summarization failed and no messages were marked oversized, summarizeWithFallback still ran a "partial" pass over the same transcript, duplicating failing API work (including retries) and the second warning log.
  • Why it matters: Under transport failures (for example fetch failed), this doubled load and log noise and worsened responsiveness during compaction.
  • What changed: Only run the partial summarization path when smallMessages is a strict subset of the original messages (i.e. at least one oversized message was excluded).
  • What did NOT change: When oversized messages exist, partial summarization still runs on the smaller set; staged summarization and other compaction behavior are unchanged.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • Gateway / orchestration

Linked Issue/PR

Root Cause (if applicable)

  • Root cause: Fallback logic treated "partial" as always distinct from "full", but when nothing was oversized the two inputs were identical.
  • Missing detection / guardrail: No check that partial would use a different message set than the failed full attempt.
  • Contributing context (if known): N/A

Regression Test Plan (if applicable)

  • Coverage level: Unit test
  • Target test or file: src/agents/compaction.summarize-fallback.test.ts
  • Scenario the test should lock in: When all messages are non-oversized and summarization fails, generateSummary is invoked only for the full path retries (3), not again for a duplicate partial pass. When one message is oversized, full and partial paths each run (6 total mock calls).
  • Why this is the smallest reliable guardrail: Asserts call counts without coupling to provider error strings.

User-visible / Behavior Changes

  • Fewer redundant summarization attempts and one fewer warning line when full summarization fails and there are no oversized messages to drop. Final text fallback behavior is unchanged.

Diagram (if applicable)

N/A

Security Impact (required)

  • New permissions/capabilities? No

Testing

  • pnpm test on src/agents/compaction.test.ts, compaction.retry.test.ts, compaction.tool-result-details.test.ts, compaction.summarize-fallback.test.ts
  • oxlint on touched TypeScript files

@greptile-apps

greptile-apps Bot commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a redundant summarization pass in summarizeWithFallback (src/agents/compaction.ts). When full summarization failed and no messages were marked as oversized, the fallback path would re-attempt summarization against the identical transcript — duplicating all API calls (including retries) and emitting a spurious second warning log. The fix adds a strict-subset check (smallMessages.length !== messages.length) so the partial path only runs when at least one oversized message was actually excluded, preserving the intended fallback behavior for mixed transcripts.

  • src/agents/compaction.ts: adds smallMessages.length !== messages.length to the partial-path guard in summarizeWithFallback
  • src/agents/compaction.summarize-fallback.test.ts: new test file asserting generateSummary call counts for the no-oversized (3 calls) and mixed-oversized (6 calls) scenarios; the vi.importActual pattern matches the existing convention in compaction.retry.test.ts
  • CHANGELOG.md: entry added correctly under the active unreleased block

Confidence Score: 4/5

Safe to merge; the fix is logically correct and well-tested with a minor observability concern

The strict-subset guard correctly prevents duplicate API calls when no messages are oversized. Both the fixed case and the regression case are covered by exact call-count assertions. The only issue is the warning log still says 'trying partial' even in the newly-skipped path, which is a minor inaccuracy in log messaging rather than a correctness bug.

src/agents/compaction.ts lines 400-405 (warning log says 'trying partial' even when partial summarization will be skipped)

Comments Outside Diff (1)

  1. src/agents/compaction.ts, line 400-405 (link)

    P2 Misleading log message after guard change

    The warning "Full summarization failed, trying partial:" is logged unconditionally in the catch block, but partial summarization is no longer always attempted after this fix. When no messages are oversized (smallMessages.length === messages.length), the code logs "trying partial" yet immediately falls through to the final fallback without running the partial pass.

    Consider dropping the "trying partial" framing from the message so the log stays accurate:

    Prompt To Fix With AI
    This is a comment left during a code review.
    Path: src/agents/compaction.ts
    Line: 400-405
    
    Comment:
    **Misleading log message after guard change**
    
    The warning `"Full summarization failed, trying partial:"` is logged unconditionally in the `catch` block, but partial summarization is no longer always attempted after this fix. When no messages are oversized (`smallMessages.length === messages.length`), the code logs "trying partial" yet immediately falls through to the final fallback without running the partial pass.
    
    Consider dropping the "trying partial" framing from the message so the log stays accurate:
    
    
    
    How can I resolve this? If you propose a fix, please make it concise.
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/agents/compaction.ts
Line: 400-405

Comment:
**Misleading log message after guard change**

The warning `"Full summarization failed, trying partial:"` is logged unconditionally in the `catch` block, but partial summarization is no longer always attempted after this fix. When no messages are oversized (`smallMessages.length === messages.length`), the code logs "trying partial" yet immediately falls through to the final fallback without running the partial pass.

Consider dropping the "trying partial" framing from the message so the log stays accurate:

```suggestion
    log.warn(
      `Full summarization failed: ${
        fullError instanceof Error ? fullError.message : String(fullError)
      }`,
    );
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (1): Last reviewed commit: "Agents: skip redundant partial compactio..." | Re-trigger Greptile

@neeravmakwana

Copy link
Copy Markdown
Contributor Author

Addressed the current AI review feedback on this PR.

What changed:

  • Updated src/agents/compaction.ts so the full-failure warning now logs Full summarization failed: ... instead of claiming it is always "trying partial".
  • This keeps the log accurate after the new guard, since we now skip the partial path when smallMessages is identical to the original transcript.

What I verified:

  • Re-ran the compaction unit coverage:
    • src/agents/compaction.summarize-fallback.test.ts
    • src/agents/compaction.test.ts
    • src/agents/compaction.retry.test.ts
    • src/agents/compaction.tool-result-details.test.ts
  • All 26 tests passed.

Follow-up commit:

I did not find any other actionable AI review comments on the PR at the moment.

@vincentkoc vincentkoc self-assigned this Apr 6, 2026
@vincentkoc vincentkoc force-pushed the fix/compaction-redundant-partial-summarization branch from b8bcaf3 to 69d551d Compare April 6, 2026 12:21
@vincentkoc vincentkoc merged commit 7df5f70 into openclaw:main Apr 6, 2026
3 checks passed
@vincentkoc

Copy link
Copy Markdown
Member

Landed via temp rebase onto latest main and squash merge.

Scoped verification:

  • pnpm test src/agents/compaction.summarize-fallback.test.ts src/agents/compaction.test.ts src/agents/compaction.retry.test.ts src/agents/compaction.tool-result-details.test.ts
  • pnpm lint -- src/agents/compaction.ts src/agents/compaction.summarize-fallback.test.ts
  • pnpm build

Repo-wide note:

  • pnpm check is currently blocked on unrelated latest-main drift in apps/macos/Sources/OpenClaw/HostEnvSecurityPolicy.generated.swift.

  • Land branch head: neeravmakwana@69d551d

  • Merge commit: 7df5f70

Thanks @neeravmakwana!

steipete pushed a commit to leoleedev/openclaw that referenced this pull request Apr 6, 2026
Mlightsnow pushed a commit to Mlightsnow/openclaw that referenced this pull request Apr 6, 2026
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Compaction summarization repeatedly fails with 'fetch failed', causing stuck sessions

2 participants