@tangle-network/agent-app 0.60.93 → 0.60.95

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.
@@ -17,6 +17,7 @@ import {
17
17
  SandboxProvisioningFailedElsewhereError,
18
18
  SandboxRecoveryFailedError,
19
19
  SandboxRuntimeAuthRefreshError,
20
+ WARM_LEASE_DECLINED_UNTIL_DDL,
20
21
  WARM_LEASE_TABLE_DDL,
21
22
  WARM_SLOTS,
22
23
  adaptSandboxStream,
@@ -84,7 +85,7 @@ import {
84
85
  warmBinOf,
85
86
  warmWeekdayOf,
86
87
  writeProfileFilesToBox
87
- } from "../chunk-QJNMYG5H.js";
88
+ } from "../chunk-BOEWSEGC.js";
88
89
  import {
89
90
  EGRESS_PROXY_RECOVERY_PHASE,
90
91
  EGRESS_PROXY_RECOVERY_REQUIRED,
@@ -157,6 +158,7 @@ export {
157
158
  SandboxRecoveryFailedError,
158
159
  SandboxRuntimeAuthRefreshError,
159
160
  SandboxTransientDeadlineError,
161
+ WARM_LEASE_DECLINED_UNTIL_DDL,
160
162
  WARM_LEASE_TABLE_DDL,
161
163
  WARM_SLOTS,
162
164
  WORKSPACE_SANDBOX_HOST_EXHAUSTED,
@@ -15,7 +15,9 @@ import { type WarmLeaseStore } from './warm-lease';
15
15
  */
16
16
  export declare const DEFAULT_WARM_LEASE_TABLE = "sandbox_warm_lease";
17
17
  /** Paste into a migration. Times are epoch milliseconds; 0 means never. */
18
- export declare const WARM_LEASE_TABLE_DDL = "CREATE TABLE IF NOT EXISTS sandbox_warm_lease (\n key TEXT PRIMARY KEY,\n lease_id TEXT,\n reason TEXT,\n started_at INTEGER NOT NULL DEFAULT 0,\n hold_until INTEGER NOT NULL DEFAULT 0,\n warm_at INTEGER NOT NULL DEFAULT 0,\n used_at INTEGER NOT NULL DEFAULT 0,\n resumed INTEGER NOT NULL DEFAULT 0,\n ping_at INTEGER NOT NULL DEFAULT 0,\n last_turn_at INTEGER NOT NULL DEFAULT 0,\n day TEXT NOT NULL DEFAULT '',\n day_warm_ms INTEGER NOT NULL DEFAULT 0,\n threshold REAL NOT NULL DEFAULT 0,\n slots TEXT NOT NULL DEFAULT '',\n slots_at INTEGER NOT NULL DEFAULT 0,\n first_seen_at INTEGER NOT NULL DEFAULT 0,\n predicted_at INTEGER NOT NULL DEFAULT 0\n)";
18
+ export declare const WARM_LEASE_TABLE_DDL = "CREATE TABLE IF NOT EXISTS sandbox_warm_lease (\n key TEXT PRIMARY KEY,\n lease_id TEXT,\n reason TEXT,\n started_at INTEGER NOT NULL DEFAULT 0,\n hold_until INTEGER NOT NULL DEFAULT 0,\n warm_at INTEGER NOT NULL DEFAULT 0,\n used_at INTEGER NOT NULL DEFAULT 0,\n resumed INTEGER NOT NULL DEFAULT 0,\n ping_at INTEGER NOT NULL DEFAULT 0,\n last_turn_at INTEGER NOT NULL DEFAULT 0,\n day TEXT NOT NULL DEFAULT '',\n day_warm_ms INTEGER NOT NULL DEFAULT 0,\n threshold REAL NOT NULL DEFAULT 0,\n slots TEXT NOT NULL DEFAULT '',\n slots_at INTEGER NOT NULL DEFAULT 0,\n first_seen_at INTEGER NOT NULL DEFAULT 0,\n predicted_at INTEGER NOT NULL DEFAULT 0,\n declined_until INTEGER NOT NULL DEFAULT 0\n)";
19
+ /** For a table created from an earlier \`WARM_LEASE_TABLE_DDL\`: paste into a migration. */
20
+ export declare const WARM_LEASE_DECLINED_UNTIL_DDL = "ALTER TABLE sandbox_warm_lease ADD COLUMN declined_until INTEGER NOT NULL DEFAULT 0";
19
21
  /** The D1 surface this store uses: `prepare().bind()` with `first`, `run` and `all`. A real `D1Database` satisfies it. */
20
22
  export interface WarmLeaseD1Like {
21
23
  prepare(query: string): {
@@ -48,7 +48,11 @@ export type WarmBoxOutcome =
48
48
  /** The box was already running: nothing to warm, nothing charged. */
49
49
  | 'running'
50
50
  /** No box exists for this key. Leases never create boxes. */
51
- | 'absent';
51
+ | 'absent'
52
+ /** The platform refused the resume for capacity (HTTP 429: the org is at its
53
+ * concurrent-box limit). A speculative warm must not compete with real work
54
+ * for the last slots, so the key cools down instead of retrying. */
55
+ | 'capacity';
52
56
  export type WarmLeaseEvent = {
53
57
  type: 'warm_started';
54
58
  key: string;
@@ -69,7 +73,7 @@ export type WarmLeaseEvent = {
69
73
  type: 'warm_declined';
70
74
  key: string;
71
75
  reason: WarmReason;
72
- why: 'budget' | 'absent';
76
+ why: 'budget' | 'absent' | 'capacity';
73
77
  } | {
74
78
  type: 'warm_failed';
75
79
  key: string;
@@ -128,6 +132,9 @@ export interface WarmLeaseRow {
128
132
  slotsAt: number;
129
133
  firstSeenAt: number;
130
134
  predictedAt: number;
135
+ /** Signals are refused without calling the product's warm until this time:
136
+ * set after an 'absent' or 'capacity' outcome, cleared by a turn. */
137
+ declinedUntil: number;
131
138
  }
132
139
  /** Persistence for leases. `begin` and `markUsed` must be atomic across isolates. */
133
140
  export interface WarmLeaseStore {
@@ -158,6 +165,8 @@ export interface WarmLeaseStore {
158
165
  writeProfile(key: string, slots: number[], slotsAt: number, firstSeenAt: number): Promise<void>;
159
166
  markPinged(key: string, at: number): Promise<void>;
160
167
  markPredicted(key: string, at: number): Promise<void>;
168
+ /** Refuse signals for `key` until `until` (cleared by the next turn). */
169
+ markDeclined(key: string, until: number): Promise<void>;
161
170
  /** Bounded batches for `sweep`. */
162
171
  listExpired(now: number, limit: number): Promise<WarmLeaseRow[]>;
163
172
  listHeld(now: number, limit: number): Promise<WarmLeaseRow[]>;
@@ -186,6 +195,10 @@ export interface WarmLeasesOptions {
186
195
  * takes the lease over and warms again. Default 2 min, past a slow resume.
187
196
  */
188
197
  warmDeadlineMs?: number;
198
+ /** After a warm finds no box, refuse that key's signals this long. Default 10 min. */
199
+ absentCooldownMs?: number;
200
+ /** After a capacity refusal, refuse that key's signals this long. Default 5 min. */
201
+ capacityCooldownMs?: number;
189
202
  /** Reasons subject to the budget. Default page-open, member-activity, predicted, scheduled. */
190
203
  budgetedReasons?: readonly string[];
191
204
  /** Starting predicted-warm threshold, a probability. Default 0.25. */
@@ -669,6 +669,7 @@ var LEASE_MS = 6e4;
669
669
  var HEARTBEAT_MS = 2e4;
670
670
  var MAX_ATTEMPTS = 3;
671
671
  var FILES_PER_REQUEST = 200;
672
+ var FILES_IN_PARALLEL = 4;
672
673
  var SOURCE_NAME = /^[a-z0-9][a-z0-9_.-]{0,95}$/;
673
674
  var LeaseLost = class extends Error {
674
675
  };
@@ -879,25 +880,36 @@ function createExportEngine(options) {
879
880
  const start = unit.cursor ?? 0;
880
881
  let seen = 0;
881
882
  let written = 0;
883
+ let chunk = [];
884
+ const flush = async () => {
885
+ const written_ = await Promise.all(
886
+ chunk.map(async ({ file, position, path }) => {
887
+ const body = await file.open();
888
+ if (body === null) return null;
889
+ const masked = toStream(body).pipeThrough(scanner.maskBytes((n) => unit.redactions += n));
890
+ return writeEntry(`${keyBase}/p${position}`, path, masked, false);
891
+ })
892
+ );
893
+ for (const entry of written_) if (entry) unit.entries.push(entry);
894
+ written += written_.filter(Boolean).length;
895
+ unit.cursor = chunk.at(-1).position + 1;
896
+ chunk = [];
897
+ };
882
898
  for await (const file of source.files()) {
883
899
  if (seen < start) {
884
900
  seen += 1;
885
901
  continue;
886
902
  }
887
- if (written >= FILES_PER_REQUEST || now() > deadline) {
903
+ if (written + chunk.length >= FILES_PER_REQUEST || now() > deadline) {
904
+ if (chunk.length) await flush();
888
905
  unit.cursor = seen;
889
906
  return;
890
907
  }
891
- const body = await file.open();
908
+ chunk.push({ file, position: seen, path: folder + safePath(file.path, used) });
892
909
  seen += 1;
893
- if (body !== null) {
894
- const path = folder + safePath(file.path, used);
895
- const masked = toStream(body).pipeThrough(scanner.maskBytes((n) => unit.redactions += n));
896
- unit.entries.push(await writeEntry(`${keyBase}/${unit.entries.length}`, path, masked, false));
897
- written += 1;
898
- }
899
- unit.cursor = seen;
910
+ if (chunk.length >= FILES_IN_PARALLEL) await flush();
900
911
  }
912
+ if (chunk.length) await flush();
901
913
  unit.cursor = void 0;
902
914
  unit.files = unit.entries.length;
903
915
  unit.status = unit.entries.length ? "done" : "empty";