Skip to content

fix(agents): retry compaction on provider-side AbortErrors#97504

Merged
vincentkoc merged 1 commit into
openclaw:mainfrom
hugenshen:fix/compaction-provider-abort-retry
Jun 28, 2026
Merged

fix(agents): retry compaction on provider-side AbortErrors#97504
vincentkoc merged 1 commit into
openclaw:mainfrom
hugenshen:fix/compaction-provider-abort-retry

Conversation

@hugenshen

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where long-running agent sessions would silently lose conversation context during compaction when the LLM API closed a connection mid-stream without the user cancelling the run.

PR #90908 fixed this classification for the outer model-fallback layer, but the inner compaction retry path still treated provider-side AbortErrors (for example undici's "This operation was aborted") as terminal user cancellations. That suppressed retries in summarizeChunks and skipped the LLM fallback in compaction-safeguard when a configured compaction provider disconnected the same way.

The user-visible symptom: compaction appeared to succeed (compacted: true) but the stored summary was a degraded placeholder such as "Summary unavailable due to size limits", erasing useful history without an obvious error.

Why This Change Was Made

The fix aligns inner compaction error handling with the #90908 pattern: only treat an error as a caller-initiated cancellation when AbortSignal.aborted is true. Provider-side AbortErrors with an unaborted signal are retried (LLM path) or fall back to built-in LLM summarization (provider path). Real non-abort transport timeouts such as "fetch failed" / ETIMEDOUT keep the existing no-retry behavior.

summarizeWithFallback now rethrows on caller abort instead of swallowing the error into the placeholder fallback path.

User Impact

  • Default LLM compaction: transient provider disconnects during summarization are retried instead of producing placeholder summaries.
  • Configured compaction provider: provider disconnects fall back to LLM summarization instead of aborting the safeguard path.
  • Explicit user/system cancellation (signal.aborted) still stops immediately with no retry.

Evidence

Behavior or issue addressed: Provider-side AbortError during compaction no longer suppresses retries or LLM fallback when the caller has not cancelled.

Real environment tested: macOS, Node 22, local OpenClaw source checkout on branch fix/compaction-provider-abort-retry, production modules src/agents/compaction.ts and src/agents/agent-hooks/compaction-safeguard.ts.

Exact steps or command run after this patch:

pnpm build
pnpm test src/agents/compaction.summarize-fallback.test.ts src/agents/agent-hooks/compaction-safeguard.test.ts src/agents/compaction.retry.test.ts
node scripts/proof-compaction-provider-abort-retry.mjs

Evidence after fix:

$ pnpm test src/agents/compaction.summarize-fallback.test.ts src/agents/agent-hooks/compaction-safeguard.test.ts src/agents/compaction.retry.test.ts
 Test Files  3 passed (3)
      Tests  106 passed (106)

$ node scripts/proof-compaction-provider-abort-retry.mjs
PASS compaction.ts retries undici AbortError when signal is not aborted (exit=0)
PASS compaction.ts stops immediately when caller signal is already aborted (exit=0)
PASS compaction-safeguard falls back to LLM after provider AbortError (exit=0)
PASS compaction-safeguard propagates AbortError when caller signal is aborted (exit=0)

=== summary ===
ALL PASS

Proof script exercises the real production call chains:

  • summarizeWithFallbacksummarizeChunksretryAsync (compaction.ts)
  • session_before_compacttryProviderSummarize → LLM fallback via summarizeInStages (compaction-safeguard.ts)

Regression tests mock only the external LLM API boundary (generateSummary / provider summarize); all classification and retry/fallback orchestration runs through production code.

Observed result after fix: Provider-side AbortError with unaborted signal triggers a second generateSummary call and returns "recovered summary after provider disconnect"; safeguard provider failure invokes summarizeInStages instead of { cancel: true }. Caller-aborted signal still throws immediately with a single attempt.

What was not tested: Live gateway compaction against a real provider that disconnects mid-stream; Crabbox pnpm check:changed (local Crabbox unavailable).

Proof limitations or environment constraints: Proof uses production compaction modules with mocked LLM/provider network boundaries. No live network disconnect was injected during proof.

