clavarium 0.2.465-next.1 → 0.2.466-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.
- package/deploy/updater.mjs +12 -3
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/server/health.mjs +6 -0
- package/server/main.mjs +3 -2
- package/server/revive.mjs +14 -10
- package/web/app.js +2 -1
package/deploy/updater.mjs
CHANGED
|
@@ -85,6 +85,10 @@ const WATCH_EVERY_MS = 3600_000;
|
|
|
85
85
|
const WATCH_RECENT_MS = 24 * 3600_000;
|
|
86
86
|
const HISTORY_MAX = 30;
|
|
87
87
|
const ASK_EVERY_MS = 6 * 3600_000;
|
|
88
|
+
/* A VERSION THAT COULD NOT EVEN BE FETCHED (16-11: npm asked one minute after it came out, before every mirror
|
|
89
|
+
had it): nothing of it ran here, so it is tried again by itself, this long after, this many times at most. */
|
|
90
|
+
export const FETCH_AGAIN_MS = 30 * 60_000;
|
|
91
|
+
export const FETCH_TRIES = 3;
|
|
88
92
|
/* Between "Switching" said in state.json and the server stopped: the pages ask the server every
|
|
89
93
|
10 seconds at most (app.js), and the server says it in each answer (updates.mjs, notice): each
|
|
90
94
|
gives way to the maintenance page before the server goes. */
|
|
@@ -602,7 +606,7 @@ export class Updater {
|
|
|
602
606
|
const unlock = this.#lock();
|
|
603
607
|
try {
|
|
604
608
|
let release;
|
|
605
|
-
try { release = await this.prepare({ version }); } catch (error) { this.#history({ action: 'update', from: from?.version ?? null, to: version, result: 'failed', why: error.message }); throw error; }
|
|
609
|
+
try { release = await this.prepare({ version }); } catch (error) { this.#history({ action: 'update', from: from?.version ?? null, to: version, result: 'failed', why: error.message, ...(/^npm could not install /.test(error.message) ? { fetch: true } : {}) }); throw error; }
|
|
606
610
|
const before = this.#dataFormat();
|
|
607
611
|
let archive;
|
|
608
612
|
try {
|
|
@@ -714,8 +718,13 @@ export class Updater {
|
|
|
714
718
|
const available = await this.check();
|
|
715
719
|
if (!available) return 'up to date';
|
|
716
720
|
if (conf.MODE === 'ask') return `${available} is out: waiting for the owner`;
|
|
717
|
-
/* A version that failed here is not tried again by itself: the owner can, from Settings.
|
|
718
|
-
|
|
721
|
+
/* A version that failed here is not tried again by itself: the owner can, from Settings. One that only
|
|
722
|
+
could not be fetched (nothing of it ran) is, later, a few times. */
|
|
723
|
+
const failed = (state.history ?? []).filter((h) => h.to === available && h.action === 'update' && h.result !== 'done');
|
|
724
|
+
if (failed.some((h) => h.fetch !== true)) return `${available} failed here before: not tried again by itself`;
|
|
725
|
+
if (failed.length >= FETCH_TRIES) return `${available} could not be fetched ${failed.length} times: not tried again by itself`;
|
|
726
|
+
const lastAt = Math.max(...failed.map((h) => new Date(h.at ?? 0).getTime()), -Infinity);
|
|
727
|
+
if (failed.length && now - lastAt < FETCH_AGAIN_MS) return `${available} could not be fetched: tried again later`;
|
|
719
728
|
const why = await this.busy(); if (why) return why;
|
|
720
729
|
await this.apply(available);
|
|
721
730
|
/* What the history says, not what was hoped: a version that did not start was undone. */
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clavarium",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.466-next.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.466-next.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@xterm/addon-fit": "^0.11.0",
|
package/package.json
CHANGED
package/server/health.mjs
CHANGED
|
@@ -33,6 +33,10 @@ import { SESSION } from './conversations.mjs';
|
|
|
33
33
|
export const RESTART_OUTSIDE = '/var/tmp/clavarium-restart-asked';
|
|
34
34
|
/* What a folder that came loose looks like on a terminal (the kernel's words for ENOTCONN). */
|
|
35
35
|
const LOOSE_WORDS = 'transport endpoint is not connected|socket is not connected|ENOTCONN';
|
|
36
|
+
/* A WORK FOLDER THE VM MANAGER CANNOT TAKE BACK (16-11, tried on a test server): its mount program died, multipass
|
|
37
|
+
cannot unmount it ("Failed to terminate SSHFS mount process") and then refuses to mount it again ("already
|
|
38
|
+
mounted"). Only a restart of its machine mounts it again. */
|
|
39
|
+
export const STUCK_MOUNT = /already mounted|terminate SSHFS mount process/i;
|
|
36
40
|
|
|
37
41
|
/* How long installing the shared-folder helper in a machine may take (it comes from the snap store). */
|
|
38
42
|
export const SHARING_MS = 180_000;
|
|
@@ -143,6 +147,7 @@ export function judge(record) {
|
|
|
143
147
|
for (const path of record.remounted ?? []) add('info', 'mount', `remounted:${path}`, `${path} had come loose in the machine: it was mounted again.`);
|
|
144
148
|
for (const { path, why } of record.failed ?? []) add('bad', 'mount', `failed:${path}`, `${path} is not reachable in the machine and could not be mounted again${why ? `: ${why}` : ''}.`);
|
|
145
149
|
for (const path of record.missing ?? []) if (!(record.failed ?? []).some((f) => f.path === path)) add('warn', 'mount', `missing:${path}`, `${path} is not reachable in the machine.`);
|
|
150
|
+
if (record.stuckWork) add('bad', 'mount', 'stuck-work', 'Its work folder cannot be mounted again in its machine: its machine is restarted, its work picks up where it was.');
|
|
146
151
|
if (record.stale) add('bad', 'mount', 'stale-tool', 'Its tool is still in a folder that came loose: it is restarted, its work picks up where it was.');
|
|
147
152
|
/* Its terminal says so while its folders look well: said, nothing done (its tool may only be quoting it). */
|
|
148
153
|
else if (record.screenLoose > 0 && !(record.missing ?? []).length) add('warn', 'mount', 'screen-loose', 'Its terminal says a folder is not connected, though its folders look well.');
|
|
@@ -249,6 +254,7 @@ export class Health {
|
|
|
249
254
|
return this.#keep(name, {
|
|
250
255
|
at, state, answering: true, memory: facts.memory, oomKills: facts.oomKills ?? 0, ...(facts.oomKinds ? { oomKinds: facts.oomKinds } : {}), disks: facts.disks,
|
|
251
256
|
paths, missing: loose(), ...(remounted.length ? { remounted } : {}), ...(failed.length ? { failed } : {}), ...(links ? { links } : {}),
|
|
257
|
+
...(failed.some((f) => f.path === '/work' && STUCK_MOUNT.test(f.why ?? '')) ? { stuckWork: true } : {}),
|
|
252
258
|
...(facts.stale ? { stale: true } : {}), ...(facts.screenLoose ? { screenLoose: facts.screenLoose } : {}), ...(facts.restartAsked ? { restartAsked: true } : {}),
|
|
253
259
|
/* What was put back stays said until a later look finds nothing to put back. */
|
|
254
260
|
});
|
package/server/main.mjs
CHANGED
|
@@ -618,16 +618,17 @@ export async function startHome({ port, host, dataDir, mntDir = dataDir, gitRese
|
|
|
618
618
|
by the server, its tool only; told through its docket first (read as it starts), its chat after. */
|
|
619
619
|
const revive = new Revive({
|
|
620
620
|
restart: (name) => all.restartTool(name),
|
|
621
|
+
restartMachine: async (name) => { const r = await all.machineAction(name, 'restart', { wait: true }); return r?.ok !== false; },
|
|
621
622
|
busy: (name) => talk.pulse(name)?.busy === true,
|
|
622
623
|
taken: (name) => vms.exec(name, ['rm', '-f', RESTART_OUTSIDE], { timeoutMs: 10_000 }),
|
|
623
624
|
tell: (name, why, step) => {
|
|
624
|
-
const loose = why === 'stale';
|
|
625
|
+
const loose = why === 'stale' || why === 'stuck';
|
|
625
626
|
if (step === 'before') {
|
|
626
627
|
if (loose) try { if (dockets.on(name)) dockets.post(name, { kind: 'restarted', text: 'Your work folder came loose in your machine and was put back: your tool was restarted to see it again (what was in the old one could not be reached). Your work picks up where it was; what ran in the background stopped.' }); } catch { /* its docket may be off */ }
|
|
627
628
|
return;
|
|
628
629
|
}
|
|
629
630
|
const text = step === 'done'
|
|
630
|
-
? (loose ? 'Its work folder had come loose: its tool was restarted to see it again. Its work picks up where it was.' : 'Its tool was restarted as it asked: its work picks up where it was.')
|
|
631
|
+
? (why === 'stuck' ? 'Its work folder could not be mounted again: its machine was restarted, the folder is back. Its work picks up where it was.' : loose ? 'Its work folder had come loose: its tool was restarted to see it again. Its work picks up where it was.' : 'Its tool was restarted as it asked: its work picks up where it was.')
|
|
631
632
|
: 'Its tool could not be restarted: open its terminal and type exit, it starts again.';
|
|
632
633
|
try { talk.event(name, { kind: step === 'done' ? 'restarted' : 'machine-problem', text, topic: step === 'done' ? 'Restarted' : 'Machine', ...(step === 'done' ? {} : { tone: 'warn' }) }); } catch { /* its chat is off */ }
|
|
633
634
|
if (step === 'failed') events.add({ kind: 'machine', text: `${name}: ${text}`, conversation: name });
|
package/server/revive.mjs
CHANGED
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* Told by health.mjs, each look (`judged`):
|
|
9
9
|
* - `stale`: a program of its tool's session is in a folder that cannot be entered;
|
|
10
|
-
* - `restartAsked`: its tool asked from outside /work (health.mjs, RESTART_OUTSIDE)
|
|
10
|
+
* - `restartAsked`: its tool asked from outside /work (health.mjs, RESTART_OUTSIDE);
|
|
11
|
+
* - `stuckWork`: its work folder cannot be mounted again (health.mjs, STUCK_MOUNT): its MACHINE is restarted
|
|
12
|
+
* (`restartMachine`), the one thing that mounts it again; it outranks the others.
|
|
11
13
|
* Then, at the next tick: its tool only is restarted (conversations.mjs restartTool, never its
|
|
12
14
|
* machine), once its turn has ended -- or after WAIT_MS anyway when stale: a tool stuck in a dead
|
|
13
15
|
* folder cannot say its turn ended (its pulse is in /work). Never a loop: not again within AGAIN_MS.
|
|
@@ -17,27 +19,29 @@ export const WAIT_MS = 5 * 60_000;
|
|
|
17
19
|
export const AGAIN_MS = 30 * 60_000;
|
|
18
20
|
|
|
19
21
|
export class Revive {
|
|
20
|
-
#restart; #busy; #tell; #taken; #now; #wanted = new Map(); #lastAt = new Map(); #going = new Set();
|
|
22
|
+
#restart; #restartMachine; #busy; #tell; #taken; #now; #wanted = new Map(); #lastAt = new Map(); #going = new Set();
|
|
21
23
|
|
|
22
24
|
/* `restart(name)`: its tool restarted, resolves with whether it was. `busy(name)`: its turn goes on.
|
|
23
25
|
`tell(name, why, step)`: said where it should be, step 'before' (its docket), then 'done' or 'failed' (main.mjs).
|
|
24
26
|
`taken(name)`: the request outside /work removed (in its machine). */
|
|
25
|
-
constructor({ restart, busy = () => false, tell = () => {}, taken = async () => {}, now = Date.now }) {
|
|
26
|
-
this.#restart = restart; this.#busy = busy; this.#tell = tell; this.#taken = taken; this.#now = now;
|
|
27
|
+
constructor({ restart, restartMachine = async () => false, busy = () => false, tell = () => {}, taken = async () => {}, now = Date.now }) {
|
|
28
|
+
this.#restart = restart; this.#restartMachine = restartMachine; this.#busy = busy; this.#tell = tell; this.#taken = taken; this.#now = now;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
31
|
/* What one look found. A look that finds it well forgets a stale one not yet acted on. */
|
|
30
32
|
judged(name, record) {
|
|
31
33
|
if (!record || record.state !== 'Running' || record.answering !== true) return;
|
|
32
34
|
if (record.restartAsked) { void Promise.resolve().then(() => this.#taken(name)).catch(() => {}); this.#want(name, 'asked'); }
|
|
33
|
-
if (record.
|
|
34
|
-
else if (this.#
|
|
35
|
+
if (record.stuckWork) this.#want(name, 'stuck');
|
|
36
|
+
else if (record.stale) this.#want(name, 'stale');
|
|
37
|
+
else if (['stale', 'stuck'].includes(this.#wanted.get(name)?.why)) this.#wanted.delete(name);
|
|
35
38
|
}
|
|
36
39
|
|
|
37
40
|
#want(name, why) {
|
|
38
41
|
const had = this.#wanted.get(name);
|
|
39
|
-
/*
|
|
40
|
-
|
|
42
|
+
/* stuck over stale over a plain request: the stronger is acted on, even while it looks busy. */
|
|
43
|
+
const rank = { asked: 0, stale: 1, stuck: 2 };
|
|
44
|
+
if (!had || rank[why] > rank[had.why]) this.#wanted.set(name, { why, since: had?.since ?? this.#now() });
|
|
41
45
|
}
|
|
42
46
|
|
|
43
47
|
wanted(name) { return this.#wanted.get(name)?.why ?? null; }
|
|
@@ -49,14 +53,14 @@ export class Revive {
|
|
|
49
53
|
for (const [name, { why, since }] of [...this.#wanted]) {
|
|
50
54
|
if (this.#going.has(name)) continue;
|
|
51
55
|
const busy = (() => { try { return this.#busy(name); } catch { return false; } })();
|
|
52
|
-
if (busy && !(why
|
|
56
|
+
if (busy && !(why !== 'asked' && this.#now() - since >= WAIT_MS)) continue;
|
|
53
57
|
this.#wanted.delete(name);
|
|
54
58
|
if (this.#now() - (this.#lastAt.get(name) ?? -Infinity) < AGAIN_MS) continue;
|
|
55
59
|
this.#lastAt.set(name, this.#now());
|
|
56
60
|
this.#going.add(name);
|
|
57
61
|
try {
|
|
58
62
|
try { this.#tell(name, why, 'before'); } catch { /* told, nothing more */ }
|
|
59
|
-
const ok = await this.#restart(name).catch(() => false);
|
|
63
|
+
const ok = await (why === 'stuck' ? this.#restartMachine(name) : this.#restart(name)).catch(() => false);
|
|
60
64
|
if (ok) done.push(name);
|
|
61
65
|
try { this.#tell(name, why, ok ? 'done' : 'failed'); } catch { /* told, nothing more */ }
|
|
62
66
|
} finally { this.#going.delete(name); }
|
package/web/app.js
CHANGED
|
@@ -8187,7 +8187,8 @@
|
|
|
8187
8187
|
apply.dataset.retry = String(failedHere);
|
|
8188
8188
|
apply.className = failedHere ? '' : 'primary';
|
|
8189
8189
|
apply.textContent = failedHere ? `Try ${u.available} again\u2026` : `Update to ${u.available ?? ''}`;
|
|
8190
|
-
|
|
8190
|
+
const onlyFetch = failedHere && u.history.filter((h) => h.action === 'update' && h.to === u.available && h.result !== 'done').every((h) => h.fetch === true);
|
|
8191
|
+
$('updates-retry-note').textContent = !failedHere ? '' : onlyFetch ? 'It could not be downloaded before; it is tried again by itself.' : `It did not start here before. If it fails again, ${u.version} is put back.`;
|
|
8191
8192
|
$('updates-retry-note').hidden = !failedHere;
|
|
8192
8193
|
$('updates-retry-yes').hidden = true; $('updates-retry-no').hidden = true; apply.hidden = false;
|
|
8193
8194
|
/* The last thing that went wrong, said once at the top, in words: a version put
|