clavarium 0.2.449-next.1 → 0.2.450-next.1

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.
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.449-next.1",
3
+ "version": "0.2.450-next.1",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "clavarium",
9
- "version": "0.2.449-next.1",
9
+ "version": "0.2.450-next.1",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@xterm/addon-fit": "^0.11.0",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clavarium",
3
- "version": "0.2.449-next.1",
3
+ "version": "0.2.450-next.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "description": "A conversation is a VM with a terminal in it. Everything else is a folder.",
@@ -15,7 +15,7 @@ import { TOOLS_PATH, LAUNCH } from './toolbox.mjs';
15
15
  import { homeExcludes, wholeStream, readManifest, workEmpty, unpackHere, restoreWork, CARRY } from './carry.mjs';
16
16
  import { availableParallelism } from 'node:os';
17
17
  import { spawn } from 'node:child_process';
18
- import { readFileSync, createReadStream, createWriteStream, mkdtempSync, rmSync, statSync, copyFileSync, mkdirSync } from 'node:fs';
18
+ import { readFileSync, createReadStream, createWriteStream, mkdtempSync, rmSync, statSync, copyFileSync, mkdirSync, existsSync } from 'node:fs';
19
19
  import { tmpdir } from 'node:os';
20
20
  import { join, dirname } from 'node:path';
21
21
 
