fix(compression): retry transient transport errors before fallback marker (#16670)#16737
Open
Tranquil-Flow wants to merge 2 commits into
Open
Conversation
Collaborator
|
Related to #16587 — both address transient transport error retry in context compression. This PR appears to be a more refined version with explicit error classifier and narrower retry scope. |
72cf524 to
59f9e75
Compare
59f9e75 to
5b198e8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Auxiliary compression's
call_llmrequest can hitRemoteProtocolError("peer closed connection without sending complete message body (incomplete chunked read)") mid-stream when the auxiliary endpoint hiccups._generate_summary's genericexceptblock inagent/context_compressor.pytreated this like any other failure: 60-second cooldown, drop the selected turns, insert a fallback context marker, repeat on the next compaction. Long Telegram sessions surface this often enough that real context is permanently lost.This PR adds a bounded in-call retry only for fast-fail mid-stream disconnect/protocol classes. Timeout-class errors are deliberately excluded (see Changes Made for why) so a genuinely slow endpoint can't stall a compaction for multiple timeout windows in a row.
Related Issue
Fixes #16670
Type of Change
Changes Made
agent/error_classifier.py— newis_transient_transport_error(error)predicate plus a narrow_DISCONNECT_TRANSPORT_TYPESregistry. ReturnsTrueonly for fast-fail mid-stream disconnect/protocol classes (RemoteProtocolError, ConnectError, ServerDisconnectedError, ConnectionResetError, ConnectionAbortedError, BrokenPipeError, ReadError, APIConnectionError, the SSL transport types). Status-coded errors (4xx/5xx) and all timeout classes (TimeoutError, ReadTimeout, ConnectTimeout, PoolTimeout, APITimeoutError) are explicitly NOT transient — retrying a timeout pays the full timeout window again, and against the 120 s compression default that would turn one missed compaction into a ~6 minute stalled response. Timeouts continue to use the existing cooldown path.agent/context_compressor.py— wraps the singlecall_llminvocation in_generate_summarywith a 1 + 2 retry loop (1 s / 3 s back-offs) gated onis_transient_transport_error. Non-transient errors fall straight through to the existing cooldown / model-fallback logic — 401/404/timeout handling is unchanged.tests/agent/test_error_classifier.py— addedTestIsTransientTransportErrorcovering disconnect strings (incomplete chunked read),RemoteProtocolError,ConnectionError, the HTTP-status rejection, and explicit non-retry coverage forTimeoutError,ReadTimeout,APITimeoutError,ConnectTimeout,PoolTimeout.tests/agent/test_context_compressor.py— addedTestSummaryTransientRetrycovering retry-then-succeed for bothincomplete chunked readstrings andRemoteProtocolError-named classes, retries-exhausted falling through to cooldown, non-transient HTTP errors not retrying, andTimeoutErrornot entering the retry loop (single call, cooldown still set).How to Test
Reproducing the original bug requires a flaky auxiliary endpoint, but the failure mode is identical to the issue's repro: the agent's compaction logs
Failed to generate context summary: peer closed connection without sending complete message body (incomplete chunked read). Further summary attempts paused for 60 seconds.followed by⚠ Compression summary failed: ...user-visible warnings. After this PR, transient mid-stream disconnects retry up to two times before that warning fires.Automated:
Result on macOS 15.6.1 / Python 3.14.2:
190 passed. Reviewer also ran the same command in a separate checkout and reported190 passed.Checklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/ -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/A (docstring on the new helper documents the timeout-exclusion rationale)cli-config.yaml.exampleif I added/changed config keys — or N/A (N/A — no config keys touched; retry budget tuned via existing module-level constants)CONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/A (N/A)time.sleepand existing transport-error registries)Screenshots / Logs