@tangle-network/agent-app 0.60.82 → 0.60.84

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.
@@ -84,7 +84,7 @@ import {
84
84
  warmBinOf,
85
85
  warmWeekdayOf,
86
86
  writeProfileFilesToBox
87
- } from "../chunk-A5CZ2X6C.js";
87
+ } from "../chunk-QJNMYG5H.js";
88
88
  import {
89
89
  EGRESS_PROXY_RECOVERY_PHASE,
90
90
  EGRESS_PROXY_RECOVERY_REQUIRED,
@@ -35,8 +35,8 @@
35
35
  * hour, within the budget. The threshold tunes itself: a predicted warm that is used lowers it,
36
36
  * one that is wasted raises it.
37
37
  *
38
- * EVENTS. `warm_started`, `warm_hit`, `warm_wasted`, `warm_declined` and
39
- * `warm_failed` each carry the key and the reason, so a product can compute hit
38
+ * EVENTS. `warm_started`, `warm_hit`, `warm_wasted`, `warm_declined`,
39
+ * `warm_failed` and `warm_abandoned` each carry the key and the reason, so a product can compute hit
40
40
  * rate and wasted minutes per workspace from its logs alone.
41
41
  */
42
42
  /** Why a warm was requested. Products may add their own reasons. */
@@ -75,6 +75,14 @@ export type WarmLeaseEvent = {
75
75
  key: string;
76
76
  reason: WarmReason;
77
77
  error: string;
78
+ }
79
+ /** The lease ended without its warm ever reporting: the request running it was
80
+ * cancelled or the isolate died. Whether the box resumed is unknown, so it is
81
+ * counted here rather than charged or dropped. */
82
+ | {
83
+ type: 'warm_abandoned';
84
+ key: string;
85
+ reason: WarmReason;
78
86
  };
79
87
  export type WarmSignalOutcome =
80
88
  /** This call started a lease and ran the product's warm. */
@@ -94,6 +102,8 @@ export interface WarmTurnResult {
94
102
  export interface WarmSweepReport {
95
103
  ended: number;
96
104
  wasted: number;
105
+ /** Expired leases whose warm never reported an outcome. */
106
+ abandoned: number;
97
107
  pinged: number;
98
108
  predicted: number;
99
109
  /** Keys whose ping or predicted warm threw; the rest of the batch still ran. */
@@ -124,10 +134,13 @@ export interface WarmLeaseStore {
124
134
  read(key: string): Promise<WarmLeaseRow | null>;
125
135
  /**
126
136
  * Start a lease with `leaseId` when none is live, otherwise extend the live
127
- * one's hold to at least `holdUntil`. Returns the live lease id after the
128
- * write; the caller started the lease exactly when it equals `leaseId`.
137
+ * one's hold to at least `holdUntil`. A lease whose warm has not reported by
138
+ * `staleBefore` counts as not live and is taken over, so a warm killed with
139
+ * its request is retried instead of blocking every later signal. Returns the
140
+ * live lease id after the write; the caller started the lease exactly when
141
+ * it equals `leaseId`.
129
142
  */
130
- begin(key: string, leaseId: string, reason: string, now: number, holdUntil: number): Promise<string>;
143
+ begin(key: string, leaseId: string, reason: string, now: number, holdUntil: number, staleBefore: number): Promise<string>;
131
144
  /** Record the result of this lease's warm. No-op for a superseded lease. */
132
145
  markWarm(key: string, leaseId: string, warmAt: number, resumed: boolean): Promise<void>;
133
146
  /**
@@ -168,6 +181,11 @@ export interface WarmLeasesOptions {
168
181
  burstHoldMs?: number;
169
182
  /** Unused-warm box time allowed per key per UTC day. Default 30 min. */
170
183
  dailyBudgetMs?: number;
184
+ /**
185
+ * How long a started warm may go without reporting before the next signal
186
+ * takes the lease over and warms again. Default 2 min, past a slow resume.
187
+ */
188
+ warmDeadlineMs?: number;
171
189
  /** Reasons subject to the budget. Default page-open, member-activity, predicted, scheduled. */
172
190
  budgetedReasons?: readonly string[];
173
191
  /** Starting predicted-warm threshold, a probability. Default 0.25. */
@@ -665,7 +665,8 @@ function createZipStream(entries) {
665
665
  // src/workspace-export/engine.ts
666
666
  var MANIFEST_SCHEMA = "tangle.workspace-export/v1";
667
667
  var SEGMENT_BYTES = 8 * 1024 * 1024;
668
- var LEASE_MS = 5 * 6e4;
668
+ var LEASE_MS = 6e4;
669
+ var HEARTBEAT_MS = 2e4;
669
670
  var MAX_ATTEMPTS = 3;
670
671
  var FILES_PER_REQUEST = 200;
671
672
  var SOURCE_NAME = /^[a-z0-9][a-z0-9_.-]{0,95}$/;
@@ -1049,9 +1050,22 @@ function createExportEngine(options) {
1049
1050
  if (job.lease && job.lease.until > now()) return job;
1050
1051
  const deadline = now() + budgetMs;
1051
1052
  let etag = loaded.etag;
1053
+ let saving = Promise.resolve();
1054
+ const save = () => {
1055
+ saving = saving.then(async () => {
1056
+ if (job.lease) job.lease.until = now() + LEASE_MS;
1057
+ etag = await saveJob(job, etag);
1058
+ });
1059
+ return saving;
1060
+ };
1061
+ let heartbeat;
1052
1062
  try {
1053
1063
  job.lease = { id: crypto.randomUUID(), until: now() + LEASE_MS };
1054
- etag = await saveJob(job, etag);
1064
+ await save();
1065
+ heartbeat = setInterval(() => {
1066
+ save().catch(() => {
1067
+ });
1068
+ }, HEARTBEAT_MS);
1055
1069
  const plan = await options.plan({ workspaceId });
1056
1070
  const scanner = createSecretScanner({ knownSecrets: await options.knownSecrets?.({ workspaceId }) ?? [] });
1057
1071
  const sources = new Map(plan.sources.map((s) => [s.name, s]));
@@ -1068,11 +1082,11 @@ function createExportEngine(options) {
1068
1082
  unit2.error ??= "the request exporting this source ended before it finished";
1069
1083
  job.status = "failed";
1070
1084
  job.error = `${unit2.name}: ${unit2.error}`;
1071
- etag = await saveJob(job, etag);
1085
+ await save();
1072
1086
  break;
1073
1087
  }
1074
1088
  for (const { unit: unit2 } of batch) unit2.attempts += 1;
1075
- etag = await saveJob(job, etag);
1089
+ await save();
1076
1090
  const failed = await Promise.all(
1077
1091
  batch.map(async ({ unit: unit2, index }) => {
1078
1092
  const source = sources.get(unit2.name);
@@ -1094,28 +1108,32 @@ function createExportEngine(options) {
1094
1108
  job.status = "failed";
1095
1109
  job.error = `${dead.unit.name}: ${dead.unit.error}`;
1096
1110
  }
1097
- job.lease = { id: job.lease.id, until: now() + LEASE_MS };
1098
1111
  if (failed.includes(true)) {
1099
- etag = await saveJob(job, etag);
1112
+ await save();
1100
1113
  break;
1101
1114
  }
1102
1115
  const { unit } = batch[0];
1103
1116
  if (unit.status === "pending") {
1104
1117
  unit.attempts = 0;
1105
- etag = await saveJob(job, etag);
1118
+ await save();
1106
1119
  break;
1107
1120
  }
1108
- etag = await saveJob(job, etag);
1121
+ await save();
1109
1122
  }
1110
1123
  if (job.status === "running" && job.units.every((u) => u.status === "done" || u.status === "empty")) {
1111
1124
  await finalize(job, plan, scanner);
1112
1125
  }
1126
+ clearInterval(heartbeat);
1127
+ await saving.catch(() => {
1128
+ });
1113
1129
  job.lease = void 0;
1114
1130
  await saveJob(job, etag);
1115
1131
  return job;
1116
1132
  } catch (err) {
1117
1133
  if (err instanceof LeaseLost) return (await loadJob(workspaceId, id))?.job ?? null;
1118
1134
  throw err;
1135
+ } finally {
1136
+ clearInterval(heartbeat);
1119
1137
  }
1120
1138
  },
1121
1139
  progress(job) {