Tests and validation

  • pnpm build — pass
  • pnpm test src/agents/compaction.summarize-fallback.test.ts src/agents/agent-hooks/compaction-safeguard.test.ts src/agents/compaction.retry.test.ts — 106 passed
  • node scripts/run-oxlint.mjs --tsconfig tsconfig.json src/agents/compaction.ts src/agents/agent-hooks/compaction-safeguard.ts — pass
  • Regression tests added in src/agents/compaction.summarize-fallback.test.ts and src/agents/agent-hooks/compaction-safeguard.test.ts

Risk checklist

  • Did user-visible behavior change? Yes — compaction now retries/fallbacks on provider disconnects instead of silently degrading summaries.
  • Did config, environment, or migration behavior change? No
  • Did security, auth, secrets, network, or tool execution behavior change? No
  • Highest-risk area: compaction retry loop could retry provider-side aborts up to 3 times before falling back.
  • Mitigation: retries are bounded (3 attempts, existing backoff); caller abort remains terminal; non-abort timeouts unchanged.

Current review state

  • Next action: awaiting maintainer review
  • Bot comments addressed: none yet

Related: #90908 (outer model-fallback fix; this PR completes the inner compaction layers)

AI-assisted.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: M labels Jun 28, 2026
@clawsweeper

clawsweeper Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed June 28, 2026, 10:58 AM ET / 14:58 UTC.

Summary
The branch changes default LLM compaction and compaction-safeguard provider fallback so provider-side AbortErrors are retried or fall back when the caller signal is not aborted.

PR surface: Source +32, Tests +197. Total +229 across 5 files.

Reproducibility: yes. at source level: current main routes AbortError-shaped compaction errors through terminal abort/timeout branches before checking whether the caller signal was aborted. I did not execute tests in this read-only review.

Review metrics: 1 noteworthy metric.

  • Compaction AbortError Classifiers: 2 runtime decision points changed. Both default LLM compaction and configured provider fallback now use caller signal state for AbortError handling, so they should be reviewed as one session-state contract.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🐚 platinum hermit
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • none.

Risk before merge

  • [P2] The change intentionally alters session-state outcomes for provider-side AbortError during compaction, so maintainers should accept the retry/fallback contract before merge.
  • [P1] The contributor proof exercises production compaction call chains with mocked external provider boundaries; it does not include a live provider disconnect trace.

Maintainer options:

  1. Accept Bounded Compaction Retry Semantics (recommended)
    Land if maintainers agree that an AbortError with an unaborted caller signal is a recoverable provider disconnect for compaction.
  2. Ask For Live Disconnect Proof
    Request a redacted live provider disconnect trace if source-level terminal proof is not enough for this session-state path.

Next step before merge

  • [P2] Maintainers should decide whether to accept the session-state retry/fallback behavior; there is no narrow automated repair to apply.

Security
Cleared: The diff changes compaction abort classification and tests only; it does not modify dependencies, workflows, permissions, secrets, packaging, or code execution surfaces.

Review details

Best possible solution:

Land the focused bug fix after maintainer acceptance of the bounded compaction retry/fallback semantics and exact-head checks; keep broader fallback/abort consolidation separate.

Do we have a high-confidence way to reproduce the issue?

Yes at source level: current main routes AbortError-shaped compaction errors through terminal abort/timeout branches before checking whether the caller signal was aborted. I did not execute tests in this read-only review.

Is this the best way to solve the issue?

Yes, this is the best narrow fix I found: it uses the existing AbortSignal already threaded through compaction, matches the merged model-fallback pattern, and adds no config or API surface.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9241b9701d9c.

Label changes

Label justifications:

  • P1: Misclassified provider-side AbortErrors during compaction can silently degrade or lose useful conversation context in long-running agent sessions.
  • merge-risk: 🚨 session-state: The PR changes when compaction retries, falls back, preserves partial summaries, or propagates cancellation, which directly affects stored session summaries.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body includes after-fix terminal output from production compaction call-chain proof plus focused tests, and the Real behavior proof check passed.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body includes after-fix terminal output from production compaction call-chain proof plus focused tests, and the Real behavior proof check passed.
Evidence reviewed

PR surface:

Source +32, Tests +197. Total +229 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 40 8 +32
Tests 3 204 7 +197
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 244 15 +229

What I checked:

