@claudexor/core 4.1.0 → 4.2.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/dist/capture-buffer.d.ts +26 -0
- package/dist/capture-buffer.d.ts.map +1 -0
- package/dist/capture-buffer.js +51 -0
- package/dist/capture-buffer.js.map +1 -0
- package/dist/capture-raw.d.ts +20 -0
- package/dist/capture-raw.d.ts.map +1 -0
- package/dist/capture-raw.js +161 -0
- package/dist/capture-raw.js.map +1 -0
- package/dist/env-scope.d.ts +7 -2
- package/dist/env-scope.d.ts.map +1 -1
- package/dist/env-scope.js +12 -3
- package/dist/env-scope.js.map +1 -1
- package/dist/host-facts.d.ts +18 -0
- package/dist/host-facts.d.ts.map +1 -0
- package/dist/host-facts.js +90 -0
- package/dist/host-facts.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/native/claudexor-process-identity +0 -0
- package/dist/proc.d.ts +25 -24
- package/dist/proc.d.ts.map +1 -1
- package/dist/proc.js +33 -159
- package/dist/proc.js.map +1 -1
- package/dist/process-drain.d.ts +31 -0
- package/dist/process-drain.d.ts.map +1 -0
- package/dist/process-drain.js +55 -0
- package/dist/process-drain.js.map +1 -0
- package/dist/process-identity.d.ts +25 -0
- package/dist/process-identity.d.ts.map +1 -1
- package/dist/process-identity.js +91 -8
- package/dist/process-identity.js.map +1 -1
- package/dist/process-lines.d.ts +1 -0
- package/dist/process-lines.d.ts.map +1 -1
- package/dist/process-lines.js +69 -13
- package/dist/process-lines.js.map +1 -1
- package/dist/process-output.d.ts +16 -0
- package/dist/process-output.d.ts.map +1 -0
- package/dist/process-output.js +28 -0
- package/dist/process-output.js.map +1 -0
- package/dist/process-registry.d.ts +15 -3
- package/dist/process-registry.d.ts.map +1 -1
- package/dist/process-registry.js +35 -3
- package/dist/process-registry.js.map +1 -1
- package/dist/process-scope-census.d.ts +196 -0
- package/dist/process-scope-census.d.ts.map +1 -0
- package/dist/process-scope-census.js +444 -0
- package/dist/process-scope-census.js.map +1 -0
- package/dist/process-scope-readers.d.ts +104 -0
- package/dist/process-scope-readers.d.ts.map +1 -0
- package/dist/process-scope-readers.js +429 -0
- package/dist/process-scope-readers.js.map +1 -0
- package/dist/process-scope.d.ts +21 -0
- package/dist/process-scope.d.ts.map +1 -0
- package/dist/process-scope.js +59 -0
- package/dist/process-scope.js.map +1 -0
- package/dist/process-table.d.ts +32 -0
- package/dist/process-table.d.ts.map +1 -0
- package/dist/process-table.js +122 -0
- package/dist/process-table.js.map +1 -0
- package/dist/process-tree.d.ts.map +1 -1
- package/dist/process-tree.js +6 -0
- package/dist/process-tree.js.map +1 -1
- package/dist/runloop.d.ts.map +1 -1
- package/dist/runloop.js +9 -0
- package/dist/runloop.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,444 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Scope census and reap: find every live process that still carries a scope
|
|
3
|
+
* marker (`process-scope.ts`) in its environment and end it by measured
|
|
4
|
+
* identity. This is the owner of the "a finished run ends what it left" rule:
|
|
5
|
+
* the PPID/process-group ladder (`process-tree.ts`) stays the fast path for a
|
|
6
|
+
* cancel while the tree is intact; a descendant that `setsid`-ed and was
|
|
7
|
+
* reparented to pid 1 after its parent died (the #449 orphans) is reachable
|
|
8
|
+
* only through the marker it inherited — or, where the kernel hides that
|
|
9
|
+
* marker, through the group and birth the daemon RECORDED while the run was
|
|
10
|
+
* live (DIRECTIVE 1): macOS SIP withholds the environment of Apple platform
|
|
11
|
+
* binaries, so membership on POSIX is the UNION of (a) marker members,
|
|
12
|
+
* (b) members of recorded process groups under the pgid-reuse rule and
|
|
13
|
+
* (c) individually recorded descendants, every one signalled by pid after its
|
|
14
|
+
* birth is re-measured (`capturedCandidates` below).
|
|
15
|
+
*
|
|
16
|
+
* Contract (shared with the embedding host):
|
|
17
|
+
* - one asynchronous process-table read per census: macOS streams
|
|
18
|
+
* `ps -E -ww -A -o pid=,command=` line by line and keeps only matching pids
|
|
19
|
+
* (the environment column is never buffered whole, logged or persisted);
|
|
20
|
+
* Linux reads `/proc/<pid>/environ` with bounded concurrency and matches the
|
|
21
|
+
* exact NUL-delimited entry `NAME=1`;
|
|
22
|
+
* - affirmative membership (`confirm`) AND the measured birth identity are
|
|
23
|
+
* checked immediately before every signal; a pid is signalled on its own,
|
|
24
|
+
* never a dead leader's historical process group;
|
|
25
|
+
* - TERM, a bounded grace, then KILL, with a few bounded rescans for forks;
|
|
26
|
+
* - truncation, timeout or reader failure is `failed` — unknown, never an
|
|
27
|
+
* empty scope; a known member whose identity turns unreadable is reported
|
|
28
|
+
* separately from unrelated unreadable processes; a vanished, birth-checked
|
|
29
|
+
* member is gone;
|
|
30
|
+
* - never pid 1, never this process; nothing is ever read from a process's
|
|
31
|
+
* environment except whether the exact marker entry is present.
|
|
32
|
+
*
|
|
33
|
+
* Limit, stated plainly: on macOS a random key sits in a text column that
|
|
34
|
+
* mixes argv and environment. A stranger whose argv literally contains
|
|
35
|
+
* `NAME=1` for a 128-bit random NAME would be censused; the random id makes
|
|
36
|
+
* that practically impossible, but it is not structural proof.
|
|
37
|
+
*
|
|
38
|
+
* Windows has no environment census without native code: coverage there is
|
|
39
|
+
* `tree_only` (the existing taskkill tree kill while the parent chain exists),
|
|
40
|
+
* disclosed, never turned into a failure.
|
|
41
|
+
*/
|
|
42
|
+
import { compareProcessBirth, compareProcessIdentity, defaultAsyncProcessIdentityReader, } from "./process-identity.js";
|
|
43
|
+
import { isScopeMarkerName } from "./process-scope.js";
|
|
44
|
+
import { createScopeCensusReader, LINUX_CONCURRENCY, mapBounded, scopeAgeSeconds, } from "./process-scope-readers.js";
|
|
45
|
+
import { birthEpochSeconds, createProcessTableReader, } from "./process-table.js";
|
|
46
|
+
/** The settlement deadline won a race against a read. */
|
|
47
|
+
const DEADLINE = Symbol("deadline");
|
|
48
|
+
/** The epoch-seconds floor of a scope: the earlier of its `lstart` and wall-clock floors. */
|
|
49
|
+
export function scopeFloorSeconds(scopeStart, scopeStartAt) {
|
|
50
|
+
const fromBirth = scopeStart ? birthEpochSeconds(scopeStart) : null;
|
|
51
|
+
const fromClock = scopeStartAt ? Math.floor(Date.parse(scopeStartAt) / 1000) : null;
|
|
52
|
+
const floors = [fromBirth, fromClock].filter((v) => v !== null && Number.isFinite(v));
|
|
53
|
+
return floors.length ? Math.min(...floors) : null;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The candidates of the recorded sources against one fresh table snapshot:
|
|
57
|
+
* every individually captured pid still alive with its recorded birth, plus
|
|
58
|
+
* every live member of a recorded group G under the pgid-reuse rule — POSIX
|
|
59
|
+
* does not reuse a pid as a group id while that group has members, so G is
|
|
60
|
+
* still ours when (i) every live member of G was born at or after the scope
|
|
61
|
+
* and (ii) a live process with pid == G has the birth we recorded for G's
|
|
62
|
+
* leader; otherwise G was reused and is skipped entirely. Pure.
|
|
63
|
+
*/
|
|
64
|
+
export function capturedCandidates(captured, rows, scopeStart, options = {}) {
|
|
65
|
+
const byPid = new Map(rows.map((row) => [row.pid, row]));
|
|
66
|
+
const candidates = new Map();
|
|
67
|
+
const reusedGroups = [];
|
|
68
|
+
for (const item of captured) {
|
|
69
|
+
const row = byPid.get(item.pid);
|
|
70
|
+
if (row && row.birth === item.birth)
|
|
71
|
+
candidates.set(row.pid, row.birth);
|
|
72
|
+
}
|
|
73
|
+
const floor = scopeFloorSeconds(scopeStart, options.scopeStartAt);
|
|
74
|
+
const rootByPgid = new Map((options.rootGroups ?? []).map((g) => [g.pgid, g]));
|
|
75
|
+
const groups = new Set([...captured.map((item) => item.pgid), ...rootByPgid.keys()]);
|
|
76
|
+
for (const group of groups) {
|
|
77
|
+
const members = rows.filter((row) => row.pgid === group);
|
|
78
|
+
if (members.length === 0)
|
|
79
|
+
continue; // emptied: simply gone
|
|
80
|
+
const root = rootByPgid.get(group);
|
|
81
|
+
const recordedLeaderBirth = captured.find((item) => item.pid === group)?.birth ?? root?.leaderBirth ?? undefined;
|
|
82
|
+
const liveLeader = byPid.get(group);
|
|
83
|
+
// Rule (ii): a live process with pid == G must be the recorded leader —
|
|
84
|
+
// by its `lstart` when one was recorded, else by the caller's identity
|
|
85
|
+
// verdict against the spawn-time handle; otherwise G was reused.
|
|
86
|
+
const leaderReused = liveLeader !== undefined &&
|
|
87
|
+
(recordedLeaderBirth !== undefined
|
|
88
|
+
? liveLeader.birth !== recordedLeaderBirth
|
|
89
|
+
: options.leaderVerdict?.get(group) !== "same");
|
|
90
|
+
const bornBefore = floor === null ||
|
|
91
|
+
members.some((row) => {
|
|
92
|
+
const at = birthEpochSeconds(row.birth);
|
|
93
|
+
return at === null || at < floor;
|
|
94
|
+
});
|
|
95
|
+
if (leaderReused || bornBefore) {
|
|
96
|
+
reusedGroups.push(group);
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
for (const row of members)
|
|
100
|
+
candidates.set(row.pid, row.birth);
|
|
101
|
+
}
|
|
102
|
+
return { candidates, reusedGroups };
|
|
103
|
+
}
|
|
104
|
+
function unsupportedOutcome(durationMs) {
|
|
105
|
+
return {
|
|
106
|
+
coverage: "tree_only",
|
|
107
|
+
census: "unsupported",
|
|
108
|
+
censusFailure: null,
|
|
109
|
+
ended: [],
|
|
110
|
+
survivors: [],
|
|
111
|
+
unreadable: [],
|
|
112
|
+
reusedGroups: [],
|
|
113
|
+
settled: false,
|
|
114
|
+
incomplete: false,
|
|
115
|
+
completeness: "not_provable",
|
|
116
|
+
completenessReason: "no environment census exists on this platform",
|
|
117
|
+
restricted: false,
|
|
118
|
+
durationMs,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
export const DARWIN_COMPLETENESS_LIMIT = "macOS hides Apple platform-binary environments (SIP): a system binary started in the background by a shell that exited before any capture cannot be ruled out";
|
|
122
|
+
/** The completeness verdict of one reap (see `ScopeReapOutcome.completeness`). */
|
|
123
|
+
export function reapCompleteness(platform, censusFailure, incomplete = false, censusUnreadable = 0) {
|
|
124
|
+
if (censusFailure !== null)
|
|
125
|
+
return { completeness: "not_provable", completenessReason: `census failed: ${censusFailure}` };
|
|
126
|
+
if (incomplete)
|
|
127
|
+
return {
|
|
128
|
+
completeness: "not_provable",
|
|
129
|
+
completenessReason: "settlement deadline expired before every source was read",
|
|
130
|
+
};
|
|
131
|
+
if (platform === "darwin")
|
|
132
|
+
return { completeness: "not_provable", completenessReason: DARWIN_COMPLETENESS_LIMIT };
|
|
133
|
+
if (censusUnreadable > 0)
|
|
134
|
+
return {
|
|
135
|
+
completeness: "not_provable",
|
|
136
|
+
completenessReason: `${censusUnreadable} same-uid process environment(s) were unreadable (other uids cannot inherit our environment through ordinary spawn and are not counted; setuid binaries are a disclosed residual)`,
|
|
137
|
+
};
|
|
138
|
+
return { completeness: "complete", completenessReason: null };
|
|
139
|
+
}
|
|
140
|
+
/** Default grace between TERM and KILL (ms). */
|
|
141
|
+
export const SCOPE_REAP_GRACE_MS = 1_000;
|
|
142
|
+
/**
|
|
143
|
+
* The ONE settlement deadline (ms) for a scope: every read, signal and wait of
|
|
144
|
+
* a settlement — the daemon index's wait for in-flight seeds included — races
|
|
145
|
+
* it, and expiry is disclosed as `incomplete`, never extended.
|
|
146
|
+
*/
|
|
147
|
+
export function scopeReapDeadlineMs(graceMs = SCOPE_REAP_GRACE_MS) {
|
|
148
|
+
return graceMs + 4_000;
|
|
149
|
+
}
|
|
150
|
+
async function reapOnce(opts) {
|
|
151
|
+
const now = opts.now ?? Date.now;
|
|
152
|
+
const sleep = opts.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
|
|
153
|
+
const platform = opts.platform ?? process.platform;
|
|
154
|
+
const start = now();
|
|
155
|
+
const census = opts.census === undefined ? createScopeCensusReader(platform) : opts.census;
|
|
156
|
+
if (!census)
|
|
157
|
+
return unsupportedOutcome(now() - start);
|
|
158
|
+
const identity = opts.identity ?? defaultAsyncProcessIdentityReader;
|
|
159
|
+
const captured = opts.captured;
|
|
160
|
+
const table = opts.table ?? (captured || opts.rootGroups ? createProcessTableReader() : null);
|
|
161
|
+
const deliver = opts.signal ?? ((pid, signal) => process.kill(pid, signal));
|
|
162
|
+
const graceMs = opts.graceMs ?? SCOPE_REAP_GRACE_MS;
|
|
163
|
+
const deadlineMs = opts.deadlineMs ?? scopeReapDeadlineMs(graceMs);
|
|
164
|
+
const probeIntervalMs = Math.max(1, opts.probeIntervalMs ?? 250);
|
|
165
|
+
const excluded = new Set(opts.excludePids ?? [1, process.pid]);
|
|
166
|
+
const restricted = platform === "darwin";
|
|
167
|
+
// ONE deadline for the whole settlement: every read (census, confirmation,
|
|
168
|
+
// identity, table) races it, and once it expires nothing is scanned or
|
|
169
|
+
// signalled any more — the outcome is disclosed as incomplete.
|
|
170
|
+
let expired = false;
|
|
171
|
+
const deadlineTimer = opts.deadlineTimer ??
|
|
172
|
+
((ms) => new Promise((resolve) => {
|
|
173
|
+
const timer = setTimeout(resolve, ms);
|
|
174
|
+
timer.unref?.();
|
|
175
|
+
}));
|
|
176
|
+
const expiry = deadlineTimer(deadlineMs).then(() => {
|
|
177
|
+
expired = true;
|
|
178
|
+
});
|
|
179
|
+
void expiry.catch(() => { });
|
|
180
|
+
const pastDeadline = () => expired || now() - start >= deadlineMs;
|
|
181
|
+
// Lazy: no read (on macOS a helper or `ps` process) STARTS past the deadline.
|
|
182
|
+
const bounded = (work) => pastDeadline()
|
|
183
|
+
? Promise.resolve(DEADLINE)
|
|
184
|
+
: Promise.race([work(), expiry.then(() => DEADLINE)]);
|
|
185
|
+
let censusUnreadable = 0;
|
|
186
|
+
const live = new Map();
|
|
187
|
+
const ended = [];
|
|
188
|
+
const unreadable = new Map();
|
|
189
|
+
const reusedGroups = new Set();
|
|
190
|
+
const seen = new Set();
|
|
191
|
+
const signalMember = (member, signal) => {
|
|
192
|
+
if (pastDeadline())
|
|
193
|
+
return; // never a late signal after the deadline
|
|
194
|
+
try {
|
|
195
|
+
deliver(member.pid, signal);
|
|
196
|
+
}
|
|
197
|
+
catch (error) {
|
|
198
|
+
const code = error?.code;
|
|
199
|
+
live.delete(member.pid);
|
|
200
|
+
if (code === "ESRCH")
|
|
201
|
+
ended.push({ pid: member.pid, startToken: member.startToken });
|
|
202
|
+
else
|
|
203
|
+
unreadable.set(member.pid, `signal_failed:${code ?? "unknown"}`);
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
/** Admit a censused pid: confirm membership + measure identity, then signal. */
|
|
207
|
+
const admitMarker = async (pid, signal) => {
|
|
208
|
+
if (excluded.has(pid) || seen.has(pid))
|
|
209
|
+
return;
|
|
210
|
+
seen.add(pid);
|
|
211
|
+
// Bracket the membership read with two identity reads: the marker is
|
|
212
|
+
// accepted only for the ONE process that was alive under the same birth
|
|
213
|
+
// before and after `confirm`, so a pid that was freed and reused between
|
|
214
|
+
// the census and the signal can never enrol a stranger (item 7).
|
|
215
|
+
const before = await bounded(() => identity.read(pid));
|
|
216
|
+
if (before === DEADLINE || before.status === "missing")
|
|
217
|
+
return;
|
|
218
|
+
if (before.status === "unknown") {
|
|
219
|
+
unreadable.set(pid, `identity_${before.reason}`);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const member = await bounded(() => census.confirm(pid, opts.marker));
|
|
223
|
+
if (member === DEADLINE || member === false)
|
|
224
|
+
return; // vanished (or reused): not ours any more
|
|
225
|
+
if (member === null) {
|
|
226
|
+
unreadable.set(pid, "membership_unreadable");
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const observed = await bounded(() => identity.read(pid));
|
|
230
|
+
if (observed === DEADLINE || observed.status === "missing")
|
|
231
|
+
return; // gone between confirm and read
|
|
232
|
+
if (observed.status === "unknown") {
|
|
233
|
+
unreadable.set(pid, `identity_${observed.reason}`);
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
if (compareProcessBirth(before, observed) !== "same")
|
|
237
|
+
return; // reused across the bracket
|
|
238
|
+
const entry = {
|
|
239
|
+
pid,
|
|
240
|
+
birth: { kind: "identity", identity: observed },
|
|
241
|
+
startToken: observed.startToken,
|
|
242
|
+
killed: signal === "SIGKILL",
|
|
243
|
+
};
|
|
244
|
+
live.set(pid, entry);
|
|
245
|
+
signalMember(entry, signal);
|
|
246
|
+
};
|
|
247
|
+
/** Admit a recorded candidate: re-measure its birth right before the signal. */
|
|
248
|
+
const admitCaptured = async (pid, expectedBirth, signal) => {
|
|
249
|
+
if (!table || excluded.has(pid) || seen.has(pid) || pastDeadline())
|
|
250
|
+
return;
|
|
251
|
+
seen.add(pid);
|
|
252
|
+
const row = await bounded(() => table.row(pid));
|
|
253
|
+
if (row === DEADLINE || row === null)
|
|
254
|
+
return; // gone (or out of time)
|
|
255
|
+
if (row === "unreadable") {
|
|
256
|
+
unreadable.set(pid, "birth_unreadable");
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
if (row.birth !== expectedBirth)
|
|
260
|
+
return; // the pid was reused since the snapshot
|
|
261
|
+
const entry = {
|
|
262
|
+
pid,
|
|
263
|
+
birth: { kind: "table", birth: row.birth },
|
|
264
|
+
startToken: `ps:${row.birth}`,
|
|
265
|
+
killed: signal === "SIGKILL",
|
|
266
|
+
};
|
|
267
|
+
live.set(pid, entry);
|
|
268
|
+
signalMember(entry, signal);
|
|
269
|
+
};
|
|
270
|
+
const scanMarker = async (signal) => {
|
|
271
|
+
const ageSeconds = scopeAgeSeconds(opts.scopeStartAt);
|
|
272
|
+
const result = await bounded(() => census.census([opts.marker], ageSeconds, pastDeadline));
|
|
273
|
+
if (result === DEADLINE || pastDeadline())
|
|
274
|
+
return null; // incomplete, never a failed census
|
|
275
|
+
if (result.status !== "ok")
|
|
276
|
+
return result.reason;
|
|
277
|
+
censusUnreadable = Math.max(censusUnreadable, result.unreadable);
|
|
278
|
+
const pids = result.members.get(opts.marker) ?? [];
|
|
279
|
+
await mapBounded(pids, LINUX_CONCURRENCY, (pid) => admitMarker(pid, signal));
|
|
280
|
+
return null;
|
|
281
|
+
};
|
|
282
|
+
const scanCaptured = async (signal) => {
|
|
283
|
+
if ((!captured && !opts.rootGroups) || !table || pastDeadline())
|
|
284
|
+
return null;
|
|
285
|
+
const rows = await bounded(() => table.snapshot());
|
|
286
|
+
if (rows === DEADLINE)
|
|
287
|
+
return null;
|
|
288
|
+
if (rows === null)
|
|
289
|
+
return "process table unreadable";
|
|
290
|
+
// A root group known only by its leader's identity (no lstart yet): if a
|
|
291
|
+
// live process owns pid == G, measure it against the spawn-time identity.
|
|
292
|
+
const leaderVerdict = new Map();
|
|
293
|
+
for (const root of opts.rootGroups ?? []) {
|
|
294
|
+
if (root.leaderBirth !== null || !root.leaderIdentity)
|
|
295
|
+
continue;
|
|
296
|
+
if (!rows.some((row) => row.pid === root.pgid))
|
|
297
|
+
continue;
|
|
298
|
+
const observed = await bounded(() => identity.read(root.pgid));
|
|
299
|
+
if (observed === DEADLINE)
|
|
300
|
+
return null;
|
|
301
|
+
leaderVerdict.set(root.pgid, compareProcessIdentity(root.leaderIdentity, observed) === "same" ? "same" : "different");
|
|
302
|
+
}
|
|
303
|
+
const found = capturedCandidates(captured ?? [], rows, opts.scopeStart, {
|
|
304
|
+
scopeStartAt: opts.scopeStartAt,
|
|
305
|
+
rootGroups: opts.rootGroups,
|
|
306
|
+
leaderVerdict,
|
|
307
|
+
});
|
|
308
|
+
for (const group of found.reusedGroups)
|
|
309
|
+
reusedGroups.add(group);
|
|
310
|
+
await mapBounded([...found.candidates], LINUX_CONCURRENCY, ([pid, birth]) => admitCaptured(pid, birth, signal));
|
|
311
|
+
return null;
|
|
312
|
+
};
|
|
313
|
+
const scan = async (signal) => {
|
|
314
|
+
const markerFailure = await scanMarker(signal);
|
|
315
|
+
const capturedFailure = await scanCaptured(signal);
|
|
316
|
+
return markerFailure ?? capturedFailure;
|
|
317
|
+
};
|
|
318
|
+
/** Is the member still the process we signalled? Its birth decides, not its current group. */
|
|
319
|
+
const stillSame = async (member) => {
|
|
320
|
+
if (member.birth.kind === "identity") {
|
|
321
|
+
const observed = await bounded(() => identity.read(member.pid));
|
|
322
|
+
if (observed === DEADLINE)
|
|
323
|
+
return "same"; // out of time: still a survivor, never a false "gone"
|
|
324
|
+
const comparison = compareProcessBirth(member.birth.identity, observed);
|
|
325
|
+
if (comparison === "same")
|
|
326
|
+
return "same";
|
|
327
|
+
if (comparison === "unknown")
|
|
328
|
+
return "unreadable";
|
|
329
|
+
return "gone"; // missing, or a different process now owns the pid
|
|
330
|
+
}
|
|
331
|
+
if (!table)
|
|
332
|
+
return "unreadable";
|
|
333
|
+
const row = await bounded(() => table.row(member.pid));
|
|
334
|
+
if (row === DEADLINE)
|
|
335
|
+
return "same";
|
|
336
|
+
if (row === null)
|
|
337
|
+
return "gone";
|
|
338
|
+
if (row === "unreadable")
|
|
339
|
+
return "unreadable";
|
|
340
|
+
return row.birth === member.birth.birth ? "same" : "gone";
|
|
341
|
+
};
|
|
342
|
+
const probe = async () => {
|
|
343
|
+
await mapBounded([...live.values()], LINUX_CONCURRENCY, async (member) => {
|
|
344
|
+
const state = await stillSame(member);
|
|
345
|
+
if (state === "same")
|
|
346
|
+
return;
|
|
347
|
+
live.delete(member.pid);
|
|
348
|
+
if (state === "unreadable")
|
|
349
|
+
unreadable.set(member.pid, "identity_unreadable");
|
|
350
|
+
else
|
|
351
|
+
ended.push({ pid: member.pid, startToken: member.startToken });
|
|
352
|
+
});
|
|
353
|
+
};
|
|
354
|
+
const outcome = (censusFailure) => ({
|
|
355
|
+
coverage: captured || opts.rootGroups ? "marker+capture" : "marker",
|
|
356
|
+
census: censusFailure === null ? "ok" : "failed",
|
|
357
|
+
censusFailure,
|
|
358
|
+
ended,
|
|
359
|
+
survivors: [...live.values()].map((m) => ({ pid: m.pid, startToken: m.startToken })),
|
|
360
|
+
unreadable: [...unreadable].map(([pid, reason]) => ({ pid, reason })),
|
|
361
|
+
reusedGroups: [...reusedGroups],
|
|
362
|
+
settled: censusFailure === null && !pastDeadline() && live.size === 0 && unreadable.size === 0,
|
|
363
|
+
incomplete: pastDeadline(),
|
|
364
|
+
...reapCompleteness(platform, censusFailure, pastDeadline(), censusUnreadable),
|
|
365
|
+
restricted,
|
|
366
|
+
durationMs: now() - start,
|
|
367
|
+
});
|
|
368
|
+
let censusFailure = await scan("SIGTERM");
|
|
369
|
+
if (live.size === 0) {
|
|
370
|
+
// Members that were already gone at the first signal (ESRCH) count as
|
|
371
|
+
// ended; a fork after that snapshot would be missed without one more look.
|
|
372
|
+
if (ended.length > 0 && !pastDeadline())
|
|
373
|
+
censusFailure ??= await scan("SIGTERM");
|
|
374
|
+
if (live.size === 0)
|
|
375
|
+
return outcome(censusFailure);
|
|
376
|
+
}
|
|
377
|
+
let escalated = false;
|
|
378
|
+
let rescans = 0;
|
|
379
|
+
for (;;) {
|
|
380
|
+
if (pastDeadline())
|
|
381
|
+
return outcome(censusFailure);
|
|
382
|
+
await sleep(probeIntervalMs);
|
|
383
|
+
if (pastDeadline())
|
|
384
|
+
return outcome(censusFailure); // members stay survivors; no probe starts
|
|
385
|
+
await probe();
|
|
386
|
+
if (pastDeadline())
|
|
387
|
+
return outcome(censusFailure);
|
|
388
|
+
const elapsed = now() - start;
|
|
389
|
+
if (elapsed >= graceMs && !escalated) {
|
|
390
|
+
escalated = true;
|
|
391
|
+
// One bounded rescan for forks before the hard signal; late arrivals get KILL.
|
|
392
|
+
rescans += 1;
|
|
393
|
+
censusFailure ??= await scan("SIGKILL");
|
|
394
|
+
for (const member of live.values()) {
|
|
395
|
+
if (member.killed)
|
|
396
|
+
continue;
|
|
397
|
+
if ((await stillSame(member)) !== "same")
|
|
398
|
+
continue;
|
|
399
|
+
member.killed = true;
|
|
400
|
+
signalMember(member, "SIGKILL");
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (live.size === 0) {
|
|
404
|
+
if (rescans < 2) {
|
|
405
|
+
rescans += 1;
|
|
406
|
+
censusFailure ??= await scan(escalated ? "SIGKILL" : "SIGTERM");
|
|
407
|
+
if (live.size === 0)
|
|
408
|
+
return outcome(censusFailure);
|
|
409
|
+
}
|
|
410
|
+
else
|
|
411
|
+
return outcome(censusFailure);
|
|
412
|
+
}
|
|
413
|
+
if (pastDeadline())
|
|
414
|
+
return outcome(censusFailure);
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Scope reaper with per-marker coalescing: a second request for a marker
|
|
419
|
+
* whose reap is in flight shares that promise instead of starting a second
|
|
420
|
+
* ladder (different markers keep separate authority and deadlines).
|
|
421
|
+
*/
|
|
422
|
+
export class ScopeReaper {
|
|
423
|
+
inflight = new Map();
|
|
424
|
+
reap(opts) {
|
|
425
|
+
if (!isScopeMarkerName(opts.marker)) {
|
|
426
|
+
return Promise.reject(new Error("scope marker name does not match the grammar"));
|
|
427
|
+
}
|
|
428
|
+
const pending = this.inflight.get(opts.marker);
|
|
429
|
+
if (pending)
|
|
430
|
+
return pending;
|
|
431
|
+
const job = reapOnce(opts).finally(() => {
|
|
432
|
+
if (this.inflight.get(opts.marker) === job)
|
|
433
|
+
this.inflight.delete(opts.marker);
|
|
434
|
+
});
|
|
435
|
+
this.inflight.set(opts.marker, job);
|
|
436
|
+
return job;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
export const defaultScopeReaper = new ScopeReaper();
|
|
440
|
+
/** End every live process of the scope (see the module doc). */
|
|
441
|
+
export function reapScopeMembers(opts) {
|
|
442
|
+
return defaultScopeReaper.reap(opts);
|
|
443
|
+
}
|
|
444
|
+
//# sourceMappingURL=process-scope-census.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-scope-census.js","sourceRoot":"","sources":["../src/process-scope-census.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,iCAAiC,GAGlC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM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MAAM,CAAC,CAAC;QAChF,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QACpC,OAAO,GAAG,CAAC;IACb,CAAC;CACF;AAED,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,WAAW,EAAE,CAAC;AAEpD,gEAAgE;AAChE,MAAM,UAAU,gBAAgB,CAAC,IAAsB;IACrD,OAAO,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
export type ScopeCensusResult =
|
|
2
|
+
/** Every requested marker mapped to the pids that carry it right now. */
|
|
3
|
+
{
|
|
4
|
+
status: "ok";
|
|
5
|
+
members: Map<string, number[]>;
|
|
6
|
+
unreadable: number;
|
|
7
|
+
}
|
|
8
|
+
/** The table could not be read completely: unknown, never empty. */
|
|
9
|
+
| {
|
|
10
|
+
status: "failed";
|
|
11
|
+
reason: string;
|
|
12
|
+
};
|
|
13
|
+
export interface ScopeCensusReader {
|
|
14
|
+
/**
|
|
15
|
+
* Every live process carrying any of `markers`. `maxAgeSeconds`, when the
|
|
16
|
+
* caller knows it, is the scope's age: a process older than that was
|
|
17
|
+
* created before the marker was minted and cannot carry it, so a reader may
|
|
18
|
+
* skip its environment (darwin does; a failed age listing falls back to the
|
|
19
|
+
* full read). Omitted = the full census. `expired`, when the caller has a
|
|
20
|
+
* deadline, turns true once it passed: no further read starts for that
|
|
21
|
+
* caller (a scan it shares with a caller still in time goes on), and a scan
|
|
22
|
+
* left without such a caller never substitutes a partial or fabricated empty `ok`.
|
|
23
|
+
*/
|
|
24
|
+
census(markers: readonly string[], maxAgeSeconds?: number, expired?: () => boolean): Promise<ScopeCensusResult>;
|
|
25
|
+
/**
|
|
26
|
+
* Affirmative membership of ONE pid immediately before it is signalled:
|
|
27
|
+
* true = the exact entry is present now, false = absent (vanished or
|
|
28
|
+
* reused), null = unreadable.
|
|
29
|
+
*/
|
|
30
|
+
confirm(pid: number, marker: string): Promise<boolean | null>;
|
|
31
|
+
}
|
|
32
|
+
export declare const LINUX_CONCURRENCY = 8;
|
|
33
|
+
/**
|
|
34
|
+
* Slack added to the scope's age before a process is deemed too old to carry
|
|
35
|
+
* its marker: `etime` truncation and the listing's own delay, and a backward
|
|
36
|
+
* wall-clock step of up to a minute during the run (a larger one can hide a
|
|
37
|
+
* marker-only member from the filtered read; recorded groups and captured
|
|
38
|
+
* descendants do not use it).
|
|
39
|
+
*/
|
|
40
|
+
export declare const SCOPE_AGE_SLACK_SECONDS = 60;
|
|
41
|
+
/** `ps -o etime=` text — `[[dd-]hh:]mm:ss`, elapsed since the process started — as seconds; null for anything else. */
|
|
42
|
+
export declare function parseEtime(text: string): number | null;
|
|
43
|
+
/**
|
|
44
|
+
* The scope's age for a census: seconds since `openedAt` (an ISO time)
|
|
45
|
+
* against the REAL wall clock — `ps` measures `etime` against the same clock
|
|
46
|
+
* at the same moment — recomputed by the caller at every scan. Undefined (the
|
|
47
|
+
* full census) when no opening time is known or it does not parse.
|
|
48
|
+
*/
|
|
49
|
+
export declare function scopeAgeSeconds(openedAt: string | null | undefined, now?: number): number | undefined;
|
|
50
|
+
/**
|
|
51
|
+
* One `ps -E` line: the leading pid and which of `markers` appear as a whole
|
|
52
|
+
* whitespace-delimited token `NAME=1`. Pure, so the matcher is testable
|
|
53
|
+
* without a process table.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseDarwinCensusLine(line: string, markers: readonly string[]): number | null;
|
|
56
|
+
export declare function darwinLineCarriesMarker(line: string, marker: string): boolean;
|
|
57
|
+
/** Exact NUL-delimited entry match over a Linux `environ` buffer. */
|
|
58
|
+
export declare function environCarriesMarker(environ: string, marker: string): boolean;
|
|
59
|
+
export type PsRunFailure = {
|
|
60
|
+
status: "failed";
|
|
61
|
+
reason: string;
|
|
62
|
+
/** What `ps` wrote to stderr (bounded); absent or empty when it wrote nothing. */
|
|
63
|
+
stderr?: string;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* `ps -p` exits 1 with no row and nothing on stderr when every listed pid has
|
|
67
|
+
* vanished: a complete, empty answer. The same exit code after a real error
|
|
68
|
+
* (an allocation failure, an invalid argument) comes with a message on
|
|
69
|
+
* stderr and stays a failure.
|
|
70
|
+
*/
|
|
71
|
+
export declare function psSelectionVanished(failure: PsRunFailure, sawRow: boolean): boolean;
|
|
72
|
+
/** Runs `ps` with `args`, streaming stdout lines; null on success (test seam). */
|
|
73
|
+
export type PsRunner = (args: string[], onLine: (line: string) => void) => Promise<PsRunFailure | null>;
|
|
74
|
+
export declare const runPs: PsRunner;
|
|
75
|
+
/**
|
|
76
|
+
* macOS: one streamed `ps -E -ww … -o pid=,command=` per census. With a known
|
|
77
|
+
* scope age the environments read are only those of processes no older than
|
|
78
|
+
* the scope (plus slack): a cheap `ps -A -o pid=,etime=` listing first, then
|
|
79
|
+
* `-p` over the young pids (none → an `ok` census with no members). `etime`
|
|
80
|
+
* is elapsed time, measured by `ps` against the same wall clock at the same
|
|
81
|
+
* moment as the age, so time zones and DST cannot hide a member; a backward
|
|
82
|
+
* wall-clock step larger than the slack during the run can (a disclosed
|
|
83
|
+
* residual for marker-only members). A row whose `etime` cannot be parsed is
|
|
84
|
+
* read, and a failed listing falls back to the full census.
|
|
85
|
+
*/
|
|
86
|
+
export declare function createDarwinScopeCensusReader(deps?: {
|
|
87
|
+
ps?: PsRunner;
|
|
88
|
+
}): ScopeCensusReader;
|
|
89
|
+
export declare function mapBounded<T, R>(items: readonly T[], concurrency: number, work: (item: T) => Promise<R>): Promise<R[]>;
|
|
90
|
+
/** Linux: bounded-concurrency `/proc/<pid>/environ` reads, exact entry match. */
|
|
91
|
+
export declare function createLinuxScopeCensusReader(deps?: {
|
|
92
|
+
readTextFile?: (path: string) => Promise<string>;
|
|
93
|
+
listProc?: () => Promise<string[]>;
|
|
94
|
+
/** The owning uid of `/proc/<pid>` (null when unknown); default: fs.stat. */
|
|
95
|
+
statUid?: (pid: number) => Promise<number | null>;
|
|
96
|
+
selfUid?: number;
|
|
97
|
+
}): ScopeCensusReader;
|
|
98
|
+
/**
|
|
99
|
+
* The census reader for a platform; null where no environment census exists.
|
|
100
|
+
* Memoised per platform so concurrent default reaps share ONE coalescing
|
|
101
|
+
* scanner (the coalescer only helps when every reap uses the same instance).
|
|
102
|
+
*/
|
|
103
|
+
export declare function createScopeCensusReader(platform?: string): ScopeCensusReader | null;
|
|
104
|
+
//# sourceMappingURL=process-scope-readers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-scope-readers.d.ts","sourceRoot":"","sources":["../src/process-scope-readers.ts"],"names":[],"mappings":"AAeA,MAAM,MAAM,iBAAiB;AAC3B,yEAAyE;AACvE;IAAE,MAAM,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE;AACtE,oEAAoE;GAClE;IAAE,MAAM,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEzC,MAAM,WAAW,iBAAiB;IAChC;;;;;;;;;OASG;IACH,MAAM,CACJ,OAAO,EAAE,SAAS,MAAM,EAAE,EAC1B,aAAa,CAAC,EAAE,MAAM,EACtB,OAAO,CAAC,EAAE,MAAM,OAAO,GACtB,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAC9B;;;;OAIG;IACH,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC;CAC/D;AAOD,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAE1C,uHAAuH;AACvH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,G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