Skip to content

fix(compaction): later provider timeouts discard completed chunks#92899

Open
mushuiyu886 wants to merge 14 commits into
openclaw:mainfrom
mushuiyu886:feat/issue-92043
Open

fix(compaction): later provider timeouts discard completed chunks#92899
mushuiyu886 wants to merge 14 commits into
openclaw:mainfrom
mushuiyu886:feat/issue-92043

Conversation

@mushuiyu886

@mushuiyu886 mushuiyu886 commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Related: #92043

What Problem This Solves

Fixes an issue where multi-chunk compaction would discard summaries from completed chunks when a later provider request timed out, replacing useful progress with the generic "Summary unavailable due to size limits" fallback.

Why This Change Was Made

Non-caller provider timeouts now use the existing partial-summary recovery path after at least one chunk has completed. Caller cancellation and wrapper safety-timeout aborts remain terminal, so this no longer changes post-timeout AgentSession persistence, lifecycle, or stored-state policy.

This update intentionally narrows the previous 20-file proposal to the primary contributor-owned invariant. The bounded post-timeout commit policy, session lifecycle drain, retained-entry remapping, timeout-helper cleanup, and failure-copy changes are no longer part of this PR.

User Impact

When an early compaction chunk succeeds and a later provider request times out, OpenClaw retains the completed summary instead of losing all progress. Explicit cancellation behavior and the outer compaction safety timeout are unchanged.

Evidence

The narrowed behavior is covered by a red/green regression test, adjacent compaction tests, and an actual loopback OpenAI-compatible HTTP/SSE before/after run.

Real behavior proof

A loopback OpenAI-compatible HTTP/SSE provider exercised the production summary transport with two chunks: the first request returned a streamed summary and the second returned HTTP 504 with a provider timeout error.

  • Before on origin/main (277f009cc902aecf09ee0cdd8345223186c16fa9): 2 provider requests; first chunk completed; later request timed out; retainedCompletedChunk=false; partialMarkerPresent=false; generic fallback returned.
  • After on 1dc4de07426a218efe07d436d5db92bd1c7c37b8: 2 provider requests; first chunk completed; later request timed out; retainedCompletedChunk=true; partialMarkerPresent=true; generic fallback absent.
  • The proof used temporary loopback-only credentials and did not call a third-party provider.

Tests and checks

  • RED: node scripts/run-vitest.mjs src/agents/compaction-partial-summary.test.ts failed because a later timeout returned the generic fallback.
  • GREEN: the same focused file passed, 9/9 tests.
  • Adjacent compaction tests: compaction-partial-summary.test.ts plus compaction.summarize-fallback.test.ts, 13/13 tests passed.
  • Formatting, conflict-marker, max-lines, dependency-pin, Plugin SDK API baseline, deprecated API, plugin-boundary, package-patch, and temp-creation checks passed.
  • Local core typecheck was blocked by three unchanged packages/net-policy/src/ip.ts errors; the identical command reproduced the same errors on a clean origin/main control worktree with the same dependency tree.
  • Structured autoreview built the final two-file bundle, but the Codex Responses WebSocket returned HTTP 403 before producing findings. The final diff was manually reviewed against summarizeWithFallbackResult, caller-abort behavior, timeout classification, and adjacent partial-summary tests.

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: XS proof: supplied External PR includes structured after-fix real behavior proof. labels Jun 14, 2026
@clawsweeper

clawsweeper Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 17, 2026, 10:03 PM ET / July 18, 2026, 02:03 UTC.

Summary
The branch changes summarizeChunks so a non-caller provider timeout after an earlier completed chunk returns the existing partial-summary result instead of discarding that progress for the generic fallback.

PR surface: Source -4, Tests +1. Total -3 across 2 files.

Reproducibility: yes. from the supplied production-path loopback HTTP/SSE proof and focused regression fixture: complete one summary chunk, then return a provider timeout for the next chunk while the caller signal remains unaborted. I did not independently execute that path in this read-only review.