Likely related people:

  • DhruvBhatia0: Symbol history ties the compaction provider registry and provider fallback surface to the pluggable compaction provider work. (role: feature introducer; confidence: high; commits: 12331f04631f; files: src/plugins/compaction-provider.ts, src/agents/agent-hooks/compaction-safeguard.ts, docs/reference/session-management-compaction.md)
  • shengting: Authored the merged outer model-fallback AbortError classification fix that this PR explicitly follows for inner compaction behavior. (role: adjacent fix author; confidence: high; commits: 98ed83f848de; files: src/agents/model-fallback.ts, src/agents/model-fallback.test.ts, src/agents/embedded-agent-runner/compact.ts)
  • Milosz Jankiewicz: Current line blame for the compaction files points to commit 84bcd50, but the commit appears broad and may have carried code forward rather than introduced the behavior. (role: recent area contributor; confidence: low; commits: 84bcd500c974; files: src/agents/compaction.ts, src/agents/agent-hooks/compaction-safeguard.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jun 28, 2026
Align inner compaction retry and compaction-safeguard provider fallback
with the openclaw#90908 signal.aborted pattern so undici disconnect AbortErrors
retry or fall back to LLM instead of producing degraded placeholder
summaries. Caller abort remains terminal.
@hugenshen
hugenshen force-pushed the fix/compaction-provider-abort-retry branch from 2a305bc to 509a193 Compare June 28, 2026 14:45
@vincentkoc
vincentkoc merged commit 245c18d into openclaw:main Jun 28, 2026
93 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jun 29, 2026
…97504)

Align inner compaction retry and compaction-safeguard provider fallback
with the openclaw#90908 signal.aborted pattern so undici disconnect AbortErrors
retry or fall back to LLM instead of producing degraded placeholder
summaries. Caller abort remains terminal.

Co-authored-by: NIO <[email protected]>
Rorqualx pushed a commit to Rorqualx/cortex that referenced this pull request Jun 29, 2026
…97504)

Align inner compaction retry and compaction-safeguard provider fallback
with the openclaw#90908 signal.aborted pattern so undici disconnect AbortErrors
retry or fall back to LLM instead of producing degraded placeholder
summaries. Caller abort remains terminal.

Co-authored-by: NIO <[email protected]>
(cherry picked from commit 245c18d)
QiuYuang pushed a commit to QiuYuang/openclaw that referenced this pull request Jul 1, 2026
…97504)

Align inner compaction retry and compaction-safeguard provider fallback
with the openclaw#90908 signal.aborted pattern so undici disconnect AbortErrors
retry or fall back to LLM instead of producing degraded placeholder
summaries. Caller abort remains terminal.

Co-authored-by: NIO <[email protected]>
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 1, 2026
…97504)

Align inner compaction retry and compaction-safeguard provider fallback
with the openclaw#90908 signal.aborted pattern so undici disconnect AbortErrors
retry or fall back to LLM instead of producing degraded placeholder
summaries. Caller abort remains terminal.

Co-authored-by: NIO <[email protected]>
amittell pushed a commit to amittell/openclaw that referenced this pull request Jul 2, 2026
…97504)

Align inner compaction retry and compaction-safeguard provider fallback
with the openclaw#90908 signal.aborted pattern so undici disconnect AbortErrors
retry or fall back to LLM instead of producing degraded placeholder
summaries. Caller abort remains terminal.

Co-authored-by: NIO <[email protected]>
(cherry picked from commit 245c18d)
chenyangjun-xy pushed a commit to chenyangjun-xy/openclaw that referenced this pull request Jul 3, 2026
…97504)

Align inner compaction retry and compaction-safeguard provider fallback
with the openclaw#90908 signal.aborted pattern so undici disconnect AbortErrors
retry or fall back to LLM instead of producing degraded placeholder
summaries. Caller abort remains terminal.

Co-authored-by: NIO <[email protected]>
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Jul 15, 2026
…97504)

Align inner compaction retry and compaction-safeguard provider fallback
with the openclaw#90908 signal.aborted pattern so undici disconnect AbortErrors
retry or fall back to LLM instead of producing degraded placeholder
summaries. Caller abort remains terminal.

Co-authored-by: NIO <[email protected]>
(cherry picked from commit 245c18d)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants