@mastra/platform-workspace 1.3.0-alpha.0 → 1.3.0-alpha.2

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.
package/dist/index.js CHANGED
@@ -835,6 +835,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
835
835
  _client;
836
836
  _environmentId;
837
837
  _sandboxId;
838
+ _seedCheckpointName;
838
839
  _idleTimeoutMinutes;
839
840
  _networkIsolation;
840
841
  _env;
@@ -914,6 +915,12 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
914
915
  * failed/timed out, but now coalesced via `_leaseInFlight`).
915
916
  */
916
917
  _transportReadyPromise = null;
918
+ /**
919
+ * The sidecar address of the most recent `start()`, kept so a timed-out
920
+ * probe can be restarted by a later exec ({@link _awaitTransportReady})
921
+ * instead of pinning the sandbox to the lease path for its lifetime.
922
+ */
923
+ _probeTarget = null;
917
924
  constructor(options = {}) {
918
925
  super({
919
926
  ...options,
@@ -926,6 +933,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
926
933
  this._environmentId = options.environmentId ?? process.env.MASTRA_ENVIRONMENT_ID ?? "";
927
934
  if (!this._environmentId && !options.sandboxId) throw new Error("environmentId is required");
928
935
  this._sandboxId = options.sandboxId;
936
+ this._seedCheckpointName = options.seedCheckpointName;
929
937
  this._idleTimeoutMinutes = options.idleTimeoutMinutes;
930
938
  this._networkIsolation = options.networkIsolation;
931
939
  this._env = options.env ?? {};
@@ -962,6 +970,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
962
970
  fetch: this._client.fetch,
963
971
  environmentId: this._environmentId,
964
972
  ...options.sandboxId !== void 0 && { sandboxId: options.sandboxId },
973
+ ...(options.seedCheckpointName ?? this._seedCheckpointName) !== void 0 && { seedCheckpointName: options.seedCheckpointName ?? this._seedCheckpointName },
965
974
  idleTimeoutMinutes: options.idleTimeoutMinutes ?? this._idleTimeoutMinutes,
966
975
  ...this._networkIsolation !== void 0 && { networkIsolation: this._networkIsolation },
967
976
  env: options.env ?? this._env,
@@ -1008,6 +1017,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1008
1017
  if (!this._environmentId) throw new Error("environmentId is required");
1009
1018
  const body = JSON.stringify({
1010
1019
  id: this.id,
1020
+ seedCheckpointName: this._seedCheckpointName,
1011
1021
  environmentId: this._environmentId,
1012
1022
  idleTimeoutMinutes: this._idleTimeoutMinutes,
1013
1023
  networkIsolation: this._networkIsolation,
@@ -1066,14 +1076,24 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1066
1076
  * HTTP round-trip.
1067
1077
  *
1068
1078
  * `null`/absent `instanceUrl` (proxy discovery failed, or an older proxy
1069
- * that predates the field) leaves the registry untouched executes fall
1070
- * through to the lease path with no branch here.
1079
+ * that predates the field) evicts any stale registry address and leaves
1080
+ * executes on the lease path.
1071
1081
  */
1072
1082
  _populateAddressFromResponse(json) {
1073
1083
  if (!this._addressRegistry) return;
1074
- if (!json.instanceUrl) return;
1084
+ if (!json.instanceUrl) {
1085
+ this._probeGeneration++;
1086
+ this._probeTarget = null;
1087
+ this._transportReadyPromise = null;
1088
+ this._addressRegistry.delete(json.id);
1089
+ return;
1090
+ }
1075
1091
  this._addressRegistry.delete(json.id);
1076
1092
  const generation = ++this._probeGeneration;
1093
+ this._probeTarget = {
1094
+ sandboxId: json.id,
1095
+ instanceUrl: json.instanceUrl
1096
+ };
1077
1097
  this._transportReadyPromise = this._probeSidecarThenRegister(json.id, json.instanceUrl, generation);
1078
1098
  }
1079
1099
  /**
@@ -1083,8 +1103,9 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1083
1103
  * fall back to the lease path until the probe succeeds.
1084
1104
  *
1085
1105
  * If the sidecar never comes up within {@link SIDECAR_PROBE_TIMEOUT_MS},
1086
- * the registry stays unpopulated and all execs go via lease for this
1087
- * sandbox's lifetime (or until a future `start()` re-runs the probe).
1106
+ * the registry stays unpopulated, `_transportReadyPromise` is cleared,
1107
+ * and a later {@link _awaitTransportReady} call restarts the probe
1108
+ * instead of pinning this sandbox to the lease path.
1088
1109
  *
1089
1110
  * @param generation - The probe generation captured at call time. If this
1090
1111
  * no longer matches `_probeGeneration` when the probe succeeds, the probe
@@ -1118,6 +1139,7 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1118
1139
  } catch {}
1119
1140
  await new Promise((r) => setTimeout(r, SIDECAR_PROBE_INTERVAL_MS));
1120
1141
  }
1142
+ if (generation === this._probeGeneration && this._transportReadyPromise) this._transportReadyPromise = null;
1121
1143
  this.logger.warn("platform-workspace probe timed out", {
1122
1144
  sandboxId,
1123
1145
  sessionId: this._client.sessionId,
@@ -1138,7 +1160,12 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1138
1160
  */
1139
1161
  async _awaitTransportReady() {
1140
1162
  if (this._sandboxId && this._addressRegistry?.get(this._sandboxId)) return;
1141
- if (!this._transportReadyPromise) return;
1163
+ if (!this._transportReadyPromise) {
1164
+ const target = this._probeTarget;
1165
+ if (!target || this._sandboxId !== target.sandboxId) return;
1166
+ const generation = ++this._probeGeneration;
1167
+ this._transportReadyPromise = this._probeSidecarThenRegister(target.sandboxId, target.instanceUrl, generation);
1168
+ }
1142
1169
  await Promise.race([this._transportReadyPromise, new Promise((r) => setTimeout(r, TRANSPORT_READY_WAIT_MS))]);
1143
1170
  }
1144
1171
  /**
@@ -1205,6 +1232,8 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1205
1232
  if (!this._sandboxId) return;
1206
1233
  const destroyedSandboxId = this._sandboxId;
1207
1234
  this._probeGeneration++;
1235
+ this._probeTarget = null;
1236
+ this._transportReadyPromise = null;
1208
1237
  await this._client.request(`/sandbox/${encodeURIComponent(destroyedSandboxId)}`, { method: "DELETE" });
1209
1238
  this._sandboxId = void 0;
1210
1239
  this._createdAt = null;
@@ -1215,6 +1244,8 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1215
1244
  async snapshot() {
1216
1245
  await this.captureCheckpoint();
1217
1246
  }
1247
+ /** Snapshots persist real checkpoints that can seed future sandboxes. */
1248
+ supportsCheckpoints = true;
1218
1249
  /**
1219
1250
  * Capture the sandbox's checkpoint on demand, outside any refresh timer the
1220
1251
  * workspace-proxy owns internally.
@@ -1334,6 +1365,9 @@ var PlatformSandbox = class PlatformSandbox extends MastraSandbox {
1334
1365
  * the cached `'running'` state (see `MastraSandbox._start`).
1335
1366
  */
1336
1367
  _clearDestroyedState(destroyedSandboxId) {
1368
+ this._probeGeneration++;
1369
+ this._probeTarget = null;
1370
+ this._transportReadyPromise = null;
1337
1371
  this._sandboxId = void 0;
1338
1372
  this._createdAt = null;
1339
1373
  this._lease = null;