Review metrics: none identified.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🦞 diamond lobster
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:

  • Refresh the exact current-main merge result and preserve the timeout-plus-caller-abort assertions before approval.

Risk before merge

  • [P2] Returning a partial summary changes the session context that can be committed after a provider timeout; before merge, confirm the current-main three-way result still preserves terminal caller cancellation and the outer compaction safety-timeout behavior.

Maintainer options:

  1. Refresh the current-main compaction proof (recommended)
    Rebase or otherwise review the clean current-main merge result, then retain the focused timeout and caller-abort coverage before approval.

Next step before merge

  • [P2] No repair lane is indicated because the current narrowed branch has no actionable source-level finding; it needs normal owner approval after a current-main review refresh.

Security
Cleared: The two-file TypeScript change adds no dependency, workflow, permission, secret, package-resolution, or execution-surface change.

Review details

Best possible solution:

Land the narrow partial-summary recovery only if the rebased current-main result retains terminal caller cancellation and safety-timeout handling while preserving completed chunks for non-caller provider failures.

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

Yes, from the supplied production-path loopback HTTP/SSE proof and focused regression fixture: complete one summary chunk, then return a provider timeout for the next chunk while the caller signal remains unaborted. I did not independently execute that path in this read-only review.

Is this the best way to solve the issue?

Yes for this bounded failure mode: it reuses the existing partial-summary path and preserves the established terminal boundary for an actually aborted caller signal. Cross-attempt persistence and timeout-budget policy remain separate work in #92043.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 3d1b77103511.

Label changes

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR supplies a before/after loopback OpenAI-compatible HTTP/SSE run through the production summary transport, and the current-head real-behavior-proof check succeeded; the evidence directly demonstrates retention of a completed first chunk after a second-request HTTP 504.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove merge-risk: 🚨 availability: Current PR review merge-risk labels are merge-risk: 🚨 session-state.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: A later provider timeout can discard completed compaction progress and leave affected agent sessions with the generic context-recovery fallback.
  • merge-risk: 🚨 session-state: The patch intentionally changes which partial compaction summary may reach session persistence after a provider timeout.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR supplies a before/after loopback OpenAI-compatible HTTP/SSE run through the production summary transport, and the current-head real-behavior-proof check succeeded; the evidence directly demonstrates retention of a completed first chunk after a second-request HTTP 504.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR supplies a before/after loopback OpenAI-compatible HTTP/SSE run through the production summary transport, and the current-head real-behavior-proof check succeeded; the evidence directly demonstrates retention of a completed first chunk after a second-request HTTP 504.
Evidence reviewed

PR surface:

Source -4, Tests +1. Total -3 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 6 -4
Tests 1 6 5 +1
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 8 11 -3

What I checked:

  • Narrow production behavior: The changed summarizeChunks catch block now rethrows only when the supplied caller signal is aborted, allowing later non-caller provider failures to flow into the existing partial-summary recovery when a chunk has already completed. (src/agents/compaction.ts:194, 1dc4de07426a)
  • Regression coverage: The changed regression test asserts that a later TimeoutError retains the first chunk summary, includes the partial marker and chunk range, and emits the existing partial-summary warning with one completed chunk. (src/agents/compaction-partial-summary.test.ts:170, 1dc4de07426a)
  • Real behavior proof: The PR body records a before/after loopback OpenAI-compatible HTTP/SSE run with two chunks: the first completed, the second returned HTTP 504, and the patched head retained the completed chunk and partial marker. The current-head Real behavior proof check also completed successfully. (1dc4de07426a)
  • Merged adjacent precedent: Merged PR fix(agents): retry compaction on provider-side AbortErrors #97504 established the adjacent compaction rule that provider-side abort-like errors are not caller cancellation when the signal is not aborted; this branch applies the same caller-signal boundary to later timeout recovery. (src/agents/compaction.ts:194, 245c18da5a6c)