@@ -1174,6 +1174,7 @@ export class Conversations {
1174
1174
  const carryId = workDir ? `copy-${to}-${Date.now()}` : '';
1175
1175
  const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
1176
1176
  if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(from, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
1177
+ if (inWork && !(await this.#workShown(from, workDir))) throw new Error('its original\'s work folder is not shown in its machine: open the original once, then copy it again');
1177
1178
  const out = await this.exportState(from, inWork ? { toWork: carryId } : {});
1178
1179
  child = out.child;
1179
1180
  let read = 0; let lastAt = Date.now(); let stalled = false;
@@ -1284,11 +1285,26 @@ export class Conversations {
1284
1285
  this.#cancelStop(name);
1285
1286
  const now = new Date().toISOString();
1286
1287
  /* `movingTo`: what a restart of this server finds, to put it back in its own machine, as it was (14-11). */
1287
- this.#store.patch(name, { phase: 'building', step: `Moving to the shared machine ${machine}`, buildingSince: now, progress: buildProgress(now), movingTo: machine, movingFromMb: c.memoryMb });
1288
+ this.#store.patch(name, { phase: 'building', step: `Moving to the shared machine ${machine}`, buildingSince: now, progress: buildProgress(now), movingTo: machine, movingFromMb: c.memoryMb, moveFailed: undefined });
1288
1289
  this.built = this.#moving(name, c, tool, machine, size, memory, state).finally(() => this.#give(name, act));
1289
1290
  return this.#store.get(name);
1290
1291
  }
1291
1292
 
1293
+ /* ITS WORK FOLDER SEEN FROM ITS MACHINE (15-11): a file made there is found here -- else what is written for the
1294
+ server to read stays inside the machine (a work folder unmounted by a move cut short). Shown again once if not. */
1295
+ async #workShown(name, workDir) {
1296
+ const seen = async () => {
1297
+ const id = `probe-${Date.now()}`;
1298
+ await this.#vms.exec(name, ['sh', '-c', `mkdir -p /work/.clavarium-carry && : > /work/.clavarium-carry/${id}`], { timeoutMs: 30_000 }).catch(() => {});
1299
+ const there = existsSync(join(workDir, '.clavarium-carry', id));
1300
+ rmSync(join(workDir, '.clavarium-carry', id), { force: true });
1301
+ return there;
1302
+ };
1303
+ if (await seen()) return true;
1304
+ await this.#vms.workMount(name, this.#uid, this.#gid).catch(() => {});
1305
+ return seen();
1306
+ }
1307
+
1292
1308
  /* ITS TOOL'S STATE, TAKEN ALONG for a move (12-11, 15-11): through its work folder, as a copy reads it (14-11),
1293
1309
  written to `carried`. -> undefined, or why it could not be. */
1294
1310
  async #takeState(name, c, tool, carried) {
@@ -1299,6 +1315,7 @@ export class Conversations {
1299
1315
  const carryId = workDir ? `move-${name}-${Date.now()}` : '';
1300
1316
  const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
1301
1317
  if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(name, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
1318
+ if (inWork && !(await this.#workShown(name, workDir))) return 'its work folder is not shown in its machine: open the conversation once, then move it again.';
1302
1319
  const { stream, child } = await this.exportState(name, inWork ? { toWork: carryId } : {});
1303
1320
  let read = 0; let lastAt = Date.now(); let stalled = false;
1304
1321
  const grew = (n) => { if (n <= read) return; read = n; lastAt = Date.now(); this.#store.patch(name, { step: `Taking ${tool.label}'s state along: ${sizeWords(read)}` }); };
@@ -1323,7 +1340,7 @@ export class Conversations {
1323
1340
  const carried = join(dir, 'state.tar.gz');
1324
1341
  const back = (why) => {
1325
1342
  /* Back to its own machine, as it was (stopped: the next opening wakes it). */
1326
- this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: c.memoryMb, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingTo: undefined, movingFromMb: undefined });
1343
+ this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: c.memoryMb, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingTo: undefined, movingFromMb: undefined, moveFailed: `Not moved: ${why}` });
1327
1344
  this.#fresh.add(name); this.#mountAgain.add(name);
1328
1345
  try { this.renewed(name, `Not moved to the shared machine ${machine}: ${why} It stays in its own machine, as it was.`, false); } catch { /* told, nothing more */ }
1329
1346
  };
@@ -1388,7 +1405,7 @@ export class Conversations {
1388
1405
  this.#cancelStop(name);
1389
1406
  const now = new Date().toISOString();
1390
1407
  /* `movingOutOf`: what a restart of this server finds, to put it back in its shared machine (constructor). */
1391
- this.#store.patch(name, { phase: 'building', step: `Moving out of the shared machine ${c.sharedMachine}`, buildingSince: now, progress: buildProgress(now), movingOutOf: { sharedMachine: c.sharedMachine, machineMb: c.machineMb, machineUser: c.machineUser, memoryMb: c.memoryMb } });
1408
+ this.#store.patch(name, { phase: 'building', step: `Moving out of the shared machine ${c.sharedMachine}`, buildingSince: now, progress: buildProgress(now), movingOutOf: { sharedMachine: c.sharedMachine, machineMb: c.machineMb, machineUser: c.machineUser, memoryMb: c.memoryMb }, moveFailed: undefined });
1392
1409
  this.built = this.#movingOut(name, c, tool, memory, state).finally(() => this.#give(name, act));
1393
1410
  return this.#store.get(name);
1394
1411
  }
@@ -1404,7 +1421,7 @@ export class Conversations {
1404
1421
  if (!this.#store.get(name)) return undefined;
1405
1422
  this.#store.patch(name, { sharedMachine: undefined });
1406
1423
  if ((await this.#vms.state(name, { fresh: true }).catch(() => undefined)) !== undefined) await this.#vms.removeVm(vmName(name)).catch(() => {});
1407
- this.#store.patch(name, { ...was, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingOutOf: undefined });
1424
+ this.#store.patch(name, { ...was, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined, movingOutOf: undefined, moveFailed: `Not moved: ${why}` });
1408
1425
  if (left) await this.#vms.workMount(name, this.#uid, this.#gid).catch(() => {});
1409
1426
  this.#fresh.add(name); this.#mountAgain.add(name);
1410
1427
  try { this.renewed(name, `Not moved out of the shared machine ${shared}: ${why} It stays there, as it was.`, false); } catch { /* told, nothing more */ }
package/server/jobs.mjs CHANGED
@@ -96,8 +96,10 @@ export class Jobs {
96
96
  if (busy || !this.#open.has(name)) return;
97
97
  const job = this.#open.get(name);
98
98
  this.#open.delete(name);
99
- const ok = after?.phase === 'ready';
100
- const why = after && !ok && after.error ? String(after.error).slice(0, 300) : '';
99
+ /* A move that went back (15-11): ready where it was, but not done -- `moveFailed` says why. */
100
+ const ok = after?.phase === 'ready' && !after.moveFailed;
101
+ const said = after?.error ?? after?.moveFailed;
102
+ const why = after && !ok && said ? String(said).slice(0, 300) : '';
101
103
  this.#add(name, after ? (ok ? 'Done' : `Failed${why ? `: ${why}` : ''}`) : 'Removed');
102
104
  const { log } = this.#logs.get(name);
103
105
  this.#logs.delete(name);