@tangle-network/agent-app 0.60.77 → 0.60.79

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.
@@ -4,7 +4,7 @@ import {
4
4
  formatSignoffReport,
5
5
  runShellAlignmentCli,
6
6
  runSignoff
7
- } from "../chunk-KBTY4AAU.js";
7
+ } from "../chunk-TVGL2OAC.js";
8
8
  import {
9
9
  invokedAsScript
10
10
  } from "../chunk-C3CAYGGQ.js";
@@ -12,7 +12,7 @@ import {
12
12
  parseShellAlignmentArgs,
13
13
  runShellAlignmentCli,
14
14
  runSignoff
15
- } from "../chunk-KBTY4AAU.js";
15
+ } from "../chunk-TVGL2OAC.js";
16
16
  export {
17
17
  SHELL_ALIGNMENT_TOLERANCE_PX,
18
18
  WORKER_COMPATIBILITY_DATE_FLOOR,
@@ -1,5 +1,4 @@
1
1
  import { type ShellAlignmentOptions } from './shell-alignment';
2
- export declare function shellAlignmentUsage(): string;
3
2
  export declare class ShellAlignmentUsageError extends Error {
4
3
  }
5
4
  export declare function parseShellAlignmentArgs(argv: readonly string[]): ShellAlignmentOptions & {
@@ -24,6 +24,8 @@ export interface ExportEngineOptions {
24
24
  }): readonly string[] | Promise<readonly string[]>;
25
25
  /** Storage key prefix. Default `workspace-exports`. */
26
26
  prefix?: string;
27
+ /** Sandbox archives read at once in one request. Default 4. */
28
+ archiveConcurrency?: number;
27
29
  now?: () => number;
28
30
  }
29
31
  export declare function createExportEngine(options: ExportEngineOptions): {
@@ -722,6 +722,18 @@ function createExportEngine(options) {
722
722
  const { storage } = options;
723
723
  const prefix = options.prefix ?? "workspace-exports";
724
724
  const now = options.now ?? (() => Date.now());
725
+ const archiveConcurrency = Math.max(1, Math.floor(options.archiveConcurrency ?? 4));
726
+ function archiveBatch(pending, from) {
727
+ const first = pending[from];
728
+ if (first.unit.kind !== "archive" || first.unit.attempts > 0) return [first];
729
+ const batch = [first];
730
+ for (let i = from + 1; i < pending.length && batch.length < archiveConcurrency; i += 1) {
731
+ const candidate = pending[i];
732
+ if (candidate.unit.kind !== "archive" || candidate.unit.attempts > 0) break;
733
+ batch.push(candidate);
734
+ }
735
+ return batch;
736
+ }
725
737
  const base = (workspaceId, id) => `${prefix}/${assertSafeKeySegment(workspaceId)}/${assertSafeKeySegment(id)}`;
726
738
  const jobKey = (workspaceId, id) => `${base(workspaceId, id)}/job.json`;
727
739
  const archiveKey = (workspaceId, id) => `${base(workspaceId, id)}/archive.zip`;
@@ -1043,37 +1055,51 @@ function createExportEngine(options) {
1043
1055
  const plan = await options.plan({ workspaceId });
1044
1056
  const scanner = createSecretScanner({ knownSecrets: await options.knownSecrets?.({ workspaceId }) ?? [] });
1045
1057
  const sources = new Map(plan.sources.map((s) => [s.name, s]));
1046
- for (const [index, unit] of job.units.entries()) {
1047
- if (unit.status !== "pending") continue;
1058
+ const pending = job.units.flatMap((unit, index) => unit.status === "pending" ? [{ unit, index }] : []);
1059
+ let next = 0;
1060
+ while (next < pending.length) {
1048
1061
  if (now() > deadline) break;
1049
- const source = sources.get(unit.name);
1050
- if (unit.attempts >= MAX_ATTEMPTS) {
1051
- unit.status = "failed";
1052
- unit.error ??= "the request exporting this source ended before it finished";
1062
+ const batch = archiveBatch(pending, next);
1063
+ next += batch.length;
1064
+ const exhausted = batch.find(({ unit: unit2 }) => unit2.attempts >= MAX_ATTEMPTS);
1065
+ if (exhausted) {
1066
+ const { unit: unit2 } = exhausted;
1067
+ unit2.status = "failed";
1068
+ unit2.error ??= "the request exporting this source ended before it finished";
1053
1069
  job.status = "failed";
1054
- job.error = `${unit.name}: ${unit.error}`;
1070
+ job.error = `${unit2.name}: ${unit2.error}`;
1055
1071
  etag = await saveJob(job, etag);
1056
1072
  break;
1057
1073
  }
1058
- unit.attempts += 1;
1074
+ for (const { unit: unit2 } of batch) unit2.attempts += 1;
1059
1075
  etag = await saveJob(job, etag);
1060
- try {
1061
- if (!source || source.kind !== unit.kind) throw new Error("source is no longer available");
1062
- await runUnit(job, unit, index, source, scanner, deadline);
1063
- unit.error = void 0;
1064
- } catch (err) {
1065
- unit.error = errorText(scanner, err);
1066
- if (unit.cursor === void 0) unit.entries = [];
1067
- if (unit.attempts >= MAX_ATTEMPTS) {
1068
- unit.status = "failed";
1069
- job.status = "failed";
1070
- job.error = `${unit.name}: ${unit.error}`;
1071
- }
1072
- job.lease = { id: job.lease.id, until: now() + LEASE_MS };
1076
+ const failed = await Promise.all(
1077
+ batch.map(async ({ unit: unit2, index }) => {
1078
+ const source = sources.get(unit2.name);
1079
+ try {
1080
+ if (!source || source.kind !== unit2.kind) throw new Error("source is no longer available");
1081
+ await runUnit(job, unit2, index, source, scanner, deadline);
1082
+ unit2.error = void 0;
1083
+ return false;
1084
+ } catch (err) {
1085
+ unit2.error = errorText(scanner, err);
1086
+ if (unit2.cursor === void 0) unit2.entries = [];
1087
+ if (unit2.attempts >= MAX_ATTEMPTS) unit2.status = "failed";
1088
+ return true;
1089
+ }
1090
+ })
1091
+ );
1092
+ const dead = batch.find(({ unit: unit2 }) => unit2.status === "failed");
1093
+ if (dead) {
1094
+ job.status = "failed";
1095
+ job.error = `${dead.unit.name}: ${dead.unit.error}`;
1096
+ }
1097
+ job.lease = { id: job.lease.id, until: now() + LEASE_MS };
1098
+ if (failed.includes(true)) {
1073
1099
  etag = await saveJob(job, etag);
1074
1100
  break;
1075
1101
  }
1076
- job.lease = { id: job.lease.id, until: now() + LEASE_MS };
1102
+ const { unit } = batch[0];
1077
1103
  if (unit.status === "pending") {
1078
1104
  unit.attempts = 0;
1079
1105
  etag = await saveJob(job, etag);