@blaxel/core 0.2.85-preview.159 → 0.2.86-preview.161

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.
@@ -5,8 +5,8 @@ import { authentication } from "../authentication/index.js";
5
5
  import { env } from "../common/env.js";
6
6
  import { fs, os, path } from "../common/node.js";
7
7
  // Build info - these placeholders are replaced at build time by build:replace-imports
8
- const BUILD_VERSION = "0.2.85-preview.159";
9
- const BUILD_COMMIT = "a9c088b49239125f1b129fbc95d1887556112a33";
8
+ const BUILD_VERSION = "0.2.86-preview.161";
9
+ const BUILD_COMMIT = "a5bdac720290868983bb67563ff7068c1cf8c67f";
10
10
  const BUILD_SENTRY_DSN = "https://fd5e60e1c9820e1eef5ccebb84a07127@o4508714045276160.ingest.us.sentry.io/4510465864564736";
11
11
  const BLAXEL_API_VERSION = "2026-04-16";
12
12
  // Cache for config.yaml tracking value
@@ -226,6 +226,32 @@ class Settings {
226
226
  }
227
227
  return isDenoRuntime();
228
228
  }
229
+ get maxConcurrentH2Requests() {
230
+ if (typeof this.config.maxConcurrentH2Requests === "number") {
231
+ return this.config.maxConcurrentH2Requests;
232
+ }
233
+ const value = env.BL_MAX_H2_INFLIGHT;
234
+ if (value) {
235
+ const parsed = parseInt(value, 10);
236
+ if (!Number.isNaN(parsed)) {
237
+ return parsed;
238
+ }
239
+ }
240
+ return 0;
241
+ }
242
+ get fsPartRetries() {
243
+ if (typeof this.config.fsPartRetries === "number") {
244
+ return this.config.fsPartRetries;
245
+ }
246
+ const value = env.BL_FS_PART_RETRIES;
247
+ if (value) {
248
+ const parsed = parseInt(value, 10);
249
+ if (!Number.isNaN(parsed)) {
250
+ return parsed;
251
+ }
252
+ }
253
+ return 0;
254
+ }
229
255
  async authenticate() {
230
256
  await this.credentials.authenticate();
231
257
  }
