@code-yeongyu/senpi-codemode 2026.11.18 → 2026.11.19-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/CHANGELOG.md +52 -0
- package/package.json +5 -5
- package/src/extension/kernel-registration.ts +2 -0
- package/src/extension/session-manager.ts +9 -0
- package/src/kernels/jl/kernel.ts +4 -0
- package/src/kernels/js/context-manager.ts +1 -1
- package/src/kernels/js/kernel-contract.ts +3 -0
- package/src/kernels/js/process-worker.ts +4 -0
- package/src/kernels/js/worker-children.ts +14 -5
- package/src/kernels/js/worker-startup.ts +1 -0
- package/src/kernels/py/kernel-contract.ts +3 -0
- package/src/kernels/py/transport.ts +4 -0
- package/src/kernels/rb/kernel.ts +4 -0
- package/src/kernels/shared/session-spawn-attestation.ts +21 -0
- package/src/kernels/shared/subprocess-contract.ts +3 -0
- package/src/kernels/shared/subprocess-kernel.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [2026.11.19-2] - 2026-11-19
|
|
4
|
+
|
|
5
|
+
### Breaking Changes
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
### Removed
|
|
14
|
+
|
|
15
|
+
## [2026.11.19] - 2026-11-19
|
|
16
|
+
|
|
17
|
+
### Breaking Changes
|
|
18
|
+
|
|
19
|
+
### Added
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
### Removed
|
|
26
|
+
|
|
27
|
+
## [2026.11.18-3] - 2026-11-18
|
|
28
|
+
|
|
29
|
+
### Breaking Changes
|
|
30
|
+
|
|
31
|
+
### Added
|
|
32
|
+
|
|
33
|
+
### Changed
|
|
34
|
+
|
|
35
|
+
### Fixed
|
|
36
|
+
|
|
37
|
+
### Removed
|
|
38
|
+
|
|
39
|
+
## [2026.11.18-2] - 2026-11-18
|
|
40
|
+
|
|
41
|
+
### Breaking Changes
|
|
42
|
+
|
|
43
|
+
### Added
|
|
44
|
+
|
|
45
|
+
- Eval kernels attest the processes they run for a session: a python, ruby or julia kernel, or a process-isolated JavaScript kernel, is recorded for its session, so every command it starts (a `Bun.$` command included) resolves to that session; a worker-thread JavaScript kernel attests the `Bun.spawn` children it reports. A `Bun.$` command of a worker-thread kernel is not attested ([#6978](https://github.com/code-yeongyu/senpi/pull/6978))
|
|
46
|
+
|
|
47
|
+
### Changed
|
|
48
|
+
|
|
49
|
+
### Fixed
|
|
50
|
+
|
|
51
|
+
- Eval kernel modules no longer load the senpi host package: the extension hands each kernel the session-bound spawn attestation, so a kernel module loads on its own again (a process-isolated JavaScript kernel resolving its runtime under plain Node, the compiled python host on Windows) ([#6996](https://github.com/code-yeongyu/senpi/pull/6996))
|
|
52
|
+
|
|
53
|
+
### Removed
|
|
54
|
+
|
|
3
55
|
## [2026.11.18] - 2026-11-18
|
|
4
56
|
|
|
5
57
|
### Breaking Changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@code-yeongyu/senpi-codemode",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.19-2",
|
|
4
4
|
"description": "Source-only senpi extension package for codemode evaluation tools",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.ts",
|
|
@@ -33,16 +33,16 @@
|
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@babel/parser": "8.0.4",
|
|
36
|
-
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.
|
|
37
|
-
"@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.
|
|
36
|
+
"@earendil-works/pi-ai": "npm:@code-yeongyu/senpi-ai@2026.11.19-2",
|
|
37
|
+
"@earendil-works/pi-realm-registry": "npm:@code-yeongyu/senpi-realm-registry@2026.11.19-2",
|
|
38
38
|
"quickjs-wasi": "3.6.2",
|
|
39
39
|
"typebox": "1.3.34"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@code-yeongyu/senpi": "2026.11.
|
|
42
|
+
"@code-yeongyu/senpi": "2026.11.19-2"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@code-yeongyu/senpi": "2026.11.
|
|
45
|
+
"@code-yeongyu/senpi": "2026.11.19-2"
|
|
46
46
|
},
|
|
47
47
|
"keywords": [
|
|
48
48
|
"senpi",
|
|
@@ -8,6 +8,7 @@ import type { PeerKernelToolsDescribe } from "../kernels/py/kernel-tools-host.ts
|
|
|
8
8
|
import { defaultSpawn } from "../kernels/py/process.ts";
|
|
9
9
|
import { RubyKernel } from "../kernels/rb/kernel.ts";
|
|
10
10
|
import type { SessionEnvironment } from "../kernels/session-env.ts";
|
|
11
|
+
import type { AttestKernelSpawn } from "../kernels/shared/session-spawn-attestation.ts";
|
|
11
12
|
import { spawnSubprocess } from "../kernels/shared/subprocess-process.ts";
|
|
12
13
|
import type { EvalKernel, EvalLanguage } from "../tool/types.ts";
|
|
13
14
|
import { type KernelMemoryReading, kernelRegistry, type RegisteredKernelSource } from "./kernel-registry.ts";
|
|
@@ -25,6 +26,7 @@ export interface SubprocessKernelStart {
|
|
|
25
26
|
readonly sessionId: string;
|
|
26
27
|
readonly cwd: string;
|
|
27
28
|
readonly sessionEnv?: SessionEnvironment;
|
|
29
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
28
30
|
readonly connection: BridgeConnectionConfig;
|
|
29
31
|
readonly onMessage: (message: KernelToHostMessage) => void;
|
|
30
32
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { join } from "node:path";
|
|
2
2
|
import type { ExtensionContext } from "@code-yeongyu/senpi";
|
|
3
3
|
import {
|
|
4
|
+
attestSessionSpawn,
|
|
4
5
|
decideKillGuardRequest,
|
|
5
6
|
KILL_GUARD_MODULE_URL,
|
|
6
7
|
killGuardProtectedPids,
|
|
@@ -290,6 +291,12 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
|
|
|
290
291
|
const localRoots =
|
|
291
292
|
this.#options.localRoots ??
|
|
292
293
|
(this.#options.artifactsDir ? { local: join(this.#options.artifactsDir, "local") } : undefined);
|
|
294
|
+
// senpi#6972: the kernels attest their processes to the session id the host gave them, never one a cell sets.
|
|
295
|
+
const attestedSessionId = this.#options.sessionEnv?.PI_SESSION_ID;
|
|
296
|
+
const attestation =
|
|
297
|
+
attestedSessionId === undefined
|
|
298
|
+
? {}
|
|
299
|
+
: { attestSpawn: (pid: number) => attestSessionSpawn(attestedSessionId, pid) };
|
|
293
300
|
if (language === "js") {
|
|
294
301
|
const memoryThresholds = resolveKernelMemoryThresholds(this.#options.settings.memory);
|
|
295
302
|
const processIsolation = resolveJsIsolation(this.#options.settings) === "process";
|
|
@@ -302,6 +309,7 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
|
|
|
302
309
|
foreignLanguageNames: () => this.#foreignKernelToolNames(),
|
|
303
310
|
memory: memoryThresholds,
|
|
304
311
|
collectOrphanedChildren,
|
|
312
|
+
...attestation,
|
|
305
313
|
...(processIsolation ? { isolation: "process" as const } : {}),
|
|
306
314
|
...(processIsolation && memoryThresholds !== undefined
|
|
307
315
|
? { processMemory: { thresholds: memoryThresholds, readFootprint: readProcessFootprint } }
|
|
@@ -333,6 +341,7 @@ class DefaultCodemodeSessionManager implements CodemodeSessionManager {
|
|
|
333
341
|
sessionId: this.#options.sessionId,
|
|
334
342
|
cwd: this.#options.cwd,
|
|
335
343
|
...(sessionEnv ? { sessionEnv } : {}),
|
|
344
|
+
...attestation,
|
|
336
345
|
...(this.#options.killGuard === true ? { killGuard: { protectedPids: killGuardProtectedPids() } } : {}),
|
|
337
346
|
connection,
|
|
338
347
|
onMessage,
|
package/src/kernels/jl/kernel.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { BridgeConnectionConfig, KernelToHostMessage } from "../../bridge/p
|
|
|
3
3
|
import type { SessionEnvironment } from "../session-env.ts";
|
|
4
4
|
import type { KernelLifecycle } from "../shared/kernel-death.ts";
|
|
5
5
|
import type { InvocationPermissions } from "../shared/invocation-authority.ts";
|
|
6
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
6
7
|
import { readProcessGroupCpuTime } from "../shared/process-group-cpu.ts";
|
|
7
8
|
import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
|
|
8
9
|
import { SubprocessKernel, type SubprocessKernelMemory, type SubprocessSpawn } from "../shared/subprocess-kernel.ts";
|
|
@@ -14,6 +15,8 @@ export interface JuliaKernelStartOptions extends KernelLifecycle {
|
|
|
14
15
|
readonly connection: BridgeConnectionConfig;
|
|
15
16
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
16
17
|
readonly sessionEnv?: SessionEnvironment;
|
|
18
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
19
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
17
20
|
readonly command?: string;
|
|
18
21
|
readonly spawn?: SubprocessSpawn;
|
|
19
22
|
readonly onMessage?: (message: KernelToHostMessage) => void;
|
|
@@ -52,6 +55,7 @@ export class JuliaKernel extends SubprocessKernel {
|
|
|
52
55
|
cwd: options.cwd,
|
|
53
56
|
sessionId: options.sessionId,
|
|
54
57
|
sessionEnv: options.sessionEnv,
|
|
58
|
+
...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
|
|
55
59
|
connection: options.connection,
|
|
56
60
|
spawn: options.spawn,
|
|
57
61
|
onMessage: options.onMessage,
|
|
@@ -86,7 +86,7 @@ export class JavaScriptKernel {
|
|
|
86
86
|
clearToolCalls: () => this.#toolCalls.clear(),
|
|
87
87
|
});
|
|
88
88
|
this.#memory = new JavaScriptKernelMemory(options, () => this.#slot.processPid);
|
|
89
|
-
this.#children = new WorkerChildren(options.collectOrphanedChildren);
|
|
89
|
+
this.#children = new WorkerChildren(options.collectOrphanedChildren, options.attestSpawn);
|
|
90
90
|
this.#moduleLoader = new LocalModuleLoader(options);
|
|
91
91
|
this.#slot = new WorkerSlot(
|
|
92
92
|
options,
|
|
@@ -3,6 +3,7 @@ import type { KernelToHostMessage } from "../../bridge/protocol.ts";
|
|
|
3
3
|
import type { EvalKernelRunInput } from "../../tool/types.ts";
|
|
4
4
|
import type { SessionEnvironment } from "../session-env.ts";
|
|
5
5
|
import type { InvocationPermissions } from "../shared/invocation-authority.ts";
|
|
6
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
6
7
|
import type { JavaScriptInterruptBounds } from "./interrupt-bounds.ts";
|
|
7
8
|
import type { CellDecision, CellOperation, CellRule } from "./permission-slots.mjs";
|
|
8
9
|
|
|
@@ -56,6 +57,8 @@ export interface JavaScriptKernelOptions {
|
|
|
56
57
|
* wait on them. Absent, they stay zombies until the host's child reaper or process exit collects them.
|
|
57
58
|
*/
|
|
58
59
|
readonly collectOrphanedChildren?: (pids: readonly number[]) => Promise<unknown>;
|
|
60
|
+
/** Attests the kernel process and each child it reports to the session (senpi#6972); absent, none is recorded. */
|
|
61
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
59
62
|
readonly parallelPoolWidth: number;
|
|
60
63
|
readonly onMessage?: (message: KernelToHostMessage) => void;
|
|
61
64
|
readonly workerEntryUrl?: URL;
|
|
@@ -7,6 +7,7 @@ import type { KernelToHostMessage } from "../../bridge/protocol.ts";
|
|
|
7
7
|
import { isKernelToHostMessage, parseBridgeJsonLine, validateBridgeMessage } from "../../bridge/protocol.ts";
|
|
8
8
|
import type { EvalRuntimeInfo } from "../../tool/types.ts";
|
|
9
9
|
import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
|
|
10
|
+
import { type AttestKernelSpawn, attestKernelChild } from "../shared/session-spawn-attestation.ts";
|
|
10
11
|
import { type SubprocessLike, SubprocessProcess, spawnSubprocess } from "../shared/subprocess-process.ts";
|
|
11
12
|
import type { WorkerLike } from "./inline-worker.ts";
|
|
12
13
|
import { runtimeNameOf } from "./runtime-name.ts";
|
|
@@ -45,6 +46,8 @@ export interface JavaScriptProcessWorkerOptions {
|
|
|
45
46
|
readonly searchPath?: string;
|
|
46
47
|
readonly execPath?: string;
|
|
47
48
|
readonly env?: NodeJS.ProcessEnv;
|
|
49
|
+
/** Attests the kernel process to the session it runs for (senpi#6972). */
|
|
50
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
48
51
|
readonly spawn?: (
|
|
49
52
|
command: string,
|
|
50
53
|
args: readonly string[],
|
|
@@ -132,6 +135,7 @@ export function spawnProcessWorker(url: URL, options: JavaScriptProcessWorkerOpt
|
|
|
132
135
|
options.spawn === undefined
|
|
133
136
|
? spawnSubprocess(undefined, { command, args, cwd: options.cwd, env })
|
|
134
137
|
: options.spawn(command, args, { cwd: options.cwd, env });
|
|
138
|
+
attestKernelChild(options.attestSpawn, child);
|
|
135
139
|
const messageHandlers = new Set<(message: KernelToHostMessage) => void>();
|
|
136
140
|
const errorHandlers = new Set<(error: Error) => void>();
|
|
137
141
|
const frameToken = randomBytes(16).toString("hex");
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { EvalStatusEvent } from "../../bridge/protocol.ts";
|
|
2
|
+
import type { SessionSpawnAttestation } from "@code-yeongyu/senpi";
|
|
3
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
2
4
|
import { terminateProcessTrees } from "./process-tree-host.ts";
|
|
3
5
|
|
|
4
6
|
/** How long a lost worker's children get to honour SIGTERM before the host sends SIGKILL. */
|
|
@@ -6,18 +8,24 @@ const WORKER_LOSS_CHILD_GRACE_MS = 1_000;
|
|
|
6
8
|
|
|
7
9
|
/** Live cell children the worker reported; retired by the host when the worker itself is lost. */
|
|
8
10
|
export class WorkerChildren {
|
|
9
|
-
readonly #pids = new
|
|
11
|
+
readonly #pids = new Map<number, SessionSpawnAttestation | undefined>();
|
|
10
12
|
readonly #collectOrphanedChildren: ((pids: readonly number[]) => Promise<unknown>) | undefined;
|
|
13
|
+
readonly #attest: AttestKernelSpawn | undefined;
|
|
11
14
|
|
|
12
|
-
constructor(collectOrphanedChildren?: (pids: readonly number[]) => Promise<unknown
|
|
15
|
+
constructor(collectOrphanedChildren?: (pids: readonly number[]) => Promise<unknown>, attest?: AttestKernelSpawn) {
|
|
13
16
|
this.#collectOrphanedChildren = collectOrphanedChildren;
|
|
17
|
+
this.#attest = attest;
|
|
14
18
|
}
|
|
15
19
|
|
|
16
20
|
track(event: EvalStatusEvent): void {
|
|
17
21
|
const pid = event.pid;
|
|
18
22
|
if (typeof pid !== "number" || !Number.isInteger(pid) || pid <= 0) return;
|
|
19
|
-
if (event.state === "spawned")
|
|
20
|
-
|
|
23
|
+
if (event.state === "spawned") {
|
|
24
|
+
if (!this.#pids.has(pid)) this.#pids.set(pid, this.#attest?.(pid));
|
|
25
|
+
} else if (event.state === "exited") {
|
|
26
|
+
void this.#pids.get(pid)?.release();
|
|
27
|
+
this.#pids.delete(pid);
|
|
28
|
+
}
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
/**
|
|
@@ -26,7 +34,8 @@ export class WorkerChildren {
|
|
|
26
34
|
*/
|
|
27
35
|
async retire(): Promise<void> {
|
|
28
36
|
if (this.#pids.size === 0) return;
|
|
29
|
-
const pids = [...this.#pids];
|
|
37
|
+
const pids = [...this.#pids.keys()];
|
|
38
|
+
for (const attestation of this.#pids.values()) void attestation?.release();
|
|
30
39
|
this.#pids.clear();
|
|
31
40
|
await terminateProcessTrees(pids, { graceMs: WORKER_LOSS_CHILD_GRACE_MS, ownerPid: process.pid });
|
|
32
41
|
// The worker that owned these children and their exit watchers is gone, so nothing else will wait on them.
|
|
@@ -78,6 +78,7 @@ function spawnWorker(options: JavaScriptKernelOptions, permissions?: KernelPermi
|
|
|
78
78
|
return spawnProcessWorker(url, {
|
|
79
79
|
cwd: options.cwd,
|
|
80
80
|
parallelPoolWidth: options.parallelPoolWidth,
|
|
81
|
+
...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
|
|
81
82
|
...(options.processCommandPath === undefined ? {} : { searchPath: options.processCommandPath }),
|
|
82
83
|
...(options.processExecPath === undefined ? {} : { execPath: options.processExecPath }),
|
|
83
84
|
});
|
|
@@ -4,6 +4,7 @@ import type { EvalKernelRunInput } from "../../tool/types.ts";
|
|
|
4
4
|
import type { SessionEnvironment } from "../session-env.ts";
|
|
5
5
|
import type { KernelLifecycle } from "../shared/kernel-death.ts";
|
|
6
6
|
import type { InvocationPermissions } from "../shared/invocation-authority.ts";
|
|
7
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
7
8
|
import type { CellDecider, RevocationFailedEvent } from "../js/kernel-contract.ts";
|
|
8
9
|
import type { PeerKernelToolsDescribe } from "./kernel-tools-host.ts";
|
|
9
10
|
import type { KernelSpawnProcess, KillProcessGroup } from "./process.ts";
|
|
@@ -20,6 +21,8 @@ export interface PythonKernelStartOptions extends KernelLifecycle {
|
|
|
20
21
|
readonly env?: NodeJS.ProcessEnv;
|
|
21
22
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
22
23
|
readonly sessionEnv?: SessionEnvironment;
|
|
24
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
25
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
23
26
|
/** The kill guard (senpi#5349): the host's protected pids; absent = the guard is off for this kernel. */
|
|
24
27
|
readonly killGuard?: { readonly protectedPids: readonly number[] };
|
|
25
28
|
/** How long a starting interpreter may show no stage change, output or CPU use before startup fails. */
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
} from "../../bridge/protocol.ts";
|
|
12
12
|
import { applySessionEnvironment, type SessionEnvironment } from "../session-env.ts";
|
|
13
13
|
import type { KernelPreludePlan } from "../shared/kernel-prelude-plan.ts";
|
|
14
|
+
import { type AttestKernelSpawn, attestKernelChild } from "../shared/session-spawn-attestation.ts";
|
|
14
15
|
import { readKernelCpuTime } from "../shared/process-cpu.ts";
|
|
15
16
|
import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
|
|
16
17
|
import {
|
|
@@ -50,6 +51,8 @@ export interface PythonTransportOptions {
|
|
|
50
51
|
readonly env?: NodeJS.ProcessEnv;
|
|
51
52
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
52
53
|
readonly sessionEnv?: SessionEnvironment;
|
|
54
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
55
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
53
56
|
/** The kill guard (senpi#5349): the host's protected pids; absent = the guard is off for this kernel. */
|
|
54
57
|
readonly killGuard?: { readonly protectedPids: readonly number[] };
|
|
55
58
|
readonly startupTimeoutMs: number;
|
|
@@ -141,6 +144,7 @@ export class PythonKernelTransport {
|
|
|
141
144
|
},
|
|
142
145
|
};
|
|
143
146
|
const child = (options.spawnProcess ?? defaultSpawn)(spawnOptions);
|
|
147
|
+
attestKernelChild(options.attestSpawn, child);
|
|
144
148
|
const transport = new PythonKernelTransport(options, child);
|
|
145
149
|
try {
|
|
146
150
|
await transport.#initialize();
|
package/src/kernels/rb/kernel.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { BridgeConnectionConfig, KernelToHostMessage } from "../../bridge/p
|
|
|
3
3
|
import type { SessionEnvironment } from "../session-env.ts";
|
|
4
4
|
import type { KernelLifecycle } from "../shared/kernel-death.ts";
|
|
5
5
|
import type { InvocationPermissions } from "../shared/invocation-authority.ts";
|
|
6
|
+
import type { AttestKernelSpawn } from "../shared/session-spawn-attestation.ts";
|
|
6
7
|
import { readProcessGroupCpuTime } from "../shared/process-group-cpu.ts";
|
|
7
8
|
import { type CodemodeRuntimeAssetEnvironment, requireCodemodeRuntimeAsset } from "../shared/runtime-asset.ts";
|
|
8
9
|
import { SubprocessKernel, type SubprocessKernelMemory, type SubprocessSpawn } from "../shared/subprocess-kernel.ts";
|
|
@@ -14,6 +15,8 @@ export interface RubyKernelStartOptions extends KernelLifecycle {
|
|
|
14
15
|
readonly connection: BridgeConnectionConfig;
|
|
15
16
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
16
17
|
readonly sessionEnv?: SessionEnvironment;
|
|
18
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
19
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
17
20
|
readonly command?: string;
|
|
18
21
|
readonly spawn?: SubprocessSpawn;
|
|
19
22
|
readonly onMessage?: (message: KernelToHostMessage) => void;
|
|
@@ -41,6 +44,7 @@ export class RubyKernel extends SubprocessKernel {
|
|
|
41
44
|
cwd: options.cwd,
|
|
42
45
|
sessionId: options.sessionId,
|
|
43
46
|
sessionEnv: options.sessionEnv,
|
|
47
|
+
...(options.attestSpawn === undefined ? {} : { attestSpawn: options.attestSpawn }),
|
|
44
48
|
connection: options.connection,
|
|
45
49
|
spawn: options.spawn,
|
|
46
50
|
onMessage: options.onMessage,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { SessionSpawnAttestation } from "@code-yeongyu/senpi";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attests a process this host spawned for a kernel to the session it runs for (senpi#6972): a kernel process, so every
|
|
5
|
+
* descendant (a `Bun.$` command, a python subprocess) resolves to that session, or a child the worker kernel reported.
|
|
6
|
+
*
|
|
7
|
+
* The extension injects it, bound to the session's own id, as it injects `collectOrphanedChildren`: a kernel module
|
|
8
|
+
* never loads the host runtime itself, so it stays loadable on its own (plain Node ESM, a compiled python host).
|
|
9
|
+
* Absent, nothing is recorded.
|
|
10
|
+
*/
|
|
11
|
+
export type AttestKernelSpawn = (pid: number) => SessionSpawnAttestation;
|
|
12
|
+
|
|
13
|
+
/** Attests a spawned kernel child through `attest` and releases the record when the child exits. */
|
|
14
|
+
export function attestKernelChild(
|
|
15
|
+
attest: AttestKernelSpawn | undefined,
|
|
16
|
+
child: { readonly pid?: number; once(event: "exit", listener: () => void): unknown },
|
|
17
|
+
): void {
|
|
18
|
+
if (attest === undefined || child.pid === undefined) return;
|
|
19
|
+
const attestation = attest(child.pid);
|
|
20
|
+
child.once("exit", () => void attestation.release());
|
|
21
|
+
}
|
|
@@ -7,6 +7,7 @@ import type { FootprintReader } from "./kernel-memory-host.ts";
|
|
|
7
7
|
import type { SubprocessSpawn } from "./subprocess-process.ts";
|
|
8
8
|
import type { SubprocessStartupOptions } from "./subprocess-startup.ts";
|
|
9
9
|
import type { InvocationPermissions } from "./invocation-authority.ts";
|
|
10
|
+
import type { AttestKernelSpawn } from "./session-spawn-attestation.ts";
|
|
10
11
|
|
|
11
12
|
export type KernelRunInput = EvalKernelRunInput;
|
|
12
13
|
|
|
@@ -27,6 +28,8 @@ export interface SubprocessKernelOptions extends KernelLifecycle {
|
|
|
27
28
|
readonly env?: NodeJS.ProcessEnv;
|
|
28
29
|
/** Per-session PI_* values merged into the interpreter environment at spawn. */
|
|
29
30
|
readonly sessionEnv?: SessionEnvironment;
|
|
31
|
+
/** Attests the interpreter process to the session it runs for (senpi#6972). */
|
|
32
|
+
readonly attestSpawn?: AttestKernelSpawn;
|
|
30
33
|
readonly sessionId: string;
|
|
31
34
|
readonly connection: BridgeConnectionConfig;
|
|
32
35
|
readonly spawn?: SubprocessSpawn;
|
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
settlePendingRun,
|
|
26
26
|
timeoutResult,
|
|
27
27
|
} from "./subprocess-run.ts";
|
|
28
|
+
import { attestKernelChild } from "./session-spawn-attestation.ts";
|
|
28
29
|
import { SubprocessStartupWatchdog } from "./subprocess-startup.ts";
|
|
29
30
|
|
|
30
31
|
export type {
|
|
@@ -228,6 +229,7 @@ export class SubprocessKernel {
|
|
|
228
229
|
? applySessionEnvironment(globalThis.process.env, this.options.sessionEnv)
|
|
229
230
|
: undefined),
|
|
230
231
|
});
|
|
232
|
+
attestKernelChild(this.options.attestSpawn, child);
|
|
231
233
|
const process = new SubprocessProcess(child, {
|
|
232
234
|
onLine: (source, line) => this.handleLine(source, line),
|
|
233
235
|
onStderr: (source, data) => this.handleMessage(source, { type: "text", stream: "stderr", data }),
|