fix(e2b): envd process streaming response parsing misreports exit code 0
Problem
E2bEnvdProcessClient.drainStartStream mishandles the Connect streaming protocol:
sint32 exit_code = 0(proto3 default, omitted from wire/JSON) is treated as "no exit code" viahasField(), so exit 0 is reported asInteger.MIN_VALUE.- End-stream envelopes (flags bit 1,
EndStreamMessageJSON) 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).
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 anendobject without a convertibleexitCodeis dropped entirely (:341-350, thesetFieldis inside thecanConvertToInt()guard), so an error-only end event is indistinguishable from a truncated stream. On the protobuf branch a presentendwith an omittedexit_codecorrectly yields0. - 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