@repo-os/repoos 0.5.96 → 0.5.97
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/.build-info.json +2 -2
- package/dist/.build-stamp.json +1 -1
- package/dist/server/system.d.ts +1 -1
- package/dist/server/system.js +47 -12
- package/package.json +1 -1
package/dist/.build-info.json
CHANGED
package/dist/.build-stamp.json
CHANGED
package/dist/server/system.d.ts
CHANGED
|
@@ -215,7 +215,7 @@ export declare function parseServePort(command: string): number | null;
|
|
|
215
215
|
*
|
|
216
216
|
* Exported for testing so classification can be exercised without spawning servers.
|
|
217
217
|
*/
|
|
218
|
-
export declare function parseServeScan(output: string, serverPid: number, knownPids: Set<number>, rootExists: (root: string | null) => boolean, ownRoot?: string): ServeScan;
|
|
218
|
+
export declare function parseServeScan(output: string, serverPid: number, knownPids: Set<number>, rootExists: (root: string | null) => boolean, ownRoot?: string, actualRoots?: ReadonlyMap<number, string>, registeredPids?: ReadonlySet<number>): ServeScan;
|
|
219
219
|
/**
|
|
220
220
|
* Census live `repoos serve` processes. Cached — `ps ax` lists every process on
|
|
221
221
|
* the machine, which is much heavier than the targeted per-PID sample.
|
package/dist/server/system.js
CHANGED
|
@@ -7,13 +7,14 @@
|
|
|
7
7
|
* ppid is no longer the server's pid, is marked orphaned.
|
|
8
8
|
*/
|
|
9
9
|
import { execFile } from "node:child_process";
|
|
10
|
-
import { existsSync, readFileSync, realpathSync, statSync, writeFileSync, mkdirSync, } from "node:fs";
|
|
10
|
+
import { existsSync, readFileSync, readlinkSync, realpathSync, statSync, writeFileSync, mkdirSync, } from "node:fs";
|
|
11
11
|
import { basename, join } from "node:path";
|
|
12
12
|
import { cpus, totalmem, freemem, loadavg, platform } from "node:os";
|
|
13
13
|
import { withOrphanedRunProcesses, } from "../core/pressure-guard.js";
|
|
14
14
|
import { localCheckLockRoot } from "../core/cross-process-slots.js";
|
|
15
15
|
import { registeredEngineerCount } from "../core/global-engineers.js";
|
|
16
16
|
import { getGitWorker, gitWorkerInFlight } from "./git-worker.js";
|
|
17
|
+
import { listServerRegistryEntries } from "../core/server-registry.js";
|
|
17
18
|
const OWNERSHIP_FILE = "repoos-ownership.json";
|
|
18
19
|
const KB = 1024;
|
|
19
20
|
function safeExecFile(cmd, args) {
|
|
@@ -296,7 +297,7 @@ export function parseServePort(command) {
|
|
|
296
297
|
*
|
|
297
298
|
* Exported for testing so classification can be exercised without spawning servers.
|
|
298
299
|
*/
|
|
299
|
-
export function parseServeScan(output, serverPid, knownPids, rootExists, ownRoot) {
|
|
300
|
+
export function parseServeScan(output, serverPid, knownPids, rootExists, ownRoot, actualRoots = new Map(), registeredPids = new Set()) {
|
|
300
301
|
const rows = [];
|
|
301
302
|
const livePids = new Set();
|
|
302
303
|
for (const line of output.split("\n")) {
|
|
@@ -311,7 +312,7 @@ export function parseServeScan(output, serverPid, knownPids, rootExists, ownRoot
|
|
|
311
312
|
for (const { pid, ppid, command } of rows) {
|
|
312
313
|
if (!SERVE_CMD_RE.test(command))
|
|
313
314
|
continue;
|
|
314
|
-
const root = parseServeRoot(command);
|
|
315
|
+
const root = actualRoots.has(pid) ? actualRoots.get(pid) || null : parseServeRoot(command);
|
|
315
316
|
const rootIsLive = rootExists(root);
|
|
316
317
|
// A parent of 1 means the process was reparented after its spawner died.
|
|
317
318
|
const supervised = ppid !== 1 && livePids.has(ppid);
|
|
@@ -319,14 +320,18 @@ export function parseServeScan(output, serverPid, knownPids, rootExists, ownRoot
|
|
|
319
320
|
? "control-plane"
|
|
320
321
|
: knownPids.has(pid)
|
|
321
322
|
? "known-preview"
|
|
322
|
-
:
|
|
323
|
-
? "
|
|
324
|
-
:
|
|
325
|
-
|
|
326
|
-
//
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
323
|
+
: registeredPids.has(pid)
|
|
324
|
+
? "foreign"
|
|
325
|
+
: supervised
|
|
326
|
+
? "in-flight"
|
|
327
|
+
: // A detached serve for another repo whose root still exists is that
|
|
328
|
+
// repo's control plane (also ppid 1) — not ours to touch. Only an
|
|
329
|
+
// orphan of OUR root, or one whose root is gone, is a real stray.
|
|
330
|
+
ownRoot && root && rootIsLive && !sameRoot(root, ownRoot)
|
|
331
|
+
? "foreign"
|
|
332
|
+
: !root
|
|
333
|
+
? "foreign"
|
|
334
|
+
: "stray";
|
|
330
335
|
processes.push({
|
|
331
336
|
pid,
|
|
332
337
|
ppid,
|
|
@@ -362,7 +367,36 @@ export async function scanServeProcesses(serverPid, knownPids, ownRoot) {
|
|
|
362
367
|
const output = await safeExecFile("ps", ["ax", "-o", "pid=,ppid=,command="]);
|
|
363
368
|
if (output === null)
|
|
364
369
|
return serveScanCache?.scan ?? null;
|
|
365
|
-
const
|
|
370
|
+
const actualRoots = new Map();
|
|
371
|
+
const registeredPids = new Set();
|
|
372
|
+
for (const entry of listServerRegistryEntries()) {
|
|
373
|
+
if (entry.pid > 0)
|
|
374
|
+
registeredPids.add(entry.pid);
|
|
375
|
+
}
|
|
376
|
+
const candidates = output.split("\n").flatMap((line) => {
|
|
377
|
+
const m = line.trim().match(/^(\d+)\s+\d+\s+(.*)$/);
|
|
378
|
+
return m && SERVE_CMD_RE.test(m[2]) ? [Number(m[1])] : [];
|
|
379
|
+
});
|
|
380
|
+
// The CLI path can be shared by every linked project. Resolve each serve's
|
|
381
|
+
// cwd (the project it serves) instead; unavailable cwd remains unknown and
|
|
382
|
+
// is conservatively preserved by parseServeScan.
|
|
383
|
+
for (const pid of candidates) {
|
|
384
|
+
actualRoots.set(pid, "");
|
|
385
|
+
try {
|
|
386
|
+
const cwd = process.platform === "linux"
|
|
387
|
+
? readlinkSync(`/proc/${pid}/cwd`).replace(/ \(deleted\)$/, "")
|
|
388
|
+
: (await safeExecFile("lsof", ["-a", "-p", String(pid), "-d", "cwd", "-Fn"]))
|
|
389
|
+
?.split("\n")
|
|
390
|
+
.find((part) => part.startsWith("n"))
|
|
391
|
+
?.slice(1);
|
|
392
|
+
if (cwd)
|
|
393
|
+
actualRoots.set(pid, cwd);
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
/* best effort */
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
const scan = parseServeScan(output, serverPid, knownPids, (root) => root !== null && existsSync(root), ownRoot, actualRoots, registeredPids);
|
|
366
400
|
serveScanCache = { at: now, scan };
|
|
367
401
|
return scan;
|
|
368
402
|
}
|
|
@@ -402,6 +436,7 @@ export async function reapStrayServeProcesses(serverPid, knownPids, kill = proce
|
|
|
402
436
|
continue;
|
|
403
437
|
try {
|
|
404
438
|
kill(p.pid, "SIGTERM");
|
|
439
|
+
console.warn(`serve-reaper: stopping pid=${p.pid} port=${p.port ?? "?"} root=${p.root ?? "unknown"} reason=orphaned serve process`);
|
|
405
440
|
reaped++;
|
|
406
441
|
}
|
|
407
442
|
catch {
|