@1mcp/agent 0.39.5 → 0.39.7
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/build/admin/assets/{admin-OAuthServicesWorkspace-BzrCR7Bi.js → admin-OAuthServicesWorkspace-CkdZwuvX.js} +1 -1
- package/build/admin/assets/{admin-console-BpUgmlrR.js → admin-console-CO0t0D1E.js} +3 -3
- package/build/admin/index.html +1 -1
- package/build/commands/serve/serveStatus.d.ts.map +1 -1
- package/build/commands/serve/serveStatus.js +3 -0
- package/build/commands/serve/serveStatus.js.map +1 -1
- package/build/commands/serve/serveStop.d.ts.map +1 -1
- package/build/commands/serve/serveStop.js +38 -6
- package/build/commands/serve/serveStop.js.map +1 -1
- package/build/commands/shared/inspectApiSchemas.d.ts +4 -4
- package/build/constants/mcp.d.ts +1 -1
- package/build/constants/mcp.js +1 -1
- package/build/core/server/pidFileManager.d.ts +20 -5
- package/build/core/server/pidFileManager.d.ts.map +1 -1
- package/build/core/server/pidFileManager.js +34 -15
- package/build/core/server/pidFileManager.js.map +1 -1
- package/build/core/server/processIdentity.d.ts +18 -0
- package/build/core/server/processIdentity.d.ts.map +1 -1
- package/build/core/server/processIdentity.js +13 -2
- package/build/core/server/processIdentity.js.map +1 -1
- package/build/core/server/runtimeOwnershipIdentityRepair.d.ts +21 -0
- package/build/core/server/runtimeOwnershipIdentityRepair.d.ts.map +1 -0
- package/build/core/server/runtimeOwnershipIdentityRepair.js +158 -0
- package/build/core/server/runtimeOwnershipIdentityRepair.js.map +1 -0
- package/build/core/server/runtimeScopeOwnership.d.ts +21 -2
- package/build/core/server/runtimeScopeOwnership.d.ts.map +1 -1
- package/build/core/server/runtimeScopeOwnership.js +145 -16
- package/build/core/server/runtimeScopeOwnership.js.map +1 -1
- package/build/core/tools/internal/schemas/index.d.ts +1 -1
- package/build/core/tools/internal/schemas/management.d.ts +1 -1
- package/build/observability/events/registry.d.ts +60 -0
- package/build/observability/events/registry.d.ts.map +1 -1
- package/build/observability/events/registry.js +60 -0
- package/build/observability/events/registry.js.map +1 -1
- package/build/observability/privacy/fields.d.ts +4 -0
- package/build/observability/privacy/fields.d.ts.map +1 -1
- package/build/observability/privacy/fields.js +4 -0
- package/build/observability/privacy/fields.js.map +1 -1
- package/build/sdk/legacy/commands/serve.d.ts.map +1 -1
- package/build/sdk/legacy/commands/serve.js +66 -3
- package/build/sdk/legacy/commands/serve.js.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.js +6 -0
- package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processIdentity.js","sourceRoot":"","sources":["../../../src/core/server/processIdentity.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,EAAE,MAAM,SAAS,CAAC;AAEzB,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAE3C,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,CAAC,kBAAkB,CAAC,UAAU,EAAE;IACpE,CAAC,CAAC,MAAM,CAAC;QACP,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC;QAC5B,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACzB,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/B,SAAS,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC;KACrC,CAAC;IACF,CAAC,CAAC,MAAM,CAAC;QACP,QAAQ,EAAE,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC;QAC7B,QAAQ,EAAE,CAAC,CAAC,MAAM,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.js';
|
|
3
|
+
/** Delayed first attempt, then bounded exponential backoff; success stops the loop. */
|
|
4
|
+
export declare const DEFAULT_IDENTITY_REPAIR_DELAYS_MS: readonly [10000, 20000, 40000, 60000, 60000];
|
|
5
|
+
export interface RuntimeOwnershipIdentityRepairOptions {
|
|
6
|
+
runtimeScope: string;
|
|
7
|
+
pid: number;
|
|
8
|
+
claimId: string;
|
|
9
|
+
delaysMs?: readonly number[];
|
|
10
|
+
acquireIdentity?: typeof acquireProcessIdentity;
|
|
11
|
+
readPidFile?: typeof readPidFile;
|
|
12
|
+
writePidFile?: typeof writePidFile;
|
|
13
|
+
}
|
|
14
|
+
export type PidRepairOutcome = 'repaired' | 'skipped' | 'retry' | 'ownership-changed' | 'unsafe';
|
|
15
|
+
/**
|
|
16
|
+
* Repairs one degraded ownership generation once the claiming process can read
|
|
17
|
+
* its own birth evidence. The record's pid+claimId must still match, so a
|
|
18
|
+
* released, reclaimed, or replaced generation is never overwritten.
|
|
19
|
+
*/
|
|
20
|
+
export declare function scheduleRuntimeOwnershipIdentityRepair(options: RuntimeOwnershipIdentityRepairOptions): () => void;
|
|
21
|
+
//# sourceMappingURL=runtimeOwnershipIdentityRepair.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeOwnershipIdentityRepair.d.ts","sourceRoot":"","sources":["../../../src/core/server/runtimeOwnershipIdentityRepair.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,WAAW,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,sBAAsB,EAAwB,MAAM,qCAAqC,CAAC;AAOnG,uFAAuF;AACvF,eAAO,MAAM,iCAAiC,8CAAoD,CAAC;AAEnG,MAAM,WAAW,qCAAqC;IACpD,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAC7B,eAAe,CAAC,EAAE,OAAO,sBAAsB,CAAC;IAChD,WAAW,CAAC,EAAE,OAAO,WAAW,CAAC;IACjC,YAAY,CAAC,EAAE,OAAO,YAAY,CAAC;CACpC;AAED,MAAM,MAAM,gBAAgB,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,GAAG,mBAAmB,GAAG,QAAQ,CAAC;AASjG;;;;GAIG;AACH,wBAAgB,sCAAsC,CAAC,OAAO,EAAE,qCAAqC,GAAG,MAAM,IAAI,CA4EjH"}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { getPidFilePath, readPidFile, writePidFile } from './pidFileManager.js';
|
|
4
|
+
import { acquireProcessIdentity } from './processIdentity.js';
|
|
5
|
+
import { readRuntimeScopeOwnership, updateRuntimeScopeOwnershipIdentity, } from './runtimeScopeOwnership.js';
|
|
6
|
+
import logger from '../../logger/logger.js';
|
|
7
|
+
/** Delayed first attempt, then bounded exponential backoff; success stops the loop. */
|
|
8
|
+
export const DEFAULT_IDENTITY_REPAIR_DELAYS_MS = [10_000, 20_000, 40_000, 60_000, 60_000];
|
|
9
|
+
/**
|
|
10
|
+
* Repairs one degraded ownership generation once the claiming process can read
|
|
11
|
+
* its own birth evidence. The record's pid+claimId must still match, so a
|
|
12
|
+
* released, reclaimed, or replaced generation is never overwritten.
|
|
13
|
+
*/
|
|
14
|
+
export function scheduleRuntimeOwnershipIdentityRepair(options) {
|
|
15
|
+
const delays = options.delaysMs ?? DEFAULT_IDENTITY_REPAIR_DELAYS_MS;
|
|
16
|
+
const acquireIdentity = options.acquireIdentity ?? acquireProcessIdentity;
|
|
17
|
+
const startedAt = Date.now();
|
|
18
|
+
let attempt = 0;
|
|
19
|
+
let cancelled = false;
|
|
20
|
+
let timer;
|
|
21
|
+
let lastPidOutcome = 'not-attempted';
|
|
22
|
+
const stop = () => {
|
|
23
|
+
cancelled = true;
|
|
24
|
+
if (timer)
|
|
25
|
+
clearTimeout(timer);
|
|
26
|
+
};
|
|
27
|
+
const scheduleNext = () => {
|
|
28
|
+
if (cancelled)
|
|
29
|
+
return;
|
|
30
|
+
if (attempt >= delays.length) {
|
|
31
|
+
logger.warn('runtimeScopeOwnership.identity.repair.exhausted', {
|
|
32
|
+
attempts: attempt,
|
|
33
|
+
elapsedMs: Date.now() - startedAt,
|
|
34
|
+
pid_outcome: lastPidOutcome,
|
|
35
|
+
});
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
timer = setTimeout(run, delays[attempt]);
|
|
39
|
+
timer.unref?.();
|
|
40
|
+
};
|
|
41
|
+
const run = () => {
|
|
42
|
+
if (cancelled)
|
|
43
|
+
return;
|
|
44
|
+
try {
|
|
45
|
+
attempt += 1;
|
|
46
|
+
const acquisition = acquireIdentity(options.pid);
|
|
47
|
+
logger.debug('runtimeScopeOwnership.identity.repair.attempt', {
|
|
48
|
+
attempts: attempt,
|
|
49
|
+
elapsedMs: Date.now() - startedAt,
|
|
50
|
+
});
|
|
51
|
+
if (!acquisition.identity) {
|
|
52
|
+
lastPidOutcome = 'not-attempted';
|
|
53
|
+
scheduleNext();
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
const result = repairOnce(options, acquisition.identity);
|
|
57
|
+
lastPidOutcome = result.pidOutcome;
|
|
58
|
+
if (result.outcome === 'ownership-changed') {
|
|
59
|
+
stop();
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (result.outcome === 'retry') {
|
|
63
|
+
scheduleNext();
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (result.outcome === 'unsafe') {
|
|
67
|
+
logger.warn('runtimeScopeOwnership.identity.repair.unsafe', {
|
|
68
|
+
attempts: attempt,
|
|
69
|
+
elapsedMs: Date.now() - startedAt,
|
|
70
|
+
pid_outcome: lastPidOutcome,
|
|
71
|
+
});
|
|
72
|
+
stop();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
logger.info('runtimeScopeOwnership.identity.repaired', {
|
|
76
|
+
attempts: attempt,
|
|
77
|
+
elapsedMs: Date.now() - startedAt,
|
|
78
|
+
pid_outcome: lastPidOutcome,
|
|
79
|
+
});
|
|
80
|
+
stop();
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
// A timer callback must never become an uncaught exception.
|
|
84
|
+
logger.warn('runtimeScopeOwnership.identity.repair.failed', { error: error });
|
|
85
|
+
stop();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
scheduleNext();
|
|
89
|
+
return stop;
|
|
90
|
+
}
|
|
91
|
+
function repairOnce(options, identity) {
|
|
92
|
+
let owner;
|
|
93
|
+
try {
|
|
94
|
+
owner = readRuntimeScopeOwnership(options.runtimeScope);
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
// Unreadable/invalid ownership metadata cannot be safely repaired.
|
|
98
|
+
logger.warn('runtimeScopeOwnership.identity.repair.failed', { error: error });
|
|
99
|
+
return { outcome: 'unsafe', pidOutcome: 'not-attempted' };
|
|
100
|
+
}
|
|
101
|
+
if (!owner || owner.pid !== options.pid || owner.claimId !== options.claimId) {
|
|
102
|
+
return { outcome: 'ownership-changed', pidOutcome: 'not-attempted' };
|
|
103
|
+
}
|
|
104
|
+
try {
|
|
105
|
+
const updated = updateRuntimeScopeOwnershipIdentity(options.runtimeScope, { pid: options.pid, claimId: options.claimId }, identity);
|
|
106
|
+
if (!updated)
|
|
107
|
+
return { outcome: 'ownership-changed', pidOutcome: 'not-attempted' };
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
logger.warn('runtimeScopeOwnership.identity.repair.failed', { error: error });
|
|
111
|
+
return { outcome: 'retry', pidOutcome: 'not-attempted' };
|
|
112
|
+
}
|
|
113
|
+
const pidOutcome = repairPidFile(options, identity);
|
|
114
|
+
if (pidOutcome === 'retry')
|
|
115
|
+
return { outcome: 'retry', pidOutcome };
|
|
116
|
+
if (pidOutcome === 'ownership-changed')
|
|
117
|
+
return { outcome: 'ownership-changed', pidOutcome };
|
|
118
|
+
if (pidOutcome === 'unsafe')
|
|
119
|
+
return { outcome: 'unsafe', pidOutcome };
|
|
120
|
+
return { outcome: 'repaired', pidOutcome };
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Repairs the derived PID record. The owner record is authoritative; a
|
|
124
|
+
* transient PID read/write failure is retried, a changed generation stops the
|
|
125
|
+
* loop, and unreadable-but-present metadata is reported as unsafe instead of
|
|
126
|
+
* being overwritten blindly.
|
|
127
|
+
*/
|
|
128
|
+
function repairPidFile(options, identity) {
|
|
129
|
+
const readPid = options.readPidFile ?? readPidFile;
|
|
130
|
+
const writePid = options.writePidFile ?? writePidFile;
|
|
131
|
+
let info;
|
|
132
|
+
try {
|
|
133
|
+
info = readPid(options.runtimeScope);
|
|
134
|
+
}
|
|
135
|
+
catch (error) {
|
|
136
|
+
logger.warn('runtimeScopeOwnership.identity.repair.failed', { error: error });
|
|
137
|
+
return 'retry';
|
|
138
|
+
}
|
|
139
|
+
if (!info) {
|
|
140
|
+
// Missing is fine (no discovery cache); present but unparseable must not be
|
|
141
|
+
// overwritten because ownership of that record cannot be verified.
|
|
142
|
+
return fs.existsSync(getPidFilePath(options.runtimeScope)) ? 'unsafe' : 'skipped';
|
|
143
|
+
}
|
|
144
|
+
if (info.pid !== options.pid || path.resolve(info.configDir) !== path.resolve(options.runtimeScope)) {
|
|
145
|
+
return 'ownership-changed';
|
|
146
|
+
}
|
|
147
|
+
if (info.ownerClaimId)
|
|
148
|
+
return 'skipped';
|
|
149
|
+
try {
|
|
150
|
+
writePid(options.runtimeScope, { ...info, processIdentity: identity, identityEvidence: undefined });
|
|
151
|
+
return 'repaired';
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
logger.warn('runtimeScopeOwnership.identity.repair.failed', { error: error });
|
|
155
|
+
return 'retry';
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=runtimeOwnershipIdentityRepair.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtimeOwnershipIdentityRepair.js","sourceRoot":"","sources":["../../../src/core/server/runtimeOwnershipIdentityRepair.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAC/F,OAAO,EAAE,sBAAsB,EAAwB,MAAM,qCAAqC,CAAC;AACnG,OAAO,EACL,yBAAyB,EACzB,mCAAmC,GACpC,MAAM,2CAA2C,CAAC;AACnD,OAAO,MAAM,MAAM,uBAAuB,CAAC;AAE3C,uFAAuF;AACvF,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAU,CAAC;AAqBnG;;;;GAIG;AACH,MAAM,UAAU,sCAAsC,CAAC,OAA8C;IACnG,MAAM,MAAM,GAAG,OAAO,CAAC,QAAQ,IAAI,iCAAiC,CAAC;IACrE,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,IAAI,sBAAsB,CAAC;IAC1E,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAC7B,IAAI,OAAO,GAAG,CAAC,CAAC;IAChB,IAAI,SAAS,GAAG,KAAK,CAAC;IACtB,IAAI,KAAgD,CAAC;IACrD,IAAI,cAAc,GAA6B,eAAe,CAAC;IAE/D,MAAM,IAAI,GAAG,GAAS,EAAE;QACtB,SAAS,GAAG,IAAI,CAAC;QACjB,IAAI,KAAK;YAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACjC,CAAC,CAAC;IAEF,MAAM,YAAY,GAAG,GAAS,EAAE;QAC9B,IAAI,SAAS;YAAE,OAAO;QACtB,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,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AAC,8CAA8C,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9E,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,4EAA4E;QAC5E,mEAAmE;QACnE,OAAO,EAAE,CAAC,UAAU,CAAC,cAAc,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACpF,CAAC;IACD,IAAI,IAAI,CAAC,GAAG,KAAK,OAAO,CAAC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QACpG,OAAO,mBAAmB,CAAC;IAC7B,CAAC;IACD,IAAI,IAAI,CAAC,YAAY;QAAE,OAAO,SAAS,CAAC;IACxC,IAAI,CAAC;QACH,QAAQ,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,GAAG,IAAI,EAAE,eAAe,EAAE,QAAQ,EAAE,gBAAgB,EAAE,SAAS,EAAE,CAAC,CAAC;QACpG,OAAO,UAAU,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CAAC,8CAA8C,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC9E,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ProcessIdentity } from './processIdentity.js';
|
|
1
|
+
import { acquireProcessIdentity, type ProcessIdentity, type UnavailableIdentityEvidence } from './processIdentity.js';
|
|
2
2
|
export type RuntimeScopeClaimantKind = 'foreground-http' | 'foreground-stdio' | 'background-supervisor';
|
|
3
3
|
export interface RuntimeScopeOwnershipRecord {
|
|
4
4
|
version: 1;
|
|
@@ -7,6 +7,8 @@ export interface RuntimeScopeOwnershipRecord {
|
|
|
7
7
|
kind: RuntimeScopeClaimantKind;
|
|
8
8
|
claimedAt: string;
|
|
9
9
|
processIdentity?: ProcessIdentity;
|
|
10
|
+
/** Explicit degraded evidence; readers keep the record held while its PID lives. */
|
|
11
|
+
identityEvidence?: UnavailableIdentityEvidence;
|
|
10
12
|
coordination?: 'flock';
|
|
11
13
|
cooperative?: true;
|
|
12
14
|
}
|
|
@@ -29,12 +31,17 @@ export declare class RuntimeScopeOwnedError extends Error {
|
|
|
29
31
|
readonly ownerPath: string;
|
|
30
32
|
readonly reason: RuntimeScopeOwnershipFailureReason;
|
|
31
33
|
readonly owner: RuntimeScopeOwnershipRecord | null;
|
|
32
|
-
|
|
34
|
+
/** Basenames only; safe to show to the local operator. */
|
|
35
|
+
readonly unknownEntries?: string[] | undefined;
|
|
36
|
+
constructor(ownerPath: string, reason: RuntimeScopeOwnershipFailureReason, owner: RuntimeScopeOwnershipRecord | null, detail?: string,
|
|
37
|
+
/** Basenames only; safe to show to the local operator. */
|
|
38
|
+
unknownEntries?: string[] | undefined);
|
|
33
39
|
}
|
|
34
40
|
interface OwnershipDependencies {
|
|
35
41
|
processAlive?: (pid: number) => boolean;
|
|
36
42
|
createClaimId?: () => string;
|
|
37
43
|
now?: () => Date;
|
|
44
|
+
acquireIdentity?: typeof acquireProcessIdentity;
|
|
38
45
|
}
|
|
39
46
|
export declare function getRuntimeScopeOwnershipPath(configDir: string): string;
|
|
40
47
|
export declare function getRuntimeScopeStopLockPath(configDir: string): string;
|
|
@@ -60,10 +67,22 @@ export declare function reclaimStaleRuntimeScopeOwnership(configDir: string, exp
|
|
|
60
67
|
export declare function verifyRuntimeScopeOwnership(configDir: string, claimId: string, expectedKind: RuntimeScopeClaimantKind, processAlive?: (pid: number) => boolean): RuntimeScopeOwnershipRecord;
|
|
61
68
|
/** Strictly reads the canonical owner record for lifecycle recovery commands. */
|
|
62
69
|
export declare function readRuntimeScopeOwnership(configDir: string): RuntimeScopeOwnershipRecord | null;
|
|
70
|
+
/**
|
|
71
|
+
* Atomically upgrades one observed ownership generation from unavailable
|
|
72
|
+
* evidence to kernel evidence. Never creates, replaces, or crosses generations.
|
|
73
|
+
*/
|
|
74
|
+
export declare function updateRuntimeScopeOwnershipIdentity(configDir: string, expected: RuntimeScopeOwnershipIdentity, identity: ProcessIdentity): boolean;
|
|
63
75
|
/**
|
|
64
76
|
* Releases only the owner observed by a lifecycle recovery command. Both PID
|
|
65
77
|
* and claim ID must still match so a replacement owner is never removed.
|
|
66
78
|
*/
|
|
67
79
|
export declare function releaseRuntimeScopeOwnership(configDir: string, expected: RuntimeScopeOwnershipIdentity): boolean;
|
|
80
|
+
export type OwnershipReleaseOutcome = 'released' | 'ownership-changed' | 'failed';
|
|
81
|
+
/**
|
|
82
|
+
* Process-lifetime cleanup contract: never throws, logs a secondary failure,
|
|
83
|
+
* and never masks the primary error of the path that invoked it.
|
|
84
|
+
*/
|
|
85
|
+
export declare function releaseRuntimeScopeOwnershipBestEffort(configDir: string, expected: RuntimeScopeOwnershipIdentity, stage?: ReleaseStage): OwnershipReleaseOutcome;
|
|
86
|
+
type ReleaseStage = 'ownership' | 'stop-lock' | 'file-lock';
|
|
68
87
|
export {};
|
|
69
88
|
//# sourceMappingURL=runtimeScopeOwnership.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtimeScopeOwnership.d.ts","sourceRoot":"","sources":["../../../src/core/server/runtimeScopeOwnership.ts"],"names":[],"mappings":"AAMA,OAAO,
|
|
1
|
+
{"version":3,"file":"runtimeScopeOwnership.d.ts","sourceRoot":"","sources":["../../../src/core/server/runtimeScopeOwnership.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,sBAAsB,EAEtB,KAAK,eAAe,EAGpB,KAAK,2BAA2B,EAEjC,MAAM,qCAAqC,CAAC;AAY7C,MAAM,MAAM,wBAAwB,GAAG,iBAAiB,GAAG,kBAAkB,GAAG,uBAAuB,CAAC;AAExG,MAAM,WAAW,2BAA2B;IAC1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AAgB,4BAA4B,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,6BAA6B,GAAG,OAAO,CAMhH;AAED,MAAM,MAAM,uBAAuB,GAAG,UAAU,GAAG,mBAAmB,GAAG,QAAQ,CAAC;AAElF;;;GAGG;AACH,wBAAgB,sCAAsC,CACpD,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,6BAA6B,EACvC,KAAK,GAAE,YAA0B,GAChC,uBAAuB,CAOzB;AAED,KAAK,YAAY,GAAG,WAAW,GAAG,WAAW,GAAG,WAAW,CAAC"}
|
|
@@ -3,7 +3,7 @@ import fs from 'node:fs';
|
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
import { readBackgroundSupervisorState } from './backgroundRuntimeSupervisorState.js';
|
|
5
5
|
import { getPidFilePath, isProcessAlive, readPidFile } from './pidFileManager.js';
|
|
6
|
-
import { inspectProcessIdentity, processIdentitySchema, readProcessIdentity, } from './processIdentity.js';
|
|
6
|
+
import { acquireProcessIdentity, inspectProcessIdentity, processIdentitySchema, readProcessIdentity, unavailableIdentityEvidenceSchema, } from './processIdentity.js';
|
|
7
7
|
import { acquireRuntimeFileLock } from './runtimeFileLock.js';
|
|
8
8
|
import logger from '../../logger/logger.js';
|
|
9
9
|
import { z } from 'zod';
|
|
@@ -16,12 +16,16 @@ export class RuntimeScopeOwnedError extends Error {
|
|
|
16
16
|
ownerPath;
|
|
17
17
|
reason;
|
|
18
18
|
owner;
|
|
19
|
-
|
|
19
|
+
unknownEntries;
|
|
20
|
+
constructor(ownerPath, reason, owner, detail,
|
|
21
|
+
/** Basenames only; safe to show to the local operator. */
|
|
22
|
+
unknownEntries) {
|
|
20
23
|
const ownerDescription = owner ? ` by ${owner.kind} (PID: ${owner.pid})` : '';
|
|
21
24
|
super(`Runtime Scope is already owned${ownerDescription}${detail ? `: ${detail}` : ''}`);
|
|
22
25
|
this.ownerPath = ownerPath;
|
|
23
26
|
this.reason = reason;
|
|
24
27
|
this.owner = owner;
|
|
28
|
+
this.unknownEntries = unknownEntries;
|
|
25
29
|
this.name = 'RuntimeScopeOwnedError';
|
|
26
30
|
}
|
|
27
31
|
}
|
|
@@ -32,6 +36,7 @@ const runtimeScopeOwnershipRecordSchema = z.object({
|
|
|
32
36
|
kind: z.enum(['foreground-http', 'foreground-stdio', 'background-supervisor']),
|
|
33
37
|
claimedAt: z.string().datetime(),
|
|
34
38
|
processIdentity: processIdentitySchema.optional(),
|
|
39
|
+
identityEvidence: unavailableIdentityEvidenceSchema.optional(),
|
|
35
40
|
coordination: z.literal('flock').optional(),
|
|
36
41
|
cooperative: z.literal(true).optional(),
|
|
37
42
|
});
|
|
@@ -60,15 +65,29 @@ export function claimRuntimeScope(configDir, claimant, dependencies = {}) {
|
|
|
60
65
|
const processAlive = dependencies.processAlive ?? isProcessAlive;
|
|
61
66
|
const createClaimId = dependencies.createClaimId ?? randomUUID;
|
|
62
67
|
const now = dependencies.now ?? currentDate;
|
|
68
|
+
const pid = claimant.pid ?? process.pid;
|
|
69
|
+
const claimedAt = now().toISOString();
|
|
70
|
+
const acquisition = claimant.cooperative ? undefined : (dependencies.acquireIdentity ?? acquireProcessIdentity)(pid);
|
|
63
71
|
const record = {
|
|
64
72
|
version: 1,
|
|
65
|
-
pid
|
|
73
|
+
pid,
|
|
66
74
|
claimId: createClaimId(),
|
|
67
75
|
kind: claimant.kind,
|
|
68
|
-
claimedAt
|
|
76
|
+
claimedAt,
|
|
69
77
|
...(claimant.cooperative
|
|
70
78
|
? { cooperative: true }
|
|
71
|
-
:
|
|
79
|
+
: acquisition?.identity
|
|
80
|
+
? { processIdentity: acquisition.identity }
|
|
81
|
+
: acquisition?.failure
|
|
82
|
+
? {
|
|
83
|
+
identityEvidence: {
|
|
84
|
+
status: 'unavailable',
|
|
85
|
+
code: acquisition.failure.code,
|
|
86
|
+
elapsedMs: acquisition.failure.elapsedMs,
|
|
87
|
+
at: claimedAt,
|
|
88
|
+
},
|
|
89
|
+
}
|
|
90
|
+
: {}),
|
|
72
91
|
};
|
|
73
92
|
fs.mkdirSync(configDir, { recursive: true });
|
|
74
93
|
const candidateDir = `${ownerDir}.${record.claimId}.candidate`;
|
|
@@ -96,6 +115,9 @@ export function claimRuntimeScope(configDir, claimant, dependencies = {}) {
|
|
|
96
115
|
}
|
|
97
116
|
const existing = inspectRuntimeScopeOwnership(configDir);
|
|
98
117
|
if (!existing) {
|
|
118
|
+
// An empty canonical directory cannot be a legitimate claim state:
|
|
119
|
+
// claims publish atomically via candidate+rename.
|
|
120
|
+
removeEmptyOwnershipDirectory(configDir);
|
|
99
121
|
continue;
|
|
100
122
|
}
|
|
101
123
|
if (claimant.cooperative || !ownerIsDead(existing.record, processAlive, fileLock !== null)) {
|
|
@@ -115,7 +137,7 @@ export function claimRuntimeScope(configDir, claimant, dependencies = {}) {
|
|
|
115
137
|
}
|
|
116
138
|
}
|
|
117
139
|
catch (error) {
|
|
118
|
-
|
|
140
|
+
releaseRuntimeScopeOwnershipBestEffort(configDir, record, 'ownership');
|
|
119
141
|
throw error;
|
|
120
142
|
}
|
|
121
143
|
let released = false;
|
|
@@ -126,12 +148,18 @@ export function claimRuntimeScope(configDir, claimant, dependencies = {}) {
|
|
|
126
148
|
if (released) {
|
|
127
149
|
return;
|
|
128
150
|
}
|
|
129
|
-
released = true;
|
|
130
151
|
try {
|
|
131
|
-
|
|
152
|
+
// Mark only after a completed (or no-longer-ours) cleanup, so a
|
|
153
|
+
// transient failure can be retried by a later call.
|
|
154
|
+
const outcome = releaseRuntimeScopeOwnershipBestEffort(configDir, record, 'ownership');
|
|
155
|
+
if (outcome !== 'failed')
|
|
156
|
+
released = true;
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
logCleanupFailure('ownership', error);
|
|
132
160
|
}
|
|
133
161
|
finally {
|
|
134
|
-
fileLock
|
|
162
|
+
releaseFileLockBestEffort(fileLock);
|
|
135
163
|
}
|
|
136
164
|
},
|
|
137
165
|
};
|
|
@@ -141,7 +169,7 @@ export function claimRuntimeScope(configDir, claimant, dependencies = {}) {
|
|
|
141
169
|
finally {
|
|
142
170
|
removeCandidateDirectoryIfPresent(candidateDir);
|
|
143
171
|
if (!retained)
|
|
144
|
-
fileLock
|
|
172
|
+
releaseFileLockBestEffort(fileLock);
|
|
145
173
|
}
|
|
146
174
|
}
|
|
147
175
|
/** Serializes stop metadata cleanup against ordinary claims and workers. */
|
|
@@ -201,7 +229,7 @@ export function acquireRuntimeScopeStopLock(configDir, expectedOwner, dependenci
|
|
|
201
229
|
}
|
|
202
230
|
}
|
|
203
231
|
finally {
|
|
204
|
-
fileLock
|
|
232
|
+
releaseFileLockBestEffort(fileLock);
|
|
205
233
|
}
|
|
206
234
|
},
|
|
207
235
|
};
|
|
@@ -211,7 +239,7 @@ export function acquireRuntimeScopeStopLock(configDir, expectedOwner, dependenci
|
|
|
211
239
|
finally {
|
|
212
240
|
removeCandidateDirectoryIfPresent(candidateDir);
|
|
213
241
|
if (!retained)
|
|
214
|
-
fileLock
|
|
242
|
+
releaseFileLockBestEffort(fileLock);
|
|
215
243
|
}
|
|
216
244
|
}
|
|
217
245
|
/**
|
|
@@ -230,7 +258,7 @@ export function reclaimStaleRuntimeScopeOwnership(configDir, expected, processAl
|
|
|
230
258
|
return reclaimObservedOwnership(configDir, observed, processAlive, fileLock !== null);
|
|
231
259
|
}
|
|
232
260
|
finally {
|
|
233
|
-
fileLock
|
|
261
|
+
releaseFileLockBestEffort(fileLock);
|
|
234
262
|
}
|
|
235
263
|
}
|
|
236
264
|
function ownerIsDead(record, processAlive, heldFileLock) {
|
|
@@ -253,7 +281,7 @@ function reclaimObservedOwnership(configDir, observed, processAlive, heldFileLoc
|
|
|
253
281
|
return removeObservedOwnership(configDir, current);
|
|
254
282
|
}
|
|
255
283
|
finally {
|
|
256
|
-
stopLock
|
|
284
|
+
releaseStopLockBestEffort(stopLock);
|
|
257
285
|
}
|
|
258
286
|
}
|
|
259
287
|
function assertDeadSupervisorIsReclaimable(configDir, ownerPath, owner, processAlive) {
|
|
@@ -346,7 +374,7 @@ function assertNoActiveStopLock(configDir, processAlive, heldFileLock = false) {
|
|
|
346
374
|
}
|
|
347
375
|
}
|
|
348
376
|
finally {
|
|
349
|
-
fileLock
|
|
377
|
+
releaseFileLockBestEffort(fileLock);
|
|
350
378
|
}
|
|
351
379
|
}
|
|
352
380
|
function inspectRuntimeScopeStopLock(configDir) {
|
|
@@ -464,6 +492,48 @@ function stopLockTombstoneName(operationId) {
|
|
|
464
492
|
export function readRuntimeScopeOwnership(configDir) {
|
|
465
493
|
return inspectRuntimeScopeOwnership(configDir)?.record ?? null;
|
|
466
494
|
}
|
|
495
|
+
/**
|
|
496
|
+
* Atomically upgrades one observed ownership generation from unavailable
|
|
497
|
+
* evidence to kernel evidence. Never creates, replaces, or crosses generations.
|
|
498
|
+
*/
|
|
499
|
+
export function updateRuntimeScopeOwnershipIdentity(configDir, expected, identity) {
|
|
500
|
+
const observed = inspectRuntimeScopeOwnership(configDir);
|
|
501
|
+
if (!observed || observed.interruptedReclaim || !ownershipMatches(observed.record, expected)) {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
const next = {
|
|
505
|
+
...observed.record,
|
|
506
|
+
processIdentity: identity,
|
|
507
|
+
identityEvidence: undefined,
|
|
508
|
+
};
|
|
509
|
+
// Keep the temp file outside the canonical ownership directory so a leftover
|
|
510
|
+
// is never an unknown ownership entry; configDir keeps it on the same
|
|
511
|
+
// filesystem, which is required for an atomic rename.
|
|
512
|
+
const tempPath = path.join(configDir, `${OWNERSHIP_DIR_NAME}.${expected.claimId}.identity.tmp`);
|
|
513
|
+
try {
|
|
514
|
+
fs.writeFileSync(tempPath, `${JSON.stringify(next)}\n`, { encoding: 'utf8', mode: 0o600 });
|
|
515
|
+
// Re-observe immediately before publication. The claim's owner lock is held
|
|
516
|
+
// for the runtime lifetime, so this is the strongest available generation
|
|
517
|
+
// guard on platforms without flock; a forced replacement of a live owner
|
|
518
|
+
// remains the only residual window.
|
|
519
|
+
const current = inspectRuntimeScopeOwnership(configDir);
|
|
520
|
+
if (!current || current.interruptedReclaim || !ownershipMatches(current.record, expected)) {
|
|
521
|
+
fs.unlinkSync(tempPath);
|
|
522
|
+
return false;
|
|
523
|
+
}
|
|
524
|
+
fs.renameSync(tempPath, current.recordPath);
|
|
525
|
+
}
|
|
526
|
+
catch (error) {
|
|
527
|
+
try {
|
|
528
|
+
fs.unlinkSync(tempPath);
|
|
529
|
+
}
|
|
530
|
+
catch {
|
|
531
|
+
// Best-effort cleanup; the original error is more useful.
|
|
532
|
+
}
|
|
533
|
+
throw error;
|
|
534
|
+
}
|
|
535
|
+
return true;
|
|
536
|
+
}
|
|
467
537
|
/**
|
|
468
538
|
* Releases only the owner observed by a lifecycle recovery command. Both PID
|
|
469
539
|
* and claim ID must still match so a replacement owner is never removed.
|
|
@@ -475,6 +545,45 @@ export function releaseRuntimeScopeOwnership(configDir, expected) {
|
|
|
475
545
|
}
|
|
476
546
|
return removeObservedOwnership(configDir, observed);
|
|
477
547
|
}
|
|
548
|
+
/**
|
|
549
|
+
* Process-lifetime cleanup contract: never throws, logs a secondary failure,
|
|
550
|
+
* and never masks the primary error of the path that invoked it.
|
|
551
|
+
*/
|
|
552
|
+
export function releaseRuntimeScopeOwnershipBestEffort(configDir, expected, stage = 'ownership') {
|
|
553
|
+
try {
|
|
554
|
+
return releaseRuntimeScopeOwnership(configDir, expected) ? 'released' : 'ownership-changed';
|
|
555
|
+
}
|
|
556
|
+
catch (error) {
|
|
557
|
+
logCleanupFailure(stage, error);
|
|
558
|
+
return 'failed';
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
function logCleanupFailure(stage, error) {
|
|
562
|
+
try {
|
|
563
|
+
logger.warn('runtimeScopeOwnership.release.failed', { error: error, stage });
|
|
564
|
+
}
|
|
565
|
+
catch {
|
|
566
|
+
// Diagnostics must never replace the primary cleanup control flow.
|
|
567
|
+
}
|
|
568
|
+
}
|
|
569
|
+
function releaseFileLockBestEffort(fileLock) {
|
|
570
|
+
if (!fileLock)
|
|
571
|
+
return;
|
|
572
|
+
try {
|
|
573
|
+
fileLock.release();
|
|
574
|
+
}
|
|
575
|
+
catch (error) {
|
|
576
|
+
logCleanupFailure('file-lock', error);
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
function releaseStopLockBestEffort(stopLock) {
|
|
580
|
+
try {
|
|
581
|
+
stopLock.release();
|
|
582
|
+
}
|
|
583
|
+
catch (error) {
|
|
584
|
+
logCleanupFailure('stop-lock', error);
|
|
585
|
+
}
|
|
586
|
+
}
|
|
478
587
|
function inspectRuntimeScopeOwnership(configDir) {
|
|
479
588
|
const ownerDir = getRuntimeScopeOwnershipPath(configDir);
|
|
480
589
|
const ownerRecordPath = path.join(ownerDir, OWNER_RECORD_NAME);
|
|
@@ -500,9 +609,14 @@ function inspectRuntimeScopeOwnership(configDir) {
|
|
|
500
609
|
}
|
|
501
610
|
throw new RuntimeScopeOwnedError(ownerDir, 'ambiguous', null, `ownership directory is unreadable: ${errorMessage(error)}`);
|
|
502
611
|
}
|
|
612
|
+
if (entries.length === 0) {
|
|
613
|
+
// Structurally impossible during a live claim; treat as absent so the
|
|
614
|
+
// caller can remove the leftover directory and retry.
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
503
617
|
const tombstones = entries.filter((entry) => /^owner\.[a-f0-9]{64}\.reclaiming\.json$/.test(entry));
|
|
504
618
|
if (entries.length !== 1 || tombstones.length !== 1) {
|
|
505
|
-
throw new RuntimeScopeOwnedError(ownerDir, 'ambiguous', null, 'ownership directory is incomplete or contains unknown files');
|
|
619
|
+
throw new RuntimeScopeOwnedError(ownerDir, 'ambiguous', null, 'ownership directory is incomplete or contains unknown files', entries.slice(0, 8));
|
|
506
620
|
}
|
|
507
621
|
const tombstonePath = path.join(ownerDir, tombstones[0]);
|
|
508
622
|
const record = readOwnershipRecord(tombstonePath, ownerDir);
|
|
@@ -604,6 +718,21 @@ function ownershipMatches(record, expected) {
|
|
|
604
718
|
function currentDate() {
|
|
605
719
|
return new Date();
|
|
606
720
|
}
|
|
721
|
+
function removeEmptyOwnershipDirectory(configDir) {
|
|
722
|
+
const ownerDir = getRuntimeScopeOwnershipPath(configDir);
|
|
723
|
+
try {
|
|
724
|
+
if (fs.readdirSync(ownerDir).length !== 0)
|
|
725
|
+
return false;
|
|
726
|
+
fs.rmdirSync(ownerDir);
|
|
727
|
+
return true;
|
|
728
|
+
}
|
|
729
|
+
catch (error) {
|
|
730
|
+
if (isCode(error, 'ENOENT'))
|
|
731
|
+
return true;
|
|
732
|
+
logger.warn('runtimeScopeOwnership.empty.ownership.directory.reclaim.failed', { error: error });
|
|
733
|
+
return false;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
607
736
|
function removeCandidateDirectoryIfPresent(candidateDir) {
|
|
608
737
|
try {
|
|
609
738
|
fs.rmSync(candidateDir, { recursive: true });
|