clavarium 0.2.207-beta.1 → 0.2.208-beta.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.
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/conversations.mjs +29 -8
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.208-beta.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "clavarium",
|
|
9
|
-
"version": "0.2.
|
|
9
|
+
"version": "0.2.208-beta.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/conversations.mjs
CHANGED
|
@@ -168,7 +168,10 @@ export class Conversations {
|
|
|
168
168
|
/* A move cut short leaves the machine as it was at that moment:
|
|
169
169
|
it is said, with where to look, rather than guessed at. */
|
|
170
170
|
if (c.phase === 'moving') store.patch(c.name, { phase: 'ready', step: undefined, moved: 'The server restarted while the work folder was being moved. The files are safe, in the machine: look at /work, /work.before-move and /work.moving.' });
|
|
171
|
-
|
|
171
|
+
/* A move into a shared machine cut short (14-11): back in its own machine, as it was -- never « build it
|
|
172
|
+
again », which would make its own machine anew and lose its tool's memory. */
|
|
173
|
+
if (c.phase === 'building' && c.movingTo) store.patch(c.name, { phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, sharedMachine: undefined, machineMb: undefined, machineUser: undefined, ...(c.movingFromMb ? { memoryMb: c.movingFromMb } : {}), movingTo: undefined, movingFromMb: undefined, stopped: true, moved: `The server restarted while it was moving to the shared machine ${c.movingTo}: it stays in its own machine, as it was. Move it again when you like.` });
|
|
174
|
+
else if (c.phase === 'building') store.patch(c.name, { phase: 'failed', error: 'The server restarted while this conversation was being built. Build it again, or archive it.' });
|
|
172
175
|
if (c.phase === 'restarting') store.patch(c.name, { phase: 'ready', step: undefined, restartingSince: undefined, restarted: 'The server restarted while this machine was being restarted: look at its state, and restart it again if needed.' });
|
|
173
176
|
/* An action cut short: said as such, never left running on the page. */
|
|
174
177
|
if (store.get(c.name)?.machine) store.patch(c.name, { machine: undefined, machineReport: { kind: c.machine.kind, ok: false, cut: true, at: new Date().toISOString(), steps: (c.machine.steps ?? []).filter((x) => x.state !== 'todo').map(({ id, state, s }) => ({ id, result: state === 'run' ? 'cut' : state, ...(s !== undefined ? { s } : {}) })), advice: 'look', said: 'The server restarted during this action: look at its state.' } });
|
|
@@ -1202,7 +1205,8 @@ export class Conversations {
|
|
|
1202
1205
|
const act = this.#take(name, 'move');
|
|
1203
1206
|
this.#cancelStop(name);
|
|
1204
1207
|
const now = new Date().toISOString();
|
|
1205
|
-
|
|
1208
|
+
/* `movingTo`: what a restart of this server finds, to put it back in its own machine, as it was (14-11). */
|
|
1209
|
+
this.#store.patch(name, { phase: 'building', step: `Moving to the shared machine ${machine}`, buildingSince: now, progress: buildProgress(now), movingTo: machine, movingFromMb: c.memoryMb });
|
|
1206
1210
|
this.built = this.#moving(name, c, tool, machine, size, memory, state).finally(() => this.#give(name, act));
|
|
1207
1211
|
return this.#store.get(name);
|
|
1208
1212
|
}
|
|
@@ -1213,7 +1217,7 @@ export class Conversations {
|
|
|
1213
1217
|
const carried = join(dir, 'state.tar.gz');
|
|
1214
1218
|
const back = (why) => {
|
|
1215
1219
|
/* Back to its own machine, as it was (stopped: the next opening wakes it). */
|
|
1216
|
-
this.#store.patch(name, { sharedMachine: undefined, machineMb: undefined, machineUser: undefined, memoryMb: c.memoryMb, phase: 'ready', step: undefined, progress: undefined, buildingSince: undefined, error: undefined });
|
|
1220
|
+
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 });
|
|
1217
1221
|
this.#fresh.add(name); this.#mountAgain.add(name);
|
|
1218
1222
|
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 */ }
|
|
1219
1223
|
};
|
|
@@ -1222,12 +1226,26 @@ export class Conversations {
|
|
|
1222
1226
|
if (state === 'Running') await this.#vms.exec(name, ['tmux', '-L', SOCKET, 'kill-server'], { timeoutMs: 10_000 }).catch(() => {});
|
|
1223
1227
|
if (tool.state) {
|
|
1224
1228
|
this.#store.patch(name, { step: `Taking ${tool.label}'s state along` });
|
|
1225
|
-
|
|
1229
|
+
/* Through its work folder, as a copy reads it (14-11): the VM manager's output stalls past ~36 KB on
|
|
1230
|
+
the owner's server -- a move then waited for ever. Its size read as it grows, said; quiet too long: ended. */
|
|
1231
|
+
const workDir = c.work === 'kept' && typeof this.workFolder === 'function' ? this.workFolder(name) : '';
|
|
1232
|
+
const carryId = workDir ? `move-${name}-${Date.now()}` : '';
|
|
1233
|
+
const inWork = carryId ? join(workDir, '.clavarium-carry', `${carryId}.tgz`) : '';
|
|
1234
|
+
if (inWork) await Promise.race([Promise.resolve().then(() => this.mounted(name, true)).catch(() => {}), new Promise((r) => { setTimeout(r, MOUNTED_MS).unref?.(); })]);
|
|
1235
|
+
const { stream, child } = await this.exportState(name, inWork ? { toWork: carryId } : {});
|
|
1236
|
+
let read = 0; let lastAt = Date.now(); let stalled = false;
|
|
1237
|
+
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)}` }); };
|
|
1238
|
+
const sizing = setInterval(() => {
|
|
1239
|
+
if (inWork) { try { grew(statSync(inWork).size); } catch { /* not there yet */ } }
|
|
1240
|
+
if (Date.now() - lastAt >= COPY_QUIET_MS) { stalled = true; child.kill('SIGKILL'); }
|
|
1241
|
+
}, 1000);
|
|
1226
1242
|
const failed = new Promise((ok) => child.on('error', () => ok(-1)));
|
|
1227
|
-
const file = createWriteStream(carried, { mode: 0o600 });
|
|
1228
|
-
stream.pipe(file);
|
|
1229
|
-
const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]);
|
|
1230
|
-
await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1243
|
+
const file = inWork ? null : createWriteStream(carried, { mode: 0o600 });
|
|
1244
|
+
if (file) { stream.on('data', (d) => grew(read + d.length)); stream.pipe(file); } else stream.resume();
|
|
1245
|
+
const code = await Promise.race([new Promise((ok) => child.on('close', ok)), failed]).finally(() => clearInterval(sizing));
|
|
1246
|
+
if (file) await new Promise((ok) => (file.writableFinished ? ok() : file.on('finish', ok)));
|
|
1247
|
+
if (inWork) { try { if (code === 0 && !stalled) copyFileSync(inWork, carried); } finally { rmSync(inWork, { force: true }); } }
|
|
1248
|
+
if (stalled) return back(`its tool's state stopped coming (${sizeWords(read)} read, then nothing for ${COPY_QUIET_MS / 60_000} min).`);
|
|
1231
1249
|
if (code !== 0) return back(`its tool's state could not be taken (exit ${code}${firstLine(child.said) ? `: ${firstLine(child.said)}` : ''}).`);
|
|
1232
1250
|
}
|
|
1233
1251
|
if (state !== undefined) {
|
|
@@ -1251,12 +1269,15 @@ export class Conversations {
|
|
|
1251
1269
|
try { await this.#unpack(name, c.tool, carried); } catch (error) {
|
|
1252
1270
|
this.#store.patch(name, { phase: 'ready', step: undefined });
|
|
1253
1271
|
this.ready(name);
|
|
1272
|
+
this.#store.patch(name, { movingTo: undefined, movingFromMb: undefined });
|
|
1254
1273
|
this.renewed(name, `Moved to the shared machine ${machine}, but ${tool.label}'s state did not come along (${error.message}): it starts afresh. Its old machine is kept, stopped.`, true);
|
|
1255
1274
|
return undefined;
|
|
1256
1275
|
}
|
|
1257
1276
|
this.#store.patch(name, { phase: 'ready', step: undefined });
|
|
1258
1277
|
this.ready(name);
|
|
1259
1278
|
}
|
|
1279
|
+
/* There for good: its own machine can go. */
|
|
1280
|
+
this.#store.patch(name, { movingTo: undefined, movingFromMb: undefined });
|
|
1260
1281
|
await this.#vms.removeVm(old).catch(() => {});
|
|
1261
1282
|
this.renewed(name, `Moved to the shared machine ${machine}: its work folder${tool.state ? `, ${tool.label}'s state` : ''} and this chat came along. Its own machine is deleted.`, true);
|
|
1262
1283
|
return undefined;
|