Compaction skips redundant partial summarization
When full summarization failed with no oversized messages to drop, the compaction logic was running the same failing API call twice—duplicating work, retries, and warning logs. A two-character fix prevents this redundant pass.
When session compaction fails during summarization, a fallback mechanism attempts a "partial" pass over the message set. The intent is to exclude oversized messages and try again on a smaller payload. But when all messages fit the size threshold, the partial pass operated on the exact same transcript as the failed full attempt.
This redundancy mattered during transport failures like network timeouts. Each failed summarization triggered retries—running that logic twice meant double the API calls, double the wait times, and two warning lines in the logs for every compaction attempt. Sessions could enter a failure loop, becoming unresponsive until manually cleared.
The fix adds a single check: only run partial summarization when the message set is actually smaller. If smallMessages.length equals messages.length, the inputs are identical and the partial pass is skipped. Otherwise, partial summarization proceeds as before.
The change lives in the compaction module that manages agent session memory. The core summarization and staging behavior remains unchanged—the fix applies only to that narrow redundancy case.
View Original GitHub Description
Summary
- Problem: When full summarization failed and no messages were marked oversized,
summarizeWithFallbackstill 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
smallMessagesis 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
- Closes #61465
- This PR fixes a bug or regression
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,
generateSummaryis 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 testonsrc/agents/compaction.test.ts,compaction.retry.test.ts,compaction.tool-result-details.test.ts,compaction.summarize-fallback.test.tsoxlinton touched TypeScript files