FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

502 Stream ended unexpectedly repeatedly when context is image-heavy (~23 MB request payload) · Issue #997 · CommandCodeAI/command-code · GitHub

Repository navigation

502 Stream ended unexpectedly repeatedly when context is image-heavy (~23 MB request payload) #997

Description

Summary

In a long session that accumulates many image tool-results, requests start failing with HTTP 502 mid-stream. Typing continue does not recover the turn — the identical retry fails again — until an automatic compaction reduces the context. The failures correlate strongly with request payload size: in the failing request, 90% of the payload was base64 image data (~21 MB of ~23 MB). The session became unusable for ~12 minutes until auto-compaction fired.

Expected Behavior

Either:

  • the request succeeds, or
  • the client surfaces a clear, actionable error when the payload exceeds the gateway limit (e.g. 413 Payload Too Large with a hint to run /compact),

instead of a mid-stream 502 that looks like a server outage and cannot be recovered by retrying.

Actual Behavior

Error: 502 Stream ended unexpectedly before completion (no finish event) — response was truncated

Type "continue" to try again. If the issue persists, contact support: https://commandcode.ai/discord
Trace ID: <id>

Occurred 3 times in one session:

Time (Asia/Shanghai) Context size Result
2026-10-06 22:51:43 — ❌ 502 — Trace ID 0f0779d55fd78bb6260376fe9ae7cd4a
2026-10-07 22:19:52 ~23 MB ❌ 502 — Trace ID 019ce383d60bfcc89ec3d86f9f096f36
2026-10-07 22:26:42 ~23 MB (unchanged — user typed continue) ❌ 502 — Trace ID acf33d5d9b6afc7b1d68423f3ffaf712
2026-10-07 22:31:08 — auto-compaction ran (tokensSaved: 400540)
2026-10-07 22:32:31 much smaller ✅ success

Payload composition at the failing request (measured from the on-disk session transcript; all 779 lines parse as valid JSON, so the local file is intact):

Component Size Share
Base64 image data 20.9 MB 90.3%
Text / tool output / thinking 2.2 MB 9.7%
Total 23.1 MB 100%

Image tool-results accumulated in the session: 63. Growth is cumulative — images stay in context and are re-sent on every subsequent turn:

after image  1:  context  0.8 MB
after image 20:  context  5.5 MB
after image 40:  context 12.0 MB
after image 60:  context 22.5 MB

Why this looks like a size problem rather than a transient outage:

  • The 22:19 failure and the 22:26 retry carried an identical payload → both failed.
  • After auto-compaction drastically reduced the payload, the very next retry succeeded.
  • The only variable that changed was payload size.

Steps to reproduce the issue

  1. Start a session and read/attach images repeatedly (e.g. screenshots for transcription), so image tool-results accumulate in context.
  2. Keep going until the serialized conversation reaches roughly 20 MB+ (63 image reads in this case).
  3. From that point, requests fail with 502, and continue does not recover the turn.
  4. Run /compact (or wait for auto-compaction) — the next request succeeds.

Command Code Version

1.74.1

Operating System

Windows

Terminal/IDE

Command Code desktop app (Electron)

Shell

PowerShell

Additional context

  • Model: deepseek/deepseek-v4.1-flash
  • Entrypoint: interactive
  • Host: Windows 11 Pro, Build 26200, ASUS TUF Gaming A15; Node v24.16.0
  • Session file: available on request. I'd rather not attach it publicly since it contains personal study material — but the measurements above were all taken from it, and the Trace IDs should let you pull the requests.
  • Suggested improvements:
    1. Return a clearer error when the request body exceeds the gateway limit (e.g. 413 + "run /compact") instead of a mid-stream 502 that a retry cannot fix.
    2. Consider ageing out or replacing already-consumed image tool-results with a lightweight text placeholder, since each image is re-sent on every subsequent turn.
    3. Consider warning the user when the serialized request crosses a size threshold, so they can compact proactively.

(Trace IDs are included for debugging — noted in case they allow looking up the associated request content.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL