@blaxel/core 0.2.87-preview.174 → 0.2.87

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.
Files changed (37) hide show
  1. package/dist/cjs/.tsbuildinfo +1 -1
  2. package/dist/cjs/common/h2fetch.js +54 -17
  3. package/dist/cjs/common/settings.js +29 -3
  4. package/dist/cjs/common/transient-retry.js +145 -0
  5. package/dist/cjs/sandbox/drive/drive.js +11 -6
  6. package/dist/cjs/sandbox/filesystem/filesystem.js +126 -158
  7. package/dist/cjs/sandbox/process/process.js +29 -16
  8. package/dist/cjs/types/common/h2fetch.d.ts +7 -0
  9. package/dist/cjs/types/common/settings.d.ts +22 -2
  10. package/dist/cjs/types/common/transient-retry.d.ts +30 -0
  11. package/dist/cjs/types/sandbox/filesystem/filesystem.d.ts +3 -0
  12. package/dist/cjs-browser/.tsbuildinfo +1 -1
  13. package/dist/cjs-browser/common/h2fetch.js +1 -0
  14. package/dist/cjs-browser/common/settings.js +29 -3
  15. package/dist/cjs-browser/common/transient-retry.js +145 -0
  16. package/dist/cjs-browser/sandbox/drive/drive.js +11 -6
  17. package/dist/cjs-browser/sandbox/filesystem/filesystem.js +126 -158
  18. package/dist/cjs-browser/sandbox/process/process.js +29 -16
  19. package/dist/cjs-browser/types/common/h2fetch.d.ts +7 -0
  20. package/dist/cjs-browser/types/common/settings.d.ts +22 -2
  21. package/dist/cjs-browser/types/common/transient-retry.d.ts +30 -0
  22. package/dist/cjs-browser/types/sandbox/filesystem/filesystem.d.ts +3 -0
  23. package/dist/esm/.tsbuildinfo +1 -1
  24. package/dist/esm/common/h2fetch.js +53 -17
  25. package/dist/esm/common/settings.js +29 -3
  26. package/dist/esm/common/transient-retry.js +141 -0
  27. package/dist/esm/sandbox/drive/drive.js +11 -6
  28. package/dist/esm/sandbox/filesystem/filesystem.js +124 -157
  29. package/dist/esm/sandbox/process/process.js +29 -16
  30. package/dist/esm-browser/.tsbuildinfo +1 -1
  31. package/dist/esm-browser/common/h2fetch.js +1 -0
  32. package/dist/esm-browser/common/settings.js +29 -3
  33. package/dist/esm-browser/common/transient-retry.js +141 -0
  34. package/dist/esm-browser/sandbox/drive/drive.js +11 -6
  35. package/dist/esm-browser/sandbox/filesystem/filesystem.js +124 -157
  36. package/dist/esm-browser/sandbox/process/process.js +29 -16
  37. package/package.json +1 -1
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SandboxProcess = void 0;
4
4
  const settings_js_1 = require("../../common/settings.js");
5
5
  const action_js_1 = require("../action.js");
6
+ const transient_retry_js_1 = require("../../common/transient-retry.js");
6
7
  const index_js_1 = require("../client/index.js");
7
8
  class SandboxProcess extends action_js_1.SandboxAction {
8
9
  constructor(sandbox) {
@@ -302,19 +303,27 @@ class SandboxProcess extends action_js_1.SandboxAction {
302
303
  return data;
303
304
  }
304
305
  async get(identifier) {
305
- const { response, data, error } = await (0, index_js_1.getProcessByIdentifier)(this.withClient({
306
- path: { identifier },
307
- baseUrl: this.url,
308
- }));
309
- this.handleResponseError(response, data, error);
310
- return data;
306
+ // Idempotent GET: self-heal a transient connection reset (also makes the
307
+ // wait() poll loop resilient). exec() stays un-retried — it is a
308
+ // non-idempotent POST and retrying it duplicates the process (ENG-2340).
309
+ return (0, transient_retry_js_1.retryOnTransientReset)(async () => {
310
+ const { response, data, error } = await (0, index_js_1.getProcessByIdentifier)(this.withClient({
311
+ path: { identifier },
312
+ baseUrl: this.url,
313
+ }));
314
+ this.handleResponseError(response, data, error);
315
+ return data;
316
+ });
311
317
  }
312
318
  async list() {
313
- const { response, data, error } = await (0, index_js_1.getProcess)(this.withClient({
314
- baseUrl: this.url,
315
- }));
316
- this.handleResponseError(response, data, error);
317
- return data;
319
+ // Idempotent GET: self-heal a transient connection reset.
320
+ return (0, transient_retry_js_1.retryOnTransientReset)(async () => {
321
+ const { response, data, error } = await (0, index_js_1.getProcess)(this.withClient({
322
+ baseUrl: this.url,
323
+ }));
324
+ this.handleResponseError(response, data, error);
325
+ return data;
326
+ });
318
327
  }
319
328
  async stop(identifier) {
320
329
  const { response, data, error } = await (0, index_js_1.deleteProcessByIdentifier)(this.withClient({
@@ -333,11 +342,15 @@ class SandboxProcess extends action_js_1.SandboxAction {
333
342
  return data;
334
343
  }
335
344
  async logs(identifier, type = "all") {
336
- const { response, data, error } = await (0, index_js_1.getProcessByIdentifierLogs)(this.withClient({
337
- path: { identifier },
338
- baseUrl: this.url,
339
- }));
340
- this.handleResponseError(response, data, error);
345
+ // Idempotent GET: self-heal a transient connection reset.
346
+ const data = await (0, transient_retry_js_1.retryOnTransientReset)(async () => {
347
+ const { response, data, error } = await (0, index_js_1.getProcessByIdentifierLogs)(this.withClient({
348
+ path: { identifier },
349
+ baseUrl: this.url,
350
+ }));
351
+ this.handleResponseError(response, data, error);
352
+ return data;
353
+ });
341
354
  if (type === "all") {
342
355
  return data?.logs || "";
343
356
  }
@@ -1,5 +1,12 @@
1
1
  import http2 from "http2";
2
2
  import type { H2Pool } from "./h2pool.js";
3
+ /**
4
+ * Run `fn` while holding an upload slot for `domain`, releasing it when `fn`
5
+ * settles (the part PUT completes or fails). Bounds concurrent in-flight upload
6
+ * parts per domain across all files sharing the connection. Used by the
7
+ * multipart upload path; a no-op wrapper when the upload cap is unset.
8
+ */
9
+ export declare function withUploadSlot<T>(domain: string, fn: () => Promise<T>): Promise<T>;
3
10
  /**
4
11
  * Creates a fetch()-compatible function that sends requests over an existing
5
12
  * HTTP/2 session. Falls back to globalThis.fetch() only when the session is
@@ -18,10 +18,28 @@ export type Config = {
18
18
  */
19
19
  maxConcurrentH2Requests?: number;
20
20
  /**
21
- * Number of retry attempts for transient resets on multipart part uploads.
22
- * `0` or `undefined` disables retry (current behavior).
21
+ * Maximum number of concurrent in-flight multipart upload-part requests per
22
+ * edge domain on the shared H2 connection. Defaults to 2 (the measured value
23
+ * that stops concurrent large uploads tripping ENHANCE_YOUR_CALM). Scoped to
24
+ * the upload-part path only; non-upload traffic is unaffected. `0` disables it.
25
+ */
26
+ maxConcurrentUploadH2Requests?: number;
27
+ /**
28
+ * Retry attempts for transient connection resets (ECONNRESET, GOAWAY,
29
+ * ENHANCE_YOUR_CALM, etc.) on file uploads. Covers both small single-PUT
30
+ * uploads and multipart parts; both are idempotent writes and safe to retry.
31
+ * Defaults to 3. Set `0` to disable.
23
32
  */
24
33
  fsPartRetries?: number;
34
+ /**
35
+ * Retry attempts for transient connection resets on IDEMPOTENT sandbox reads
36
+ * (fs.read/readBinary/ls/search/find/grep, drives.list, process.get/list/logs).
37
+ * Higher than the upload default so a later attempt can span a multi-second
38
+ * sandbox cold-start/standby wake (the window a first-call read reset falls in).
39
+ * Defaults to 5. Set `0` to disable. Never applied to non-idempotent ops
40
+ * (process.exec, drives.mount, etc.).
41
+ */
42
+ sandboxReadRetries?: number;
25
43
  /**
26
44
  * Client credentials for OAuth2 client_credentials flow.
27
45
  *
@@ -62,7 +80,9 @@ declare class Settings {
62
80
  get region(): string | undefined;
63
81
  get disableH2(): boolean;
64
82
  get maxConcurrentH2Requests(): number;
83
+ get maxConcurrentUploadH2Requests(): number;
65
84
  get fsPartRetries(): number;
85
+ get sandboxReadRetries(): number;
66
86
  /**
67
87
  * Fail fast with a clear, actionable error when credentials are missing or
68
88
  * incomplete, instead of sending empty workspace/authorization headers and
@@ -0,0 +1,30 @@
1
+ /**
2
+ * True only for transport-level resets/drops that are safe to retry on an
3
+ * IDEMPOTENT request (transient HTTP/2 stream reset, GOAWAY, or a dropped
4
+ * connection). Application errors (4xx/5xx — even when their body text contains
5
+ * a marker word) and a bare "fetch failed" with no transport code are
6
+ * deliberately NOT transient, so auto-retry never masks a real server error or
7
+ * duplicates a non-idempotent call.
8
+ *
9
+ * This is the single classifier shared by the upload-part retry (ENG-2680) and
10
+ * the idempotent sandbox-op retry (read/list/etc.), so both judge "transient"
11
+ * identically.
12
+ */
13
+ export declare function isTransientResetError(error: unknown): boolean;
14
+ export type RetryOptions = {
15
+ retries?: number;
16
+ baseDelayMs?: number;
17
+ maxDelayMs?: number;
18
+ };
19
+ /**
20
+ * Run `fn`, retrying only on transient transport resets (see
21
+ * isTransientResetError) with exponential backoff. Caller owns idempotency:
22
+ * ONLY wrap idempotent operations (GET-shaped reads/lists, or an idempotent
23
+ * PUT of the same bytes) — never a non-idempotent POST such as process.exec,
24
+ * which would duplicate the side effect (ENG-2340).
25
+ *
26
+ * Defaults to `settings.sandboxReadRetries` (the higher idempotent-read budget,
27
+ * sized for a multi-second standby wake). The upload path passes
28
+ * `{ retries: settings.fsPartRetries }` to keep its own (lower) budget.
29
+ */
30
+ export declare function retryOnTransientReset<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
@@ -1,8 +1,11 @@
1
1
  import { Sandbox } from "../../client/types.gen.js";
2
+ import { isTransientResetError } from "../../common/transient-retry.js";
2
3
  import { SandboxAction } from "../action.js";
3
4
  import { ContentSearchResponse, Directory, FindResponse, FuzzySearchResponse, SuccessResponse } from "../client/index.js";
4
5
  import { SandboxProcess } from "../process/index.js";
5
6
  import { CopyResponse, FilesystemFindOptions, FilesystemGrepOptions, FilesystemSearchOptions, SandboxFilesystemFile, WatchEvent } from "./types.js";
7
+ export declare const isTransientUploadError: typeof isTransientResetError;
8
+ export declare function retryOnTransient<T>(fn: () => Promise<T>): Promise<T>;
6
9
  export declare class SandboxFileSystem extends SandboxAction {
7
10
  private process;
8
11
  constructor(sandbox: Sandbox, process: SandboxProcess);