Skip to content

fix(agent): classify mid-response stream deaths as transient upstream failures#3394

Merged
tatoalo merged 1 commit into
mainfrom
posthog-code/classify-mid-response-stream-drop
Jul 13, 2026
Merged

fix(agent): classify mid-response stream deaths as transient upstream failures#3394
tatoalo merged 1 commit into
mainfrom
posthog-code/classify-mid-response-stream-drop

Conversation

@tatoalo

@tatoalo tatoalo commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Problem

When the SSE stream dies after content has started streaming (like a gateway pod replaced mid-stream, cc surfaces it as:

API Error: Connection closed mid-response. The response above may be incomplete.

classifyAgentError doesn't recognize this string (it only matches terminated, Connection error, timeouts, and 429/5xx), so the failure is classified as a fatal agent_error: the whole cloud task run is marked failed and the user sees the raw transport error instead of the "upstream provider failed, please retry" message

Changes

  • Classify API Error: … Connection closed mid-response as upstream_stream_terminated.
  • Also classify transport-level socket connection (was) closed variants (wording differs across fetch implementations) the same way

@trunk-io

trunk-io Bot commented Jul 13, 2026

Copy link
Copy Markdown

Merging to main in this repository is managed by Trunk.

  • To merge this pull request, check the box to the left or comment /trunk merge below.

After your PR is submitted to the merge queue, this comment will be automatically updated with its status. If the PR fails, failure details will also be posted here

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

React Doctor found no issues in the changed files. 🎉

Reviewed by React Doctor for commit 5ecb99a.

@tatoalo tatoalo self-assigned this Jul 13, 2026
@tatoalo tatoalo marked this pull request as ready for review July 13, 2026 13:59
@greptile-apps

greptile-apps Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Reviews (1): Last reviewed commit: "fix(agent): classify mid-response stream..." | Re-trigger Greptile

Comment thread packages/agent/src/adapters/error-classification.ts Outdated
Comment thread packages/agent/src/adapters/error-classification.ts
… failures

Claude Code surfaces an SSE stream that dies after content started as
"API Error: Connection closed mid-response. The response above may be
incomplete." classifyAgentError did not recognize that string (nor the
transport-level "socket connection was closed" variants), so these
transient transport failures fell through to agent_error and hard-failed
the whole task run with a raw error message instead of being treated as
retriable upstream failures.

Generated-By: PostHog Code
Task-Id: a04c4d02-9070-4e5d-9748-bfceb251e3fa
@tatoalo tatoalo force-pushed the posthog-code/classify-mid-response-stream-drop branch from bcef67e to 5ecb99a Compare July 13, 2026 14:08
@tatoalo tatoalo added the Stamphog This will request an autostamp by stamphog on small changes label Jul 13, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low-risk error classification fix with good test coverage; the two substantive bot concerns (prefix-less socket patterns, classifier divergence) are both addressed in the current diff.

@tatoalo tatoalo requested a review from a team July 13, 2026 14:18
@tatoalo tatoalo merged commit 9bf31ec into main Jul 13, 2026
31 checks passed
@tatoalo tatoalo deleted the posthog-code/classify-mid-response-stream-drop branch July 13, 2026 14:46
charlesvien pushed a commit to ricardo-leiva/code that referenced this pull request Jul 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Stamphog This will request an autostamp by stamphog on small changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant