@ddtcorex/dsh-maestro-supervisor 0.6.8 → 0.7.0
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/lib/cli.d.ts +13 -0
- package/lib/cli.js +87 -55
- package/lib/plugin.d.ts +1 -1
- package/lib/plugin.js +73 -1
- package/lib/restart-guards.d.ts +11 -0
- package/lib/restart-guards.js +23 -0
- package/lib/restart-tool.d.ts +70 -0
- package/lib/restart-tool.js +241 -0
- package/lib/scan.d.ts +20 -0
- package/lib/scan.js +71 -0
- package/lib/self-kill-guard.d.ts +26 -0
- package/lib/self-kill-guard.js +63 -0
- package/lib/skill-provider.d.ts +6 -0
- package/lib/skill-provider.js +70 -0
- package/lib/supervisor.d.ts +9 -0
- package/lib/supervisor.js +73 -1
- package/package.json +2 -1
- package/skills/dsh-safe-restart/SKILL.md +90 -0
- package/skills/dsh-safe-restart/scripts/restart-dsh-web.sh +279 -0
package/lib/scan.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-restart session scan: walk recent session logs under
|
|
3
|
+
* <dshHome>/sessions/<project>/<session>/ and flag torn tails (a zstd frame
|
|
4
|
+
* that fails to decode, or a plain-text log that is unreadable). Runs after
|
|
5
|
+
* an intentional dsh-web restart so the supervisor can report whether any
|
|
6
|
+
* in-flight session log was left truncated by the restart.
|
|
7
|
+
*/
|
|
8
|
+
import { readdirSync, statSync } from 'node:fs';
|
|
9
|
+
import { join, extname, basename } from 'node:path';
|
|
10
|
+
import { execFileSync } from 'node:child_process';
|
|
11
|
+
async function decodeOk(file) {
|
|
12
|
+
try {
|
|
13
|
+
if (extname(file) === '.zstd') {
|
|
14
|
+
execFileSync('zstd', ['-d', '-c', file], { encoding: 'utf8', maxBuffer: 64 * 1024 * 1024, timeout: 30_000 });
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
const { readFileSync } = await import('node:fs');
|
|
18
|
+
readFileSync(file, 'utf8');
|
|
19
|
+
}
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Scan session logs whose mtime falls within the window. A file whose decode
|
|
28
|
+
* fails (torn zstd frame or unreadable plain text) is reported as torn. A
|
|
29
|
+
* missing sessions root yields an empty scan, never an error.
|
|
30
|
+
*/
|
|
31
|
+
export async function scanSessions(dshHome, opts = {}) {
|
|
32
|
+
const sessionsRoot = join(dshHome, 'sessions');
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
const withinMs = opts.withinMs ?? 10 * 60 * 1000;
|
|
35
|
+
const files = [];
|
|
36
|
+
try {
|
|
37
|
+
for (const proj of readdirSync(sessionsRoot)) {
|
|
38
|
+
const projDir = join(sessionsRoot, proj);
|
|
39
|
+
if (!statSync(projDir).isDirectory())
|
|
40
|
+
continue;
|
|
41
|
+
for (const sess of readdirSync(projDir)) {
|
|
42
|
+
const sessDir = join(projDir, sess);
|
|
43
|
+
if (!statSync(sessDir).isDirectory())
|
|
44
|
+
continue;
|
|
45
|
+
for (const f of readdirSync(sessDir)) {
|
|
46
|
+
const name = basename(f);
|
|
47
|
+
if (!name.endsWith('.zstd') && !name.endsWith('.jsonl'))
|
|
48
|
+
continue;
|
|
49
|
+
const fp = join(sessDir, f);
|
|
50
|
+
let mtime = 0;
|
|
51
|
+
try {
|
|
52
|
+
mtime = statSync(fp).mtimeMs;
|
|
53
|
+
}
|
|
54
|
+
catch {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (now - mtime > withinMs)
|
|
58
|
+
continue;
|
|
59
|
+
files.push(fp);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch { /* sessions root absent */ }
|
|
65
|
+
const torn = [];
|
|
66
|
+
for (const f of files) {
|
|
67
|
+
if (!(await decodeOk(f)))
|
|
68
|
+
torn.push(f);
|
|
69
|
+
}
|
|
70
|
+
return { scanned: files.length, torn };
|
|
71
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-kill guard for `tools/pre-execute`: deny bash/shell commands that would
|
|
3
|
+
* kill or restart the very dsh web process the agent is running inside. The
|
|
4
|
+
* model must route restarts through the supervisor's dsh_web_restart tool, not
|
|
5
|
+
* by killing the host.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Whether a shell command is a self-kill. `livePids` are the pids currently
|
|
9
|
+
* holding listening sockets; a `kill <pid>` whose pid is one of ours is a
|
|
10
|
+
* self-kill regardless of anything else in the command. The kill parser accepts
|
|
11
|
+
* flag forms (`kill -9 <pid>`, `kill -TERM <pid>`). A command that is
|
|
12
|
+
* essentially JUST a `kill <unrelated-pid>` is allowed (idempotent cleanups
|
|
13
|
+
* are common), as are kill attempts whose output reports "not found"/"done" —
|
|
14
|
+
* but any compound that chains a restart/kill after it (or before the end)
|
|
15
|
+
* stays denied.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isSelfKillCommand(cmd: string, livePids: number[]): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Build a `tools/pre-execute` waterfall listener: deny matching
|
|
20
|
+
* bash/shell/exec commands, otherwise delegate to `next()`. Live pids default
|
|
21
|
+
* to the pids holding listening sockets (`ss -tlnp`) so `kill <pid>` of a
|
|
22
|
+
* live host process is caught even when the command names no tool.
|
|
23
|
+
*/
|
|
24
|
+
export declare function makePreExecuteGuard(opts?: {
|
|
25
|
+
livePids?: () => number[];
|
|
26
|
+
}): (exec: any, next: () => Promise<any>) => Promise<any>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Self-kill guard for `tools/pre-execute`: deny bash/shell commands that would
|
|
3
|
+
* kill or restart the very dsh web process the agent is running inside. The
|
|
4
|
+
* model must route restarts through the supervisor's dsh_web_restart tool, not
|
|
5
|
+
* by killing the host.
|
|
6
|
+
*/
|
|
7
|
+
import { createRequire } from 'node:module';
|
|
8
|
+
const require = createRequire(import.meta.url);
|
|
9
|
+
// Patterns that restart/stop/start or kill dsh web (systemctl --user units,
|
|
10
|
+
// pkill/killall over the dsh tree, killing holders of :3080, and the
|
|
11
|
+
// dsh-safe-web-update helper itself). The bare `kill\s+` alternative is
|
|
12
|
+
// narrowed below so a kill of an unrelated pid is not denied as a self-kill.
|
|
13
|
+
const SELF_KILL_RE = /(systemctl\s+--?user\s+.*(restart|stop|start).*dsh-web|pkill\s+.*dsh|killall\s+.*dsh|ss\s+.*3080.*kill|restart-dsh-web|kill\s+)/i;
|
|
14
|
+
/**
|
|
15
|
+
* Whether a shell command is a self-kill. `livePids` are the pids currently
|
|
16
|
+
* holding listening sockets; a `kill <pid>` whose pid is one of ours is a
|
|
17
|
+
* self-kill regardless of anything else in the command. The kill parser accepts
|
|
18
|
+
* flag forms (`kill -9 <pid>`, `kill -TERM <pid>`). A command that is
|
|
19
|
+
* essentially JUST a `kill <unrelated-pid>` is allowed (idempotent cleanups
|
|
20
|
+
* are common), as are kill attempts whose output reports "not found"/"done" —
|
|
21
|
+
* but any compound that chains a restart/kill after it (or before the end)
|
|
22
|
+
* stays denied.
|
|
23
|
+
*/
|
|
24
|
+
export function isSelfKillCommand(cmd, livePids) {
|
|
25
|
+
if (/kill\s+(?:-\S+\s+)?(\d+)/i.test(cmd)) {
|
|
26
|
+
const pid = Number(cmd.match(/kill\s+(?:-\S+\s+)?(\d+)/i)?.[1]);
|
|
27
|
+
if (livePids.includes(pid))
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
return SELF_KILL_RE.test(cmd)
|
|
31
|
+
// Exclude only a command that is JUST `kill [flags] <unrelated pid>` —
|
|
32
|
+
// anchored end-to-end so `kill 1234 && systemctl restart dsh-web` cannot
|
|
33
|
+
// whitelist the compound through its prefix.
|
|
34
|
+
&& !/^kill\s+(?:-\S+\s+)?\d+\s*$/i.test(cmd.trim())
|
|
35
|
+
&& !/kill\s+(?:-\S+\s+)?(\d+)\s+.*(not found|done)/i.test(cmd);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Build a `tools/pre-execute` waterfall listener: deny matching
|
|
39
|
+
* bash/shell/exec commands, otherwise delegate to `next()`. Live pids default
|
|
40
|
+
* to the pids holding listening sockets (`ss -tlnp`) so `kill <pid>` of a
|
|
41
|
+
* live host process is caught even when the command names no tool.
|
|
42
|
+
*/
|
|
43
|
+
export function makePreExecuteGuard(opts = {}) {
|
|
44
|
+
const livePids = opts.livePids ?? (() => {
|
|
45
|
+
try {
|
|
46
|
+
const { execSync } = require('node:child_process');
|
|
47
|
+
const out = execSync(`ss -tlnp 2>/dev/null | grep -oP 'pid=\\K[0-9]+' | sort -u`, { encoding: 'utf8' });
|
|
48
|
+
return out.trim().split('\n').filter(Boolean).map(Number);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return [];
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
return async (exec, next) => {
|
|
55
|
+
// dsh-tools hands the frozen ToolExecution (name + arguments); the guard
|
|
56
|
+
// also accepts the `args` shape for tests/embedded hosts.
|
|
57
|
+
const cmd = String(exec?.args?.command ?? exec?.args?.input ?? exec?.arguments?.command ?? exec?.arguments?.input ?? '');
|
|
58
|
+
if ((exec?.name === 'bash' || exec?.name === 'shell' || exec?.name === 'exec') && isSelfKillCommand(cmd, livePids())) {
|
|
59
|
+
return { kind: 'deny', reason: 'DENIED — this command restarts the dsh web process you are running inside. Use the dsh_web_restart tool (supervisor) for a safe restart.' };
|
|
60
|
+
}
|
|
61
|
+
return next();
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { SkillCandidate, SkillDefinition, SkillLookupOptions } from '@deepseek-ai/dsh-skill';
|
|
2
|
+
export declare function makeSkillProvider(skillsDir: string): {
|
|
3
|
+
name: string;
|
|
4
|
+
list(_options: SkillLookupOptions): Promise<SkillCandidate[]>;
|
|
5
|
+
get(candidate: SkillCandidate, _options: SkillLookupOptions): Promise<SkillDefinition | undefined>;
|
|
6
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { readFile, stat } from 'node:fs/promises';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
const SKILL_NAME = 'dsh-safe-restart';
|
|
4
|
+
/** Minimal frontmatter reader for our own SKILL.md — enough to serve the provider contract. */
|
|
5
|
+
function parseFrontmatter(raw) {
|
|
6
|
+
const m = raw.match(/^---\n([\s\S]*?)\n---\n([\s\S]*)$/);
|
|
7
|
+
if (!m)
|
|
8
|
+
return { name: SKILL_NAME, description: '', body: raw };
|
|
9
|
+
const fm = m[1].split('\n').reduce((acc, line) => {
|
|
10
|
+
const kv = line.match(/^([A-Za-z0-9_-]+):\s*(.*)$/);
|
|
11
|
+
if (kv)
|
|
12
|
+
acc[kv[1]] = kv[2].replace(/^["']|["']$/g, '');
|
|
13
|
+
return acc;
|
|
14
|
+
}, {});
|
|
15
|
+
return { name: fm.name || SKILL_NAME, description: fm.description || '', body: m[2] };
|
|
16
|
+
}
|
|
17
|
+
export function makeSkillProvider(skillsDir) {
|
|
18
|
+
return {
|
|
19
|
+
// The dsh-skill service attributes candidates through the provider
|
|
20
|
+
// object's own `name` (maestro-skills returns `{ name, list, get }`); a
|
|
21
|
+
// missing name surfaces at runtime as `skill provider "undefined" returned
|
|
22
|
+
// skill ... for provider "maestro-supervisor"` and fails every turn.
|
|
23
|
+
name: 'maestro-supervisor',
|
|
24
|
+
async list(_options) {
|
|
25
|
+
const entry = join(skillsDir, SKILL_NAME);
|
|
26
|
+
const st = await stat(entry).catch(() => null);
|
|
27
|
+
if (!st?.isDirectory())
|
|
28
|
+
return [];
|
|
29
|
+
const skillFilePath = join(entry, 'SKILL.md');
|
|
30
|
+
const fileSt = await stat(skillFilePath).catch(() => null);
|
|
31
|
+
if (!fileSt?.isFile())
|
|
32
|
+
return [];
|
|
33
|
+
const raw = await readFile(skillFilePath, 'utf-8').catch(() => null);
|
|
34
|
+
if (raw === null)
|
|
35
|
+
return [];
|
|
36
|
+
const { name, description } = parseFrontmatter(raw);
|
|
37
|
+
return [{
|
|
38
|
+
name,
|
|
39
|
+
description,
|
|
40
|
+
invocation: { modelInvocable: true, userInvocable: true },
|
|
41
|
+
source: 'custom',
|
|
42
|
+
provider: 'maestro-supervisor',
|
|
43
|
+
rank: 360,
|
|
44
|
+
locator: skillFilePath,
|
|
45
|
+
path: skillFilePath,
|
|
46
|
+
resourceBase: { kind: 'directory', path: entry },
|
|
47
|
+
metadata: { name, description },
|
|
48
|
+
}];
|
|
49
|
+
},
|
|
50
|
+
async get(candidate, _options) {
|
|
51
|
+
try {
|
|
52
|
+
const raw = await readFile(candidate.path, 'utf-8');
|
|
53
|
+
const { name, description, body } = parseFrontmatter(raw);
|
|
54
|
+
return {
|
|
55
|
+
name, description,
|
|
56
|
+
invocation: candidate.invocation,
|
|
57
|
+
source: candidate.source,
|
|
58
|
+
provider: candidate.provider,
|
|
59
|
+
resourceBase: candidate.resourceBase,
|
|
60
|
+
path: candidate.path,
|
|
61
|
+
content: body,
|
|
62
|
+
metadata: candidate.metadata,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
catch {
|
|
66
|
+
return undefined;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
package/lib/supervisor.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HealthState } from './health-poller.js';
|
|
2
|
+
import type { RestartRequest } from './restart-guards.js';
|
|
2
3
|
export interface SupervisorDeps {
|
|
3
4
|
pollHealth: () => Promise<HealthState>;
|
|
4
5
|
writeLKG: () => Promise<{
|
|
@@ -26,6 +27,7 @@ export interface SupervisorDeps {
|
|
|
26
27
|
isPlannedRestartActive?: () => boolean | Promise<boolean>;
|
|
27
28
|
writePlannedRestart?: (ttlMs?: number) => void;
|
|
28
29
|
checkPlannedRestart?: () => boolean;
|
|
30
|
+
clearPlannedRestart?: () => void;
|
|
29
31
|
runDebugAgent?: (opts: {
|
|
30
32
|
reportPath: string;
|
|
31
33
|
health: HealthState;
|
|
@@ -40,6 +42,8 @@ export interface SupervisorDeps {
|
|
|
40
42
|
resumeSessions?: (ids: string[]) => Promise<{
|
|
41
43
|
resumed: string[];
|
|
42
44
|
}>;
|
|
45
|
+
readRestartRequest?: () => RestartRequest | undefined;
|
|
46
|
+
onRestartRequestHandled?: (req: RestartRequest) => void;
|
|
43
47
|
}
|
|
44
48
|
export declare function resumeViaRpc(ids: string[], fetchFn?: (url: string, init: RequestInit) => Promise<Response>): Promise<{
|
|
45
49
|
resumed: string[];
|
|
@@ -53,9 +57,14 @@ export declare class Supervisor {
|
|
|
53
57
|
private consecutiveDown;
|
|
54
58
|
private consecutiveDegraded;
|
|
55
59
|
private timer;
|
|
60
|
+
private restartRequestHandled;
|
|
61
|
+
private restartRequestTimer;
|
|
62
|
+
private awaitingHealthyBoot;
|
|
63
|
+
private pendingRestartRequest;
|
|
56
64
|
constructor(deps: SupervisorDeps);
|
|
57
65
|
private getWritePlannedRestart;
|
|
58
66
|
private getCheckPlannedRestart;
|
|
67
|
+
private getClearPlannedRestart;
|
|
59
68
|
restartWeb(): Promise<void>;
|
|
60
69
|
private getRunDebugAgent;
|
|
61
70
|
private getFindInterrupted;
|
package/lib/supervisor.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as path from 'node:path';
|
|
|
5
5
|
import * as os from 'node:os';
|
|
6
6
|
import { resolveHarnessRoot } from './paths.js';
|
|
7
7
|
import { readSupervisorConfig } from './config.js';
|
|
8
|
-
import { writePlannedRestart as defaultWritePlannedRestart, checkPlannedRestart as defaultCheckPlannedRestart } from './restart-guards.js';
|
|
8
|
+
import { writePlannedRestart as defaultWritePlannedRestart, checkPlannedRestart as defaultCheckPlannedRestart, clearPlannedRestart, PLANNED_RESTART_TTL_MS } from './restart-guards.js';
|
|
9
9
|
import { buildKillStalePortsCommand } from './restart-guards.js';
|
|
10
10
|
export async function resumeViaRpc(ids, fetchFn = globalThis.fetch) {
|
|
11
11
|
const rpcId = crypto.randomUUID();
|
|
@@ -36,6 +36,10 @@ export class Supervisor {
|
|
|
36
36
|
consecutiveDown = 0;
|
|
37
37
|
consecutiveDegraded = 0;
|
|
38
38
|
timer = null;
|
|
39
|
+
restartRequestHandled = false;
|
|
40
|
+
restartRequestTimer = null;
|
|
41
|
+
awaitingHealthyBoot = false;
|
|
42
|
+
pendingRestartRequest;
|
|
39
43
|
constructor(deps) {
|
|
40
44
|
this.deps = deps;
|
|
41
45
|
}
|
|
@@ -45,6 +49,9 @@ export class Supervisor {
|
|
|
45
49
|
getCheckPlannedRestart() {
|
|
46
50
|
return this.deps.checkPlannedRestart ?? defaultCheckPlannedRestart;
|
|
47
51
|
}
|
|
52
|
+
getClearPlannedRestart() {
|
|
53
|
+
return this.deps.clearPlannedRestart ?? clearPlannedRestart;
|
|
54
|
+
}
|
|
48
55
|
async restartWeb() {
|
|
49
56
|
this.getWritePlannedRestart()(30000);
|
|
50
57
|
if (this.deps.restartWeb) {
|
|
@@ -291,6 +298,44 @@ export class Supervisor {
|
|
|
291
298
|
}
|
|
292
299
|
async tick() {
|
|
293
300
|
const health = await this.deps.pollHealth();
|
|
301
|
+
// dsh_web_restart hand-off: the tool wrote a caller marker and handed the
|
|
302
|
+
// restart to the daemon (out-of-band). Honor one request per marker — one
|
|
303
|
+
// grace timer → restartWeb once → notify. The suppression marker and the
|
|
304
|
+
// single-flight latch are held until a post-restart health.up tick clears
|
|
305
|
+
// them, so the in-flight down of our own restart can never be mistaken for
|
|
306
|
+
// a crash and raced with a rollback + second restart by the crash path.
|
|
307
|
+
const restartReq = this.deps.readRestartRequest ? this.deps.readRestartRequest() : undefined;
|
|
308
|
+
if (restartReq?.callerSessionId && !this.restartRequestHandled) {
|
|
309
|
+
this.restartRequestHandled = true;
|
|
310
|
+
this.restartRequestTimer = setTimeout(() => {
|
|
311
|
+
void (async () => {
|
|
312
|
+
try {
|
|
313
|
+
// Debounce crash handling from the moment the restart is issued —
|
|
314
|
+
// the crash path sets lastRollback the same way. A slow boot must
|
|
315
|
+
// not be classified as a crash even after the suppression marker's
|
|
316
|
+
// own 30s TTL runs out.
|
|
317
|
+
this.lastRollback = this.deps.getTime ? this.deps.getTime() : Date.now();
|
|
318
|
+
await this.restartWeb();
|
|
319
|
+
// Supervisor.restartWeb() wrote a 30s marker; extend it past a slow
|
|
320
|
+
// boot. It is cleared only once the boot proves healthy below.
|
|
321
|
+
this.getWritePlannedRestart()(PLANNED_RESTART_TTL_MS);
|
|
322
|
+
await this.deps.notify(`restarted dsh-web after self-restart by session ${restartReq.callerSessionId}`);
|
|
323
|
+
}
|
|
324
|
+
catch (e) {
|
|
325
|
+
await this.deps.notify(`self-restart dsh-web failed: ${e?.message ?? String(e)}`).catch(() => { });
|
|
326
|
+
}
|
|
327
|
+
finally {
|
|
328
|
+
// Hold the marker and latch until health.up: clearing here would
|
|
329
|
+
// drop crash suppression mid-restart, and re-arming here would let
|
|
330
|
+
// a still-present marker re-fire into a second restart.
|
|
331
|
+
this.awaitingHealthyBoot = true;
|
|
332
|
+
this.pendingRestartRequest = restartReq;
|
|
333
|
+
this.restartRequestTimer = null;
|
|
334
|
+
}
|
|
335
|
+
})();
|
|
336
|
+
}, 5000);
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
294
339
|
// DEGRADED: http 200 but log has plugin error → report + notify, rollback after consecutive threshold
|
|
295
340
|
if (health.degraded) {
|
|
296
341
|
this.consecutiveDown = 0;
|
|
@@ -404,6 +449,29 @@ export class Supervisor {
|
|
|
404
449
|
if (health.up) {
|
|
405
450
|
this.consecutiveDown = 0;
|
|
406
451
|
this.consecutiveDegraded = 0;
|
|
452
|
+
// Post-self-restart boot proved healthy: clear the suppression marker,
|
|
453
|
+
// run the post-restart session-scan hook and re-arm the single-flight
|
|
454
|
+
// latch. A failed clear keeps the latch set so the same marker is never
|
|
455
|
+
// re-handled into a second restart.
|
|
456
|
+
if (this.awaitingHealthyBoot) {
|
|
457
|
+
this.awaitingHealthyBoot = false;
|
|
458
|
+
const req = this.pendingRestartRequest;
|
|
459
|
+
this.pendingRestartRequest = undefined;
|
|
460
|
+
let cleared = false;
|
|
461
|
+
try {
|
|
462
|
+
this.getClearPlannedRestart()();
|
|
463
|
+
cleared = true;
|
|
464
|
+
}
|
|
465
|
+
catch { }
|
|
466
|
+
if (cleared)
|
|
467
|
+
this.restartRequestHandled = false;
|
|
468
|
+
if (req) {
|
|
469
|
+
try {
|
|
470
|
+
this.deps.onRestartRequestHandled?.(req);
|
|
471
|
+
}
|
|
472
|
+
catch { }
|
|
473
|
+
}
|
|
474
|
+
}
|
|
407
475
|
// Throttle LKG writes to at most once per 5 minutes
|
|
408
476
|
const now = this.deps.getTime ? this.deps.getTime() : Date.now();
|
|
409
477
|
if (now - this.lastLKGWrite > 5 * 60 * 1000) {
|
|
@@ -543,5 +611,9 @@ export class Supervisor {
|
|
|
543
611
|
clearInterval(this.timer);
|
|
544
612
|
this.timer = null;
|
|
545
613
|
}
|
|
614
|
+
if (this.restartRequestTimer) {
|
|
615
|
+
clearTimeout(this.restartRequestTimer);
|
|
616
|
+
this.restartRequestTimer = null;
|
|
617
|
+
}
|
|
546
618
|
}
|
|
547
619
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ddtcorex/dsh-maestro-supervisor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Supervisor daemon for DSH Web resilience — auto-detect crashes, rollback to LKG, report",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
},
|
|
34
34
|
"files": [
|
|
35
35
|
"lib",
|
|
36
|
+
"skills",
|
|
36
37
|
"README.md",
|
|
37
38
|
"cordis.patch.yml"
|
|
38
39
|
],
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: dsh-safe-restart
|
|
3
|
+
description: Use before updating any dsh-maestro-* client bundle or DSH Web asset, or before reloading the running dsh web host process; validate first and perform a user-approved host restart through the bundled guarded recipe. In-session agents use the `dsh_web_restart` tool; hand off to a human only if the tool is unavailable.
|
|
4
|
+
compatibility: dsh
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
# Safe DSH Web Restart
|
|
8
|
+
|
|
9
|
+
## Purpose
|
|
10
|
+
|
|
11
|
+
One `dsh web` process serves both the live Web UI on port 3080 and the
|
|
12
|
+
GitLab-webhook service on port 3000. A host restart drops the live socket and
|
|
13
|
+
the in-flight turn, although sessions rehydrate from the append-only log when
|
|
14
|
+
the browser reconnects. Treat a restart as disruptive: validate first and get
|
|
15
|
+
explicit user consent before a real swap.
|
|
16
|
+
|
|
17
|
+
## Classify the change before touching the live process
|
|
18
|
+
|
|
19
|
+
- **Static asset in `apps/web/dist/`** — patch the asset and verify served
|
|
20
|
+
bytes with `curl`; no restart.
|
|
21
|
+
- **Client plugin bundle** (client JavaScript, CSS, slots, React) — run that
|
|
22
|
+
package's `build:client`, confirm a bundle marker, then refresh the browser;
|
|
23
|
+
no host restart.
|
|
24
|
+
- **Host Node library, `cordis.patch.yml`, or profile plugin composition** —
|
|
25
|
+
validate a candidate and restart only after the user says to do so.
|
|
26
|
+
|
|
27
|
+
## Required preflight for a host restart
|
|
28
|
+
|
|
29
|
+
1. Run relevant package tests and build steps, then check the output really
|
|
30
|
+
carries the expected marker.
|
|
31
|
+
2. Dry-boot the candidate on an ephemeral port with an isolated `DSH_HOME`.
|
|
32
|
+
Keep the live process and its sessions/settings untouched. If the review
|
|
33
|
+
webhook conflicts on port 3000, exclude that provider for the candidate or
|
|
34
|
+
run a no-server composition check instead.
|
|
35
|
+
3. Verify HTTP 200 and the new marker on the candidate. Retain last-known-good
|
|
36
|
+
assets until the real swap has passed post-swap checks.
|
|
37
|
+
4. Ask for explicit consent and timing. “restart đi” is consent; silence is
|
|
38
|
+
not.
|
|
39
|
+
|
|
40
|
+
## Run the bundled helper only after consent
|
|
41
|
+
|
|
42
|
+
The skill loader provides this directory as the skill resource base. Substitute
|
|
43
|
+
that real path for `<skill-resource-base>`; never use a copied, machine-specific
|
|
44
|
+
path from documentation.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
# Safe inspection only: resolves the serving tree but changes nothing.
|
|
48
|
+
bash <skill-resource-base>/scripts/restart-dsh-web.sh \
|
|
49
|
+
--repo /path/to/deepseek-harness --dry-run
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Run the `dsh_web_restart` tool instead of executing the helper — the helper is
|
|
53
|
+
for external agents and humans. In-session agents must never run it from their
|
|
54
|
+
own turn (see "Never do these" below).
|
|
55
|
+
|
|
56
|
+
`--repo` may be replaced by `DSH_REPO`; `--log` or `DSH_RESTART_LOG` changes
|
|
57
|
+
the append-only log destination. The helper refuses a real swap without
|
|
58
|
+
`--confirm`, dynamically resolves listeners rather than trusting saved PIDs,
|
|
59
|
+
and refuses to launch if ports are still occupied. `--dry-run` never runs
|
|
60
|
+
`kill` or `setsid`.
|
|
61
|
+
|
|
62
|
+
## Post-swap checks
|
|
63
|
+
|
|
64
|
+
Do not read the top of an old append-only log as liveness evidence. Instead:
|
|
65
|
+
|
|
66
|
+
1. Confirm exactly one healthy listener tree owns ports 3000 and 3080 with
|
|
67
|
+
`ss -tlnp`.
|
|
68
|
+
2. Confirm HTTP 200 from port 3080.
|
|
69
|
+
3. Check served bytes contain the **new**, unique marker; or make a fresh
|
|
70
|
+
browser/Playwright probe for the changed UI. Shared third-party markers are
|
|
71
|
+
not sufficient proof.
|
|
72
|
+
4. If a marker or live behaviour is wrong, restore the retained last-known-good
|
|
73
|
+
assets and relaunch with the same guarded process.
|
|
74
|
+
|
|
75
|
+
## Never do these
|
|
76
|
+
|
|
77
|
+
- Kill the process from an inline agent shell; the killing action can terminate
|
|
78
|
+
that shell before it relaunches DSH.
|
|
79
|
+
- **Never invoke this skill from inside a DSH chat session's agent turn.** The agent itself runs inside `dsh web`; killing `dsh web` from its own turn interrupts that turn (`interrupted` in the append-only log) and the `setsid nohup` relaunch never completes from the killed shell. If you are an agent, run the `dsh_web_restart` tool instead — it performs the swap from the safe side of the tree. Print the exact `setsid nohup ... --confirm` command only when the tool is unavailable, and only for the human to run in their own terminal; do not execute it yourself.
|
|
80
|
+
- Restart for a client-only or static change.
|
|
81
|
+
- Hard-code a PID or a local developer's workspace path.
|
|
82
|
+
- Treat a 200 response alone as proof that a rebuilt plugin was loaded.
|
|
83
|
+
|
|
84
|
+
## Agent handoff (required when you are an agent)
|
|
85
|
+
|
|
86
|
+
If you are running inside `dsh web` (any `dsh-*` skill, `maestro-*` skill, or subagent), you **must not** execute the helper or the restart yourself:
|
|
87
|
+
|
|
88
|
+
1. Run all preflight checks (`--dry-run`, `pnpm verify`, marker grep) and report the results.
|
|
89
|
+
2. Run the `dsh_web_restart` tool instead of executing the helper — the helper is for external agents and humans.
|
|
90
|
+
3. If the tool reports it is unavailable, print the exact detached `setsid nohup ... --confirm` command for the human to run; then wait for explicit human confirmation in a new terminal. The interrupted turn will rehydrate from the log when the browser reconnects — no data is lost.
|