@molecule/api-code-sandbox-e2b 1.2.7 → 1.2.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EACV,qBAAqB,EAErB,aAAa,EAKb,oBAAoB,EACpB,kBAAkB,EAClB,OAAO,EACP,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,eAAe,EAGf,UAAU,EACX,MAAM,4BAA4B,CAAA;AAEnC,OAAO,KAAK,EAGV,SAAS,EACT,oBAAoB,EAMrB,MAAM,YAAY,CAAA;AA2zBnB;;;;;;;;GAQG;AACH,qBAAa,kBAAmB,YAAW,eAAe;IACxD,QAAQ,CAAC,IAAI,SAAQ;IAErB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA0D;IACjF,OAAO,CAAC,aAAa,CAA6C;IAClE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAsB;IAEtD;;;;;OAKG;gBACS,MAAM,GAAE,SAAc,EAAE,cAAc,CAAC,EAAE,oBAAoB;IAYzE;;;;OAIG;YACW,MAAM;IASpB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACG,MAAM,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAIrD;;;;;;;;;;;;;;OAcG;YACW,aAAa;IAkD3B;;;;;OAKG;IACG,GAAG,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAoB9C;;;;;;;;;;;;;;;OAeG;IACG,QAAQ,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAkC7D;;;;;OAKG;IACG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC;IAgB/C;;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M,CAAA;IACf,mCAAmC;IACnC,UAAU,EAAE,MAAM,CAAA;IAClB,sCAAsC;IACtC,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,aAAa,CA8B1E;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,MAAM,GAAE,SAAc,EACtB,cAAc,CAAC,EAAE,oBAAoB,GACpC,kBAAkB,CAEpB;AAED,kEAAkE;AAClE,eAAO,MAAM,QAAQ,EAAE,eAAkC,CAAA"}
package/dist/provider.js CHANGED
@@ -26,6 +26,23 @@ const DEFAULT_SPAWN_TIMEOUT_MS = 60 * 60 * 1000;
26
26
  * this instead of the caller's whole timeout.
27
27
  */
28
28
  const SETTLE_PROBE_MS = 1_500;
29
+ /**
30
+ * How long to wait for the handle to REPORT the exit code after the started pid
31
+ * is confirmed gone. envd closes the output stream right behind a real exit, so
32
+ * a finished command's `end` event — the only thing that carries its exit code —
33
+ * lands within this window; only a stream held by a stranded descendant
34
+ * outlives it.
35
+ */
36
+ const EXIT_REPORT_GRACE_MS = 2_000;
37
+ /**
38
+ * The exit code reported when a command's outcome cannot be observed at all:
39
+ * the started pid is gone but the stream it was reading is still held, so the
40
+ * SDK never delivers the `end` event that carries the real code. 128+SIGKILL
41
+ * (137), the conventional status of a killed process — because "unknown" must
42
+ * read as failure, never as the fabricated `0` that once reported a killed
43
+ * build (partial `dist/` and all) as a successful one.
44
+ */
45
+ const EXIT_CODE_UNKNOWN = 137;
29
46
  /** Default lifetime for a PTY session; same reasoning as {@link DEFAULT_SPAWN_TIMEOUT_MS}. */
30
47
  const DEFAULT_PTY_TIMEOUT_MS = 60 * 60 * 1000;
31
48
  /**
@@ -309,6 +326,14 @@ class E2BSandbox {
309
326
  * running and the caller's own timeout is the right bound. Never a guess from
310
327
  * the shape of the command.
311
328
  *
329
+ * But "over" is not "succeeded": the SDK delivers the exit code on the
330
+ * stream's `end` event, and the descendant holding the stream keeps that
331
+ * event from ever arriving. A gone pid therefore gets a bounded grace window
332
+ * for the handle to report the real code, and a handle that never does is
333
+ * reported as {@link EXIT_CODE_UNKNOWN} — failure — because an outcome that
334
+ * cannot be observed (a build OOM-killed mid-run) must never be fabricated
335
+ * into success.
336
+ *
312
337
  * @param handle - The started command.
313
338
  * @returns The command's result.
314
339
  */
@@ -328,11 +353,29 @@ class E2BSandbox {
328
353
  const alive = await this.isProcessAlive(handle.pid);
329
354
  if (alive)
330
355
  return finished;
331
- // The process is gone; whatever still holds the stream is not it.
356
+ // The process is gone; whatever still holds the stream is not it. The real
357
+ // exit code rides the stream's `end` event, so give the handle a bounded
358
+ // window to deliver it — when the process truly finished, envd closes the
359
+ // stream right behind it and the result lands here.
360
+ const reported = await Promise.race([
361
+ finished,
362
+ new Promise((resolve) => setTimeout(() => resolve(null), EXIT_REPORT_GRACE_MS)),
363
+ ]);
364
+ if (reported)
365
+ return reported;
366
+ if (typeof handle.exitCode === 'number') {
367
+ return { stdout: handle.stdout ?? '', stderr: handle.stderr ?? '', exitCode: handle.exitCode };
368
+ }
369
+ // Still nothing: the exit code is UNKNOWN. Reporting `0` here used to
370
+ // fabricate success for exactly this shape — a killed build whose stranded
371
+ // daemon held the stream shipped its partial `dist/` as a finished site —
372
+ // so fail closed instead, with a line that says why the code is missing.
373
+ const unknownNote = `e2b: exit code unknown — the started process (pid ${handle.pid}) is gone but its ` +
374
+ 'output stream is still held, so its real outcome cannot be observed; reporting failure';
332
375
  return {
333
376
  stdout: handle.stdout ?? '',
334
- stderr: handle.stderr ?? '',
335
- exitCode: handle.exitCode ?? 0,
377
+ stderr: handle.stderr ? `${handle.stderr}\n${unknownNote}` : unknownNote,
378
+ exitCode: EXIT_CODE_UNKNOWN,
336
379
  };
337
380
  }
338
381
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-code-sandbox-e2b",
3
- "version": "1.2.7",
3
+ "version": "1.2.8",
4
4
  "description": "E2B (e2b.dev) code sandbox provider — Firecracker microVMs with golden templates, fork, and pause/resume",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",