Skip to content

fix(e2b): envd process streaming response parsing misreports exit code 0 #3338

Closed

Description

@chcodex

Problem

E2bEnvdProcessClient.drainStartStream mishandles the Connect streaming protocol:

  • sint32 exit_code = 0 (proto3 default, omitted from wire/JSON) is treated as "no exit code" via hasField(), so exit 0 is reported as Integer.MIN_VALUE.
  • End-stream envelopes (flags bit 1, EndStreamMessage JSON) are not parsed; error end-streams are silently ignored.
  • Compressed frames (bit 0) and reserved flag bits have no handling; message-length mask (& 0x7FFFFFFF) contradicts the spec (unsigned int).
  • EndEvent.error (signal kills) never reaches stderr.

Scope

E2bEnvdProcessClient frame parsing only: parse end-stream (throw on error, break cleanly otherwise), reject compressed frames, skip reserved bits, read exit_code via getField(), forward EndEvent.error to stderr, extract buildEnvdRequest. Plus unit + integration tests.

Local branch: split/e2b-a-envd-parsing (stacked base, split from #2196).

Activity

  1. oss-maintainer commented on Sep 28, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Status: Partially confirmed (verified against main @ 525706267) | Severity: medium

    Claim-by-claim result against the current source:

    Claim Result Evidence
    (a) hasField() on exit_code turns exit 0 into Integer.MIN_VALUE Not confirmed on main the exit code is read with end.getField(ec) with no presence check (E2bEnvdProcessClient.java:203-209); there is no Integer.MIN_VALUE sentinel anywhere in the class
    (b) EndStream envelopes (flags bit 1) are not parsed; error end-streams are silently ignored Confirmed every non-zero flag byte is dropped by if (flags != 0x00) continue; (:189-190), so an EndStreamMessage — including a Connect error end-stream — never reaches any handler
    (c) compressed frames (bit 0) / reserved bits unhandled; & 0x7FFFFFFF length mask contradicts the unsigned spec Confirmed same flags != 0x00 skip (:189-190); length is ByteBuffer.getInt() & 0x7FFFFFFF (:181), which makes the len < 0 guard at :182 unreachable and silently truncates the top bit of a legitimate length ≥ 2^31
    (d) EndEvent.error (signal kills) never reaches stderr Confirmed stderr is only fed from DataEvent.stderr (:198-201, :221-233); the end branch reads exit_code only (:203-209), and the JSON path reads exitCode only (:341-350)

    Two refinements worth recording:

    • The real failure mode for a missing/zero exit code is not a wrong int — it is the terminal IOException("envd process stream ended before receiving a process exit code") at :215-218. On the JSON branch an end object without a convertible exitCode is dropped entirely (:341-350, the setField is inside the canConvertToInt() guard), so an error-only end event is indistinguishable from a truncated stream. On the protobuf branch a present end with an omitted exit_code correctly yields 0.
    • The (b)/(c) defects are what actually make exit codes misreport in production: an EndStream carrying a Connect error is skipped, the loop then hits EOF and throws the generic "stream ended before…" exception, so the real cause (server-side error, compressed frame, or oversized length) is lost.

    Coordination: PR #3341 (split/e2b-a-envd-parsing) is open against this issue and main does not contain those changes yet. We are not opening a competing PR. Suggested coverage for #3341: protobuf exit_code = 0, JSON end without exitCode, JSON end with error only, EndStream with error flags, compressed frame rejection, reserved-bit skip, and a length value with the top bit set.


    Automated evaluation by github-manager-bot

  2. added
    bug
    area/extensions
    on Sep 28, 2026
  3. added a commit that references this issue on Oct 11, 2026
    897c486
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

    area/extensionsbug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions