@yaks/sandbox 0.0.0-stage → 0.2.36

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 (74) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +400 -2
  3. package/_dist/bubblewrap.d.ts +38 -0
  4. package/_dist/bubblewrap.d.ts.map +1 -0
  5. package/_dist/cloudflare.d.ts +136 -0
  6. package/_dist/cloudflare.d.ts.map +1 -0
  7. package/_dist/configuration.d.ts +13 -0
  8. package/_dist/configuration.d.ts.map +1 -0
  9. package/_dist/docker.d.ts +15 -0
  10. package/_dist/docker.d.ts.map +1 -0
  11. package/_dist/effects.d.ts +6 -0
  12. package/_dist/effects.d.ts.map +1 -0
  13. package/_dist/lifecycle.d.ts +38 -0
  14. package/_dist/lifecycle.d.ts.map +1 -0
  15. package/_dist/mod.d.ts +4 -0
  16. package/_dist/mod.d.ts.map +1 -0
  17. package/_dist/provider.d.ts +33 -0
  18. package/_dist/provider.d.ts.map +1 -0
  19. package/_dist/pve.d.ts +17 -0
  20. package/_dist/pve.d.ts.map +1 -0
  21. package/_dist/recovery.d.ts +71 -0
  22. package/_dist/recovery.d.ts.map +1 -0
  23. package/_dist/tools.d.ts +4 -0
  24. package/_dist/tools.d.ts.map +1 -0
  25. package/_dist/vocab.d.ts +5 -0
  26. package/_dist/vocab.d.ts.map +1 -0
  27. package/archive.js +60 -0
  28. package/archive.js.map +1 -0
  29. package/archive.ts +49 -0
  30. package/bubblewrap.js +495 -0
  31. package/bubblewrap.js.map +1 -0
  32. package/bubblewrap.ts +555 -0
  33. package/cloudflare.js +434 -0
  34. package/cloudflare.js.map +1 -0
  35. package/cloudflare.ts +592 -0
  36. package/configuration.js +84 -0
  37. package/configuration.js.map +1 -0
  38. package/configuration.ts +120 -0
  39. package/deno.json +1 -0
  40. package/docker.js +149 -0
  41. package/docker.js.map +1 -0
  42. package/docker.ts +206 -0
  43. package/effects.js +86 -0
  44. package/effects.js.map +1 -0
  45. package/effects.ts +78 -0
  46. package/lifecycle.js +153 -0
  47. package/lifecycle.js.map +1 -0
  48. package/lifecycle.ts +207 -0
  49. package/mod.js +6 -0
  50. package/mod.js.map +1 -0
  51. package/mod.ts +7 -0
  52. package/package.json +64 -4
  53. package/provider.js +11 -0
  54. package/provider.js.map +1 -0
  55. package/provider.ts +44 -0
  56. package/pve.js +197 -0
  57. package/pve.js.map +1 -0
  58. package/pve.ts +259 -0
  59. package/recovery-script.js +187 -0
  60. package/recovery-script.js.map +1 -0
  61. package/recovery-script.ts +186 -0
  62. package/recovery.js +231 -0
  63. package/recovery.js.map +1 -0
  64. package/recovery.ts +317 -0
  65. package/sandbox-runner.js +218 -0
  66. package/sandbox-runner.js.map +1 -0
  67. package/sandbox-runner.ts +217 -0
  68. package/tools.js +42 -0
  69. package/tools.js.map +1 -0
  70. package/tools.ts +45 -0
  71. package/vocab.js +13 -0
  72. package/vocab.js.map +1 -0
  73. package/vocab.json +180 -0
  74. package/vocab.ts +11 -0
package/cloudflare.js ADDED
@@ -0,0 +1,434 @@
1
+ // Cloudflare containers as sandbox providers. The namespace supplies the
2
+ // deployed image; the host supplies invocation environment and RPC retry policy.
3
+ // Grants, accounts and billing are not container concerns.
4
+ import { sleep, system } from "@yaks/fp";
5
+ import { identityEid } from "@yaks/graph";
6
+ import { shellStat } from "@yaks/machine";
7
+ /** The deployed image's writable working directory. */ export let CWD = '/workspace';
8
+ /** Commands have a four-minute ceiling, including background processes. */ export let TIMEOUT = 240_000;
9
+ /** An idle workbench releases its container after one minute. */ export let NAP = 60;
10
+ export let SLEEP = `${NAP / 60}m`;
11
+ /** How long one call keeps a container awake, in seconds: the longest
12
+ * command, then the nap before it sleeps on its own. */ export let HELD = TIMEOUT / 1000 + NAP;
13
+ let POOL_WAIT = 90_000;
14
+ let POOL_POLL = 2_000;
15
+ let MAX_INSTANCES = 'Maximum number of running container instances exceeded';
16
+ export let POOL_BUSY = 'All sandbox containers are busy. Try the same call again shortly.';
17
+ let capacity = (error)=>{
18
+ for(let cause = error; cause instanceof Error; cause = cause.cause){
19
+ if (cause.message.includes(MAX_INSTANCES)) return true;
20
+ }
21
+ return false;
22
+ };
23
+ /** Wait for a free slot during startup, before any workspace operation runs.
24
+ * The window gives an idle workbench time to snapshot and release its slot. */ export let admitted = async (start, clock = system)=>{
25
+ let until = clock.now() + POOL_WAIT;
26
+ for(;;){
27
+ try {
28
+ return await start();
29
+ } catch (error) {
30
+ if (!capacity(error)) throw error;
31
+ let left = until - clock.now();
32
+ if (left <= 0) throw new Error(POOL_BUSY, {
33
+ cause: error
34
+ });
35
+ await sleep(Math.min(left, POOL_POLL), undefined, clock);
36
+ }
37
+ }
38
+ };
39
+ let STATUS_WAIT = 5_000;
40
+ let UPDATE_WAIT = 5 * 60_000;
41
+ let UPDATE_POLL = 10_000;
42
+ // A kernel can take a deployment before its active workbench. Cloudflare
43
+ // defers the object's update for up to five minutes. Only its missing stream
44
+ // RPC means it has yet to update. A file error must still reach the caller.
45
+ let afterUpdate = async (read, clock = system)=>{
46
+ let until = clock.now() + UPDATE_WAIT;
47
+ for(;;){
48
+ try {
49
+ return await read();
50
+ } catch (error) {
51
+ let left = until - clock.now();
52
+ if (left <= 0 || !(error instanceof Error) || !error.message.includes('RPC receiver does not implement the method "readBytes"')) throw error;
53
+ await sleep(Math.min(left, UPDATE_POLL), undefined, clock);
54
+ }
55
+ }
56
+ };
57
+ /** Process status is a short, read-only control request. The HTTP SDK bounds
58
+ * startup retries, but one unresponsive container read can consume minutes.
59
+ * Cancel that read at the transport and try again. The container proxy's
60
+ * plain 500 also means it could not reach the container. Sandbox API errors
61
+ * carry JSON, including a missing process. */ export let processStatus = async (req, send, clock = system)=>{
62
+ let timeout = new DOMException('Sandbox process status timed out', 'TimeoutError');
63
+ let read = async ()=>{
64
+ let stop = new AbortController();
65
+ let cancel = clock.after(STATUS_WAIT, ()=>stop.abort(timeout));
66
+ try {
67
+ return await send(new Request(req, {
68
+ signal: AbortSignal.any([
69
+ req.signal,
70
+ stop.signal
71
+ ])
72
+ }));
73
+ } catch (error) {
74
+ throw stop.signal.aborted && !req.signal.aborted ? timeout : error;
75
+ } finally{
76
+ cancel();
77
+ }
78
+ };
79
+ try {
80
+ let response = await read();
81
+ if (response.status != 500 || req.signal.aborted || response.headers.get('content-type')?.includes('application/json')) {
82
+ return response;
83
+ }
84
+ await response.body?.cancel();
85
+ } catch (error) {
86
+ if (error !== timeout || req.signal.aborted) throw error;
87
+ }
88
+ return read();
89
+ };
90
+ /** The container a group lends one person, by name: one each, so the
91
+ * person's every way in reaches one workbench. The group's id rather than a
92
+ * name of it, since a renamed group keeps its containers. */ export let named = (within, to)=>`build-${within}-${to}`;
93
+ let lentRow = (within, to, until)=>({
94
+ entity: {
95
+ eid: identityEid('lent', [
96
+ within,
97
+ to
98
+ ])
99
+ },
100
+ lent: {
101
+ to,
102
+ within,
103
+ until: until == null ? null : new Date(until * 1000).toISOString()
104
+ }
105
+ });
106
+ /** Every sandbox the group has lent, awake or asleep: whose editable files
107
+ * must survive group trash, members who have since left included. */ export let lending = async (store, within)=>(await store.read(`.lent.within=${within}`)).map((row)=>{
108
+ let { to, until } = row.lent;
109
+ return {
110
+ to: String(to),
111
+ until: until ? Math.floor(Date.parse(String(until)) / 1000) : 0
112
+ };
113
+ });
114
+ /** How many of the group's sandboxes are awake at second `now` beside `to`'s. */ export let awakeBeside = (lent, to, now)=>lent.filter((l)=>l.to != to && l.until > now).length;
115
+ /**
116
+ * `to`'s sandbox in the group, held awake for {@link HELD} more seconds —
117
+ * unless `allowed` others already are, when nothing is written and the answer
118
+ * is how many. The row is written only once its hold is half spent: a build
119
+ * calls faster than its store need hear about it.
120
+ */ export let hold = async (store, within, to, allowed, now = Date.now())=>{
121
+ let t = Math.floor(now / 1000);
122
+ let lent = await lending(store, within);
123
+ let awake = awakeBeside(lent, to, t);
124
+ if (awake >= allowed) return {
125
+ held: false,
126
+ awake
127
+ };
128
+ let mine = lent.find((l)=>l.to == to);
129
+ if (!mine || mine.until - t <= HELD / 2) {
130
+ await store.apply([
131
+ lentRow(within, to, t + HELD)
132
+ ]);
133
+ }
134
+ return {
135
+ held: true
136
+ };
137
+ };
138
+ /** `to`'s sandbox in the group, asleep: a stopped container gives its place
139
+ * back at once rather than when its nap would. */ export let slept = async (store, within, to)=>{
140
+ await store.apply([
141
+ lentRow(within, to, null)
142
+ ]);
143
+ };
144
+ let exported = (path)=>{
145
+ if (!path || path.split('/').includes('..')) {
146
+ throw new Error(`cloudflare: invalid export path: ${path}`);
147
+ }
148
+ return path.startsWith('/') ? path : `${CWD}/${path}`;
149
+ };
150
+ let base64 = (bytes)=>{
151
+ let parts = [];
152
+ for(let i = 0; i < bytes.length; i += 8192){
153
+ parts.push(String.fromCharCode(...bytes.subarray(i, i + 8192)));
154
+ }
155
+ return btoa(parts.join(''));
156
+ };
157
+ let checked = async (box, command)=>{
158
+ let result = await box.exec(command, {
159
+ timeout: TIMEOUT
160
+ });
161
+ if (result.exitCode !== 0) {
162
+ throw new Error(`cloudflare: workspace command failed: ${result.stderr}`);
163
+ }
164
+ return result.stdout;
165
+ };
166
+ /** A provider bound to one deployed container namespace. Stable request ids
167
+ * are the namespace names, so connect, export and dispose need no live handle.
168
+ * `from`, `image` and addresses are refused: this namespace boots its deployed
169
+ * image, not a graph commit or an existing sandbox. */ export let cloudflareProvider = (ns, options = {})=>{
170
+ let retry = options.retry ?? (async (send)=>await send());
171
+ let boxOf = (ref, invocation = true, internal = false)=>{
172
+ if (ref.address != null) {
173
+ throw new Error('cloudflare: cannot attach an existing sandbox');
174
+ }
175
+ let call = (send)=>retry(async ()=>{
176
+ if (options.ephemeral || internal) {
177
+ let box = ns.get(ns.idFromName(ref.id));
178
+ if (!internal) await options.prepare?.(ref, box);
179
+ return await send(box);
180
+ }
181
+ if (!options.lifecycle) {
182
+ throw new Error('cloudflare: durable lifecycle storage is required');
183
+ }
184
+ return await options.lifecycle.locked(ref.id, async ({ state })=>{
185
+ if (state != 'ready') {
186
+ throw new Error('cloudflare: sandbox is not ready or was disposed');
187
+ }
188
+ let box = ns.get(ns.idFromName(ref.id));
189
+ let { status } = await box.getState();
190
+ if (status != 'running' && status != 'healthy') {
191
+ throw new Error('cloudflare: sandbox storage is unavailable; refusing recreation');
192
+ }
193
+ // Hold the lifecycle lock through RPC completion: disposal cannot
194
+ // race a stale workspace handle into recreating destroyed storage.
195
+ await options.prepare?.(ref, box);
196
+ return await send(box);
197
+ });
198
+ });
199
+ let dressed = async (opts)=>({
200
+ ...opts,
201
+ ...invocation ? {
202
+ env: {
203
+ ...await options.env?.(),
204
+ ...opts?.env
205
+ }
206
+ } : {}
207
+ });
208
+ return {
209
+ exec: (cmd, opts)=>call(async (box)=>box.exec(cmd, await dressed(opts))),
210
+ getState: ()=>call((box)=>box.getState()),
211
+ startProcess: (cmd, opts)=>{
212
+ let sent = false, failure;
213
+ return call(async (box)=>{
214
+ let id = opts?.processId;
215
+ if (sent) {
216
+ if (id) {
217
+ let found = await box.getProcess(id);
218
+ if (found) return {
219
+ id,
220
+ pid: found.pid
221
+ };
222
+ }
223
+ throw new Error('Sandbox process start could not be confirmed', {
224
+ cause: failure
225
+ });
226
+ }
227
+ let args = await dressed(opts);
228
+ sent = true;
229
+ try {
230
+ return await box.startProcess(cmd, args);
231
+ } catch (error) {
232
+ failure = error;
233
+ throw error;
234
+ }
235
+ });
236
+ },
237
+ getProcess: (id)=>call((box)=>box.getProcess(id)),
238
+ killProcess: (id)=>call((box)=>box.killProcess(id)),
239
+ getProcessLogs: (id)=>call((box)=>box.getProcessLogs(id)),
240
+ mkdir: (path, opts)=>call((box)=>box.mkdir(path, opts)),
241
+ writeFile: (path, content, opts)=>call((box)=>box.writeFile(path, content, opts)),
242
+ readFile: (path, opts)=>call((box)=>box.readFile(path, opts)),
243
+ readBytes: (path)=>call((box)=>box.readBytes(path)),
244
+ destroy: ()=>call((box)=>box.destroy()),
245
+ setSleepAfter: (after)=>call((box)=>box.setSleepAfter?.(after))
246
+ };
247
+ };
248
+ let lifecycle = (ref, act)=>{
249
+ // Validate addresses even when no lifecycle store is configured.
250
+ boxOf(ref);
251
+ if (!options.lifecycle) {
252
+ throw new Error('cloudflare: durable lifecycle storage is required');
253
+ }
254
+ return options.lifecycle.locked(ref.id, act);
255
+ };
256
+ let connection = (ref)=>({
257
+ workspace: workspaceOf(boxOf(ref)),
258
+ root: CWD
259
+ });
260
+ return {
261
+ request: async (request)=>{
262
+ if (request.from != null || request.image != null) {
263
+ throw new Error("cloudflare: uses the namespace's deployed image; from and image are unsupported");
264
+ }
265
+ let prepare = async ()=>{
266
+ let box = boxOf(request, true, true);
267
+ // mkdir is idempotent and starts the namespace's deployed image.
268
+ if (!options.ephemeral) await box.mkdir(CWD, {
269
+ recursive: true
270
+ });
271
+ await Promise.resolve(box.setSleepAfter?.(SLEEP)).catch((e)=>options.sleepError?.(e));
272
+ return connection(request);
273
+ };
274
+ if (options.ephemeral) return await prepare();
275
+ return await lifecycle(request, async (receipt)=>{
276
+ if (receipt.state == 'released' || receipt.state == 'disposing') {
277
+ throw new Error('cloudflare: sandbox was disposed; request a new id');
278
+ }
279
+ if (receipt.state == 'ready') {
280
+ let { status } = await boxOf(request, true, true).getState();
281
+ if (status != 'running' && status != 'healthy') {
282
+ throw new Error('cloudflare: sandbox storage is unavailable; refusing recreation');
283
+ }
284
+ return connection(request);
285
+ }
286
+ if (receipt.state == 'provisioning') {
287
+ // An interrupted first request may have created writable storage.
288
+ // A stopped/missing instance cannot prove that storage survived.
289
+ let { status } = await boxOf(request, true, true).getState();
290
+ if (status != 'running' && status != 'healthy') {
291
+ throw new Error('cloudflare: interrupted provisioning; refusing recreation');
292
+ }
293
+ }
294
+ await receipt.save('provisioning');
295
+ let lent = await prepare();
296
+ await receipt.save('ready');
297
+ return lent;
298
+ });
299
+ },
300
+ connect: async (ref)=>{
301
+ if (options.ephemeral) return connection(ref);
302
+ return await lifecycle(ref, async ({ state })=>{
303
+ if (state != 'ready') {
304
+ throw new Error('cloudflare: sandbox is not ready or was disposed');
305
+ }
306
+ let { status } = await boxOf(ref, true, true).getState();
307
+ if (status != 'running' && status != 'healthy') {
308
+ throw new Error('cloudflare: sandbox storage is unavailable; refusing recreation');
309
+ }
310
+ return connection(ref);
311
+ });
312
+ },
313
+ dispose: async (ref)=>{
314
+ if (!options.trash) {
315
+ throw new Error('cloudflare: recoverable trash storage is required');
316
+ }
317
+ boxOf(ref);
318
+ let trash = ()=>retry(()=>options.trash(ref, ns.get(ns.idFromName(ref.id))));
319
+ if (options.ephemeral) {
320
+ await trash();
321
+ return;
322
+ }
323
+ await lifecycle(ref, async (receipt)=>{
324
+ if (receipt.state == 'released') return;
325
+ await receipt.save('disposing');
326
+ await trash();
327
+ await receipt.save('released');
328
+ });
329
+ },
330
+ restore: async (ref)=>{
331
+ if (!options.restore) {
332
+ throw new Error('cloudflare: restore is not configured');
333
+ }
334
+ await lifecycle(ref, async (receipt)=>{
335
+ if (receipt.state == 'ready') return;
336
+ await retry(()=>options.restore(ref, ns.get(ns.idFromName(ref.id))));
337
+ await receipt.save('ready');
338
+ });
339
+ },
340
+ exec: (ref, command)=>boxOf(ref).exec(command, {
341
+ cwd: CWD
342
+ }),
343
+ open: (ref, path)=>{
344
+ let at = exported(path);
345
+ let box = boxOf(ref);
346
+ return afterUpdate(()=>box.readBytes(at), options.clock);
347
+ },
348
+ put: async (ref, { path, bytes })=>{
349
+ let box = boxOf(ref);
350
+ let at = path.startsWith('/') ? path : `${CWD}/${path}`;
351
+ await writeFile(box, at, base64(bytes), 'base64');
352
+ },
353
+ export: async function*(ref, paths) {
354
+ // Absolute paths are kept for sandbox_ship's published contract. Relative
355
+ // paths resolve from the deployed image's workspace.
356
+ let box = boxOf(ref);
357
+ for (let path of paths){
358
+ let { content } = await box.readFile(exported(path), {
359
+ encoding: 'base64'
360
+ });
361
+ yield {
362
+ path,
363
+ bytes: Uint8Array.from(atob(content.trim()), (c)=>c.charCodeAt(0))
364
+ };
365
+ }
366
+ }
367
+ };
368
+ };
369
+ // What the container calls a process that has not ended yet.
370
+ let RUNNING = new Set([
371
+ 'starting',
372
+ 'running'
373
+ ]);
374
+ let lines = (said)=>said ? said.replace(/\n$/, '').split('\n') : [];
375
+ /**
376
+ * A container as the workspace @yaks/harness's machine tools run on
377
+ * (`machineTools`). Every command is a background process of the container's
378
+ * own, bounded by {@link TIMEOUT} and kept after it exits so a later `wait`
379
+ * still finds its code; the container's destruction clears them all.
380
+ *
381
+ * Its output is two streams where a box has one, so an answer's tail is what
382
+ * it printed to stdout followed by what it printed to stderr, where a
383
+ * compiler's errors are. A kill is the container's one kill: it takes no
384
+ * signal, so SIGTERM and SIGKILL are the same call.
385
+ */ let workspaceOf = (box)=>({
386
+ // Every look is a call into the container, so it looks twice a second.
387
+ poll: 500,
388
+ start: async (command, cwd, call)=>(await box.startProcess(command, {
389
+ cwd: cwd ?? CWD,
390
+ timeout: TIMEOUT,
391
+ autoCleanup: false,
392
+ ...call ? {
393
+ processId: call
394
+ } : {}
395
+ })).id,
396
+ receipt: async (call)=>await box.getProcess(call) ? call : undefined,
397
+ look: async (id)=>{
398
+ let p = await box.getProcess(id);
399
+ return p && {
400
+ ...p.pid ? {
401
+ pid: p.pid
402
+ } : {},
403
+ ...RUNNING.has(p.status) ? {} : {
404
+ exit: {
405
+ code: p.exitCode ?? null
406
+ }
407
+ }
408
+ };
409
+ },
410
+ tail: async (id, n)=>{
411
+ let { stdout, stderr } = await box.getProcessLogs(id);
412
+ return [
413
+ ...lines(stdout),
414
+ ...lines(stderr)
415
+ ].slice(-n);
416
+ },
417
+ kill: async (id)=>{
418
+ await box.killProcess(id);
419
+ },
420
+ read: async (path)=>(await box.readFile(path)).content,
421
+ stat: shellStat((script)=>checked(box, `cd ${CWD} || exit 1\n${script}`)),
422
+ write: (path, content)=>writeFile(box, path, content),
423
+ writeBytes: (path, bytes)=>writeFile(box, path, base64(bytes), 'base64')
424
+ });
425
+ let writeFile = async (box, path, content, encoding)=>{
426
+ let dir = path.slice(0, path.lastIndexOf('/'));
427
+ if (dir) await box.mkdir(dir, {
428
+ recursive: true
429
+ });
430
+ await box.writeFile(path, content, encoding ? {
431
+ encoding
432
+ } : undefined);
433
+ };
434
+ //# sourceMappingURL=cloudflare.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cloudflare.js","sources":["./cloudflare.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,iFAAiF;AACjF,2DAA2D;AAC3D,SAAqB,KAAK,EAAE,MAAM,wBAA6B;AAC/D,SAAiC,WAAW,2BAAgC;AAC5E,SAAS,SAAS,6BAAkD;AAqDpE,qDAAqD,GACrD,OAAO,IAAI,MAAM,aAAY;AAC7B,yEAAyE,GACzE,OAAO,IAAI,UAAU,QAAO;AAC5B,+DAA+D,GAC/D,OAAO,IAAI,MAAM,GAAE;AACnB,OAAO,IAAI,QAAQ,GAAG,MAAM,GAAG,CAAC,CAAC,CAAA;AACjC;sDACsD,GACtD,OAAO,IAAI,OAAO,UAAU,OAAO,IAAG;AAEtC,IAAI,YAAY;AAChB,IAAI,YAAY;AAChB,IAAI,gBAAgB;AACpB,OAAO,IAAI,YACT,oEAAmE;AAErE,IAAI,WAAW,CAAC;EACd,IAAK,IAAI,QAAQ,OAAO,iBAAiB,OAAO,QAAQ,MAAM,KAAK,CAAE;IACnE,IAAI,MAAM,OAAO,CAAC,QAAQ,CAAC,gBAAgB,OAAO;EACpD;EACA,OAAO;AACT;AAEA;6EAC6E,GAC7E,OAAO,IAAI,WAAW,OACpB,OACA,QAAe,MAAM;EAErB,IAAI,QAAQ,MAAM,GAAG,KAAK;EAC1B,OAAS;IACP,IAAI;MACF,OAAO,MAAM;IACf,EAAE,OAAO,OAAO;MACd,IAAI,CAAC,SAAS,QAAQ,MAAM;MAC5B,IAAI,OAAO,QAAQ,MAAM,GAAG;MAC5B,IAAI,QAAQ,GAAG,MAAM,IAAI,MAAM,WAAW;QAAE,OAAO;MAAM;MACzD,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,YAAY,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