Likely related people:

  • hugenshen: Authored the merged provider-side compaction abort-classification work that established the nearby caller-signal invariant used by this patch. (role: adjacent behavior introducer; confidence: high; commits: 245c18da5a6c; files: src/agents/compaction.ts, src/agents/compaction.summarize-fallback.test.ts)
  • vincentkoc: Was assigned this PR and is identified in the related preflight-compaction history as carrying the connection between reply lifecycle and compaction behavior. (role: recent compaction review owner; confidence: medium; commits: 280d1cb97; files: src/agents/compaction.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.
Review history (27 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-14T23:22:06.270Z sha 67b8ab1 :: needs changes before merge. :: [P1] Restore the timeout helper used by the Pi runtime
  • reviewed 2026-07-14T23:40:01.725Z sha 67b8ab1 :: needs changes before merge. :: [P1] Restore the timeout helper used by the Pi runtime
  • reviewed 2026-07-14T23:57:07.279Z sha 67b8ab1 :: needs changes before merge. :: [P1] Restore the timeout helper required by Pi compaction
  • reviewed 2026-07-15T00:16:11.688Z sha 67b8ab1 :: needs changes before merge. :: [P1] Keep the shared timeout helper required by Pi
  • reviewed 2026-07-15T00:44:49.412Z sha 67b8ab1 :: needs changes before merge. :: [P1] Preserve the shared timeout helper required by Pi
  • reviewed 2026-07-16T02:28:26.309Z sha c5cdaef :: needs maintainer review before merge. :: none
  • reviewed 2026-07-16T04:06:30.443Z sha c5cdaef :: needs maintainer review before merge. :: none
  • reviewed 2026-07-18T01:21:44.726Z sha 1dc4de0 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. labels Jun 14, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Jun 14, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jun 15, 2026
@vincentkoc vincentkoc self-assigned this Jun 16, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 18, 2026
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Jun 19, 2026
@clawsweeper clawsweeper Bot added 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. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. 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. labels Jul 14, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

This PR no longer has blocked security-sensitive file changes. A future security-sensitive change requires a fresh /allow-security-sensitive-change comment after the guard blocks that new head SHA.

  • Current SHA: 1dc4de07426a218efe07d436d5db92bd1c7c37b8

@github-actions

github-actions Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Dependency graph guard cleared

This PR no longer has blocked dependency graph changes. A future dependency graph change requires a fresh /allow-dependencies-change comment after the guard blocks that new head SHA.

  • Current SHA: 1dc4de07426a218efe07d436d5db92bd1c7c37b8

@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@mushuiyu886

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@mushuiyu886

Copy link
Copy Markdown
Contributor Author

Updated the branch to resolve the current main conflicts and narrowed the PR to the primary contributor-owned invariant from the review.

  • Final surface: 2 files, 8 additions / 11 deletions.
  • Removed from this PR: post-timeout AgentSession commits, stored-state/boundary changes, lifecycle drain/invalidation, timeout-helper deletion, and failure-copy changes.
  • Preserved behavior: caller cancellation and wrapper safety-timeout aborts remain terminal.
  • Focused tests: 9/9 passed; adjacent compaction tests: 13/13 passed.
  • Actual loopback OpenAI-compatible HTTP/SSE proof: the first chunk completed and the second request returned HTTP 504. origin/main discarded the completed chunk; this head retained it with the existing partial-summary marker.
  • Formatting and repository guards passed. Core typecheck reached an unchanged packages/net-policy/src/ip.ts dependency/type mismatch that reproduced identically on a clean origin/main control worktree.
  • Codex structured autoreview could not produce findings because the Responses WebSocket returned HTTP 403; the final two-file diff was manually reviewed against timeout classification, caller-abort handling, and adjacent partial-summary paths.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

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. proof: supplied External PR includes structured after-fix real behavior proof. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS stale Marked as stale due to inactivity 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.

3 participants