harnery 0.45.1 → 0.45.2
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/dist/commands/workflow.d.ts.map +1 -1
- package/dist/commands/workflow.js +6 -45
- package/dist/core/agents/coord-client.d.ts.map +1 -1
- package/dist/core/agents/coord-client.js +0 -18
- package/dist/core/agents/state/pidmap.js +2 -2
- package/dist/core/agents/state/proc-start.d.ts +20 -31
- package/dist/core/agents/state/proc-start.d.ts.map +1 -1
- package/dist/core/agents/state/proc-start.js +37 -70
- package/dist/core/agents/state/service-process.d.ts +61 -0
- package/dist/core/agents/state/service-process.d.ts.map +1 -0
- package/dist/core/agents/state/service-process.js +143 -0
- package/dist/core/context/index.d.ts +6 -4
- package/dist/core/context/index.d.ts.map +1 -1
- package/dist/core/context/index.js +194 -256
- package/dist/core/context/observation.d.ts +9 -9
- package/dist/core/context/observation.d.ts.map +1 -1
- package/dist/core/context/observation.js +37 -6
- package/dist/core/events/v3/runtime-build.d.ts +14 -0
- package/dist/core/events/v3/runtime-build.d.ts.map +1 -1
- package/dist/core/events/v3/runtime-build.js +44 -0
- package/dist/core/governor/index.d.ts +2 -1
- package/dist/core/governor/index.d.ts.map +1 -1
- package/dist/core/governor/index.js +2 -1
- package/dist/core/governor/service-read.d.ts +3 -10
- package/dist/core/governor/service-read.d.ts.map +1 -1
- package/dist/core/governor/service-read.js +10 -94
- package/dist/core/governor/service.d.ts +3 -7
- package/dist/core/governor/service.d.ts.map +1 -1
- package/dist/core/governor/service.js +17 -182
- package/dist/core/hooks/resolve/owner.js +2 -2
- package/dist/core/resources/sampler.js +2 -2
- package/dist/core/resources/service-status.d.ts +2 -14
- package/dist/core/resources/service-status.d.ts.map +1 -1
- package/dist/core/resources/service-status.js +3 -23
- package/dist/core/resources/service.d.ts +3 -7
- package/dist/core/resources/service.d.ts.map +1 -1
- package/dist/core/resources/service.js +12 -101
- package/dist/core/resources/status.d.ts.map +1 -1
- package/dist/core/resources/status.js +3 -2
- package/dist/core/semantic/service.d.ts.map +1 -1
- package/dist/core/semantic/service.js +9 -2
- package/dist/core/servers/index.d.ts +0 -2
- package/dist/core/servers/index.d.ts.map +1 -1
- package/dist/core/servers/index.js +3 -18
- package/dist/core/supervisor/service.d.ts +4 -7
- package/dist/core/supervisor/service.d.ts.map +1 -1
- package/dist/core/supervisor/service.js +23 -122
- package/dist/core/supervisor/services.js +2 -2
- package/dist/core/supervisor/status.d.ts +3 -17
- package/dist/core/supervisor/status.d.ts.map +1 -1
- package/dist/core/supervisor/status.js +7 -70
- package/dist/core/workflow/engine.js +2 -1
- package/dist/core/workflow/index.d.ts +3 -4
- package/dist/core/workflow/index.d.ts.map +1 -1
- package/dist/core/workflow/index.js +2 -2
- package/dist/core/workflow/proof.d.ts.map +1 -1
- package/dist/core/workflow/proof.js +30 -74
- package/dist/core/workflow/resume-lock.d.ts +17 -0
- package/dist/core/workflow/resume-lock.d.ts.map +1 -0
- package/dist/core/workflow/resume-lock.js +158 -0
- package/dist/core/workflow/run-state.d.ts +0 -21
- package/dist/core/workflow/run-state.d.ts.map +1 -1
- package/dist/core/workflow/run-state.js +3 -174
- package/dist/core/workflow/workspaces/leases.d.ts +4 -0
- package/dist/core/workflow/workspaces/leases.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/leases.js +1 -1
- package/dist/core/workflow/workspaces/local-git.js +91 -210
- package/dist/core/workflow/workspaces/ownership.d.ts +0 -7
- package/dist/core/workflow/workspaces/ownership.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/ownership.js +3 -130
- package/dist/core/workflow/workspaces/reclaim.d.ts +4 -7
- package/dist/core/workflow/workspaces/reclaim.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/reclaim.js +0 -4
- package/dist/core/workflow/workspaces/recovery.d.ts +1 -1
- package/dist/core/workflow/workspaces/recovery.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/recovery.js +1 -1
- package/dist/core/workflow/workspaces/state.d.ts.map +1 -1
- package/dist/core/workflow/workspaces/state.js +1 -4
- package/package.json +1 -1
- package/src/commands/workflow.ts +8 -58
- package/src/core/agents/coord-client.ts +0 -20
- package/src/core/agents/state/pidmap.ts +2 -2
- package/src/core/agents/state/proc-start.ts +41 -69
- package/src/core/agents/state/service-process.ts +217 -0
- package/src/core/context/index.ts +207 -272
- package/src/core/context/observation.ts +40 -9
- package/src/core/events/v3/runtime-build.ts +62 -0
- package/src/core/governor/index.ts +1 -2
- package/src/core/governor/service-read.ts +15 -114
- package/src/core/governor/service.ts +36 -220
- package/src/core/hooks/resolve/owner.ts +2 -2
- package/src/core/resources/sampler.ts +3 -2
- package/src/core/resources/service-status.ts +6 -35
- package/src/core/resources/service.ts +23 -133
- package/src/core/resources/status.ts +3 -2
- package/src/core/semantic/service.ts +8 -2
- package/src/core/servers/index.ts +3 -23
- package/src/core/supervisor/service.ts +33 -155
- package/src/core/supervisor/services.ts +2 -2
- package/src/core/supervisor/status.ts +10 -85
- package/src/core/workflow/engine.ts +1 -1
- package/src/core/workflow/index.ts +2 -13
- package/src/core/workflow/proof.ts +35 -83
- package/src/core/workflow/resume-lock.ts +179 -0
- package/src/core/workflow/run-state.ts +3 -207
- package/src/core/workflow/workspaces/leases.ts +1 -1
- package/src/core/workflow/workspaces/local-git.ts +120 -239
- package/src/core/workflow/workspaces/ownership.ts +3 -158
- package/src/core/workflow/workspaces/reclaim.ts +3 -9
- package/src/core/workflow/workspaces/recovery.ts +1 -1
- package/src/core/workflow/workspaces/state.ts +1 -5
- package/dist/core/agents/state/process-handle.d.ts +0 -26
- package/dist/core/agents/state/process-handle.d.ts.map +0 -1
- package/dist/core/agents/state/process-handle.js +0 -121
- package/dist/core/workflow/recovery-audit.d.ts +0 -30
- package/dist/core/workflow/recovery-audit.d.ts.map +0 -1
- package/dist/core/workflow/recovery-audit.js +0 -116
- package/src/core/agents/state/process-handle.ts +0 -165
- package/src/core/workflow/recovery-audit.ts +0 -181
|
@@ -5,7 +5,7 @@ import { basename, join } from "node:path";
|
|
|
5
5
|
import { performance } from "node:perf_hooks";
|
|
6
6
|
import { readLiveCoordinationRows } from "../agents/state/live-coordination-view.ts";
|
|
7
7
|
import { parsePidmapRow } from "../agents/state/pidmap.ts";
|
|
8
|
-
import {
|
|
8
|
+
import { verifyProcessGeneration } from "../agents/state/proc-start.ts";
|
|
9
9
|
import {
|
|
10
10
|
RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
11
11
|
type ResourceProcessGroup,
|
|
@@ -386,7 +386,8 @@ function readOwnershipAnchors(
|
|
|
386
386
|
if (!byPid.has(pid)) continue;
|
|
387
387
|
try {
|
|
388
388
|
const row = parsePidmapRow(readFileSync(join(directory, entry), "utf8"));
|
|
389
|
-
if (!row.instanceId ||
|
|
389
|
+
if (!row.instanceId || verifyProcessGeneration(pid, row.startToken) === "different")
|
|
390
|
+
continue;
|
|
390
391
|
anchors.set(pid, { kind: "agent", id: row.instanceId, source: "pid-map" });
|
|
391
392
|
} catch {
|
|
392
393
|
// An unreadable or racing row cannot prove ownership.
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { existsSync } from "node:fs";
|
|
2
|
-
import { hostname } from "node:os";
|
|
3
2
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "../agents/state/
|
|
3
|
+
observeServiceProcess,
|
|
4
|
+
type ServiceProcessDependencies,
|
|
5
|
+
} from "../agents/state/service-process.ts";
|
|
7
6
|
import {
|
|
8
7
|
RESOURCE_SERVICE_STATUS_SCHEMA_VERSION,
|
|
9
8
|
type ResourceServiceStatus,
|
|
@@ -13,15 +12,10 @@ import { readResourceServiceRecord, resourcePaths } from "./storage.ts";
|
|
|
13
12
|
|
|
14
13
|
const STALE_HEARTBEAT_MS = 15_000;
|
|
15
14
|
|
|
16
|
-
export interface ResourceProcessDependencies {
|
|
17
|
-
readToken?: (pid: number) => string | null;
|
|
18
|
-
probePid?: (pid: number) => unknown;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
15
|
export function readResourceServiceStatus(
|
|
22
16
|
coordRoot: string,
|
|
23
17
|
nowMs = Date.now(),
|
|
24
|
-
dependencies:
|
|
18
|
+
dependencies: ServiceProcessDependencies = {},
|
|
25
19
|
): ResourceServiceStatus {
|
|
26
20
|
const paths = resourcePaths(coordRoot);
|
|
27
21
|
const record = readResourceServiceRecord(coordRoot);
|
|
@@ -37,13 +31,11 @@ export function readResourceServiceStatus(
|
|
|
37
31
|
}
|
|
38
32
|
const heartbeatAt = Date.parse(record.heartbeat_at);
|
|
39
33
|
const stale = !Number.isFinite(heartbeatAt) || nowMs - heartbeatAt > STALE_HEARTBEAT_MS;
|
|
40
|
-
const
|
|
41
|
-
const liveness =
|
|
42
|
-
owner.generation === "same" && record.state === "stopped" ? "stopped" : owner.liveness;
|
|
34
|
+
const { generation, liveness } = observeServiceProcess(record, dependencies);
|
|
43
35
|
return {
|
|
44
36
|
running: liveness === "running" && !stale,
|
|
45
37
|
stale,
|
|
46
|
-
generation
|
|
38
|
+
generation,
|
|
47
39
|
liveness,
|
|
48
40
|
record,
|
|
49
41
|
status_path: paths.service,
|
|
@@ -62,24 +54,3 @@ function validRecord(
|
|
|
62
54
|
typeof value.heartbeat_at === "string"
|
|
63
55
|
);
|
|
64
56
|
}
|
|
65
|
-
|
|
66
|
-
export function resourceProcessLiveness(
|
|
67
|
-
owner: { pid: number; host: string; start_token?: string },
|
|
68
|
-
dependencies: ResourceProcessDependencies = {},
|
|
69
|
-
): { generation: ProcessGenerationVerdict; liveness: ResourceServiceStatus["liveness"] } {
|
|
70
|
-
if (owner.host !== hostname()) return { generation: "unknown", liveness: "unknown" };
|
|
71
|
-
try {
|
|
72
|
-
(dependencies.probePid ?? ((pid) => process.kill(pid, 0)))(owner.pid);
|
|
73
|
-
} catch (error) {
|
|
74
|
-
return {
|
|
75
|
-
generation: "unknown",
|
|
76
|
-
liveness: (error as NodeJS.ErrnoException).code === "ESRCH" ? "stopped" : "unknown",
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
const generation = verifyProcessGeneration(owner.pid, owner.start_token, dependencies.readToken);
|
|
80
|
-
return {
|
|
81
|
-
generation,
|
|
82
|
-
liveness:
|
|
83
|
-
generation === "same" ? "running" : generation === "different" ? "stopped" : "unknown",
|
|
84
|
-
};
|
|
85
|
-
}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
closeSync,
|
|
4
|
-
existsSync,
|
|
5
|
-
mkdirSync,
|
|
6
|
-
openSync,
|
|
7
|
-
readFileSync,
|
|
8
|
-
rmSync,
|
|
9
|
-
unlinkSync,
|
|
10
|
-
writeFileSync,
|
|
11
|
-
} from "node:fs";
|
|
1
|
+
import { existsSync, rmSync } from "node:fs";
|
|
12
2
|
import { hostname } from "node:os";
|
|
13
3
|
import { resolve } from "node:path";
|
|
4
|
+
import { processStartToken } from "../agents/state/proc-start.ts";
|
|
14
5
|
import {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
acquireServiceLease,
|
|
7
|
+
requestServiceStop,
|
|
8
|
+
type ServiceLiveness,
|
|
9
|
+
type ServiceProcessDependencies,
|
|
10
|
+
type ServiceStopFields,
|
|
11
|
+
serviceStartRefusal,
|
|
12
|
+
} from "../agents/state/service-process.ts";
|
|
20
13
|
import { resolveBinName } from "../config.ts";
|
|
21
14
|
import { closeProcessLoggers, legacyLogFields, processLogger } from "../storage/logger.ts";
|
|
22
|
-
import { stateDirMode, stateFileMode } from "../storage/modes.ts";
|
|
23
15
|
import {
|
|
24
16
|
RESOURCE_SERVICE_STATUS_SCHEMA_VERSION,
|
|
25
17
|
type ResourceSamplerState,
|
|
@@ -27,25 +19,13 @@ import {
|
|
|
27
19
|
type ResourceServiceStatusRecord,
|
|
28
20
|
} from "./contract.ts";
|
|
29
21
|
import { sampleResources } from "./sampler.ts";
|
|
30
|
-
import {
|
|
31
|
-
type ResourceProcessDependencies,
|
|
32
|
-
readResourceServiceStatus,
|
|
33
|
-
resourceProcessLiveness,
|
|
34
|
-
} from "./service-status.ts";
|
|
22
|
+
import { readResourceServiceStatus } from "./service-status.ts";
|
|
35
23
|
import { resourcePaths, writePrivateJsonAtomic } from "./storage.ts";
|
|
36
24
|
|
|
37
25
|
export const RESOURCE_SERVICE_DEFAULT_INTERVAL_MS = 2_000;
|
|
38
26
|
const RESOURCE_SERVICE_MIN_INTERVAL_MS = 500;
|
|
39
27
|
const RESOURCE_SERVICE_MAX_INTERVAL_MS = 60_000;
|
|
40
28
|
|
|
41
|
-
interface ResourceServiceLease {
|
|
42
|
-
pid: number;
|
|
43
|
-
start_token?: string;
|
|
44
|
-
host: string;
|
|
45
|
-
nonce: string;
|
|
46
|
-
created_at: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
29
|
export interface RunResourceServiceInput {
|
|
50
30
|
coordRoot: string;
|
|
51
31
|
intervalMs?: number;
|
|
@@ -55,37 +35,15 @@ export interface RunResourceServiceInput {
|
|
|
55
35
|
wait?: (milliseconds: number) => Promise<void>;
|
|
56
36
|
}
|
|
57
37
|
|
|
58
|
-
export
|
|
59
|
-
signal_sent: boolean;
|
|
60
|
-
signal_verdict: ProcessGenerationVerdict;
|
|
61
|
-
}
|
|
38
|
+
export type ResourceServiceStopResult = ResourceServiceStatus & ServiceStopFields;
|
|
62
39
|
|
|
63
40
|
export function requestResourceServiceStop(
|
|
64
41
|
coordRootRaw: string,
|
|
65
|
-
dependencies:
|
|
42
|
+
dependencies: ServiceProcessDependencies = {},
|
|
66
43
|
): ResourceServiceStopResult {
|
|
67
44
|
const coordRoot = resolve(coordRootRaw);
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
mkdirSync(paths.root, { recursive: true, mode: stateDirMode() });
|
|
71
|
-
writePrivateJsonAtomic(paths.stop, {
|
|
72
|
-
requested_at: new Date().toISOString(),
|
|
73
|
-
requested_by_pid: process.pid,
|
|
74
|
-
});
|
|
75
|
-
const signal =
|
|
76
|
-
status.liveness === "running" && status.record?.host === hostname()
|
|
77
|
-
? signalIfSameGeneration(
|
|
78
|
-
status.record.pid,
|
|
79
|
-
status.record.start_token,
|
|
80
|
-
"SIGTERM",
|
|
81
|
-
dependencies,
|
|
82
|
-
)
|
|
83
|
-
: { sent: false, verdict: status.generation };
|
|
84
|
-
return {
|
|
85
|
-
...readResourceServiceStatus(coordRoot, Date.now(), dependencies),
|
|
86
|
-
signal_sent: signal.sent,
|
|
87
|
-
signal_verdict: signal.verdict,
|
|
88
|
-
};
|
|
45
|
+
const read = () => readResourceServiceStatus(coordRoot, Date.now(), dependencies);
|
|
46
|
+
return requestServiceStop(read(), read, resourcePaths(coordRoot).stop, dependencies);
|
|
89
47
|
}
|
|
90
48
|
|
|
91
49
|
export async function runResourceService(
|
|
@@ -93,15 +51,13 @@ export async function runResourceService(
|
|
|
93
51
|
): Promise<ResourceServiceStatusRecord> {
|
|
94
52
|
const coordRoot = resolve(input.coordRoot);
|
|
95
53
|
const current = readResourceServiceStatus(coordRoot);
|
|
96
|
-
if (current.liveness
|
|
97
|
-
if (current.liveness === "running")
|
|
98
|
-
throw new Error(`resource observer is already running under pid ${current.record?.pid}`);
|
|
54
|
+
if (current.liveness !== "stopped") throw startRefusal(current.record?.pid, current.liveness);
|
|
99
55
|
const paths = resourcePaths(coordRoot);
|
|
100
56
|
const intervalMs = normalizeInterval(input.intervalMs);
|
|
101
57
|
const now = input.now ?? (() => new Date());
|
|
102
58
|
const sample = input.sample ?? sampleResources;
|
|
103
59
|
const wait = input.wait ?? delay;
|
|
104
|
-
const lease =
|
|
60
|
+
const lease = acquireServiceLease(paths.lease, startRefusal);
|
|
105
61
|
rmSync(paths.stop, { force: true });
|
|
106
62
|
const startedAt = now().toISOString();
|
|
107
63
|
const daemonStartToken = processStartToken(process.pid);
|
|
@@ -178,84 +134,18 @@ export async function runResourceService(
|
|
|
178
134
|
try {
|
|
179
135
|
await closeProcessLoggers();
|
|
180
136
|
} finally {
|
|
181
|
-
|
|
137
|
+
lease.release();
|
|
182
138
|
}
|
|
183
139
|
}
|
|
184
140
|
return status;
|
|
185
141
|
}
|
|
186
142
|
|
|
187
|
-
function
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
pid: process.pid,
|
|
194
|
-
...(daemonStartToken ? { start_token: daemonStartToken } : {}),
|
|
195
|
-
host: hostname(),
|
|
196
|
-
nonce: randomUUID(),
|
|
197
|
-
created_at: now.toISOString(),
|
|
198
|
-
};
|
|
199
|
-
try {
|
|
200
|
-
const fd = openSync(paths.lease, "wx", stateFileMode());
|
|
201
|
-
try {
|
|
202
|
-
writeFileSync(fd, `${JSON.stringify(lease)}\n`, "utf8");
|
|
203
|
-
} finally {
|
|
204
|
-
closeSync(fd);
|
|
205
|
-
}
|
|
206
|
-
return lease;
|
|
207
|
-
} catch (error) {
|
|
208
|
-
if ((error as NodeJS.ErrnoException).code !== "EEXIST") throw error;
|
|
209
|
-
const existing = readLease(paths.lease);
|
|
210
|
-
const liveness = existing ? leaseIsLive(existing) : "unknown";
|
|
211
|
-
if (liveness === "unknown") throw unknownResourceOwnerError();
|
|
212
|
-
if (existing && liveness === "running") {
|
|
213
|
-
throw new Error(`resource observer lease is held by pid ${existing.pid}`);
|
|
214
|
-
}
|
|
215
|
-
try {
|
|
216
|
-
unlinkSync(paths.lease);
|
|
217
|
-
} catch {
|
|
218
|
-
// A concurrent starter may have replaced or removed the stale lease.
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
throw new Error("resource observer could not acquire its singleton lease");
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function releaseLease(path: string, nonce: string): void {
|
|
226
|
-
const current = readLease(path);
|
|
227
|
-
if (current?.nonce !== nonce) return;
|
|
228
|
-
try {
|
|
229
|
-
unlinkSync(path);
|
|
230
|
-
} catch {
|
|
231
|
-
// A missing lease is already released.
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function readLease(path: string): ResourceServiceLease | undefined {
|
|
236
|
-
try {
|
|
237
|
-
const value = JSON.parse(readFileSync(path, "utf8")) as ResourceServiceLease;
|
|
238
|
-
return value &&
|
|
239
|
-
Number.isSafeInteger(value.pid) &&
|
|
240
|
-
value.pid > 0 &&
|
|
241
|
-
typeof value.host === "string" &&
|
|
242
|
-
value.host.length > 0 &&
|
|
243
|
-
typeof value.nonce === "string" &&
|
|
244
|
-
value.nonce.length > 0
|
|
245
|
-
? value
|
|
246
|
-
: undefined;
|
|
247
|
-
} catch {
|
|
248
|
-
return undefined;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
function leaseIsLive(lease: ResourceServiceLease): ResourceServiceStatus["liveness"] {
|
|
253
|
-
return resourceProcessLiveness(lease).liveness;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
function unknownResourceOwnerError(): Error {
|
|
257
|
-
return new Error(
|
|
258
|
-
`resource observer process identity is unknown; run ${resolveBinName()} supervisor stop to write the durable stop request before starting again`,
|
|
143
|
+
function startRefusal(pid: number | undefined, liveness: ServiceLiveness): Error {
|
|
144
|
+
return serviceStartRefusal(
|
|
145
|
+
"resource observer",
|
|
146
|
+
`${resolveBinName()} supervisor stop`,
|
|
147
|
+
pid,
|
|
148
|
+
liveness,
|
|
259
149
|
);
|
|
260
150
|
}
|
|
261
151
|
|
|
@@ -6,13 +6,14 @@ import {
|
|
|
6
6
|
type PressureAssessment,
|
|
7
7
|
type PressureHysteresisState,
|
|
8
8
|
} from "../diagnostics/contract.ts";
|
|
9
|
+
import { installedHarneryBuild } from "../events/v3/runtime-build.ts";
|
|
9
10
|
import {
|
|
10
11
|
SUPERVISOR_PRESSURE_SCHEMA_VERSION,
|
|
11
12
|
type SupervisorCapability,
|
|
12
13
|
type SupervisorPressureRecord,
|
|
13
14
|
type SupervisorStatus,
|
|
14
15
|
} from "../supervisor/contract.ts";
|
|
15
|
-
import {
|
|
16
|
+
import { readSupervisorStatus } from "../supervisor/status.ts";
|
|
16
17
|
import { supervisorPaths } from "../supervisor/storage.ts";
|
|
17
18
|
import {
|
|
18
19
|
RESOURCE_SNAPSHOT_SCHEMA_VERSION,
|
|
@@ -465,7 +466,7 @@ function unknownWriterState(): ResourceStatus["writer"] {
|
|
|
465
466
|
generation: "unknown",
|
|
466
467
|
liveness: "unknown",
|
|
467
468
|
running_build: null,
|
|
468
|
-
installed_build:
|
|
469
|
+
installed_build: installedHarneryBuild(),
|
|
469
470
|
restart_needed: true,
|
|
470
471
|
build_status: "running build unknown; restart needed",
|
|
471
472
|
};
|
|
@@ -225,13 +225,19 @@ export async function ensureSemanticServiceRunning(
|
|
|
225
225
|
|
|
226
226
|
export function requestSemanticServiceStop(coordRootRaw: string): SemanticServiceStatus {
|
|
227
227
|
const coordRoot = resolve(coordRootRaw);
|
|
228
|
+
const status = readSemanticServiceStatus(coordRoot);
|
|
228
229
|
mkdirSync(semanticPaths(coordRoot).root, { recursive: true, mode: stateDirMode() });
|
|
229
230
|
writePrivateJsonAtomic(semanticPaths(coordRoot).stop, {
|
|
230
231
|
requested_at: new Date().toISOString(),
|
|
231
232
|
requested_by_pid: process.pid,
|
|
232
233
|
});
|
|
233
|
-
|
|
234
|
-
|
|
234
|
+
if (status.running && status.record?.host === hostname()) {
|
|
235
|
+
try {
|
|
236
|
+
process.kill(status.record.pid, "SIGTERM");
|
|
237
|
+
} catch {
|
|
238
|
+
// The durable stop request remains for a racing or restarted daemon.
|
|
239
|
+
}
|
|
240
|
+
}
|
|
235
241
|
return readSemanticServiceStatus(coordRoot);
|
|
236
242
|
}
|
|
237
243
|
|
|
@@ -598,26 +598,6 @@ export interface StopResult {
|
|
|
598
598
|
|
|
599
599
|
export interface ServerProcessDependencies extends ProcessGenerationSignalDependencies {
|
|
600
600
|
probePid?: (pid: number) => boolean;
|
|
601
|
-
/** Numeric signal, used for the process group and in tests. */
|
|
602
|
-
kill?: (pid: number, signal: NodeJS.Signals) => void;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/** Recheck the generation, then signal. A supplied `kill` replaces the handle path. */
|
|
606
|
-
function signalVerified(
|
|
607
|
-
pid: number,
|
|
608
|
-
token: string | undefined,
|
|
609
|
-
name: NodeJS.Signals,
|
|
610
|
-
dependencies: ServerProcessDependencies,
|
|
611
|
-
): { sent: boolean; verdict: ProcessGenerationVerdict } {
|
|
612
|
-
if (!dependencies.kill) return signalIfSameGeneration(pid, token, name, dependencies);
|
|
613
|
-
const verdict = verifyProcessGeneration(pid, token, dependencies.readToken);
|
|
614
|
-
if (verdict !== "same") return { sent: false, verdict };
|
|
615
|
-
try {
|
|
616
|
-
dependencies.kill(pid, name);
|
|
617
|
-
return { sent: true, verdict };
|
|
618
|
-
} catch {
|
|
619
|
-
return { sent: false, verdict };
|
|
620
|
-
}
|
|
621
601
|
}
|
|
622
602
|
|
|
623
603
|
/**
|
|
@@ -680,7 +660,7 @@ export async function stopServer(
|
|
|
680
660
|
const result =
|
|
681
661
|
target.pid === record.pid
|
|
682
662
|
? signalServerLeader(target.pid, target.token, name, dependencies)
|
|
683
|
-
:
|
|
663
|
+
: signalIfSameGeneration(target.pid, target.token, name, dependencies);
|
|
684
664
|
if (result.verdict !== "same") return refuse(target.pid, result.verdict);
|
|
685
665
|
}
|
|
686
666
|
const observed = await waitForExit(targets, name === "SIGTERM" ? graceMs : 2_000, dependencies);
|
|
@@ -706,13 +686,13 @@ function signalServerLeader(
|
|
|
706
686
|
// The leader's generation authorizes its group. A failed group signal must
|
|
707
687
|
// not reuse that observation for the direct-PID fallback.
|
|
708
688
|
const kill = dependencies.kill ?? process.kill;
|
|
709
|
-
const group =
|
|
689
|
+
const group = signalIfSameGeneration(pid, token, name, {
|
|
710
690
|
readToken: dependencies.readToken,
|
|
711
691
|
kill: (leader, signal) => kill(-leader, signal),
|
|
712
692
|
});
|
|
713
693
|
return group.sent || group.verdict !== "same"
|
|
714
694
|
? group
|
|
715
|
-
:
|
|
695
|
+
: signalIfSameGeneration(pid, token, name, dependencies);
|
|
716
696
|
}
|
|
717
697
|
|
|
718
698
|
async function waitForExit(
|