@@ -6,6 +6,94 @@ import { deleteFilesystemByPath, deleteFilesystemMultipartByUploadIdAbort, getFi
6
6
  const MULTIPART_THRESHOLD = 5 * 1024 * 1024; // 5MB
7
7
  const CHUNK_SIZE = 5 * 1024 * 1024; // 5MB per part
8
8
  const MAX_PARALLEL_UPLOADS = 3; // Number of parallel part uploads
9
+ // Base backoff between part-upload retries, in milliseconds. Grows linearly
10
+ // per attempt and is jittered to avoid synchronized retries (thundering herd)
11
+ // when several parallel parts fail against the same edge at the same time.
12
+ const RETRY_BASE_DELAY_MS = 200;
13
+ // Markers that, when present anywhere in the error chain, are unambiguous
14
+ // signals of a transient HTTP/2 stream reset or connection drop. These are
15
+ // protocol/transport level codes, not application payloads, so substring
16
+ // matching them does not over-match a server-sent error body. Each entry is
17
+ // matched case-sensitively against the error message and its cause.
18
+ //
19
+ // Deliberately excluded: bare "INTERNAL_ERROR" and "fetch failed". Both are
20
+ // too generic on their own (an application 500 body or any failed fetch would
21
+ // match), so we only treat them as transient when paired with a transport
22
+ // error code on the cause (see isTransientUploadError).
23
+ const TRANSIENT_RESET_MARKERS = [
24
+ "ENHANCE_YOUR_CALM", // H2 flow-control backpressure reset
25
+ "NGHTTP2_INTERNAL_ERROR", // H2 internal stream error (qualified form)
26
+ "ERR_HTTP2", // node http2 error code family
27
+ "GOAWAY", // peer is draining the connection
28
+ "HTTP/2 session closed before response", // thrown by our own h2 transport
29
+ "HTTP/2 session sent GOAWAY before response",
30
+ ];
31
+ // Node-level error codes (from `error.code` / `error.cause.code`) that mean
32
+ // the connection itself dropped mid-flight and the request never completed.
33
+ // These are safe to retry for an idempotent part upload.
34
+ const TRANSIENT_ERROR_CODES = new Set([
35
+ "ECONNRESET",
36
+ "ECONNREFUSED",
37
+ "ETIMEDOUT",
38
+ "EPIPE",
39
+ "ERR_HTTP2_STREAM_ERROR",
40
+ "ERR_HTTP2_GOAWAY_SESSION",
41
+ "ERR_HTTP2_SESSION_ERROR",
42
+ ]);
43
+ function collectErrorText(error) {
44
+ const messages = [];
45
+ const codes = [];
46
+ // Walk the error -> cause chain (bounded) so a transport error wrapped by a
47
+ // higher-level "fetch failed" is still classified correctly.
48
+ let current = error;
49
+ for (let depth = 0; depth < 5 && current && typeof current === "object"; depth++) {
50
+ const node = current;
51
+ if (typeof node.message === "string")
52
+ messages.push(node.message);
53
+ if (typeof node.code === "string")
54
+ codes.push(node.code);
55
+ current = node.cause;
56
+ }
57
+ return { messages, codes };
58
+ }
59
+ function isTransientUploadError(error) {
60
+ if (!error || typeof error !== "object") {
61
+ return false;
62
+ }
63
+ const { messages, codes } = collectErrorText(error);
64
+ // 1. An explicit transient transport error code anywhere in the chain.
65
+ if (codes.some((code) => TRANSIENT_ERROR_CODES.has(code))) {
66
+ return true;
67
+ }
68
+ // 2. An unambiguous protocol-level reset marker in any message.
69
+ if (messages.some((text) => TRANSIENT_RESET_MARKERS.some((marker) => text.includes(marker)))) {
70
+ return true;
71
+ }
72
+ return false;
73
+ }
74
+ function nextRetryDelayMs(attempt) {
75
+ // Linear backoff (200ms, 400ms, ...) plus up to one extra base delay of
76
+ // random jitter so concurrent part retries do not all fire on the same tick.
77
+ const base = RETRY_BASE_DELAY_MS * attempt;
78
+ const jitter = Math.floor(Math.random() * RETRY_BASE_DELAY_MS);
79
+ return base + jitter;
80
+ }
81
+ async function retryOnTransient(fn) {
82
+ const retries = settings.fsPartRetries; // 0 = off (current default behavior)
83
+ let attempt = 0;
84
+ for (;;) {
85
+ try {
86
+ return await fn();
87
+ }
88
+ catch (error) {
89
+ attempt++;
90
+ if (retries <= 0 || attempt > retries || !isTransientUploadError(error)) {
91
+ throw error;
92
+ }
93
+ await new Promise((resolve) => setTimeout(resolve, nextRetryDelayMs(attempt)));
94
+ }
95
+ }
96
+ }
9
97
  export class SandboxFileSystem extends SandboxAction {
10
98
  process;
11
99
  constructor(sandbox, process) {
@@ -423,7 +511,7 @@ export class SandboxFileSystem extends SandboxAction {
423
511
  const start = (partNumber - 1) * CHUNK_SIZE;
424
512
  const end = Math.min(start + CHUNK_SIZE, size);
425
513
  const chunk = blob.slice(start, end);
426
- batch.push(this.uploadPart(uploadId, partNumber, chunk));
514
+ batch.push(retryOnTransient(() => this.uploadPart(uploadId, partNumber, chunk)));
427
515
  }
428
516
  // Wait for batch to complete
429
517
  const batchResults = await Promise.all(batch);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaxel/core",
3
- "version": "0.2.85-preview.159",
3
+ "version": "0.2.86-preview.161",
4
4
  "description": "Blaxel Core SDK for TypeScript",
5
5
  "license": "MIT",
6
6
  "author": "Blaxel, INC (https://blaxel.ai)",